-
Notifications
You must be signed in to change notification settings - Fork 0
/
path-updater.go
37 lines (29 loc) · 958 Bytes
/
path-updater.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
package main
import (
"bytes"
"io/ioutil"
"log"
"strings"
)
func updatePaths(paths []string, srcPath string, fileToReplacePath string) {
input, err := ioutil.ReadFile(srcPath)
if err != nil {
log.Fatal(err)
}
for _, path := range paths {
fileName := getFileName(path)
// remove file extension
spl := strings.Split(fileName, ".")
spl = spl[:len(spl)-1]
fileName = strings.Join(spl, ".")
replaceFromSingleQuote := []byte("from " + "'" + path + "'")
replaceFromDoubleQuote := []byte("from " + `"` + path + `"`)
replaceToSingleQuote := []byte("from " + "'" + "./out/" + fileName + "'")
replaceToDoubleQuote := []byte("from " + `"` + "./out/" + fileName + `"`)
input = bytes.Replace(input, replaceFromSingleQuote, replaceToSingleQuote, -1)
input = bytes.Replace(input, replaceFromDoubleQuote, replaceToDoubleQuote, -1)
}
if err = ioutil.WriteFile(fileToReplacePath+".ts", input, 0666); err != nil {
log.Fatal(err)
}
}