Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
package | should package all files and folders in the build folder
Browse files Browse the repository at this point in the history
Fixes #64
  • Loading branch information
pieterclaerhout committed Oct 31, 2019
1 parent fabcaa8 commit c3df8f2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions internal/common/compressors/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 14 additions & 1 deletion internal/common/compressors/tarball.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,30 @@ 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 {

if len(archive.entries) == 0 {
return errors.New("No files found to compress")
}

log.Debug("Creating:", archive.path)
file, err := os.Create(archive.path)
if err != nil {
return err
Expand Down
14 changes: 13 additions & 1 deletion internal/common/compressors/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
2 changes: 1 addition & 1 deletion internal/packager/packager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c3df8f2

Please sign in to comment.