-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzapper.go
106 lines (82 loc) · 2.31 KB
/
zapper.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"encoding/json"
"errors"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
)
func prepareAppUpload(configAppPath string) (appPath string, appName string, manifestPath string, err error) {
if configAppPath == "" {
configAppPath = "."
}
appPath, err = filepath.Abs(configAppPath)
if err != nil {
log.Printf("Invalid App path: %s\n", appPath)
return "", "", "", err
}
manifestPath = appPath + "/app.manifest"
if _, err = os.Stat(manifestPath); os.IsNotExist(err) {
log.Printf("App manifest not found: %s\n", manifestPath)
return "", "", "", err
}
type AppManifestName struct {
Name string `json:"name"`
}
var manifestObject AppManifestName
manifestData, err := ioutil.ReadFile(manifestPath)
if err != nil {
log.Println("Couldn't read the app.manifest")
return "", "", "", err
}
err = json.Unmarshal(manifestData, &manifestObject)
if err != nil {
log.Println("Couldn't parse the app.manifest")
return "", "", "", err
}
if manifestObject.Name == "" {
log.Println("The name is missing from the app manifest")
return "", "", "", errors.New("The name is missing from the app manifest")
}
appName = manifestObject.Name
return appPath, appName, manifestPath, nil
}
func createZapPackage(appPath string) (string, error) {
tempFolder, err := ioutil.TempDir("", "appix")
if err != nil {
log.Println("Could not create temp folder!")
return "", err
}
zapFile := tempFolder + "/app.zap"
if verbose {
log.Println("Creating ZAP file: " + zapFile)
}
err = zipFolder(appPath, zapFile, includePathInZapFile)
if err != nil {
log.Println("Could not process App folder!")
return "", err
}
return zapFile, err
}
func includePathInZapFile(relPath string, isDir bool) bool {
path := strings.ToLower(relPath)
canInclude := !strings.Contains(path, "/node_modules/") && // exclude node_modules
!strings.Contains(path, "/temp/") &&
!strings.Contains(path, ".git") &&
!strings.HasSuffix(path, ".idea/") &&
!strings.HasSuffix(path, ".vscode/") &&
!strings.HasSuffix(path, ".ds_store") &&
!strings.HasSuffix(path, "thumbs.db") &&
!strings.HasSuffix(path, DevFileName) &&
!strings.HasSuffix(path, "desktop.ini")
if verbose {
if canInclude {
log.Printf("\tAdding %s\n", relPath)
} else {
log.Printf("\tSkipping %s\n", relPath)
}
}
return canInclude
}