Skip to content

Commit 28535db

Browse files
committed
refactor(core): update NewTaskComposer args
1 parent 32ddfff commit 28535db

File tree

10 files changed

+38
-41
lines changed

10 files changed

+38
-41
lines changed

cmd/add_air.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var addGoAirCmd = &cli.Command{
1919
}
2020

2121
func addGoAir() core.Runner {
22-
return util.NewTaskComposer("",
22+
return util.NewTaskComposer("").AddFile(
2323
&core.FileDesc{
2424
Path: "air.toml",
2525
Data: func() []byte {

cmd/add_cp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var addPriceUpdateConfigCmd = &cli.Command{
3333
}
3434

3535
func addPriceUpdateEntry(name string) core.Runner {
36-
return util.NewTaskComposer(name,
36+
return util.NewTaskComposer(name).AddFile(
3737
&core.FileDesc{
3838
Path: "provider.yml",
3939
Data: func() []byte {

cmd/add_react.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ var addReactCmd = &cli.Command{
8080
}
8181

8282
func addReactEmotion() core.Runner {
83-
return util.NewTaskComposer("",
83+
return util.NewTaskComposer("").AddFile(
8484
&core.FileDesc{
8585
Path: ".babelrc",
8686
Data: func() []byte {
@@ -149,5 +149,5 @@ func addReactComponent(name, dir string, scss, story bool) core.Runner {
149149
},
150150
})
151151

152-
return util.NewTaskComposer(dir, desc...)
152+
return util.NewTaskComposer(dir).AddFile(desc...)
153153
}

cmd/add_typescript.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var addTypescriptCmd = &cli.Command{
4747
}
4848

4949
func addTypescriptToNode() core.Runner {
50-
return util.NewTaskComposer("",
50+
return util.NewTaskComposer("").AddFile(
5151
&core.FileDesc{
5252
Path: ".eslintrc.js",
5353
Data: func() []byte {
@@ -83,7 +83,7 @@ func addTypescriptToNode() core.Runner {
8383
}
8484

8585
func addTypescriptToReact() core.Runner {
86-
return util.NewTaskComposer("",
86+
return util.NewTaskComposer("").AddFile(
8787
&core.FileDesc{
8888
Path: ".eslintrc.js",
8989
Data: func() []byte {

cmd/add_viper_tag.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ var addViperTagCmd = &cli.Command{
4747
func addViperFlag(config *addViperTagConfig) (core.Runner, error) {
4848
var outData bytes.Buffer
4949

50-
return util.NewTaskComposer("", &core.FileDesc{
51-
Path: config.ConfigPath,
52-
Overwrite: true,
53-
Data: func() []byte {
54-
return outData.Bytes()
55-
},
56-
}).AddCommand(&core.Command{
50+
return util.NewTaskComposer("").AddFile(
51+
&core.FileDesc{
52+
Path: config.ConfigPath,
53+
Overwrite: true,
54+
Data: func() []byte {
55+
return outData.Bytes()
56+
},
57+
}).AddCommand(&core.Command{
5758
Bin: "gomodifytags",
5859
Before: true,
5960
Args: []string{

cmd/gen_api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var genAPICmd = &cli.Command{
7878
}
7979

8080
func generateGoApi(config *genApiConfig) core.Runner {
81-
return util.NewTaskComposer("",
81+
return util.NewTaskComposer("").AddFile(
8282
&core.FileDesc{
8383
Path: fmt.Sprintf("%s/%s_handler.go", "server", config.PackagePath),
8484
Data: func() []byte {

cmd/gen_backend.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ var generateBECmd = &cli.Command{
7171
}
7272

7373
func newGolangBackendGenerator(config *genBEConfig) core.Runner {
74-
return util.NewTaskComposer(
75-
config.ProjectName,
74+
return util.NewTaskComposer(config.ProjectName).AddFile(
7675
&core.FileDesc{
7776
Path: "cmd/web.go",
7877
Data: func() []byte {

cmd/gen_flags.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,22 @@ func generateFlagsFile(config *genFlagsConfig) (core.Runner, error) {
6969

7070
pkg := visitor.pkg
7171
fileName := config.FileName + constants.GoSuffix
72-
return util.NewTaskComposer(pkg, &core.FileDesc{
73-
Path: fileName,
74-
Overwrite: true,
75-
Data: func() []byte {
76-
var buf bytes.Buffer
72+
return util.NewTaskComposer(pkg).AddFile(
73+
&core.FileDesc{
74+
Path: fileName,
75+
Overwrite: true,
76+
Data: func() []byte {
77+
var buf bytes.Buffer
7778

78-
templates.WriteGoGenPflags(&buf, pkg, fm)
79-
data, err := format.Source(buf.Bytes())
80-
if err != nil {
81-
log.WithField("err", err).Error("failed to format code")
82-
return buf.Bytes()
83-
}
84-
return data
85-
},
86-
}).AddCommand(&core.Command{
79+
templates.WriteGoGenPflags(&buf, pkg, fm)
80+
data, err := format.Source(buf.Bytes())
81+
if err != nil {
82+
log.WithField("err", err).Error("failed to format code")
83+
return buf.Bytes()
84+
}
85+
return data
86+
},
87+
}).AddCommand(&core.Command{
8788
Bin: "goimports",
8889
Args: []string{"-w", path.Join(pkg, fileName)},
8990
}).AddCommand(&core.Command{

pkg/util/composer.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,29 @@ type TaskComposer struct {
1313
root string // generation root
1414
files []*core.FileDesc
1515
commands []*core.Command
16-
runner core.Runner
17-
cleaned bool
1816
}
1917

2018
var _ core.Runner = &TaskComposer{}
2119

22-
func NewTaskComposer(root string, files ...*core.FileDesc) *TaskComposer {
23-
return &TaskComposer{root: root, files: files, cleaned: false}
20+
func NewTaskComposer(root string) *TaskComposer {
21+
return &TaskComposer{root: root}
2422
}
2523

2624
// AddFile add file task
27-
func (tc *TaskComposer) AddFile(fd *core.FileDesc) *TaskComposer {
28-
tc.files = append(tc.files, fd)
25+
func (tc *TaskComposer) AddFile(fds ...*core.FileDesc) *TaskComposer {
26+
tc.files = append(tc.files, fds...)
2927
return tc
3028
}
3129

3230
// AddCommand add command
33-
func (tc *TaskComposer) AddCommand(cmd *core.Command) *TaskComposer {
34-
tc.commands = append(tc.commands, cmd)
31+
func (tc *TaskComposer) AddCommand(cmds ...*core.Command) *TaskComposer {
32+
tc.commands = append(tc.commands, cmds...)
3533
return tc
3634
}
3735

3836
func (tc *TaskComposer) Run() error {
3937
log.Debugf("generation tree:\n%s", tc.getGenerationTree())
4038
runner := tc.makeRunner()
41-
tc.runner = runner
42-
4339
return runner.Run()
4440
}
4541

templates/add_air.qtpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ cmd = "go build -o ./tmp/main ."
88
# Binary file yields from `cmd`.
99
bin = "tmp/main"
1010
# Watch these filename extensions.
11-
include_ext = ["go", "yaml"]
11+
include_ext = ["go", "yml"]
1212
# Ignore these filename extensions or directories.
1313
exclude_dir = ["assets", "tmp", "vendor"]
1414
# Watch these directories if you specified.

0 commit comments

Comments
 (0)