From c3df8f254f5d837859ed20a34b729e4b77d610f4 Mon Sep 17 00:00:00 2001 From: Pieter Claerhout Date: Thu, 31 Oct 2019 11:05:56 +0100 Subject: [PATCH] package | should package all files and folders in the build folder Fixes #64 --- .vscode/tasks.json | 2 +- internal/common/compressors/common.go | 1 + internal/common/compressors/tarball.go | 15 ++++++++++++++- internal/common/compressors/zip.go | 14 +++++++++++++- internal/packager/packager.go | 2 +- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 8a53d0f..7b71938 100755 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -21,7 +21,7 @@ }, { "label": "go-james | package", - "command": "./build/go-james package -v", + "command": "DEBUG=1 ./build/go-james package -v", "type": "shell", "group": "build", "problemMatcher": [ diff --git a/internal/common/compressors/common.go b/internal/common/compressors/common.go index 2fbcca0..1486aef 100644 --- a/internal/common/compressors/common.go +++ b/internal/common/compressors/common.go @@ -4,6 +4,7 @@ package compressors type Compressor interface { Path() string // Path returns the path to the archive AddFile(name string, path string) // AddFile adds the file from path as name to the archive + AddDirectory(path string) // AddDirectory adds all files from within a directory Close() error // Close creates and closes the archive } diff --git a/internal/common/compressors/tarball.go b/internal/common/compressors/tarball.go index b99072b..fcd8ecc 100644 --- a/internal/common/compressors/tarball.go +++ b/internal/common/compressors/tarball.go @@ -41,10 +41,22 @@ func (archive *TarballCompressor) AddFile(name string, path string) { Name: name, Path: path, } - log.Debug(entry, "Adding:") + log.Debug("Adding:", entry) archive.entries = append(archive.entries, entry) } +// AddDirectory adds all files from within a directory +func (archive *TarballCompressor) AddDirectory(dirPath string) { + filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error { + if info.IsDir() { + return nil + } + relPath, _ := filepath.Rel(dirPath, path) + archive.AddFile(relPath, path) + return nil + }) +} + // Close creates and closes the archive func (archive *TarballCompressor) Close() error { @@ -52,6 +64,7 @@ func (archive *TarballCompressor) Close() error { return errors.New("No files found to compress") } + log.Debug("Creating:", archive.path) file, err := os.Create(archive.path) if err != nil { return err diff --git a/internal/common/compressors/zip.go b/internal/common/compressors/zip.go index 5bee69b..86e047b 100644 --- a/internal/common/compressors/zip.go +++ b/internal/common/compressors/zip.go @@ -40,10 +40,22 @@ func (archive *ZipCompressor) AddFile(name string, path string) { Name: name, Path: path, } - log.Debug(entry, "Adding:") + log.Debug("Adding:", entry) archive.entries = append(archive.entries, entry) } +// AddDirectory adds all files from within a directory +func (archive *ZipCompressor) AddDirectory(dirPath string) { + filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error { + if info.IsDir() { + return nil + } + relPath, _ := filepath.Rel(dirPath, path) + archive.AddFile(relPath, path) + return nil + }) +} + // Close creates and closes the archive func (archive *ZipCompressor) Close() error { diff --git a/internal/packager/packager.go b/internal/packager/packager.go index e2e5817..2d15c54 100644 --- a/internal/packager/packager.go +++ b/internal/packager/packager.go @@ -90,7 +90,7 @@ func (packager Packager) buildDistribution(project common.Project, cfg config.Co compressor = packager.CreateZip(archivePath) } - compressor.AddFile("", buildOutputPath) + compressor.AddDirectory(filepath.Dir(buildOutputPath)) readmePath := project.RelPath("README.md") if cfg.Package.IncludeReadme && packager.FileExists(readmePath) {