diff --git a/cmd/jb/install_test.go b/cmd/jb/install_test.go index 4ef2918..3c06d64 100644 --- a/cmd/jb/install_test.go +++ b/cmd/jb/install_test.go @@ -40,26 +40,28 @@ func TestInstallCommand(t *testing.T) { ExpectedJsonnetFile: []byte(`{"dependencies":null}`), ExpectedJsonnetLockFile: []byte(`{"dependencies":null}`), }, { - Name: "OneURL", - URLs: []*url.URL{ - { - Scheme: "https", - Host: "github.com", - Path: "jsonnet-bundler/jsonnet-bundler@v0.1.0", - }, - }, + Name: "OneURL", + URLs: []string{"github.com/jsonnet-bundler/jsonnet-bundler@v0.1.0"}, ExpectedCode: 0, ExpectedJsonnetFile: []byte(`{"dependencies": [{"name": "jsonnet-bundler", "source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "v0.1.0"}]}`), ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"name": "jsonnet-bundler", "source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "080f157c7fb85ad0281ea78f6c641eaa570a582f"}]}`), + }, { + Name: "Relative", + URLs: []string{"test/jsonnet/foobar"}, + ExpectedCode: 0, + ExpectedJsonnetFile: []byte(`{"dependencies":null}`), + ExpectedJsonnetLockFile: []byte(`{"dependencies":null}`), }, } for _, tc := range testcases { - t.Run(tc.Name, func(t *testing.T) { + _ = t.Run(tc.Name, func(t *testing.T) { tempDir, err := ioutil.TempDir("", "jb-install") assert.NoError(t, err) + err = os.MkdirAll(filepath.Join(tempDir, "test/jsonnet/foobar"), os.ModePerm) + assert.NoError(t, err) defer os.Remove(tempDir) - defer os.RemoveAll("vendor") // delete test vendor folder + defer os.RemoveAll("vendor") // cloning jsonnet-bundler will create this folder jsonnetFile := filepath.Join(tempDir, jsonnetfile.File) jsonnetLockFile := filepath.Join(tempDir, jsonnetfile.LockFile) diff --git a/cmd/jb/main.go b/cmd/jb/main.go index 74f727d..f7137f1 100644 --- a/cmd/jb/main.go +++ b/cmd/jb/main.go @@ -226,8 +226,6 @@ func parseLocalDependency(p string) *spec.Dependency { info, err := os.Stat(clean) if err != nil { - wd, _ := os.Getwd() - fmt.Println(err, wd) return nil } @@ -238,11 +236,10 @@ func parseLocalDependency(p string) *spec.Dependency { return &spec.Dependency{ Name: info.Name(), Source: spec.Source{ - GitSource: &spec.GitSource{ - Remote: ".", - Subdir: clean, + LocalSource: &spec.LocalSource{ + Directory: clean, }, }, - Version: ".", + Version: "", } } diff --git a/cmd/jb/main_test.go b/cmd/jb/main_test.go index ee85eac..594264f 100644 --- a/cmd/jb/main_test.go +++ b/cmd/jb/main_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestParseDepedency(t *testing.T) { +func TestParseDependency(t *testing.T) { const testFolder = "test/jsonnet/foobar" err := os.MkdirAll(testFolder, os.ModePerm) if err != nil { @@ -79,12 +79,11 @@ func TestParseDepedency(t *testing.T) { want: &spec.Dependency{ Name: "foobar", Source: spec.Source{ - GitSource: &spec.GitSource{ - Remote: ".", - Subdir: "test/jsonnet/foobar", + LocalSource: &spec.LocalSource{ + Directory: "test/jsonnet/foobar", }, }, - Version: ".", + Version: "", }, }, } diff --git a/pkg/local.go b/pkg/local.go new file mode 100644 index 0000000..d3aedbc --- /dev/null +++ b/pkg/local.go @@ -0,0 +1,42 @@ +// Copyright 2018 jsonnet-bundler authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package pkg + +import ( + "context" + "fmt" + + "github.com/jsonnet-bundler/jsonnet-bundler/spec" +) + +type LocalPackage struct { + Source *spec.LocalSource +} + +func NewLocalPackage(source *spec.LocalSource) Interface { + return &LocalPackage{ + Source: source, + } +} + +func (p *LocalPackage) Install(ctx context.Context, dir, version string) (lockVersion string, err error) { + fmt.Println("SYMLINK THIS SHIT, HAHA") + + // TODO: Where do I get the name of the package? + + fmt.Println(ctx, dir, version) + + return "", nil +} diff --git a/pkg/packages.go b/pkg/packages.go index d5afaa7..3c7a70a 100644 --- a/pkg/packages.go +++ b/pkg/packages.go @@ -54,6 +54,9 @@ func Install(ctx context.Context, isLock bool, dependencySourceIdentifier string p = NewGitPackage(dep.Source.GitSource) subdir = dep.Source.GitSource.Subdir } + if dep.Source.LocalSource != nil { + p = NewLocalPackage(dep.Source.LocalSource) + } lockVersion, err := p.Install(ctx, tmpDir, dep.Version) if err != nil { @@ -100,7 +103,7 @@ func Install(ctx context.Context, isLock bool, dependencySourceIdentifier string return nil, err } depsDeps, err := LoadJsonnetfile(filepath) - // It is ok for depedencies not to have a JsonnetFile, it just means + // It is ok for dependencies not to have a JsonnetFile, it just means // they do not have transitive dependencies of their own. if err != nil && !os.IsNotExist(err) { return nil, err diff --git a/spec/spec.go b/spec/spec.go index 657571e..0eafee9 100644 --- a/spec/spec.go +++ b/spec/spec.go @@ -26,10 +26,15 @@ type Dependency struct { } type Source struct { - GitSource *GitSource `json:"git"` + GitSource *GitSource `json:"git,omitempty"` + LocalSource *LocalSource `json:"local,omitempty"` } type GitSource struct { Remote string `json:"remote"` Subdir string `json:"subdir"` } + +type LocalSource struct { + Directory string `json:"directory"` +}