hackmud-script-manager 0.21.1-d4bf990 → 0.21.1-e3e8246
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -38
- package/bin/hsm.js +252 -245
- package/env.d.ts +301 -244
- package/generateTypeDeclaration.js +1 -1
- package/index.js +2 -2
- package/package.json +26 -26
- package/processScript/index.d.ts +12 -9
- package/processScript/index.js +46 -39
- package/processScript/minify.d.ts +11 -8
- package/processScript/minify.js +10 -10
- package/processScript/preprocess.d.ts +4 -2
- package/processScript/preprocess.js +7 -7
- package/processScript/transform.d.ts +8 -6
- package/processScript/transform.js +32 -32
- package/pull.d.ts +6 -4
- package/pull.js +1 -1
- package/push.d.ts +23 -18
- package/push.js +6 -6
- package/syncMacros.js +14 -15
- package/watch.d.ts +11 -7
- package/watch.js +6 -6
package/bin/hsm.js
CHANGED
@@ -1,26 +1,21 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
import { AutoMap } from "@samual/lib/AutoMap"
|
3
|
-
import { assert } from "@samual/lib/assert"
|
4
|
-
import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
|
5
|
-
import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
|
6
2
|
import { writeFile, readFile } from "fs/promises"
|
7
3
|
import { homedir } from "os"
|
8
4
|
import { resolve, extname, basename, dirname, relative } from "path"
|
5
|
+
import { assert } from "@samual/lib/assert"
|
6
|
+
import { AutoMap } from "@samual/lib/AutoMap"
|
7
|
+
import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
|
8
|
+
import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
|
9
9
|
import { supportedExtensions } from "../constants.js"
|
10
10
|
import { generateTypeDeclaration } from "../generateTypeDeclaration.js"
|
11
11
|
import { pull } from "../pull.js"
|
12
12
|
import { syncMacros } from "../syncMacros.js"
|
13
13
|
import "@samual/lib/readDirectoryWithStats"
|
14
14
|
import "@samual/lib/copyFilePersistent"
|
15
|
-
const
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
let hash = 0
|
20
|
-
for (const char of user) hash += (hash >> 1) + hash + "xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(char) + 1
|
21
|
-
return [colourJ, colourK, colourM, colourW, colourL, colourB][hash % 6](user)
|
22
|
-
}),
|
23
|
-
log = message => console.log(colourS(message))
|
15
|
+
const options = new Map(),
|
16
|
+
commands = []
|
17
|
+
let didParseOption = !1,
|
18
|
+
didParseOptionAfterCommand = !1
|
24
19
|
for (const argument of process.argv.slice(2))
|
25
20
|
if ("-" == argument[0]) {
|
26
21
|
const argumentEqualsIndex = argument.indexOf("=")
|
@@ -35,7 +30,11 @@ for (const argument of process.argv.slice(2))
|
|
35
30
|
}
|
36
31
|
if ("-" == argument[1]) options.set(key.slice(2), value)
|
37
32
|
else for (const option of key.slice(1)) options.set(option, value)
|
38
|
-
|
33
|
+
didParseOption = !0
|
34
|
+
} else {
|
35
|
+
didParseOption && (didParseOptionAfterCommand = !0)
|
36
|
+
commands.push(argument)
|
37
|
+
}
|
39
38
|
const pushModule = import("../push.js"),
|
40
39
|
processScriptModule = import("../processScript/index.js"),
|
41
40
|
watchModule = import("../watch.js"),
|
@@ -53,7 +52,23 @@ const pushModule = import("../push.js"),
|
|
53
52
|
colourN = chalk.rgb(0, 255, 255),
|
54
53
|
colourS = chalk.rgb(122, 178, 244),
|
55
54
|
colourV = chalk.rgb(255, 0, 236),
|
56
|
-
colourW = chalk.rgb(255, 150, 224)
|
55
|
+
colourW = chalk.rgb(255, 150, 224),
|
56
|
+
formatOption = name => colourN(`-${1 == name.length ? "" : "-"}${name}`),
|
57
|
+
userColours = new AutoMap(user => {
|
58
|
+
let hash = 0
|
59
|
+
for (const char of user) hash += (hash >> 1) + hash + "xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(char) + 1
|
60
|
+
return [colourJ, colourK, colourM, colourW, colourL, colourB][hash % 6](user)
|
61
|
+
}),
|
62
|
+
log = message => console.log(colourS(message))
|
63
|
+
if (didParseOptionAfterCommand) {
|
64
|
+
process.exitCode = 1
|
65
|
+
console.warn(
|
66
|
+
colourF(
|
67
|
+
chalk.bold("Warning:") +
|
68
|
+
" Options should come after commands when calling the script.\n This warning will become an error in the next minor version of HSM."
|
69
|
+
)
|
70
|
+
)
|
71
|
+
}
|
57
72
|
if (process.version.startsWith("v21.")) {
|
58
73
|
process.exitCode = 1
|
59
74
|
console.warn(
|
@@ -63,7 +78,7 @@ if (process.version.startsWith("v21.")) {
|
|
63
78
|
)
|
64
79
|
}
|
65
80
|
if ("v" == commands[0] || "version" == commands[0] || popOption("version", "v")?.value) {
|
66
|
-
console.log("0.21.1-
|
81
|
+
console.log("0.21.1-e3e8246")
|
67
82
|
process.exit()
|
68
83
|
}
|
69
84
|
let warnedDeprecatedEmitDtsAlias = !1
|
@@ -77,275 +92,267 @@ switch (commands[0]) {
|
|
77
92
|
case "dev":
|
78
93
|
case "watch":
|
79
94
|
case "golf":
|
80
|
-
case "minify":
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
`${chalk.bold("Warning:")} ${formatOption(noMinifyOption.name)} is deprecated and will be removed in the next minor\n release of HSM\n You should switch to using its alias ${colourN("--no-minify")}\n`
|
88
|
-
)
|
95
|
+
case "minify": {
|
96
|
+
const noMinifyOption = popOption("no-minify", "skip-minify")
|
97
|
+
if (noMinifyOption && "no-minify" != noMinifyOption.name) {
|
98
|
+
process.exitCode = 1
|
99
|
+
console.warn(
|
100
|
+
colourF(
|
101
|
+
`${chalk.bold("Warning:")} ${formatOption(noMinifyOption.name)} is deprecated and will be removed in the next minor\n release of HSM\n You should switch to using its alias ${colourN("--no-minify")}\n`
|
89
102
|
)
|
103
|
+
)
|
104
|
+
}
|
105
|
+
const mangleNamesOption = popOption("mangle-names"),
|
106
|
+
forceQuineCheatsOption = popOption("force-quine-cheats"),
|
107
|
+
noQuineCheatsOptions = popOption("no-quine-cheats"),
|
108
|
+
noMinifyIncompatibleOption = mangleNamesOption || forceQuineCheatsOption || noQuineCheatsOptions
|
109
|
+
if (noMinifyOption && noMinifyIncompatibleOption) {
|
110
|
+
logError(
|
111
|
+
`Options ${formatOption(noMinifyOption.name)} and ${formatOption(noMinifyIncompatibleOption.name)} are incompatible\n`
|
112
|
+
)
|
113
|
+
logHelp()
|
114
|
+
process.exit(1)
|
115
|
+
}
|
116
|
+
if (forceQuineCheatsOption && noQuineCheatsOptions) {
|
117
|
+
logError(
|
118
|
+
`Options ${formatOption(forceQuineCheatsOption.name)} and ${formatOption(noQuineCheatsOptions.name)} are incompatible\n`
|
119
|
+
)
|
120
|
+
logHelp()
|
121
|
+
process.exit(1)
|
122
|
+
}
|
123
|
+
noMinifyOption && assertOptionIsBoolean(noMinifyOption)
|
124
|
+
mangleNamesOption && assertOptionIsBoolean(mangleNamesOption)
|
125
|
+
forceQuineCheatsOption && assertOptionIsBoolean(forceQuineCheatsOption)
|
126
|
+
noQuineCheatsOptions && assertOptionIsBoolean(noQuineCheatsOptions)
|
127
|
+
const rootFolderPathOption = popOption("root-folder-path"),
|
128
|
+
rootFolderPath = rootFolderPathOption && resolve(rootFolderPathOption.value + "")
|
129
|
+
if ("golf" == commands[0] || "minify" == commands[0]) {
|
130
|
+
const watchOption = popOption("watch"),
|
131
|
+
target = commands[1]
|
132
|
+
if (!target) {
|
133
|
+
logError("Must provide target\n")
|
134
|
+
logHelp()
|
135
|
+
process.exit(1)
|
90
136
|
}
|
91
|
-
const
|
92
|
-
|
93
|
-
noQuineCheatsOptions = popOption("no-quine-cheats"),
|
94
|
-
noMinifyIncompatibleOption = mangleNamesOption || forceQuineCheatsOption || noQuineCheatsOptions
|
95
|
-
if (noMinifyOption && noMinifyIncompatibleOption) {
|
137
|
+
const fileExtension = extname(target)
|
138
|
+
if (!supportedExtensions.includes(fileExtension)) {
|
96
139
|
logError(
|
97
|
-
`
|
140
|
+
`Unsupported file extension "${chalk.bold(fileExtension)}"\nSupported extensions are "${supportedExtensions.map(extension => chalk.bold(extension)).join('", "')}"`
|
98
141
|
)
|
99
|
-
logHelp()
|
100
142
|
process.exit(1)
|
101
143
|
}
|
102
|
-
|
103
|
-
|
104
|
-
|
144
|
+
complainAboutUnrecognisedOptions()
|
145
|
+
const { processScript } = await processScriptModule,
|
146
|
+
fileBaseName = basename(target, fileExtension),
|
147
|
+
fileBaseNameEndsWithDotSrc = fileBaseName.endsWith(".src"),
|
148
|
+
scriptName = fileBaseNameEndsWithDotSrc ? fileBaseName.slice(0, -4) : fileBaseName,
|
149
|
+
scriptUser =
|
150
|
+
"scripts" == basename(resolve(target, "..")) && "hackmud" == basename(resolve(target, "../../.."))
|
151
|
+
? basename(resolve(target, "../.."))
|
152
|
+
: void 0
|
153
|
+
let outputPath =
|
154
|
+
commands[2] ||
|
155
|
+
resolve(
|
156
|
+
dirname(target),
|
157
|
+
fileBaseNameEndsWithDotSrc
|
158
|
+
? scriptName + ".js"
|
159
|
+
: ".js" == fileExtension
|
160
|
+
? fileBaseName + ".min.js"
|
161
|
+
: fileBaseName + ".js"
|
105
162
|
)
|
163
|
+
const golfFile = () =>
|
164
|
+
readFile(target, { encoding: "utf8" }).then(async source => {
|
165
|
+
const timeStart = performance.now(),
|
166
|
+
{ script, warnings } = await processScript(source, {
|
167
|
+
minify: noMinifyOption && !noMinifyOption.value,
|
168
|
+
scriptUser,
|
169
|
+
scriptName,
|
170
|
+
filePath: target,
|
171
|
+
mangleNames: mangleNamesOption?.value,
|
172
|
+
forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
|
173
|
+
rootFolderPath
|
174
|
+
}),
|
175
|
+
timeTook = performance.now() - timeStart
|
176
|
+
warnings.length && (process.exitCode = 1)
|
177
|
+
for (const { message } of warnings) console.warn(colourF(`${chalk.bold("Warning:")} ${message}`))
|
178
|
+
await writeFilePersistent(outputPath, script)
|
179
|
+
.catch(error => {
|
180
|
+
if (!commands[2] || "EISDIR" != error.code) throw error
|
181
|
+
outputPath = resolve(outputPath, basename(target, fileExtension) + ".js")
|
182
|
+
return writeFilePersistent(outputPath, script)
|
183
|
+
})
|
184
|
+
.then(() =>
|
185
|
+
log(
|
186
|
+
`Wrote ${chalk.bold(countHackmudCharacters(script))} chars to ${chalk.bold(relative(".", outputPath))} | took ${Math.round(100 * timeTook) / 100}ms`
|
187
|
+
)
|
188
|
+
)
|
189
|
+
})
|
190
|
+
if (watchOption) {
|
191
|
+
const { watch: watchFile } = await chokidarModule
|
192
|
+
watchFile(target, { awaitWriteFinish: { stabilityThreshold: 100 } })
|
193
|
+
.on("ready", () => log("Watching " + target))
|
194
|
+
.on("change", golfFile)
|
195
|
+
autoExit = !1
|
196
|
+
} else await golfFile()
|
197
|
+
} else {
|
198
|
+
const hackmudPath = getHackmudPath(),
|
199
|
+
sourcePath = commands[1]
|
200
|
+
if (!sourcePath) {
|
201
|
+
logError(`Must provide the directory to ${"push" == commands[0] ? "push from" : "watch"}\n`)
|
106
202
|
logHelp()
|
107
203
|
process.exit(1)
|
108
204
|
}
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
const watchOption = popOption("watch"),
|
117
|
-
target = commands[1]
|
118
|
-
if (!target) {
|
119
|
-
logError("Must provide target\n")
|
205
|
+
const scripts = commands.slice(2)
|
206
|
+
if (scripts.length) {
|
207
|
+
const invalidScript = scripts.find(
|
208
|
+
script => !/^(?:[a-z_][a-z\d_]{0,24}|\*)\.(?:[a-z_][a-z\d_]{0,24}|\*)$/.test(script)
|
209
|
+
)
|
210
|
+
if (invalidScript) {
|
211
|
+
logError(`Invalid script name: ${JSON.stringify(invalidScript)}\n`)
|
120
212
|
logHelp()
|
121
213
|
process.exit(1)
|
122
214
|
}
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
215
|
+
} else scripts.push("*.*")
|
216
|
+
const watchOption = popOption("watch")
|
217
|
+
if ("push" != commands[0] || watchOption?.value) {
|
218
|
+
const dtsPathOption = popOption(
|
219
|
+
"dts-path",
|
220
|
+
"type-declaration-path",
|
221
|
+
"type-declaration",
|
222
|
+
"dts",
|
223
|
+
"gen-types"
|
224
|
+
)
|
225
|
+
if (
|
226
|
+
dtsPathOption &&
|
227
|
+
"dts-path" != dtsPathOption.name &&
|
228
|
+
"type-declaration-path" != dtsPathOption.name
|
229
|
+
) {
|
230
|
+
process.exitCode = 1
|
231
|
+
console.warn(
|
232
|
+
colourF(
|
233
|
+
`${chalk.bold("Warning:")} ${formatOption(dtsPathOption.name)} is deprecated and will be removed in the\n next minor release of HSM\n You should switch to using its alias ${colourN("--dts-path")}\n`
|
234
|
+
)
|
127
235
|
)
|
128
|
-
process.exit(1)
|
129
236
|
}
|
130
237
|
complainAboutUnrecognisedOptions()
|
131
|
-
const {
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
dirname(target),
|
144
|
-
fileBaseNameEndsWithDotSrc
|
145
|
-
? scriptName + ".js"
|
146
|
-
: ".js" == fileExtension
|
147
|
-
? fileBaseName + ".min.js"
|
148
|
-
: fileBaseName + ".js"
|
149
|
-
)
|
150
|
-
const golfFile = () =>
|
151
|
-
readFile(target, { encoding: "utf8" }).then(async source => {
|
152
|
-
const timeStart = performance.now(),
|
153
|
-
{ script, warnings } = await processScript(source, {
|
154
|
-
minify: noMinifyOption && !noMinifyOption.value,
|
155
|
-
scriptUser,
|
156
|
-
scriptName,
|
157
|
-
filePath: target,
|
158
|
-
mangleNames: mangleNamesOption?.value,
|
159
|
-
forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
|
160
|
-
rootFolderPath
|
161
|
-
}),
|
162
|
-
timeTook = performance.now() - timeStart
|
163
|
-
warnings.length && (process.exitCode = 1)
|
164
|
-
for (const { message } of warnings)
|
165
|
-
console.warn(colourF(`${chalk.bold("Warning:")} ${message}`))
|
166
|
-
await writeFilePersistent(outputPath, script)
|
167
|
-
.catch(error => {
|
168
|
-
if (!commands[2] || "EISDIR" != error.code) throw error
|
169
|
-
outputPath = resolve(outputPath, basename(target, fileExtension) + ".js")
|
170
|
-
return writeFilePersistent(outputPath, script)
|
171
|
-
})
|
172
|
-
.then(() =>
|
173
|
-
log(
|
174
|
-
`Wrote ${chalk.bold(countHackmudCharacters(script))} chars to ${chalk.bold(relative(".", outputPath))} | took ${Math.round(100 * timeTook) / 100}ms`
|
175
|
-
)
|
176
|
-
)
|
177
|
-
})
|
178
|
-
if (watchOption) {
|
179
|
-
const { watch: watchFile } = await chokidarModule
|
180
|
-
watchFile(target, { awaitWriteFinish: { stabilityThreshold: 100 } })
|
181
|
-
.on("ready", () => log("Watching " + target))
|
182
|
-
.on("change", golfFile)
|
183
|
-
autoExit = !1
|
184
|
-
} else await golfFile()
|
238
|
+
const { watch } = await watchModule
|
239
|
+
watch(sourcePath, hackmudPath, {
|
240
|
+
scripts,
|
241
|
+
onPush: info => logInfo(info, hackmudPath),
|
242
|
+
typeDeclarationPath: dtsPathOption?.value.toString(),
|
243
|
+
minify: noMinifyOption && !noMinifyOption.value,
|
244
|
+
mangleNames: mangleNamesOption?.value,
|
245
|
+
onReady: () => log("Watching"),
|
246
|
+
forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
|
247
|
+
rootFolderPath
|
248
|
+
})
|
249
|
+
autoExit = !1
|
185
250
|
} else {
|
186
|
-
const
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
if (scripts.length) {
|
195
|
-
const invalidScript = scripts.find(
|
196
|
-
script => !/^(?:[a-z_][a-z\d_]{0,24}|\*)\.(?:[a-z_][a-z\d_]{0,24}|\*)$/.test(script)
|
197
|
-
)
|
198
|
-
if (invalidScript) {
|
199
|
-
logError(`Invalid script name: ${JSON.stringify(invalidScript)}\n`)
|
251
|
+
const dtsPathOption = popOption("dts-path")
|
252
|
+
complainAboutUnrecognisedOptions()
|
253
|
+
let declarationPathPromise
|
254
|
+
if (dtsPathOption) {
|
255
|
+
if ("string" != typeof dtsPathOption.value) {
|
256
|
+
logError(
|
257
|
+
`Option ${formatOption(dtsPathOption.name)} must be a string, got ${colourV(dtsPathOption.value)}\n`
|
258
|
+
)
|
200
259
|
logHelp()
|
201
260
|
process.exit(1)
|
202
261
|
}
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
"type-declaration-path" != dtsPathOption.name
|
217
|
-
) {
|
218
|
-
process.exitCode = 1
|
219
|
-
console.warn(
|
220
|
-
colourF(
|
221
|
-
`${chalk.bold("Warning:")} ${formatOption(dtsPathOption.name)} is deprecated and will be removed in the\n next minor release of HSM\n You should switch to using its alias ${colourN("--dts-path")}\n`
|
222
|
-
)
|
223
|
-
)
|
224
|
-
}
|
225
|
-
complainAboutUnrecognisedOptions()
|
226
|
-
const { watch } = await watchModule
|
227
|
-
watch(sourcePath, hackmudPath, {
|
262
|
+
let typeDeclarationPath = resolve(dtsPathOption.value)
|
263
|
+
const typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
|
264
|
+
declarationPathPromise = writeFile(typeDeclarationPath, typeDeclaration)
|
265
|
+
.catch(error => {
|
266
|
+
assert(error instanceof Error, "src/bin/hsm.ts:318:38")
|
267
|
+
if ("EISDIR" != error.code) throw error
|
268
|
+
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
269
|
+
return writeFile(typeDeclarationPath, typeDeclaration)
|
270
|
+
})
|
271
|
+
.then(() => typeDeclarationPath)
|
272
|
+
}
|
273
|
+
const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } = await pushModule,
|
274
|
+
infos = await push(sourcePath, hackmudPath, {
|
228
275
|
scripts,
|
229
276
|
onPush: info => logInfo(info, hackmudPath),
|
230
|
-
typeDeclarationPath: dtsPathOption?.value.toString(),
|
231
277
|
minify: noMinifyOption && !noMinifyOption.value,
|
232
278
|
mangleNames: mangleNamesOption?.value,
|
233
|
-
onReady: () => log("Watching"),
|
234
279
|
forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
|
235
280
|
rootFolderPath
|
236
281
|
})
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
`
|
282
|
+
if (infos instanceof Error) {
|
283
|
+
logError(infos.message)
|
284
|
+
if (infos instanceof MissingSourceFolderError || infos instanceof NoUsersError) {
|
285
|
+
console.log()
|
286
|
+
logHelp()
|
287
|
+
} else
|
288
|
+
infos instanceof MissingHackmudFolderError &&
|
289
|
+
log(
|
290
|
+
`If this is not where your hackmud folder is, you can specify it with the\n${colourN("--hackmud-path")}=${colourB("<path>")} option or ${colourN("HSM_HACKMUD_PATH")} environment variable`
|
246
291
|
)
|
247
|
-
|
248
|
-
|
249
|
-
}
|
250
|
-
let typeDeclarationPath = resolve(dtsPathOption.value)
|
251
|
-
const typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
|
252
|
-
declarationPathPromise = writeFile(typeDeclarationPath, typeDeclaration)
|
253
|
-
.catch(error => {
|
254
|
-
assert(error instanceof Error, "src/bin/hsm.ts:299:38")
|
255
|
-
if ("EISDIR" != error.code) throw error
|
256
|
-
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
257
|
-
return writeFile(typeDeclarationPath, typeDeclaration)
|
258
|
-
})
|
259
|
-
.then(() => typeDeclarationPath)
|
260
|
-
}
|
261
|
-
const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } =
|
262
|
-
await pushModule,
|
263
|
-
infos = await push(sourcePath, hackmudPath, {
|
264
|
-
scripts,
|
265
|
-
onPush: info => logInfo(info, hackmudPath),
|
266
|
-
minify: noMinifyOption && !noMinifyOption.value,
|
267
|
-
mangleNames: mangleNamesOption?.value,
|
268
|
-
forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
|
269
|
-
rootFolderPath
|
270
|
-
})
|
271
|
-
if (infos instanceof Error) {
|
272
|
-
logError(infos.message)
|
273
|
-
if (infos instanceof MissingSourceFolderError || infos instanceof NoUsersError) {
|
274
|
-
console.log()
|
275
|
-
logHelp()
|
276
|
-
} else
|
277
|
-
infos instanceof MissingHackmudFolderError &&
|
278
|
-
log(
|
279
|
-
`If this is not where your hackmud folder is, you can specify it with the\n${colourN("--hackmud-path")}=${colourB("<path>")} option or ${colourN("HSM_HACKMUD_PATH")} environment variable`
|
280
|
-
)
|
281
|
-
} else infos.length || logError("Could not find any scripts to push")
|
282
|
-
declarationPathPromise &&
|
283
|
-
log("Wrote type declaration to " + chalk.bold(await declarationPathPromise))
|
284
|
-
}
|
292
|
+
} else infos.length || logError("Could not find any scripts to push")
|
293
|
+
declarationPathPromise && log("Wrote type declaration to " + chalk.bold(await declarationPathPromise))
|
285
294
|
}
|
286
295
|
}
|
287
296
|
break
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
}
|
297
|
-
complainAboutUnrecognisedOptions()
|
298
|
-
const sourcePath = commands[2] || "."
|
299
|
-
await pull(sourcePath, hackmudPath, script).catch(error => {
|
300
|
-
console.error(error)
|
301
|
-
logError(`Something went wrong, did you forget to ${colourC("#down")} the script?`)
|
302
|
-
})
|
297
|
+
}
|
298
|
+
case "pull": {
|
299
|
+
const hackmudPath = getHackmudPath(),
|
300
|
+
script = commands[1]
|
301
|
+
if (!script) {
|
302
|
+
logError("Must provide the script to pull\n")
|
303
|
+
logHelp()
|
304
|
+
process.exit(1)
|
303
305
|
}
|
306
|
+
complainAboutUnrecognisedOptions()
|
307
|
+
const sourcePath = commands[2] || "."
|
308
|
+
await pull(sourcePath, hackmudPath, script).catch(error => {
|
309
|
+
console.error(error)
|
310
|
+
logError(`Something went wrong, did you forget to ${colourC("#down")} the script?`)
|
311
|
+
})
|
304
312
|
break
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
}
|
313
|
+
}
|
314
|
+
case "sync-macros": {
|
315
|
+
const hackmudPath = getHackmudPath()
|
316
|
+
complainAboutUnrecognisedOptions()
|
317
|
+
const { macrosSynced, usersSynced } = await syncMacros(hackmudPath)
|
318
|
+
log(`Synced ${macrosSynced} macros to ${usersSynced} users`)
|
312
319
|
break
|
320
|
+
}
|
313
321
|
case "generate-type-declaration":
|
314
322
|
case "gen-type-declaration":
|
315
323
|
case "gen-dts":
|
316
324
|
case "gen-types":
|
317
|
-
case "emit-dts":
|
318
|
-
{
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
`${chalk.bold("Warning:")} ${colourC("hsm")} ${colourL(commands[0])} is deprecated and will be removed\n in the next minor release of HSM\n You should switch to using its alias ${colourC("hsm")} ${colourL("emit-dts")}\n`
|
325
|
-
)
|
325
|
+
case "emit-dts": {
|
326
|
+
if ("emit-dts" != commands[0] && "gen-dts" != commands[0]) {
|
327
|
+
warnedDeprecatedEmitDtsAlias = !0
|
328
|
+
process.exitCode = 1
|
329
|
+
console.warn(
|
330
|
+
colourF(
|
331
|
+
`${chalk.bold("Warning:")} ${colourC("hsm")} ${colourL(commands[0])} is deprecated and will be removed\n in the next minor release of HSM\n You should switch to using its alias ${colourC("hsm")} ${colourL("emit-dts")}\n`
|
326
332
|
)
|
327
|
-
|
328
|
-
const hackmudPath = getHackmudPath(),
|
329
|
-
target = commands[1]
|
330
|
-
if (!target) {
|
331
|
-
logError("Must provide target directory\n")
|
332
|
-
logHelp()
|
333
|
-
process.exit(1)
|
334
|
-
}
|
335
|
-
complainAboutUnrecognisedOptions()
|
336
|
-
const sourcePath = resolve(target),
|
337
|
-
outputPath = commands[2] || "./player.d.ts",
|
338
|
-
typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
|
339
|
-
let typeDeclarationPath = resolve(outputPath)
|
340
|
-
await writeFile(typeDeclarationPath, typeDeclaration).catch(error => {
|
341
|
-
assert(error instanceof Error, "src/bin/hsm.ts:438:35")
|
342
|
-
if ("EISDIR" != error.code) throw error
|
343
|
-
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
344
|
-
return writeFile(typeDeclarationPath, typeDeclaration)
|
345
|
-
})
|
346
|
-
log("Wrote type declaration to " + chalk.bold(typeDeclarationPath))
|
333
|
+
)
|
347
334
|
}
|
335
|
+
const hackmudPath = getHackmudPath(),
|
336
|
+
target = commands[1]
|
337
|
+
if (!target) {
|
338
|
+
logError("Must provide target directory\n")
|
339
|
+
logHelp()
|
340
|
+
process.exit(1)
|
341
|
+
}
|
342
|
+
complainAboutUnrecognisedOptions()
|
343
|
+
const sourcePath = resolve(target),
|
344
|
+
outputPath = commands[2] || "./player.d.ts",
|
345
|
+
typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
|
346
|
+
let typeDeclarationPath = resolve(outputPath)
|
347
|
+
await writeFile(typeDeclarationPath, typeDeclaration).catch(error => {
|
348
|
+
assert(error instanceof Error, "src/bin/hsm.ts:462:35")
|
349
|
+
if ("EISDIR" != error.code) throw error
|
350
|
+
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
351
|
+
return writeFile(typeDeclarationPath, typeDeclaration)
|
352
|
+
})
|
353
|
+
log("Wrote type declaration to " + chalk.bold(typeDeclarationPath))
|
348
354
|
break
|
355
|
+
}
|
349
356
|
case "help":
|
350
357
|
logHelp()
|
351
358
|
break
|
@@ -411,7 +418,7 @@ function logHelp() {
|
|
411
418
|
default:
|
412
419
|
console.log(
|
413
420
|
colourS(
|
414
|
-
`${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.1-
|
421
|
+
`${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.1-e3e8246")}\n\n${colourA("Commands:")}\n${colourL("push")}\n ${pushCommandDescription}\n${colourL("minify")}\n Minify a script file on the spot\n${colourL("emit-dts")}\n Generate a type declaration file for a directory of scripts\n${colourL("sync-macros")}\n Sync macros across all hackmud users\n${colourL("pull")}\n Pull a script a from a hackmud user's script directory\n\n${colourA("Options:")}\n${colourN("--help")}\n Can be used on any command e.g. ${colourC("hsm")} ${colourL("push")} ${colourN("--help")} to show helpful information`
|
415
422
|
)
|
416
423
|
)
|
417
424
|
}
|