hackmud-script-manager 0.20.4-c17726e → 0.20.4-c908d16

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.
Files changed (2) hide show
  1. package/bin/hsm.js +126 -57
  2. package/package.json +2 -2
package/bin/hsm.js CHANGED
@@ -24,16 +24,16 @@ const formatOption = name => colourN(`-${1 == name.length ? "" : "-"}${name}`),
24
24
  log = message => console.log(colourS(message))
25
25
  for (const argument of process.argv.slice(2))
26
26
  if ("-" == argument[0]) {
27
- const [key, valueRaw] = argument.split("=")
28
- let value = valueRaw
29
- if (value)
30
- if ("true" == value) value = !0
31
- else if ("false" == value) value = !1
32
- else {
33
- const number = Number(value)
34
- isFinite(number) && (value = number)
35
- }
36
- else value = !0
27
+ const argumentEqualsIndex = argument.indexOf("=")
28
+ let key, value
29
+ if (-1 == argumentEqualsIndex) {
30
+ key = argument
31
+ value = !0
32
+ } else {
33
+ key = argument.slice(0, argumentEqualsIndex)
34
+ value = argument.slice(argumentEqualsIndex + 1)
35
+ "true" == value ? (value = !0) : "false" == value && (value = !1)
36
+ }
37
37
  if ("-" == argument[1]) options.set(key.slice(2), value)
38
38
  else for (const option of key.slice(1)) options.set(option, value)
39
39
  } else commands.push(argument)
@@ -58,13 +58,14 @@ const pushModule = import("../push.js"),
58
58
  process.version.startsWith("v21.") &&
