/
main.go
48 lines (38 loc) · 776 Bytes
/
main.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
package main
import (
"encoding/json"
"io/ioutil"
"os"
"github.com/ogier/pflag"
"github.com/pocke/orderedmap.go"
)
func main() {
path := ""
pflag.StringVarP(&path, "tsconfig", "t", "tsconfig.json", "your tsconfig.json path")
pflag.Parse()
if err := Update(path, pflag.Args()); err != nil {
panic(err)
}
}
func Update(tsconfigPath string, files []string) error {
f, err := os.Open(tsconfigPath)
if err != nil {
return err
}
defer f.Close()
v := omap.New()
if err := json.NewDecoder(f).Decode(v); err != nil {
return err
}
f.Close()
if files == nil {
files = []string{}
}
v.Set("files", files)
b, err := json.MarshalIndent(v, "", " ")
if err != nil {
return err
}
ioutil.WriteFile(tsconfigPath, append(b, '\n'), 0644)
return nil
}