diff --git a/pkg/zeaburpack/plan.go b/pkg/zeaburpack/plan.go index b1bc33f81..08289c08d 100644 --- a/pkg/zeaburpack/plan.go +++ b/pkg/zeaburpack/plan.go @@ -47,6 +47,34 @@ func Plan(opt PlanOptions) (types.PlanType, types.PlanMeta) { src = afero.NewBasePathFs(afero.NewOsFs(), *opt.Path) } + config := plan.NewProjectConfigurationFromFs(src) + + // You can specify customBuildCommand, customStartCommand, and + // outputDir in the project configuration file, with the following + // form: + // + // [project] + // build_command = "..." + // start_command = "..." + // output_dir = "..." + // + // [project.submodule] + // build_command = "..." + // start_command = "..." + // output_dir = "..." + // + // The submodule-specific configuration overrides the project + // configuration if defined. + if opt.CustomBuildCommand == nil { + opt.CustomBuildCommand = getProjectConfigValue(config, *opt.SubmoduleName, "build_command") + } + if opt.CustomStartCommand == nil { + opt.CustomStartCommand = getProjectConfigValue(config, *opt.SubmoduleName, "start_command") + } + if opt.OutputDir == nil { + opt.OutputDir = getProjectConfigValue(config, *opt.SubmoduleName, "output_dir") + } + planner := plan.NewPlanner( &plan.NewPlannerOptions{ Source: src, @@ -62,3 +90,31 @@ func Plan(opt PlanOptions) (types.PlanType, types.PlanMeta) { t, m := planner.Plan() return t, m } + +// getProjectConfigValue returns the project-specific configuration of the specified key. +// +// The format of project-specific configuration is like: +// +// [project] # global +// key = "value" +// +// [project.submodule] # submoduleName specific +// key = "value" # overrides global +// +// If no such key is found in config, it returns nil. +func getProjectConfigValue(config plan.ProjectConfiguration, submoduleName string, key string) *string { + submoduleKey := "project." + submoduleName + "." + globalKey := "project." + + if config.IsSet(submoduleKey + key) { + value := config.GetString(submoduleKey + key) + return &value + } + + if config.IsSet(globalKey + key) { + value := config.GetString(globalKey + key) + return &value + } + + return nil +}