59
59
  console.warn(
60
60
  colourF(
61
- "Warning: Support for Node.js 21 will be dropped in the next minor version of HSM\n You should update your version of Node.js\n https://nodejs.org/en/download/package-manager"
61
+ `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
62
  )
63
63
  )
64
64
  if ("v" == commands[0] || "version" == commands[0] || popOption("version", "v")?.value) {
65
- console.log("0.20.4-c17726e")
65
+ console.log("0.20.4-c908d16")
66
66
  process.exit()
67
67
  }
68
+ let warnedDeprecatedEmitDtsAlias = !1
68
69
  if (popOption("help", "h")?.value) {
69
70
  logHelp()
70
71
  process.exit()
@@ -77,8 +78,15 @@ switch (commands[0]) {
77
78
  case "golf":
78
79
  case "minify":
79
80
  {
80
- const noMinifyOption = popOption("no-minify", "skip-minify"),
81
- mangleNamesOption = popOption("mangle-names"),
81
+ const noMinifyOption = popOption("no-minify", "skip-minify")
82
+ noMinifyOption &&
83
+ "no-minify" != noMinifyOption.name &&
84
+ console.warn(
85
+ colourF(
86
+ `Warning: ${formatOption(noMinifyOption.name)} is being 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"),
82
90
  forceQuineCheatsOption = popOption("force-quine-cheats"),
83
91
  noMinifyIncompatibleOption = mangleNamesOption || forceQuineCheatsOption
84
92
  if (noMinifyOption && noMinifyIncompatibleOption) {
@@ -178,16 +186,67 @@ switch (commands[0]) {
178
186
  process.exit(1)
179
187
  }
180
188
  } else scripts.push("*.*")
181
- if ("push" == commands[0]) {
182
- const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } = await pushModule
189
+ const watchOption = popOption("watch")
190
+ if ("push" != commands[0] || watchOption?.value) {
191
+ const dtsPathOption = popOption(
192
+ "dts-path",
193
+ "type-declaration-path",
194
+ "type-declaration",
195
+ "dts",
196
+ "gen-types"
197
+ )
198
+ dtsPathOption &&
199
+ "dts-path" != dtsPathOption.name &&
200
+ "type-declaration-path" != dtsPathOption.name &&
201
+ console.warn(
202
+ colourF(
203
+ `Warning: ${formatOption(dtsPathOption.name)} is being 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`
204
+ )
205
+ )
183
206
  complainAboutUnrecognisedOptions()
184
- const infos = await push(sourcePath, hackmudPath, {
207
+ const { watch } = await watchModule
208
+ watch(sourcePath, hackmudPath, {
185
209
  scripts,
186
210
  onPush: info => logInfo(info, hackmudPath),
211
+ typeDeclarationPath: dtsPathOption?.value.toString(),
187
212
  minify: noMinifyOption && !noMinifyOption.value,
188
213
  mangleNames: mangleNamesOption?.value,
214
+ onReady: () => log("Watching"),
189
215
  forceQuineCheats: forceQuineCheatsOption?.value
190
216
  })
217
+ autoExit = !1
218
+ } else {
219
+ const dtsPathOption = popOption("dts-path")
220
+ complainAboutUnrecognisedOptions()
221
+ let declarationPathPromise
222
+ if (dtsPathOption) {
223
+ if ("string" != typeof dtsPathOption.value) {
224
+ logError(
225
+ `Option ${formatOption(dtsPathOption.name)} must be a string, got ${colourV(dtsPathOption.value)}\n`
226
+ )
227
+ logHelp()
228
+ process.exit(1)
229
+ }
230
+ let typeDeclarationPath = resolve(dtsPathOption.value)
231
+ const typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
232
+ declarationPathPromise = writeFile(typeDeclarationPath, typeDeclaration)
233
+ .catch(error => {
234
+ assert(error instanceof Error, "src/bin/hsm.ts:274:38")
235
+ if ("EISDIR" != error.code) throw error
236
+ typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
237
+ return writeFile(typeDeclarationPath, typeDeclaration)
238
+ })
239
+ .then(() => typeDeclarationPath)
240
+ }
241
+ const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } =
242
+ await pushModule,
243
+ infos = await push(sourcePath, hackmudPath, {
244
+ scripts,
245
+ onPush: info => logInfo(info, hackmudPath),
246
+ minify: noMinifyOption && !noMinifyOption.value,
247
+ mangleNames: mangleNamesOption?.value,
248
+ forceQuineCheats: forceQuineCheatsOption?.value
249
+ })
191
250
  if (infos instanceof Error) {
192
251
  logError(infos.message)
193
252
  if (infos instanceof MissingSourceFolderError || infos instanceof NoUsersError) {
@@ -199,25 +258,8 @@ switch (commands[0]) {
199
258
  `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`
200
259
  )
201
260
  } else infos.length || logError("Could not find any scripts to push")
202
- } else {
203
- const typeDeclarationPathOption = popOption(
204
- "type-declaration-path",
205
- "type-declaration",
206
- "dts",
207
- "gen-types"
208
- )
209
- complainAboutUnrecognisedOptions()
210
- const { watch } = await watchModule
211
- watch(sourcePath, hackmudPath, {
212
- scripts,
213
- onPush: info => logInfo(info, hackmudPath),
214
- typeDeclarationPath: typeDeclarationPathOption?.value.toString(),
215
- minify: noMinifyOption && !noMinifyOption.value,
216
- mangleNames: mangleNamesOption?.value,
217
- onReady: () => log("Watching"),
218
- forceQuineCheats: forceQuineCheatsOption?.value
219
- })
220
- autoExit = !1
261
+ declarationPathPromise &&
262
+ log("Wrote type declaration to " + chalk.bold(await declarationPathPromise))
221
263
  }
222
264
  }
223
265
  }
@@ -251,7 +293,16 @@ switch (commands[0]) {
251
293
  case "gen-type-declaration":
252
294
  case "gen-dts":
253
295
  case "gen-types":
296
+ case "emit-dts":
254
297
  {
298
+ if ("emit-dts" != commands[0] && "gen-dts" != commands[0]) {
299
+ warnedDeprecatedEmitDtsAlias = !0
300
+ console.warn(
301
+ colourF(
302
+ `Warning: ${colourC("hsm")} ${colourL(commands[0])} is being 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`
303
+ )
304
+ )
305
+ }
255
306
  const hackmudPath = getHackmudPath(),
256
307
  target = commands[1]
257
308
  if (!target) {
@@ -265,7 +316,7 @@ switch (commands[0]) {
265
316
  typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
266
317
  let typeDeclarationPath = resolve(outputPath)
267
318
  await writeFile(typeDeclarationPath, typeDeclaration).catch(error => {
268
- assert(error instanceof Error, "src/bin/hsm.ts:343:35")
319
+ assert(error instanceof Error, "src/bin/hsm.ts:408:35")
269
320
  if ("EISDIR" != error.code) throw error
270
321
  typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
271
322
  return writeFile(typeDeclarationPath, typeDeclaration)
@@ -274,7 +325,6 @@ switch (commands[0]) {
274
325
  }
275
326
  break
276
327
  case "help":
277
- case "h":
278
328
  logHelp()
279
329
  break
280
330
  default:
@@ -286,21 +336,20 @@ function logHelp() {
286
336
  const pushCommandDescription = "Push scripts from a directory to hackmud user's scripts directories",
287
337
  forceQuineCheatsOptionDescription = `Force quine cheats on. Use ${colourN("--force-quine-cheats")}=${colourV("false")} to force off`,
288
338
  hackmudPathOption = `${colourN("--hackmud-path")}=${colourB("<path>")}\n Override hackmud path`
289
- console.log(colourN("Version") + colourS(": ") + colourV("0.20.4-c17726e"))
290
339
  switch (commands[0]) {
291
340
  case "dev":
292
341
  case "watch":
293
342
  case "push":
294
343
  console.log(
295
344
  colourS(
296
- `\n${colourJ("push" == commands[0] ? pushCommandDescription : "Watch a directory and push a script when modified")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB('<directory> ["<script user>.<script name>"...]')}\n\n${colourA("Arguments:")}\n${colourB("<directory>")}\n The source directory containing your scripts\n${colourB("<script user>")}\n A user to push script(s) to. Can be set to wild card (${colourV("*")}) which will try\n and discover users to push to\n${colourB("<script name>")}\n Name of a script to push. Can be set to wild card (${colourV("*")}) to find all scripts\n\n${colourA("Options:")}\n${colourN("--no-minify")}\n Skip minification to produce a "readable" script\n${colourN("--mangle-names")}\n Reduce character count further but lose function names in error call stacks\n${colourN("--force-quine-cheats")}\n ${forceQuineCheatsOptionDescription}\n${hackmudPathOption}\n${"push" == commands[0] ? "" : `${colourN("--type-declaration-path")}=${colourB("<path>")}\n Path to generate a type declaration file for the scripts\n`}\n${colourA("Examples:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")}\n Pushes all scripts found in ${colourV("src")} folder to all users\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("foo")}${colourV(".")}${colourL("bar")}\n Pushes a script named ${colourL("bar")} found in ${colourV("src")} folder to user ${userColours.get("foo")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("foo")}${colourV(".")}${colourL("bar")} ${colourC("baz")}${colourV(".")}${colourL("qux")}\n Multiple can be specified\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("foo")}${colourV(".")}${colourL("*")}\n Pushes all scripts found in ${colourV("src")} folder to user ${userColours.get("foo")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("*")}${colourV(".")}${colourL("foo")}\n Pushes all scripts named ${colourL("foo")} found in ${colourV("src")} folder to all user\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("*")}${colourV(".")}${colourL("*")}\n Pushes all scripts found in ${colourV("src")} folder to all users`
345
+ `${colourJ("push" == commands[0] ? pushCommandDescription : "Watch a directory and push a script when modified")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB('<directory> ["<script user>.<script name>"...]')}\n\n${colourA("Arguments:")}\n${colourB("<directory>")}\n The source directory containing your scripts\n${colourB("<script user>")}\n A user to push script(s) to. Can be set to wild card (${colourV("*")}) which will try\n and discover users to push to\n${colourB("<script name>")}\n Name of a script to push. Can be set to wild card (${colourV("*")}) to find all scripts\n\n${colourA("Options:")}\n${colourN("--no-minify")}\n Skip minification to produce a "readable" script\n${colourN("--mangle-names")}\n Reduce character count further but lose function names in error call stacks\n${colourN("--force-quine-cheats")}\n ${forceQuineCheatsOptionDescription}\n${hackmudPathOption}\n${colourN("--dts-path")}=${colourB("<path>")}\n Path to generate a type declaration (.d.ts) file for the scripts\n${colourN("--watch")}\n Watch for changes\n\n${colourA("Examples:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")}\n Pushes all scripts found in ${colourV("src")} folder to all users\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("foo")}${colourV(".")}${colourL("bar")}\n Pushes a script named ${colourL("bar")} found in ${colourV("src")} folder to user ${userColours.get("foo")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("foo")}${colourV(".")}${colourL("bar")} ${colourC("baz")}${colourV(".")}${colourL("qux")}\n Multiple can be specified\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("foo")}${colourV(".")}${colourL("*")}\n Pushes all scripts found in ${colourV("src")} folder to user ${userColours.get("foo")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("*")}${colourV(".")}${colourL("foo")}\n Pushes all scripts named ${colourL("foo")} found in ${colourV("src")} folder to all user\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("*")}${colourV(".")}${colourL("*")}\n Pushes all scripts found in ${colourV("src")} folder to all users`
297
346
  )
298
347
  )
299
348
  break
300
349
  case "pull":
301
350
  console.log(
302
351
  colourS(
303
- `\n${colourJ("Pull a script a from a hackmud user's script directory")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB("<script user>")}${colourV(".")}${colourB("<script name>")}\n\n${colourA("Options:")}\n${hackmudPathOption}`
352
+ `${colourJ("Pull a script a from a hackmud user's script directory")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB("<script user>")}${colourV(".")}${colourB("<script name>")}\n\n${colourA("Options:")}\n${hackmudPathOption}`
304
353
  )
305
354
  )
306
355
  break
@@ -308,7 +357,7 @@ function logHelp() {
308
357
  case "golf":
309
358
  console.log(
310
359
  colourS(
311
- `\n${colourJ("Minify a script file on the spot")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB("<target> [output path]")}\n\n${colourA("Options:")}\n${colourN("--no-minify")}\n Skip minification to produce a "readable" script\n${colourN("--mangle-names")}\n Reduce character count further but lose function names in error call stacks\n${colourN("--force-quine-cheats")}\n ${forceQuineCheatsOptionDescription}\n${colourN("--watch")}\n Watch for changes`
360
+ `${colourJ("Minify a script file on the spot")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB("<target> [output path]")}\n\n${colourA("Options:")}\n${colourN("--no-minify")}\n Skip minification to produce a "readable" script\n${colourN("--mangle-names")}\n Reduce character count further but lose function names in error call stacks\n${colourN("--force-quine-cheats")}\n ${forceQuineCheatsOptionDescription}\n${colourN("--watch")}\n Watch for changes`
312
361
  )
313
362
  )
314
363
  break
@@ -316,6 +365,15 @@ function logHelp() {
316
365
  case "gen-type-declaration":
317
366
  case "gen-dts":
318
367
  case "gen-types":
368
+ case "emit-dts":
369
+ warnedDeprecatedEmitDtsAlias ||
370
+ "emit-dts" == commands[0] ||
371
+ "gen-dts" == commands[0] ||
372
+ console.warn(
373
+ colourF(
374
+ `Warning: ${colourC("hsm")} ${colourL(commands[0])} is being 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`
375
+ )
376
+ )
319
377
  console.log(
320
378
  colourS(
321
379
  `${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}`
@@ -325,14 +383,14 @@ function logHelp() {
325
383
  case "sync-macros":
326
384
  console.log(
327
385
  colourS(
328
- `\n${colourJ("Sync macros across all hackmud users")}\n\n${colourA("Options:")}\n${hackmudPathOption}`
386
+ `${colourJ("Sync macros across all hackmud users")}\n\n${colourA("Options:")}\n${hackmudPathOption}`
329
387
  )
330
388
  )
331
389
  break
332
390
  default:
333
391
  console.log(
334
392
  colourS(
335
- `\n${colourJ("Hackmud Script Manager")}\n\n${colourA("Commands:")}\n${colourL("push")}\n ${pushCommandDescription}\n${colourL("dev")}\n Watch a directory and push a script when modified\n${colourL("golf")}\n Minify a script file on the spot\n${colourL("gen-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`
393
+ `${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.20.4-c908d16")}\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`
336
394
  )
337
395
  )
338
396
  }
@@ -350,17 +408,29 @@ function logError(message) {
350
408
  process.exitCode = 1
351
409
  }
352
410
  function getHackmudPath() {
353
- const hackmudPathOption = popOption("hackmud-path")?.value
354
- if (null != hackmudPathOption && "string" != typeof hackmudPathOption) {
355
- logError(`Option ${colourN("--hackmud-path")} must be a string, got ${colourV(hackmudPathOption)}\n`)
356
- logHelp()
357
- process.exit(1)
411
+ const hackmudPathOption = popOption("hackmud-path")
412
+ if (hackmudPathOption) {
413
+ if ("string" != typeof hackmudPathOption.value) {
414
+ logError(`Option ${colourN("--hackmud-path")} must be a string, got ${colourV(hackmudPathOption.value)}\n`)
415
+ logHelp()
416
+ process.exit(1)
417
+ }
418
+ if (!hackmudPathOption.value) {
419
+ logError(`Option ${colourN("--hackmud-path")} was specified but empty\n`)
420
+ logHelp()
421
+ process.exit(1)
422
+ }
423
+ return hackmudPathOption.value
358
424
  }
359
- return (
360
- hackmudPathOption ||
361
- process.env.HSM_HACKMUD_PATH ||
362
- ("win32" == process.platform ? resolve(process.env.APPDATA, "hackmud") : resolve(homedir(), ".config/hackmud"))
363
- )
425
+ if (null != process.env.HSM_HACKMUD_PATH) {
426
+ if (!process.env.HSM_HACKMUD_PATH) {
427
+ logError(`Environment variable ${colourN("HSM_HACKMUD_PATH")} was specified but empty\n`)
428
+ logHelp()
429
+ process.exit(1)
430
+ }
431
+ return process.env.HSM_HACKMUD_PATH
432
+ }
433
+ return "win32" == process.platform ? resolve(process.env.APPDATA, "hackmud") : resolve(homedir(), ".config/hackmud")
364
434
  }
365
435
  function assertOptionIsBoolean(option) {
366
436
  if ("boolean" != typeof option.value) {
@@ -372,16 +442,15 @@ function assertOptionIsBoolean(option) {
372
442
  function popOption(...names) {
373
443
  const presentOptionNames = names.filter(name => options.has(name))
374
444
  if (!presentOptionNames.length) return
375
- const presentOptionNamesWithDashDash = presentOptionNames.map(formatOption)
376
445
  if (presentOptionNames.length > 1) {
377
446
  logError(
378
- `The options ${presentOptionNamesWithDashDash.join(", ")} are aliases for each other. Please only specify one`
447
+ `The options ${presentOptionNames.map(formatOption).join(", ")} are aliases for each other. Please only specify one`
379
448
  )
380
449
  process.exit(1)
381
450
  }
382
451
  const value = options.get(presentOptionNames[0])
383
452
  options.delete(presentOptionNames[0])
384
- return { name: presentOptionNamesWithDashDash[0], value }
453
+ return { name: presentOptionNames[0], value }
385
454
  }
386
455
  function complainAboutUnrecognisedOptions() {
387
456
  if (options.size) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hackmud-script-manager",
3
- "version": "0.20.4-c17726e",
3
+ "version": "0.20.4-c908d16",
4
4
  "description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
5
5
  "keywords": [
6
6
  "api",
@@ -86,6 +86,6 @@
86
86
  "hsm": "bin/hsm.js"
87
87
  },
88
88
  "engines": {
89
- "node": "^18 || ^20 || >=22"
89
+ "node": "^18 || >=20"
90
90
  }
91
91
  }