generated from stscoundrel/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (46 loc) · 1.13 KB
/
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
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"io/ioutil"
"os"
)
var BUILD_RESOURCE_PATH = "resources/crosslinks.json.gz"
var NPM_RESOURCE_PATH = "npm-module/resources/crosslinks.json.gz"
var README_PATH = "README.md"
var NPM_README_PATH = "npm-module/README.md"
func fileExists(filepath string) bool {
info, err := os.Stat(filepath)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}
func deleteFile(filepath string) error {
return os.Remove(filepath)
}
func copyFile(source string, destination string) error {
sourceBytes, err := ioutil.ReadFile(source)
if err != nil {
return err
}
err = ioutil.WriteFile(destination, sourceBytes, 0644)
return err
}
func updateResourceFile(source string, destination string) {
if fileExists(destination) {
deleteError := deleteFile(destination)
if deleteError != nil {
fmt.Println(deleteError)
}
}
copyError := copyFile(source, destination)
if copyError != nil {
fmt.Println(copyError)
} else {
fmt.Println("Updated " + destination + " resource!")
}
}
func main() {
updateResourceFile(BUILD_RESOURCE_PATH, NPM_RESOURCE_PATH)
updateResourceFile(README_PATH, NPM_README_PATH)
}