This repository has been archived by the owner on May 13, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
dep.pony
139 lines (120 loc) · 3.26 KB
/
dep.pony
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
129
130
131
132
133
134
135
136
137
138
139
use "json"
use "files"
interface DepAny
fun root_path(): String
fun packages_path(): String
fun ref fetch()?
primitive Dep
fun apply(bundle: Bundle box, info: JsonObject box): DepAny ? =>
match info.data("type")?
| "github" => DepGitHosted(bundle, info, "https://github.com/")?
| "gitlab" => DepGitHosted(bundle, info, "https://gitlab.com/")?
| "local-git" => DepLocalGit(bundle, info)?
| "local" => DepLocal(bundle, info)?
else error
end
class DepGitHosted
let bundle: Bundle box
let info: JsonObject box
let domain: String
let repo: String
let subdir: String
let git_tag: (String | None)
new create(b: Bundle box, i: JsonObject box, d: String) ? =>
bundle = b
info = i
domain = d
repo =
try info.data("repo")? as String
else
bundle.log("No 'repo' key in dep: " + info.string())
error
end
subdir =
try info.data("subdir")? as String
else ""
end
git_tag =
try info.data("tag")? as String
else None
end
fun root_path(): String =>
Path.join(bundle.path.path, Path.join(".deps", repo))
fun packages_path(): String =>
Path.join(root_path(), subdir)
fun url(): String =>
domain + repo
fun ref fetch() ? =>
let fpath = FilePath(bundle.path, root_path())?
if fpath.exists() then
Shell("git -C " + root_path() + " fetch")?
else
fpath.mkdir()
Shell("git clone " + url() + " " + root_path())?
end
_CheckoutTag(root_path(), git_tag)?
class DepLocalGit
let bundle: Bundle box
let info: JsonObject box
let package_name: String
let local_path: String
let git_tag: (String | None)
new create(b: Bundle box, i: JsonObject box) ? =>
bundle = b
info = i
local_path =
try info.data("local-path")? as String
else
bundle.log("No 'local-path' key in dep: " + info.string())
error
end
package_name =
try _SubdirNameGenerator(local_path)?
else
bundle.log("Something went wrong generating dir name ")
error
end
bundle.log(package_name)
git_tag =
try info.data("tag")? as String
else None
end
bundle.log(package_name)
fun root_path(): String =>
Path.join(bundle.path.path, Path.join(".deps", package_name))
fun packages_path(): String =>
root_path()
fun ref fetch() ? =>
let fpath = FilePath(bundle.path, root_path())?
if fpath.exists() then
Shell("git -C " + root_path() + " pull " + local_path)?
else
fpath.mkdir()
Shell("git clone " + local_path + " " + root_path())?
end
_CheckoutTag(root_path(), git_tag)?
class DepLocal
let bundle: Bundle box
let info: JsonObject box
let local_path: String
new create(b: Bundle box, i: JsonObject box) ? =>
bundle = b
info = i
local_path =
try info.data("local-path")? as String
else
bundle.log("No 'local-path' key in dep: " + info.string())
error
end
fun root_path(): String =>
local_path
fun packages_path(): String =>
root_path()
fun ref fetch() =>
None
primitive _CheckoutTag
fun apply(root_path: String, git_tag: (String | None)) ? =>
match git_tag
| let str: String =>
Shell("cd " + root_path + " && git checkout " + str)?
end