diff --git a/cmd/autoupdate/npm.go b/cmd/autoupdate/npm.go index 92499fa1..59c1f31e 100644 --- a/cmd/autoupdate/npm.go +++ b/cmd/autoupdate/npm.go @@ -3,8 +3,6 @@ package main import ( "context" "fmt" - "io/ioutil" - "net/http" "os" "path" "sort" @@ -92,7 +90,7 @@ func doUpdateNpm(ctx context.Context, pckg *packages.Package, versions []npm.Npm util.Check(os.MkdirAll(pckgpath, os.ModePerm)) - tarballDir := downloadTar(ctx, version.Tarball) + tarballDir := npm.DownloadTar(ctx, version.Tarball) filesToCopy := pckg.NpmFilesFrom(tarballDir) if len(filesToCopy) > 0 { @@ -149,19 +147,3 @@ func npmVersionDiff(a []npm.NpmVersion, b []string) []npm.NpmVersion { return diff } - -// Extract the tarball url in a temporary location -func downloadTar(ctx context.Context, url string) string { - dest, err := ioutil.TempDir("", "npmtarball") - util.Check(err) - - util.Debugf(ctx, "download %s in %s", url, dest) - - resp, err := http.Get(url) - util.Check(err) - - defer resp.Body.Close() - - util.Check(npm.Untar(dest, resp.Body)) - return dest -} diff --git a/cmd/checker/main.go b/cmd/checker/main.go index d53b9ed0..69269f70 100644 --- a/cmd/checker/main.go +++ b/cmd/checker/main.go @@ -47,7 +47,29 @@ func main() { func showFiles(path string) { ctx := util.ContextWithName(path) - err(ctx, "not implemented yet") + pckg, readerr := packages.ReadPackageJSON(ctx, path) + if readerr != nil { + err(ctx, readerr.Error()) + return + } + + npmVersions := npm.GetVersions(pckg.Autoupdate.Target) + if len(npmVersions) == 0 { + err(ctx, "no version found on npm") + return + } + lastNpmVersion := npmVersions[len(npmVersions)-1] + util.Printf(ctx, "%s:\n", lastNpmVersion) + + tarballDir := npm.DownloadTar(ctx, lastNpmVersion.Tarball) + filesToCopy := pckg.NpmFilesFrom(tarballDir) + + if len(filesToCopy) == 0 { + err(ctx, "no files to copy") + return + } + + util.Printf(ctx, "%s\n", filesToCopy) } func lintPackage(path string) { diff --git a/npm/tar.go b/npm/tar.go index 90c0c9cc..1bf27847 100644 --- a/npm/tar.go +++ b/npm/tar.go @@ -3,10 +3,15 @@ package npm import ( "archive/tar" "compress/gzip" + "context" "io" + "io/ioutil" + "net/http" "os" "path" "path/filepath" + + "github.com/cdnjs/tools/util" ) func removePackageDir(path string) string { @@ -93,3 +98,19 @@ func Untar(dst string, r io.Reader) error { } } } + +// Extract the tarball url in a temporary location +func DownloadTar(ctx context.Context, url string) string { + dest, err := ioutil.TempDir("", "npmtarball") + util.Check(err) + + util.Debugf(ctx, "download %s in %s", url, dest) + + resp, err := http.Get(url) + util.Check(err) + + defer resp.Body.Close() + + util.Check(Untar(dest, resp.Body)) + return dest +} diff --git a/util/fileglob.go b/util/fileglob.go index faf23650..8a2c391b 100644 --- a/util/fileglob.go +++ b/util/fileglob.go @@ -15,7 +15,7 @@ func ListFilesGlob(base string, pattern string) []string { return []string{} } - fmt.Println("match", pattern, "in", base) + // fmt.Println("match", pattern, "in", base) cmd := exec.Command(path.Join(GetBotBasePath(), "glob", "index.js"), pattern) var out bytes.Buffer