-
Notifications
You must be signed in to change notification settings - Fork 0
/
fluxscaffold.go
67 lines (54 loc) · 1.96 KB
/
fluxscaffold.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"flag"
"os"
)
var domain, constant, action string
var isApi bool
var resourceOptions ResourceOptions
var generators []ResourceGenerator
func main() {
parseInputOrExit()
createResourceOptions()
createGenerators()
executeGenerators()
}
func parseInputOrExit() {
flag.StringVar(&domain, "domain", "", "A domain object name e.g user, product");
flag.StringVar(&constant, "const", "", "A constant name, eg. USERS_FETCH");
flag.StringVar(&action, "action", "", "An action name, fetchUsers");
flag.BoolVar(&isApi, "api", false, "If enabled, will create an api file and import it in the action-creator file")
flag.Parse();
if (domain == "" || constant == "" || action == "") {
fmt.Println("domain, constant and action are required \n");
os.Exit(1);
}
}
func createResourceOptions() {
resourceOptions = ResourceOptions{Domain: domain, Constant: constant, Action: action, IsApi: isApi}
}
func createGenerators() {
constantGenerator := ResourceGenerator{&Constant{ResourceOptions(resourceOptions)}}
actionGenerator := ResourceGenerator{&Action{ResourceOptions(resourceOptions)}}
storeGenerator := ResourceGenerator{&Store{ResourceOptions(resourceOptions)}}
componentGenerator := ResourceGenerator{&Component{ResourceOptions(resourceOptions)}}
generators = append(generators, constantGenerator)
generators = append(generators, actionGenerator)
generators = append(generators, storeGenerator)
generators = append(generators, componentGenerator)
if (isApi) {
apiGenerator := ResourceGenerator{&Api{ResourceOptions(resourceOptions)}}
generators = append(generators, apiGenerator)
}
}
func executeGenerators() {
race := make(chan bool)
for i := range generators {
generator := generators[i]
go generator.Execute(race)
}
for j, generatorsLen := 0, len(generators); j < generatorsLen; j++ {
<- race
}
}