/
plugins.go
128 lines (110 loc) 路 3.08 KB
/
plugins.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"./provider"
"./ui"
"./utils"
)
func PluginLink(path string) {
configPath := utils.Path(path + "/gupm.json")
if utils.FileExists(configPath) {
packageConfig := new(utils.GupmEntryPoint)
errConfig := utils.ReadJSON(configPath, &packageConfig)
if errConfig != nil {
ui.Error("Can't read provider configuration")
ui.Error(errConfig)
return
}
pluginFolder := utils.HOMEDIR(".") + utils.Path("/.gupm/plugins/")
os.MkdirAll(pluginFolder, os.ModePerm)
err := os.Symlink(utils.AbsPath(path), pluginFolder+packageConfig.Name)
if err != nil {
ui.Error(err)
}
} else {
ui.Error("Can't find provider configuration")
}
}
func PluginInstall(path string, plugins []string) error {
ui.Title("Install plugin...")
pluginFolder := utils.HOMEDIR(".") + utils.Path("/.gupm/plugins/")
for _, rls := range plugins {
ui.Log(rls)
newDep, err := provider.ResolveDependencyLocation(utils.BuildDependencyFromString("https", rls))
if err != nil {
return err
}
pluginName := filepath.Base(newDep["name"].(string))
if len(strings.Split(pluginName, ":")) > 1 {
pluginName = strings.Split(pluginName, ":")[1]
}
if len(strings.Split(pluginName, "/")) > 1 {
pluginName = strings.Split(pluginName, "/")[1]
}
newDep["path"] = pluginFolder + utils.Path(pluginName)
getRes, errorGD := provider.GetDependency(
newDep["provider"].(string),
newDep["name"].(string),
newDep["version"].(string),
newDep["url"].(string),
newDep["path"].(string),
)
if errorGD != nil {
return errorGD
}
_, errorPGD := provider.PostGetDependency(
newDep["provider"].(string),
newDep["name"].(string),
newDep["version"].(string),
newDep["url"].(string),
newDep["path"].(string),
getRes,
)
if errorPGD != nil {
return errorPGD
}
InstallProject(newDep["path"].(string))
ui.Title("Installation done 鉂わ笍")
}
return nil
}
func PluginDelete(path string, plugins []string) {
folders := make([]string, 0)
pluginFolder := utils.HOMEDIR(".") + utils.Path("/.gupm/plugins/")
for _, str := range plugins {
folders = append(folders, pluginFolder+str)
}
utils.RemoveFiles(folders)
fmt.Println("Done deleting.")
}
func PluginCreate(path string) {
fmt.Println("Welcome to the plugin creation assistant")
name := "provider-" + ui.WaitForInput("What is the name of the plugin? provider-")
description := ui.WaitForInput("Enter a description: ")
author := ui.WaitForInput("Enter the author: ")
licence := ui.WaitForInput("Enter the licence (ISC): ")
ppath := utils.Path(path + "/" + name)
os.MkdirAll(ppath, os.ModePerm)
os.MkdirAll(ppath+utils.Path("/docs/repo"), os.ModePerm)
utils.WriteFile(ppath+utils.Path("/gupm.json"), `{
"name": "`+name+`",
"version": "0.0.1",
"description": "`+description+`",
"author": "`+author+`",
"licence": "`+licence+`",
"publish": {
"source": ["."],
"dest": "../docs/repo"
},
"config": {
"default": {
"entrypoint": "gupm.json",
"installPath": "gupm_modules"
}
}
}`)
fmt.Println("creation done.")
}