Compare commits
3 Commits
deps
...
0.9.2-alph
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3be144f644 | ||
|
|
2560dc23fc | ||
|
|
3d6c3d10bf |
2
fx.go
2
fx.go
@@ -17,7 +17,7 @@ import (
|
||||
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
|
||||
)
|
||||
|
||||
const version = "0.9.1"
|
||||
const version = "0.9.2"
|
||||
|
||||
func init() {
|
||||
go checkForUpdate()
|
||||
|
||||
2
go.mod
2
go.mod
@@ -15,7 +15,7 @@ require (
|
||||
github.com/gin-gonic/gin v1.4.0
|
||||
github.com/gobuffalo/envy v1.8.1 // indirect
|
||||
github.com/gobuffalo/packr v1.30.1
|
||||
github.com/golang/mock v1.4.0
|
||||
github.com/golang/mock v1.4.1
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
github.com/google/go-querystring v1.0.0
|
||||
github.com/google/uuid v1.1.1
|
||||
|
||||
2
go.sum
2
go.sum
@@ -117,6 +117,8 @@ github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s=
|
||||
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
|
||||
github.com/golang/mock v1.4.0 h1:Rd1kQnQu0Hq3qvJppYSG0HtP+f5LPPUiDswTLiEegLg=
|
||||
github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
||||
github.com/golang/mock v1.4.1 h1:ocYkMQY5RrXTYgXl7ICpV0IXwlEQGwKIsery4gyXa1U=
|
||||
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
||||
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"master": "52.78.196.250",
|
||||
"agents": [
|
||||
"13.125.243.192",
|
||||
],
|
||||
@@ -1,53 +0,0 @@
|
||||
package packer
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// JavaScriptExt extension of JavaScript source file
|
||||
const JavaScriptExt = ".js"
|
||||
|
||||
func depsJavaScript(src string) ([]string, error) {
|
||||
deps := []string{}
|
||||
file, err := os.Open(src)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
if strings.HasPrefix(line, "import") || strings.HasPrefix(line, "require") {
|
||||
reg, err := regexp.Compile(`(\'.*\'|\".*\")`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
str := reg.FindString(line)
|
||||
if str != "" {
|
||||
deps = append(deps, strings.ReplaceAll(strings.ReplaceAll(str, "\"", ""), "'", ""))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return deps, nil
|
||||
}
|
||||
|
||||
// Deps to get the dependencies required from a source code in a file
|
||||
func Deps(src string) ([]string, error) {
|
||||
switch filepath.Ext(src) {
|
||||
case JavaScriptExt:
|
||||
{
|
||||
return depsJavaScript(src)
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("not support language: %s", filepath.Ext(src))
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package packer
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDeps(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
content string
|
||||
expect []string
|
||||
}{
|
||||
{name: "import with singe quote", content: "import 'pkg1'", expect: []string{"pkg1"}},
|
||||
{name: "import with double quote", content: `import "pkg1"`, expect: []string{"pkg1"}},
|
||||
{name: "require with singe quote", content: "require 'pkg1'", expect: []string{"pkg1"}},
|
||||
{name: "require with double quote", content: `require "pkg1"`, expect: []string{"pkg1"}},
|
||||
{
|
||||
name: "require and import with singe quote",
|
||||
content: `
|
||||
require 'pkg1'
|
||||
import 'pkg2'`,
|
||||
expect: []string{"pkg1", "pkg2"},
|
||||
},
|
||||
{
|
||||
name: "require and import with double quote",
|
||||
content: `
|
||||
require "pkg1"
|
||||
import "pkg2"`,
|
||||
expect: []string{"pkg1", "pkg2"},
|
||||
},
|
||||
{
|
||||
name: "require and import with double quote and single quote",
|
||||
content: `
|
||||
require 'pkg1'
|
||||
import "pkg2"`,
|
||||
expect: []string{"pkg1", "pkg2"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
fd, err := ioutil.TempFile("", "dep_pkg_*.js")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(fd.Name())
|
||||
|
||||
err = ioutil.WriteFile(fd.Name(), []byte(c.content), 0666)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
deps, err := Deps(fd.Name())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(deps, c.expect) {
|
||||
t.Fatalf("%s: should get %s but got %s", c.name, c.expect, deps)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,9 +149,21 @@ func merge(dest string, input ...string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := copy.Copy(file, dest); err != nil {
|
||||
stat, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if stat.Mode().IsRegular() {
|
||||
destDir := filepath.Join(dest, filepath.Dir(path))
|
||||
if err := utils.EnsureDir(destDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := copy.Copy(file, destDir); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user