-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.go
95 lines (86 loc) · 2.32 KB
/
data.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
package main
import (
"bytes"
"embed"
"path/filepath"
"text/template"
"github.com/AlecAivazis/survey/v2"
)
//go:embed plugin/*
var pluginsData embed.FS
var schemaURL = "https://bitcart.ai/schemas/plugin/1.3.0/plugin.schema.json"
var envFile = "../conf/.env"
var COINS = map[string]string{
"btc": "5000",
"ltc": "5001",
"eth": "5002",
"bsty": "5003",
"bch": "5004",
"xrg": "5005",
"bnb": "5006",
"sbch": "5007",
"matic": "5008",
"trx": "5009",
"grs": "5010",
"xmr": "5011",
}
var componentData = map[string]interface{}{
"backend": map[string]interface{}{
"name": "bitcart",
"validator": survey.WithValidator(backendDirectoryValidator),
},
"admin": map[string]interface{}{
"name": "bitcart-admin",
"validator": survey.WithValidator(frontendDirectoryValidator),
},
"store": map[string]interface{}{
"name": "bitcart-store",
"validator": survey.WithValidator(frontendDirectoryValidator),
},
"docker": map[string]interface{}{
"name": "bitcart-docker",
"validator": survey.WithValidator(dockerDirectoryValidator),
},
}
var basicPluginCreate = []*survey.Question{
{
Name: "name",
Prompt: &survey.Input{Message: "Enter the name for your plugin"},
Validate: survey.Required,
},
{
Name: "author",
Prompt: &survey.Input{Message: "Enter the author name for your plugin"},
Validate: survey.Required,
},
{
Name: "description",
Prompt: &survey.Input{Message: "Enter plugin description (optional)"},
},
{
Name: "ComponentTypes",
Prompt: &survey.MultiSelect{
Message: "Select which components will your plugin update",
Options: []string{"backend", "admin", "store", "docker"},
},
},
}
func copyFileContents(src, dst string) {
fileContent, err := pluginsData.ReadFile(src)
checkErr(err)
copyData(fileContent, dst)
}
func executeTemplate(templatePath string, data interface{}, stripSpaces bool) []byte {
tmpl, err := template.New(filepath.Base(templatePath)).Funcs(template.FuncMap{
"IsLast": func(i, size int) bool { return i == size-1 },
}).ParseFS(pluginsData, templatePath)
checkErr(err)
buf := new(bytes.Buffer)
checkErr(tmpl.ExecuteTemplate(buf, filepath.Base(templatePath), &data))
if !stripSpaces {
return buf.Bytes()
}
newBuf := new(bytes.Buffer)
removeBlankLines(bytes.NewReader(buf.Bytes()), newBuf)
return newBuf.Bytes()
}