hackmud-script-manager 0.21.1-583d190 → 0.21.1-591fafe
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 +47 -39
- package/bin/hsm.js +260 -244
- package/env.d.ts +326 -270
- package/generateTypeDeclaration.js +24 -23
- package/index.js +2 -3
- package/package.json +26 -24
- package/processScript/index.d.ts +12 -9
- package/processScript/index.js +91 -75
- package/processScript/minify.d.ts +11 -8
- package/processScript/minify.js +13 -16
- package/processScript/preprocess.d.ts +4 -2
- package/processScript/preprocess.js +15 -15
- package/processScript/transform.d.ts +8 -6
- package/processScript/transform.js +129 -50
- package/pull.d.ts +6 -4
- package/pull.js +1 -1
- package/push.d.ts +23 -18
- package/push.js +9 -7
- package/syncMacros.js +14 -15
- package/watch.d.ts +11 -7
- package/watch.js +26 -17
package/bin/hsm.js
CHANGED
@@ -1,27 +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
|
-
import "path/posix"
|
15
14
|
import "@samual/lib/copyFilePersistent"
|
16
|
-
const
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
let hash = 0
|
21
|
-
for (const char of user) hash += (hash >> 1) + hash + "xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(char) + 1
|
22
|
-
return [colourJ, colourK, colourM, colourW, colourL, colourB][hash % 6](user)
|
23
|
-
}),
|
24
|
-
log = message => console.log(colourS(message))
|
15
|
+
const options = new Map(),
|
16
|
+
commands = []
|
17
|
+
let didParseOption = !1,
|
18
|
+
didParseOptionAfterCommand = !1
|
25
19
|
for (const argument of process.argv.slice(2))
|
26
20
|
if ("-" == argument[0]) {
|
27
21
|
const argumentEqualsIndex = argument.indexOf("=")
|
@@ -36,7 +30,11 @@ for (const argument of process.argv.slice(2))
|
|
36
30
|
}
|
37
31
|
if ("-" == argument[1]) options.set(key.slice(2), value)
|
38
32
|
else for (const option of key.slice(1)) options.set(option, value)
|
39
|
-
|
33
|
+
didParseOption = !0
|
34
|
+
} else {
|
35
|
+
didParseOption && (didParseOptionAfterCommand = !0)
|
36
|
+
commands.push(argument)
|
37
|
+
}
|
40
38
|
const pushModule = import("../push.js"),
|
41
39
|
processScriptModule = import("../processScript/index.js"),
|
42
40
|
watchModule = import("../watch.js"),
|
@@ -54,15 +52,33 @@ const pushModule = import("../push.js"),
|
|
54
52
|
colourN = chalk.rgb(0, 255, 255),
|
55
53
|
colourS = chalk.rgb(122, 178, 244),
|
56
54
|
colourV = chalk.rgb(255, 0, 236),
|
57
|
-
colourW = chalk.rgb(255, 150, 224)
|
58
|
-
|
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
|
+
}
|
72
|
+
if (process.version.startsWith("v21.")) {
|
73
|
+
process.exitCode = 1
|
59
74
|
console.warn(
|
60
75
|
colourF(
|
61
76
|
`${chalk.bold("Warning:")} Support for Node.js 21 will be dropped in the next minor version of HSM\n Your current version of Node.js is ${chalk.bold(process.version)}\n You should update your version of Node.js\n https://nodejs.org/en/download/package-manager\n`
|
62
77
|
)
|
63
78
|
)
|
79
|
+
}
|
64
80
|
if ("v" == commands[0] || "version" == commands[0] || popOption("version", "v")?.value) {
|
65
|
-
console.log("0.21.1-
|
81
|
+
console.log("0.21.1-591fafe")
|
66
82
|
process.exit()
|
67
83
|
}
|
68
84
|
let warnedDeprecatedEmitDtsAlias = !1
|
@@ -76,268 +92,267 @@ switch (commands[0]) {
|
|
76
92
|
case "dev":
|
77
93
|
case "watch":
|
78
94
|
case "golf":
|
79
|
-
case "minify":
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
`${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`
|
87
|
-
)
|
88
|
-
)
|
89
|
-
const mangleNamesOption = popOption("mangle-names"),
|
90
|
-
forceQuineCheatsOption = popOption("force-quine-cheats"),
|
91
|
-
noQuineCheatsOptions = popOption("no-quine-cheats"),
|
92
|
-
noMinifyIncompatibleOption = mangleNamesOption || forceQuineCheatsOption || noQuineCheatsOptions
|
93
|
-
if (noMinifyOption && noMinifyIncompatibleOption) {
|
94
|
-
logError(
|
95
|
-
`Options ${formatOption(noMinifyOption.name)} and ${formatOption(noMinifyIncompatibleOption.name)} are incompatible\n`
|
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`
|
96
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")
|
97
134
|
logHelp()
|
98
135
|
process.exit(1)
|
99
136
|
}
|
100
|
-
|
137
|
+
const fileExtension = extname(target)
|
138
|
+
if (!supportedExtensions.includes(fileExtension)) {
|
101
139
|
logError(
|
102
|
-
`
|
140
|
+
`Unsupported file extension "${chalk.bold(fileExtension)}"\nSupported extensions are "${supportedExtensions.map(extension => chalk.bold(extension)).join('", "')}"`
|
103
141
|
)
|
142
|
+
process.exit(1)
|
143
|
+
}
|
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"
|
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`)
|
104
202
|
logHelp()
|
105
203
|
process.exit(1)
|
106
204
|
}
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
const watchOption = popOption("watch"),
|
115
|
-
target = commands[1]
|
116
|
-
if (!target) {
|
117
|
-
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`)
|
118
212
|
logHelp()
|
119
213
|
process.exit(1)
|
120
214
|
}
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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
|
+
)
|
125
235
|
)
|
126
|
-
process.exit(1)
|
127
236
|
}
|
128
237
|
complainAboutUnrecognisedOptions()
|
129
|
-
const {
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
commands[2] ||
|
142
|
-
resolve(
|
143
|
-
dirname(target),
|
144
|
-
fileBaseNameEndsWithDotSrc ? scriptName + ".js"
|
145
|
-
: ".js" == fileExtension ? fileBaseName + ".min.js"
|
146
|
-
: fileBaseName + ".js"
|
147
|
-
)
|
148
|
-
const golfFile = () =>
|
149
|
-
readFile(target, { encoding: "utf8" }).then(async source => {
|
150
|
-
const timeStart = performance.now(),
|
151
|
-
{ script, warnings } = await processScript(source, {
|
152
|
-
minify: noMinifyOption && !noMinifyOption.value,
|
153
|
-
scriptUser,
|
154
|
-
scriptName,
|
155
|
-
filePath: target,
|
156
|
-
mangleNames: mangleNamesOption?.value,
|
157
|
-
forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
|
158
|
-
rootFolderPath
|
159
|
-
}),
|
160
|
-
timeTook = performance.now() - timeStart
|
161
|
-
for (const { message } of warnings)
|
162
|
-
console.warn(colourF(`${chalk.bold("Warning:")} ${message}`))
|
163
|
-
await writeFilePersistent(outputPath, script)
|
164
|
-
.catch(error => {
|
165
|
-
if (!commands[2] || "EISDIR" != error.code) throw error
|
166
|
-
outputPath = resolve(outputPath, basename(target, fileExtension) + ".js")
|
167
|
-
return writeFilePersistent(outputPath, script)
|
168
|
-
})
|
169
|
-
.then(() =>
|
170
|
-
log(
|
171
|
-
`Wrote ${chalk.bold(countHackmudCharacters(script))} chars to ${chalk.bold(relative(".", outputPath))} | took ${Math.round(100 * timeTook) / 100}ms`
|
172
|
-
)
|
173
|
-
)
|
174
|
-
})
|
175
|
-
if (watchOption) {
|
176
|
-
const { watch: watchFile } = await chokidarModule
|
177
|
-
watchFile(target, { awaitWriteFinish: { stabilityThreshold: 100 } })
|
178
|
-
.on("ready", () => log("Watching " + target))
|
179
|
-
.on("change", golfFile)
|
180
|
-
autoExit = !1
|
181
|
-
} 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
|
182
250
|
} else {
|
183
|
-
const
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
if (scripts.length) {
|
192
|
-
const invalidScript = scripts.find(
|
193
|
-
script => !/^(?:[a-z_][a-z\d_]{0,24}|\*)\.(?:[a-z_][a-z\d_]{0,24}|\*)$/.test(script)
|
194
|
-
)
|
195
|
-
if (invalidScript) {
|
196
|
-
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
|
+
)
|
197
259
|
logHelp()
|
198
260
|
process.exit(1)
|
199
261
|
}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
console.warn(
|
214
|
-
colourF(
|
215
|
-
`${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`
|
216
|
-
)
|
217
|
-
)
|
218
|
-
complainAboutUnrecognisedOptions()
|
219
|
-
const { watch } = await watchModule
|
220
|
-
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, {
|
221
275
|
scripts,
|
222
276
|
onPush: info => logInfo(info, hackmudPath),
|
223
|
-
typeDeclarationPath: dtsPathOption?.value.toString(),
|
224
277
|
minify: noMinifyOption && !noMinifyOption.value,
|
225
278
|
mangleNames: mangleNamesOption?.value,
|
226
|
-
onReady: () => log("Watching"),
|
227
279
|
forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
|
228
280
|
rootFolderPath
|
229
281
|
})
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
`
|
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`
|
239
291
|
)
|
240
|
-
|
241
|
-
|
242
|
-
}
|
243
|
-
let typeDeclarationPath = resolve(dtsPathOption.value)
|
244
|
-
const typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
|
245
|
-
declarationPathPromise = writeFile(typeDeclarationPath, typeDeclaration)
|
246
|
-
.catch(error => {
|
247
|
-
assert(error instanceof Error, "src/bin/hsm.ts:292:38")
|
248
|
-
if ("EISDIR" != error.code) throw error
|
249
|
-
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
250
|
-
return writeFile(typeDeclarationPath, typeDeclaration)
|
251
|
-
})
|
252
|
-
.then(() => typeDeclarationPath)
|
253
|
-
}
|
254
|
-
const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } =
|
255
|
-
await pushModule,
|
256
|
-
infos = await push(sourcePath, hackmudPath, {
|
257
|
-
scripts,
|
258
|
-
onPush: info => logInfo(info, hackmudPath),
|
259
|
-
minify: noMinifyOption && !noMinifyOption.value,
|
260
|
-
mangleNames: mangleNamesOption?.value,
|
261
|
-
forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
|
262
|
-
rootFolderPath
|
263
|
-
})
|
264
|
-
if (infos instanceof Error) {
|
265
|
-
logError(infos.message)
|
266
|
-
if (infos instanceof MissingSourceFolderError || infos instanceof NoUsersError) {
|
267
|
-
console.log()
|
268
|
-
logHelp()
|
269
|
-
} else
|
270
|
-
infos instanceof MissingHackmudFolderError &&
|
271
|
-
log(
|
272
|
-
`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`
|
273
|
-
)
|
274
|
-
} else infos.length || logError("Could not find any scripts to push")
|
275
|
-
declarationPathPromise &&
|
276
|
-
log("Wrote type declaration to " + chalk.bold(await declarationPathPromise))
|
277
|
-
}
|
292
|
+
} else infos.length || logError("Could not find any scripts to push")
|
293
|
+
declarationPathPromise && log("Wrote type declaration to " + chalk.bold(await declarationPathPromise))
|
278
294
|
}
|
279
295
|
}
|
280
296
|
break
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
}
|
290
|
-
complainAboutUnrecognisedOptions()
|
291
|
-
const sourcePath = commands[2] || "."
|
292
|
-
await pull(sourcePath, hackmudPath, script).catch(error => {
|
293
|
-
console.error(error)
|
294
|
-
logError(`Something went wrong, did you forget to ${colourC("#down")} the script?`)
|
295
|
-
})
|
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)
|
296
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
|
+
})
|
297
312
|
break
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
}
|
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`)
|
305
319
|
break
|
320
|
+
}
|
306
321
|
case "generate-type-declaration":
|
307
322
|
case "gen-type-declaration":
|
308
323
|
case "gen-dts":
|
309
324
|
case "gen-types":
|
310
|
-
case "emit-dts":
|
311
|
-
{
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
)
|
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`
|
318
332
|
)
|
319
|
-
|
320
|
-
const hackmudPath = getHackmudPath(),
|
321
|
-
target = commands[1]
|
322
|
-
if (!target) {
|
323
|
-
logError("Must provide target directory\n")
|
324
|
-
logHelp()
|
325
|
-
process.exit(1)
|
326
|
-
}
|
327
|
-
complainAboutUnrecognisedOptions()
|
328
|
-
const sourcePath = resolve(target),
|
329
|
-
outputPath = commands[2] || "./player.d.ts",
|
330
|
-
typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
|
331
|
-
let typeDeclarationPath = resolve(outputPath)
|
332
|
-
await writeFile(typeDeclarationPath, typeDeclaration).catch(error => {
|
333
|
-
assert(error instanceof Error, "src/bin/hsm.ts:428:35")
|
334
|
-
if ("EISDIR" != error.code) throw error
|
335
|
-
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
336
|
-
return writeFile(typeDeclarationPath, typeDeclaration)
|
337
|
-
})
|
338
|
-
log("Wrote type declaration to " + chalk.bold(typeDeclarationPath))
|
333
|
+
)
|
339
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))
|
340
354
|
break
|
355
|
+
}
|
341
356
|
case "help":
|
342
357
|
logHelp()
|
343
358
|
break
|
@@ -379,14 +394,14 @@ function logHelp() {
|
|
379
394
|
case "gen-dts":
|
380
395
|
case "gen-types":
|
381
396
|
case "emit-dts":
|
382
|
-
warnedDeprecatedEmitDtsAlias
|
383
|
-
|
384
|
-
"gen-dts" == commands[0] ||
|
397
|
+
if (!warnedDeprecatedEmitDtsAlias && "emit-dts" != commands[0] && "gen-dts" != commands[0]) {
|
398
|
+
process.exitCode = 1
|
385
399
|
console.warn(
|
386
400
|
colourF(
|
387
401
|
`${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`
|
388
402
|
)
|
389
403
|
)
|
404
|
+
}
|
390
405
|
console.log(
|
391
406
|
colourS(
|
392
407
|
`${colourJ("Generate a type declaration file for a directory of scripts")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB("<directory> [output path]")}\n\n${colourA("Options:")}\n${hackmudPathOption}`
|
@@ -403,7 +418,7 @@ function logHelp() {
|
|
403
418
|
default:
|
404
419
|
console.log(
|
405
420
|
colourS(
|
406
|
-
`${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-591fafe")}\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`
|
407
422
|
)
|
408
423
|
)
|
409
424
|
}
|
@@ -412,6 +427,7 @@ function logInfo({ path, users, characterCount, error, warnings }, hackmudPath)
|
|
412
427
|
path = relative(".", path)
|
413
428
|
if (error) logError(`Error "${chalk.bold(error.message)}" in ${chalk.bold(path)}`)
|
414
429
|
else {
|
430
|
+
warnings.length && (process.exitCode = 1)
|
415
431
|
for (const warning of warnings) console.warn(colourF(`${chalk.bold("Warning:")} ${warning.message}`))
|
416
432
|
log(
|
417
433
|
`Pushed ${chalk.bold(path)} to ${users.map(user => chalk.bold(userColours.get(user))).join(", ")} | ${chalk.bold(characterCount + "")} chars | ${chalk.bold(resolve(hackmudPath, users[0], "scripts", basename(path, extname(path))) + ".js")}`
|