Skip to content

Commit

Permalink
Config file checks.
Browse files Browse the repository at this point in the history
Calculate module sub sir from package.json.
Added `module` first party translation.
  • Loading branch information
pkedy committed Jun 8, 2021
1 parent aef08fc commit bcc5e18
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
12 changes: 12 additions & 0 deletions pkg/commands/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ func (c *GenerateCmd) generate(configYAML string) error {
if err := yaml.Unmarshal([]byte(configYAML), &config); err != nil {
return err
}
if config.Schema == "" {
return errors.New("schema is required")
}
if len(config.Generates) == 0 {
return errors.New("generates is required")
}

schemaBytes, err := readFile(config.Schema)
if err != nil {
Expand All @@ -108,6 +114,12 @@ func (c *GenerateCmd) generate(configYAML string) error {
srcDir := filepath.Join(homeDir, "src")

for filename, target := range config.Generates {
if target.Module == "" {
return fmt.Errorf("module is required for %s", filename)
}
if target.VisitorClass == "" {
return fmt.Errorf("visitorClass is required for %s", filename)
}
if target.IfNotExists {
_, err := os.Stat(filename)
if err != nil && !os.IsNotExist(err) {
Expand Down
18 changes: 12 additions & 6 deletions pkg/commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ func (c *InstallCmd) doRun(ctx *Context, homeDir string) error {

fmt.Printf("Installing %s/%s %s...\n", release.Org, release.Module, release.Tag)

moduleSubDir := release.Module
if release.Org != "" {
moduleSubDir = filepath.Join(release.Org, release.Module)
}

if release.Directory != "" {
moduleSubDir := release.Module
if release.Org != "" {
moduleSubDir = filepath.Join(release.Org, release.Module)
}

return c.installDir(
release.Directory,
homeDir,
Expand Down Expand Up @@ -130,7 +130,13 @@ func (c *InstallCmd) doRun(ctx *Context, homeDir string) error {
for _, entry := range dirEntries {
if entry.IsDir() {
contentsDir := filepath.Join(downloadDir, entry.Name())
readPackage(contentsDir, release)
if err = readPackage(contentsDir, release); err != nil {
return err
}
moduleSubDir := release.Module
if release.Org != "" {
moduleSubDir = filepath.Join(release.Org, release.Module)
}

if err = c.installDir(
contentsDir,
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type NewCmd struct {
}

var firstPartyTranslations = map[string]string{
"module": filepath.Join("@wapc", "widl", "module"),
"assemblyscript": filepath.Join("@wapc", "widl-codegen", "assemblyscript"),
"rust": filepath.Join("@wapc", "widl-codegen", "rust"),
"tinygo": filepath.Join("@wapc", "widl-codegen", "tinygo"),
Expand Down

0 comments on commit bcc5e18

Please sign in to comment.