-
Notifications
You must be signed in to change notification settings - Fork 0
/
newProject.luau
195 lines (158 loc) · 5.1 KB
/
newProject.luau
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
local fs = require("@lune/fs") :: any
local serde = require("@lune/serde") :: any
local excludeFromView = {
[".vscode"] = true,
["lib"] = true,
["node_modules"] = true,
["src/scripts"] = true,
[".gitattributes"] = true,
[".luaurc"] = true,
["aftman.toml"] = true,
["package-lock.json"] = true,
["package.json"] = true,
["selene.toml"] = true,
["sourcemap.json"] = true,
}
local ignoreFromGit = {
".vscode",
"lib",
"node_modules",
".luaurc",
"aftman.toml",
"selene.toml",
"sourcemap.json",
}
local toCreate = {
{ `.gitattributes`, `*.luau linguist-language=Lua` },
{ `.gitignore`, table.concat(ignoreFromGit, "\n") },
{ `.luaurc`, serde.encode( "json", { lint = { ["*"] = true } }) },
}
local toDelete = {
".editorconfig",
`game.sublime-project`,
`roblox.yml`,
`README.md`,
}
local function createFiles(source)
fs.writeDir(`{source}/.vscode`)
fs.writeFile(`{source}/.vscode/settings.json`, serde.encode("json", { ["files.exclude"] = excludeFromView }))
for _, entry in toCreate do
local name, context = table.unpack(entry)
if fs.isFile(`{source}\\{name}`) then
continue
end
fs.writeFile(`{source}\\{name}`, context or "")
end
end
local function deleteFiles(source)
for _, entry in fs.readDir(source) do
if not table.find(toDelete, entry) then
continue
end
fs.removeFile(`{source}\\{entry}`)
end
end
local function writeDir(origin: string, target: string?)
assert(origin, "Bad origin")
for _, result in { origin, target :: string } do
if fs.isDir(result) then
continue
end
fs.writeDir(result)
end
if not target then
return
end
for _, result in fs.readDir(origin) do
local originalPath = `{origin}\\{result}`
local targetPath = `{target}\\{result}`
if fs.isFile(originalPath) then
local ok, results = pcall(fs.readFile, originalPath)
if not ok then
continue
end
if not (
string.find(targetPath, "lib") or
string.find(targetPath, "node_modules") or
string.find(targetPath, "packages")
) then
local nameBeforeExtension = string.match(result, "^(.+)%..+$")
local extension = string.match(result, "^.*%.(.+)$")
if extension == "lua" then
extension = "luau"
targetPath = `{target}\\{nameBeforeExtension}.{extension}`
end
end
fs.writeFile(targetPath, results)
else
writeDir(originalPath, targetPath)
end
end
end
local function setup()
local args, count = {}, #process.args
local cwd = string.sub(process.cwd, 1, -2)
args.name = "Game"
if count == 1 then
args.name = process.args[1] or args.name
elseif count >= 2 then
for i = 2, #process.args, 2 do
local key = process.args[i - 1]
local value = process.args[i]
args[key] = value
end
end
local luneTemp = process.env["TEMP"] do
if not luneTemp then
error("TEMP not found")
return
end
luneTemp ..= "\\.lune"
if not fs.isDir(luneTemp) then
fs.writeDir(luneTemp)
end
end
local canCreateFiles = (args.forceUpdate == "true")
if not canCreateFiles then
for _, fileToCreate in toCreate do
if fs.isFile(`{luneTemp}\\{fileToCreate[1]}`) then
continue
end
canCreateFiles = true
break
end
end
if canCreateFiles then
createFiles(luneTemp)
for _, command in {
`npx @quenty/nevermore-cli init {args.name}`,
"aftman add Kampfkarren/selene",
"aftman add rojo-rbx/rojo",
"aftman install",
`cd lib && git clone https://github.com/Elttob/Fusion && cd ..`,
} do
if not fs.isDir(`{luneTemp}/lib`) then
fs.writeDir(`{luneTemp}/lib`)
end
process.spawn("cmd", { "/c", command }, { cwd = luneTemp })
end
end
local projectFile = `{luneTemp}/default.project.json`
local projectFileContents = serde.decode("json", fs.readFile(projectFile))
projectFileContents["tree"]["ServerScriptService"]["Game"]["packages"]["@elttob"] = {
["$className"] = "Folder",
["fusion"] = {
["$className"] = "Folder",
["Shared"] = {
["$className"] = "Folder",
["Fusion"] = {
["$path"] = "lib/Fusion",
},
},
},
}
fs.writeFile(projectFile, serde.encode("json", projectFileContents))
deleteFiles(luneTemp)
writeDir(luneTemp, cwd)
end
setup()