Skip to content

Commit 9b9e2b7

Browse files
committed
added project deploy support
1 parent 881e5b6 commit 9b9e2b7

File tree

4 files changed

+64
-16
lines changed

4 files changed

+64
-16
lines changed

controllers/functions.go

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,9 @@ func ProgramStarting(cnf *string, filepath string, modOrFile string, command str
3737
if *cnf == "cmd" {
3838

3939
} else if *cnf == "cnf" {
40-
jsonFile, err := os.Open("godemon-cnf.json")
41-
ErrorHandle(err)
42-
defer jsonFile.Close()
43-
byteValue, err := ioutil.ReadAll(jsonFile)
44-
ErrorHandle(err)
45-
var commands models.Commands
46-
json.Unmarshal(byteValue, &commands)
47-
for i := 0; i < len(commands.Commands); i++ {
48-
if command == commands.Commands[i].Name {
49-
fmt.Println(commands.Commands[i].Path)
50-
fmt.Println(commands.Commands[i].Option)
51-
filepath = commands.Commands[i].Path
52-
modOrFile = commands.Commands[i].Option
53-
}
54-
}
40+
filepath, modOrFile = loadDataFromCnf(cnf, command, "", "")
41+
} else if *cnf == "deploy" {
42+
_, _ = loadDataFromCnf(cnf, command, "", "")
5543
} else if *help == true {
5644
fmt.Printf("Godemon %v: \n 1. -cnf <- in this flag put info about what do you want to do - if use cmd option use -cnf=cmd, if config file use -cnf=cnf \n 2. -path <- path to file/directory \n 3. -modOrFile <- are you using modules or one file \n 4. -command <- binded command in config file \n", version)
5745
os.Exit(1)
@@ -91,3 +79,48 @@ func killProcess() {
9179
cmd.Stderr = os.Stderr
9280
cmd.Run()
9381
}
82+
83+
func loadDataFromCnf(cnf *string, command string, filepath string, modOrFile string) (string, string) {
84+
jsonFile, err := os.Open("godemon-cnf.json")
85+
ErrorHandle(err)
86+
defer jsonFile.Close()
87+
byteValue, err := ioutil.ReadAll(jsonFile)
88+
ErrorHandle(err)
89+
var projectInfo models.ProjectInfo
90+
json.Unmarshal(byteValue, &projectInfo)
91+
if *cnf == "cnf" {
92+
commandsL := projectInfo.Commands.Commands
93+
for i := 0; i < len(commandsL); i++ {
94+
if command == commandsL[i].Name {
95+
fmt.Println(commandsL[i].Path)
96+
fmt.Println(commandsL[i].Option)
97+
filepath = commandsL[i].Path
98+
modOrFile = commandsL[i].Option
99+
}
100+
}
101+
} else if *cnf == "deploy" {
102+
log := time.Now().Format("2006-01-02, 15:04 \n\n")
103+
log = `Building project: ` + log + `: `
104+
cmd := exec.Command("printf", "\\e[1;34m%-6s\\e[m\n", log)
105+
cmd.Stdout = os.Stdout
106+
cmd.Stderr = os.Stderr
107+
cmd.Run()
108+
path := projectInfo.Project.Path
109+
osP := projectInfo.Project.OS
110+
arch := projectInfo.Project.Arch
111+
goos := "GOOS=" + osP
112+
archos := "GOARCH=" + arch
113+
name := projectInfo.Project.Name
114+
os.Chdir(path)
115+
cmd = exec.Command("env", goos, archos, "go", "build", "-o", name)
116+
cmd.Stdout = os.Stdout
117+
cmd.Stderr = os.Stderr
118+
cmd.Run()
119+
cmd = exec.Command("printf", "\\e[1;34m%-6s\\e[m\n", "Project builded")
120+
cmd.Stdout = os.Stdout
121+
cmd.Stderr = os.Stderr
122+
cmd.Run()
123+
os.Exit(1)
124+
}
125+
return filepath, modOrFile
126+
}

controllers/loadFlags.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ func LoadCMD(filepath string, modOrFile string) (string, string, string, string,
1717
filepath = *filepathP
1818
command := *commandP
1919
modOrFile = *modOrFileP
20+
if cnf == "" {
21+
*helpP = true
22+
}
2023
return filepath, modOrFile, cnf, command, helpP
2124
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func main() {
10-
version := "2.0.0"
10+
version := "2.0.5"
1111
doneChan := make(chan bool)
1212
filepath, modOrFile, cnf, command, help := controllers.LoadCMD("", "")
1313
filepath, modOrFile = controllers.ProgramStarting(&cnf, filepath, modOrFile, command, help, version)

models/cnf.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ type Command struct {
66
Option string `json:"file"`
77
}
88

9+
type Project struct {
10+
Name string `json:"name"`
11+
OS string `json:"platformOS"`
12+
Arch string `json:"platformArch"`
13+
Path string `json:"path"`
14+
}
15+
916
type Commands struct {
1017
Commands []Command `json:"commands"`
1118
}
19+
20+
type ProjectInfo struct {
21+
Project Project `json:"project"`
22+
Commands Commands
23+
}

0 commit comments

Comments
 (0)