This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
/
gen_bundler_json.go
86 lines (74 loc) · 1.88 KB
/
gen_bundler_json.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"encoding/json"
"flag"
"fmt"
)
var bundler = `{
"app_name": "Kelp",
"icon_path_darwin": "resources/kelp-icon@2x.icns",
"icon_path_linux": "resources/kelp-icon@2x.png",
"icon_path_windows": "resources/kelp-icon@2x.ico",
"bind": {
"output_path": "./cmd",
"package": "cmd"
}
}`
var environments = `{
"environments": [
{"os": "darwin", "arch": "amd64"},
{"os": "linux", "arch": "amd64"},
{"os": "windows", "arch": "amd64"}
]
}`
var environmentsDarwin = `{
"environments": [
{"os": "darwin", "arch": "amd64"}
]
}`
var environmentsLinux = `{
"environments": [
{"os": "linux", "arch": "amd64"}
]
}`
var environmentsWindows = `{
"environments": [
{"os": "windows", "arch": "amd64"}
]
}`
func main() {
buildAllP := flag.Bool("a", false, "whether to build for all platforms (default builds only for native platform)")
buildPlatformP := flag.String("p", "", "explicitly specify a specific platform to build for")
flag.Parse()
buildAll := *buildAllP
var bundlerJSON map[string]interface{}
e := json.Unmarshal([]byte(bundler), &bundlerJSON)
if e != nil {
panic(e)
}
if *buildPlatformP == "darwin" {
setPlatform(environmentsDarwin, bundlerJSON)
} else if *buildPlatformP == "linux" {
setPlatform(environmentsLinux, bundlerJSON)
} else if *buildPlatformP == "windows" {
setPlatform(environmentsWindows, bundlerJSON)
} else if buildAll {
setPlatform(environments, bundlerJSON)
} // else only for native platform
jsonBytes, e := json.MarshalIndent(bundlerJSON, "", " ")
if e != nil {
panic(e)
}
jsonString := string(jsonBytes)
fmt.Println(jsonString)
}
func setPlatform(envs string, bundlerJSON map[string]interface{}) {
var environmentsJSON map[string]interface{}
e := json.Unmarshal([]byte(envs), &environmentsJSON)
if e != nil {
panic(e)
}
for k, v := range environmentsJSON {
bundlerJSON[k] = v
}
}