-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidators.go
56 lines (49 loc) · 1.4 KB
/
validators.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
package main
import (
"errors"
"log"
"os"
"path/filepath"
)
func validateFileExists(path string) bool {
return exists(path)
}
func directoryValidator(val interface{}) error {
statResult, err := os.Stat(val.(string))
if os.IsNotExist(err) {
return errors.New("Directory does not exist")
}
if !statResult.IsDir() {
return errors.New("Path is not a directory")
}
return nil
}
func backendDirectoryValidator(val interface{}) error {
if !validateFileExists(filepath.Join(val.(string), "gunicorn.conf.py")) {
return errors.New(
"Directory does not look to be a cloned https://github.com/bitcart/bitcart repository",
)
}
return nil
}
func dockerDirectoryValidator(val interface{}) error {
if !validateFileExists(filepath.Join(val.(string), "setup.sh")) {
return errors.New(
"Directory does not look to be a cloned https://github.com/bitcart/bitcart-docker repository",
)
}
return nil
}
func frontendDirectoryValidator(val interface{}) error {
if !validateFileExists(filepath.Join(val.(string), "nuxt.config.js")) {
return errors.New("Directory does not look to be a frontend repository")
}
return nil
}
func validateFrontend(componentType string, path string) {
for _, file := range []string{"index.js", "package.json", "config/index.js"} {
if !validateFileExists(filepath.Join(path, file)) {
log.Fatalf("Plugin's %s component %s does not include %s", componentType, path, file)
}
}
}