Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add build path #933

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var (
dataDirPath string
// dumpDataPath dump data path
dumpDataPath string
// place to build new answer
buildDir string
// plugins needed to build in answer application
buildWithPlugins []string
// build output path
Expand All @@ -60,6 +62,8 @@ func init() {

buildCmd.Flags().StringVarP(&buildOutput, "output", "o", "", "build output path")

buildCmd.Flags().StringVarP(&buildDir, "build-dir", "b", "", "dir for build process")

upgradeCmd.Flags().StringVarP(&upgradeVersion, "from", "f", "", "upgrade from specific version, eg: -f v1.1.0")

configCmd.Flags().StringSliceVarP(&configFields, "with", "w", []string{}, "the fields that need to be set to the default value, eg: -w allow_password_login")
Expand Down Expand Up @@ -209,7 +213,7 @@ To run answer, use:
Long: `Build a new Answer with plugins that you need`,
Run: func(_ *cobra.Command, _ []string) {
fmt.Printf("try to build a new answer with plugins:\n%s\n", strings.Join(buildWithPlugins, "\n"))
err := cli.BuildNewAnswer(buildOutput, buildWithPlugins, cli.OriginalAnswerInfo{
err := cli.BuildNewAnswer(buildDir, buildOutput, buildWithPlugins, cli.OriginalAnswerInfo{
Version: Version,
Revision: Revision,
Time: Time,
Expand Down
14 changes: 9 additions & 5 deletions internal/cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ type pluginInfo struct {
Version string
}

func newAnswerBuilder(outputPath string, plugins []string, originalAnswerInfo OriginalAnswerInfo) *answerBuilder {
func newAnswerBuilder(buildDir, outputPath string, plugins []string, originalAnswerInfo OriginalAnswerInfo) *answerBuilder {
material := &buildingMaterial{originalAnswerInfo: originalAnswerInfo}
parentDir, _ := filepath.Abs(".")
material.tmpDir, _ = os.MkdirTemp(parentDir, "answer_build")
if buildDir != "" {
material.tmpDir = filepath.Join(parentDir, buildDir)
} else {
material.tmpDir, _ = os.MkdirTemp(parentDir, "answer_build")
}
if len(outputPath) == 0 {
outputPath = filepath.Join(parentDir, "new_answer")
}
Expand All @@ -117,8 +121,8 @@ func (a *answerBuilder) DoTask(task func(b *buildingMaterial) error) {
}

// BuildNewAnswer builds a new answer with specified plugins
func BuildNewAnswer(outputPath string, plugins []string, originalAnswerInfo OriginalAnswerInfo) (err error) {
builder := newAnswerBuilder(outputPath, plugins, originalAnswerInfo)
func BuildNewAnswer(buildDir, outputPath string, plugins []string, originalAnswerInfo OriginalAnswerInfo) (err error) {
builder := newAnswerBuilder(buildDir, outputPath, plugins, originalAnswerInfo)
builder.DoTask(createMainGoFile)
builder.DoTask(downloadGoModFile)
builder.DoTask(copyUIFiles)
Expand All @@ -144,7 +148,7 @@ func formatPlugins(plugins []string) (formatted []*pluginInfo) {

// createMainGoFile creates main.go file in tmp dir that content is mainGoTpl
func createMainGoFile(b *buildingMaterial) (err error) {
fmt.Printf("[build] tmp dir: %s\n", b.tmpDir)
fmt.Printf("[build] build dir: %s\n", b.tmpDir)
err = dir.CreateDirIfNotExist(b.tmpDir)
if err != nil {
return err
Expand Down