-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathScriptFunctions.go
53 lines (45 loc) · 1.34 KB
/
ScriptFunctions.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
package main
import (
"os"
"path/filepath"
)
func writeScripts(scripts *[]ScriptEntity, parentDir string, seenNames map[string]bool) {
for i := range *scripts {
script := &(*scripts)[i]
if script.IsFolder == "no" {
handleScripts(&script.Scripts, parentDir, seenNames)
}
writeScriptFiles(script, parentDir, seenNames)
}
}
func writeScriptJson(scripts *[]ScriptEntity, parentDir string) {
writeJsonToFilewriteJsonToFile(scripts, parentDir, "scripts.json")
}
func handleScripts(scripts *[]ScriptEntity, parentDir string, seenNames map[string]bool) {
if len(*scripts) == 0 {
return
}
if parentDir != "" {
if err := os.MkdirAll(parentDir, 0755); err != nil {
panic(err)
}
}
writeScripts(scripts, parentDir, seenNames)
writeScriptJson(scripts, parentDir)
}
func handleScriptGroups(groups *[]ScriptEntity, baseDir string, seenNames map[string]bool) {
for i := range *groups {
group := &(*groups)[i]
groupPath := filepath.Join(baseDir, group.Name)
if err := os.MkdirAll(groupPath, 0755); err != nil {
panic(err)
}
handleScripts(&group.Scripts, groupPath, seenNames)
handleScriptGroups(&group.ScriptGroup, groupPath, seenNames)
group.Scripts = nil
var singleGroup []ScriptEntity
singleGroup = append(singleGroup, *group)
writeScripts(&singleGroup, baseDir, seenNames)
writeScriptJson(&singleGroup, baseDir)
}
}