Skip to content

Commit

Permalink
feat: add single module folder with kcl mod file with entries config
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Nov 16, 2023
1 parent bf93d5f commit c43ed7a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
8 changes: 8 additions & 0 deletions me/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "me"
edition = "0.0.1"
version = "0.0.1"

[profile]
entries = ["svc/main.k"]

Empty file added me/kcl.mod.lock
Empty file.
1 change: 1 addition & 0 deletions me/svc/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'
17 changes: 14 additions & 3 deletions pkg/options/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/acarl005/stripansi"
"github.com/pkg/errors"
"kcl-lang.io/cli/pkg/fs"
"kcl-lang.io/kcl-go/pkg/kcl"
"kcl-lang.io/kpm/pkg/api"
"kcl-lang.io/kpm/pkg/client"
Expand Down Expand Up @@ -88,7 +89,7 @@ func (o *RunOptions) Run() error {
}
if entry.IsEmpty() {
// kcl compiles the current package under '$pwd'.
if _, found := api.GetKclPackage(pwd); found == nil {
if _, e := api.GetKclPackage(pwd); e == nil {
opts.SetPkgPath(pwd)
result, err = cli.CompileWithOpts(opts)
} else {
Expand All @@ -112,8 +113,18 @@ func (o *RunOptions) Run() error {
}
transformedEntries = append(transformedEntries, entry)
}
opts.SetEntries(transformedEntries)
opts.SetPkgPath(entry.PackageSource())
// Maybe a single KCL module folder, use the kcl.mod entry profile to run.
if pkg, e := api.GetKclPackage(transformedEntries[0]); e == nil && fs.IsDir(transformedEntries[0]) {
entries := pkg.GetPkgProfile().Entries
if len(entries) > 0 {
opts.SetEntries(entries)
}
opts.SetPkgPath(transformedEntries[0])
} else {
// Multiple entries with the kcl.mod file and deps.
opts.SetEntries(transformedEntries)
opts.SetPkgPath(entry.PackageSource())
}
result, err = cli.CompileWithOpts(opts)
} else if entry.IsTar() {
// kcl compiles the package from the kcl package tar.
Expand Down

0 comments on commit c43ed7a

Please sign in to comment.