Skip to content

Commit

Permalink
if program dir is empty, pack the source code
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Nov 10, 2023
1 parent 1cae30d commit 4c4663b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lpm-builder/pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func prepare(templateDir string) BuilderCtx {

ctx.TemplateFields = template.DeserializeTemplate(ctx.TemplateDir)

ctx.PkgFilesData = make([]File, 0)

ctx.System.BuilderVersion = common.BuilderVersion
ctx.System.MinSupportedLpmVersion = common.MinSupportedLpmVersion

Expand Down
11 changes: 9 additions & 2 deletions lpm-builder/pkg/builder/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@ package builder

import (
"context"
"io/ioutil"
"os"
"path/filepath"

"github.com/mholt/archiver/v4"
)

func PackLodFile(rootDir string, destFile string) error {
// absolute path -- package level path
filesToPack := map[string]string{
filepath.Join(rootDir, "meta"): "meta",
filepath.Join(rootDir, "program"): "program",
filepath.Join(rootDir, "scripts"): "scripts",
filepath.Join(rootDir, "system.json"): "system.json",
}

programPath := filepath.Join(rootDir, "program")
if content, _ := ioutil.ReadDir(programPath); len(content) != 0 {
filesToPack[programPath] = "program"
} else {
filesToPack[filepath.Join(rootDir, "src") ] = "src"
}

files, err := archiver.FilesFromDisk(nil, filesToPack)

if err != nil {
Expand Down

0 comments on commit 4c4663b

Please sign in to comment.