hackmud-script-manager 0.19.1-5bceac8 → 0.19.1-6d8d544

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  # Hackmud Script Manager
2
2
  Command made for [hackmud-environment](https://github.com/samualtnorman/hackmud-environment), which is a scripting environment for hackmud with minification, autocompletes / intellisense, and TypeScript support.
3
3
 
4
- Install with `npm install hackmud-script-manager -g` to make the `hsm` command available everywhere.
4
+ Install with `npm install -g hackmud-script-manager` to make the `hsm` command available everywhere.
5
5
 
6
6
  ## Features
7
7
  - Minification
package/bin/hsm.d.ts CHANGED
File without changes
package/bin/hsm.js CHANGED
@@ -3,16 +3,16 @@ import { Cache } from "@samual/lib/Cache"
3
3
  import { assert } from "@samual/lib/assert"
4
4
  import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
5
5
  import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
6
- import { readFile, writeFile, mkdir, rmdir } from "fs/promises"
6
+ import { writeFile, readFile } from "fs/promises"
7
7
  import { homedir } from "os"
8
- import { resolve, extname, basename, dirname, relative } from "path"
8
+ import { extname, basename, resolve, dirname, relative } from "path"
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
+ import "@samual/lib/readDirectoryWithStats"
13
14
  import "@samual/lib/copyFilePersistent"
14
- const configDirectoryPath = resolve(homedir(), ".config"),
15
- configFilePath = resolve(configDirectoryPath, "hsm.json"),
15
+ const version = "0.19.1-6d8d544",
16
16
  options = new Map(),
17
17
  commands = [],
18
18
  userColours = new Cache(user => {
@@ -20,119 +20,7 @@ const configDirectoryPath = resolve(homedir(), ".config"),
20
20
  for (const char of user) hash += (hash >> 1) + hash + "xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(char) + 1
21
21
  return [colourJ, colourK, colourM, colourW, colourL, colourB][hash % 6](user)
22
22
  }),
23
- logNeedHackmudPathMessage = () =>
24
- console.error(
25
- colourS(
26
- `${colourD("You need to set hackmudPath in config before you can use this command")}\n\n${colourA("To fix this:")}\nOpen hackmud and run "${colourC("#dir")}"\nThis will open a file browser and print your hackmud user's script directory\nGo up 2 directories and then copy the path\nThen in a terminal run "${colourC("hsm")} ${colourL("config set")} ${colourV("hackmudPath")} ${colourB("<the path you copied>")}"`
27
- )
28
- ),
29
- logHelp = () => {
30
- const pushCommandDescription = "Push scripts from a directory to hackmud user's scripts directories",
31
- mangleNamesOptionDescription =
32
- "Reduce character count further but lose function names in error call stacks",
33
- forceQuineCheatsOptionDescription = `Force quine cheats on. Use ${colourN("--force-quine-cheats")}=${colourV("false")} to force off.`
34
- console.log(colourN("Version") + colourS(": ") + colourV("0.19.1-5bceac8"))
35
- switch (commands[0]) {
36
- case "config":
37
- switch (commands[1]) {
38
- case "get":
39
- console.log(
40
- `\n${colourJ("Retrieve a value from the config file")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(`${commands[0]} ${commands[1]}`)} ${colourB("<key>")}`
41
- )
42
- break
43
- case "set":
44
- console.log(
45
- `\n${colourJ("Assign a value to the config file")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(`${commands[0]} ${commands[1]}`)} ${colourB("<key> <value>")}`
46
- )
47
- break
48
- case "delete":
49
- console.log(
50
- `\n${colourJ("Remove a key and value from the config file")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(`${commands[0]} ${commands[1]}`)} ${colourB("<key>")}`
51
- )
52
- break
53
- default:
54
- console.log(
55
- colourS(
56
- `${colourN("Config path")}: ${colourV(configFilePath)}\n\n${colourJ("Modify the config file")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0] + " get")} ${colourB("<key>")}\n Retrieve a value from the config file\n${colourC("hsm")} ${colourL(commands[0] + " set")} ${colourB("<key> <value>")}\n Assign a value to the config file\n${colourC("hsm")} ${colourL(commands[0] + " delete")} ${colourB("<key>")}\n Remove a key and value from the config file`
57
- )
58
- )
59
- }
60
- break
61
- case "push":
62
- console.log(
63
- colourS(
64
- `\n${colourJ(pushCommandDescription)}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB("<directory> [<script user>.<script name>...]")}\n\n${colourA("Options:")}\n${colourN("--no-minify")}\n Skip minification to produce a "readable" script\n${colourN("--mangle-names")}\n ${mangleNamesOptionDescription}\n${colourN("--force-quine-cheats")}\n ${forceQuineCheatsOptionDescription}`
65
- )
66
- )
67
- break
68
- case "dev":
69
- case "watch":
70
- console.log(
71
- colourS(
72
- `\n${colourJ("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("Options:")}\n${colourN("--no-minify")}\n Skip minification to produce a "readable" script\n${colourN("--mangle-names")}\n ${mangleNamesOptionDescription}\n${colourN("--type-declaration-path")}=${colourB("<path>")}\n Path to generate a type declaration file for the scripts\n${colourN("--force-quine-cheats")}\n ${forceQuineCheatsOptionDescription}`
73
- )
74
- )
75
- break
76
- case "pull":
77
- console.log(
78
- colourS(
79
- `\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>")}`
80
- )
81
- )
82
- break
83
- case "minify":
84
- case "golf":
85
- console.log(
86
- colourS(
87
- `\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 ${mangleNamesOptionDescription}\n${colourN("--force-quine-cheats")}\n ${forceQuineCheatsOptionDescription}\n${colourN("--watch")}\n Watch for changes`
88
- )
89
- )
90
- break
91
- case "generate-type-declaration":
92
- case "gen-type-declaration":
93
- case "gen-dts":
94
- case "gen-types":
95
- console.log(
96
- colourS(
97
- `${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]")}`
98
- )
99
- )
100
- break
101
- case "sync-macros":
102
- console.log("\n" + colourJ("Sync macros across all hackmud users"))
103
- break
104
- default:
105
- console.log(
106
- colourS(
107
- `\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("config")}\n Modify and view the config file\n${colourL("pull")}\n Pull a script a from a hackmud user's script directory`
108
- )
109
- )
110
- }
111
- },
112
- exploreObject = (object, keys, createPath = !1) => {
113
- for (const key of keys)
114
- object =
115
- createPath ?
116
- "object" == typeof object[key] ?
117
- object[key]
118
- : (object[key] = {})
119
- : object?.[key]
120
- return object
121
- },
122
- logInfo = ({ file, users, minLength, error }, hackmudPath) => {
123
- error ?
124
- logError(`error "${chalk.bold(error.message)}" in ${chalk.bold(file)}`)
125
- : console.log(
126
- `pushed ${chalk.bold(file)} to ${users.map(user => chalk.bold(userColours.get(user))).join(", ")} | ${chalk.bold(minLength + "")} chars | ${chalk.bold(resolve(hackmudPath, users[0], "scripts", basename(file, extname(file))) + ".js")}`
127
- )
128
- },
129
- log = message => {
130
- console.log(colourS(message))
131
- },
132
- logError = message => {
133
- console.error(colourD(message))
134
- process.exitCode = 1
135
- }
23
+ log = message => console.log(colourS(message))
136
24
  for (const argument of process.argv.slice(2))
137
25
  if ("-" == argument[0]) {
138
26
  const [key, valueRaw] = argument.split("=")
@@ -149,35 +37,10 @@ for (const argument of process.argv.slice(2))
149
37
  else for (const option of key.slice(1)) options.set(option, value)
150
38
  } else commands.push(argument)
151
39
  if ("v" == commands[0] || "version" == commands[0] || options.get("version") || options.get("v")) {
152
- console.log("0.19.1-5bceac8")
40
+ console.log(version)
153
41
  process.exit()
154
42
  }
155
- let configDidNotExist = !1
156
- const configPromise = readFile(configFilePath, { encoding: "utf-8" }).then(
157
- configFile => {
158
- let temporaryConfig
159
- try {
160
- temporaryConfig = JSON.parse(configFile)
161
- } catch {
162
- log("Config file was corrupted, resetting")
163
- return {}
164
- }
165
- if (!temporaryConfig || "object" != typeof temporaryConfig) {
166
- log("Config file was corrupted, resetting")
167
- return {}
168
- }
169
- if ("hackmudPath" in temporaryConfig && "string" != typeof temporaryConfig.hackmudPath) {
170
- log('Property "hackmudPath" of config file was corrupted, removing')
171
- delete temporaryConfig.hackmudPath
172
- }
173
- return temporaryConfig
174
- },
175
- () => {
176
- configDidNotExist = !0
177
- return {}
178
- }
179
- ),
180
- pushModule = import("../push.js"),
43
+ const pushModule = import("../push.js"),
181
44
  processScriptModule = import("../processScript/index.js"),
182
45
  watchModule = import("../watch.js"),
183
46
  chokidarModule = import("chokidar"),
@@ -202,12 +65,8 @@ let autoExit = !0
202
65
  switch (commands[0]) {
203
66
  case "push":
204
67
  {
205
- const { hackmudPath } = await configPromise
206
- if (!hackmudPath) {
207
- logNeedHackmudPathMessage()
208
- break
209
- }
210
- const sourcePath = commands[1]
68
+ const hackmudPath = getHackmudPath(),
69
+ sourcePath = commands[1]
211
70
  if (!sourcePath) {
212
71
  logError("Must provide the directory to push from\n")
213
72
  logHelp()
@@ -275,12 +134,8 @@ switch (commands[0]) {
275
134
  case "dev":
276
135
  case "watch":
277
136
  {
278
- const { hackmudPath } = await configPromise
279
- if (!hackmudPath) {
280
- logNeedHackmudPathMessage()
281
- break
282
- }
283
- const sourcePath = commands[1]
137
+ const hackmudPath = getHackmudPath(),
138
+ sourcePath = commands[1]
284
139
  if (!sourcePath) {
285
140
  logError("Must provide the directory to watch\n")
286
141
  logHelp()
@@ -353,34 +208,24 @@ switch (commands[0]) {
353
208
  break
354
209
  case "pull":
355
210
  {
356
- const { hackmudPath } = await configPromise
357
- if (!hackmudPath) {
358
- logNeedHackmudPathMessage()
359
- break
360
- }
361
- const script = commands[1]
211
+ const hackmudPath = getHackmudPath(),
212
+ script = commands[1]
362
213
  if (!script) {
363
214
  logError("Must provide the script to pull\n")
364
215
  logHelp()
365
216
  break
366
217
  }
367
218
  const sourcePath = commands[2] || "."
368
- try {
369
- await pull(sourcePath, hackmudPath, script)
370
- } catch (error) {
219
+ await pull(sourcePath, hackmudPath, script).catch(error => {
371
220
  console.error(error)
372
221
  logError(`Something went wrong, did you forget to ${colourC("#down")} the script?`)
373
- }
222
+ })
374
223
  }
375
224
  break
376
225
  case "sync-macros":
377
226
  {
378
- const { hackmudPath } = await configPromise
379
- if (!hackmudPath) {
380
- logNeedHackmudPathMessage()
381
- break
382
- }
383
- const { macrosSynced, usersSynced } = await syncMacros(hackmudPath)
227
+ const hackmudPath = getHackmudPath(),
228
+ { macrosSynced, usersSynced } = await syncMacros(hackmudPath)
384
229
  log(`Synced ${macrosSynced} macros to ${usersSynced} users`)
385
230
  }
386
231
  break
@@ -397,100 +242,17 @@ switch (commands[0]) {
397
242
  }
398
243
  const sourcePath = resolve(target),
399
244
  outputPath = commands[2] || "./player.d.ts",
400
- typeDeclaration = await generateTypeDeclaration(sourcePath, (await configPromise).hackmudPath)
245
+ typeDeclaration = await generateTypeDeclaration(sourcePath, getHackmudPath())
401
246
  let typeDeclarationPath = resolve(outputPath)
402
- try {
403
- await writeFile(typeDeclarationPath, typeDeclaration)
404
- } catch (error) {
405
- assert(error instanceof Error)
247
+ await writeFile(typeDeclarationPath, typeDeclaration).catch(error => {
248
+ assert(error instanceof Error, "src/bin/hsm.ts:327:35")
406
249
  if ("EISDIR" != error.code) throw error
407
250
  typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
408
- await writeFile(typeDeclarationPath, typeDeclaration)
409
- }
251
+ return writeFile(typeDeclarationPath, typeDeclaration)
252
+ })
410
253
  log("Wrote type declaration to " + chalk.bold(typeDeclarationPath))
411
254
  }
412
255
  break
413
- case "config":
414
- switch (commands[1]) {
415
- case "get":
416
- {
417
- const key = commands[2]
418
- key ? log(exploreObject(await configPromise, key.split("."))) : console.log(await configPromise)
419
- }
420
- break
421
- case "delete":
422
- {
423
- const key = commands[2]
424
- if (!key) {
425
- logError("Must provide a key to delete\n")
426
- logHelp()
427
- break
428
- }
429
- const keyParts = key.split("."),
430
- pathName = keyParts
431
- .map(name => (/^[a-z_$][\w$]*$/i.test(name) ? name : JSON.stringify(name)))
432
- .join("."),
433
- lastKey = keyParts.pop(),
434
- config = await configPromise
435
- delete exploreObject(config, keyParts)?.[lastKey]
436
- log(`Removed ${colourV(pathName)} from config file`)
437
- }
438
- break
439
- case "set":
440
- {
441
- const key = commands[2],
442
- value = commands[3]
443
- if (!key) {
444
- logError("Must provide a key and value\n")
445
- logHelp()
446
- break
447
- }
448
- const keys = key.split("."),
449
- pathName = keys
450
- .map(name => (/^[a-z_$][\w$]*$/i.test(name) ? name : JSON.stringify(name)))
451
- .join(".")
452
- if (!value) {
453
- logError(`Must provide a value for the key ${pathName}\n`)
454
- logHelp()
455
- break
456
- }
457
- const lastKey = keys.pop(),
458
- config = await configPromise
459
- if (keys.length || "hackmudPath" != lastKey) {
460
- let object = config
461
- for (const key of keys)
462
- if ("object" == typeof object[key]) object = object[key]
463
- else {
464
- object[key] = {}
465
- object = object[key]
466
- }
467
- object[lastKey] = value
468
- } else config.hackmudPath = resolve(value.startsWith("~/") ? homedir() + value.slice(1) : value)
469
- console.log(config)
470
- await (async config => {
471
- const json = JSON.stringify(config, void 0, "\t")
472
- configDidNotExist && log("Creating config file at " + configFilePath)
473
- await writeFile(configFilePath, json).catch(async error => {
474
- switch (error.code) {
475
- case "EISDIR":
476
- await rmdir(configFilePath)
477
- break
478
- case "ENOENT":
479
- await mkdir(configDirectoryPath)
480
- break
481
- default:
482
- throw error
483
- }
484
- await writeFile(configFilePath, json)
485
- })
486
- })(config)
487
- }
488
- break
489
- default:
490
- commands[1] && logError(`Unknown command: ${JSON.stringify(commands[1])}\n`)
491
- logHelp()
492
- }
493
- break
494
256
  case "help":
495
257
  case "h":
496
258
  logHelp()
@@ -518,7 +280,7 @@ switch (commands[0]) {
518
280
  scriptUser =
519
281
  "scripts" == basename(resolve(target, "..")) && "hackmud" == basename(resolve(target, "../../..")) ?
520
282
  basename(resolve(target, "../.."))
521
- : "UNKNOWN",
283
+ : void 0,
522
284
  optionsHasNoMinify = options.has("no-minify")
523
285
  if ((optionsHasNoMinify || options.has("skip-minify")) && options.has("mangle-names")) {
524
286
  logError(
@@ -554,36 +316,31 @@ switch (commands[0]) {
554
316
  : fileBaseName + ".js"
555
317
  )
556
318
  const golfFile = () =>
557
- readFile(target, { encoding: "utf-8" }).then(
558
- async source => {
559
- const timeStart = performance.now(),
560
- { script, warnings } = await processScript(source, {
561
- minify: !(options.get("no-minify") || options.get("skip-minify")),
562
- scriptUser,
563
- scriptName,
564
- filePath: target,
565
- mangleNames,
566
- forceQuineCheats
567
- }),
568
- timeTook = performance.now() - timeStart
569
- for (const { message, line } of warnings)
570
- log(`Warning "${chalk.bold(message)}" on line ${chalk.bold(line + "")}`)
571
- await writeFilePersistent(outputPath, script)
572
- .catch(async error => {
573
- if (!commands[2] || "EISDIR" != error.code) throw error
574
- outputPath = resolve(outputPath, basename(target, fileExtension) + ".js")
575
- await writeFilePersistent(outputPath, script)
576
- })
577
- .then(
578
- () =>
579
- log(
580
- `Wrote ${chalk.bold(countHackmudCharacters(script))} chars to ${chalk.bold(relative(".", outputPath))} | took ${Math.round(100 * timeTook) / 100}ms`
581
- ),
582
- error => logError(error.message)
319
+ readFile(target, { encoding: "utf8" }).then(async source => {
320
+ const timeStart = performance.now(),
321
+ { script, warnings } = await processScript(source, {
322
+ minify: !(options.get("no-minify") || options.get("skip-minify")),
323
+ scriptUser,
324
+ scriptName,
325
+ filePath: target,
326
+ mangleNames,
327
+ forceQuineCheats
328
+ }),
329
+ timeTook = performance.now() - timeStart
330
+ for (const { message, line } of warnings)
331
+ log(`Warning "${chalk.bold(message)}" on line ${chalk.bold(line + "")}`)
332
+ await writeFilePersistent(outputPath, script)
333
+ .catch(error => {
334
+ if (!commands[2] || "EISDIR" != error.code) throw error
335
+ outputPath = resolve(outputPath, basename(target, fileExtension) + ".js")
336
+ return writeFilePersistent(outputPath, script)
337
+ })
338
+ .then(() =>
339
+ log(
340
+ `Wrote ${chalk.bold(countHackmudCharacters(script))} chars to ${chalk.bold(relative(".", outputPath))} | took ${Math.round(100 * timeTook) / 100}ms`
583
341
  )
584
- },
585
- error => logError(error.message)
586
- )
342
+ )
343
+ })
587
344
  if (options.get("watch")) {
588
345
  const { watch: watchFile } = await chokidarModule
589
346
  watchFile(target, { awaitWriteFinish: { stabilityThreshold: 100 } })
@@ -594,7 +351,87 @@ switch (commands[0]) {
594
351
  }
595
352
  break
596
353
  default:
597
- commands[0] && logError(`Unknown command: ${JSON.stringify(commands[0])}\n`)
354
+ commands[0] && logError(`Unknown command: ${colourL(commands[0])}\n`)
598
355
  logHelp()
599
356
  }
600
357
  autoExit && process.exit()
358
+ function logHelp() {
359
+ const pushCommandDescription = "Push scripts from a directory to hackmud user's scripts directories",
360
+ forceQuineCheatsOptionDescription = `Force quine cheats on. Use ${colourN("--force-quine-cheats")}=${colourV("false")} to force off`,
361
+ hackmudPathOption = `${colourN("--hackmud-path")}=${colourB("<path>")}\n Override hackmud path`
362
+ console.log(colourN("Version") + colourS(": ") + colourV(version))
363
+ switch (commands[0]) {
364
+ case "dev":
365
+ case "watch":
366
+ case "push":
367
+ console.log(
368
+ colourS(
369
+ `\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\tPushes 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\tPushes 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\tPushes 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\tPushes all scripts found in ${colourV("src")} folder to all users`
370
+ )
371
+ )
372
+ break
373
+ case "pull":
374
+ console.log(
375
+ colourS(
376
+ `\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}`
377
+ )
378
+ )
379
+ break
380
+ case "minify":
381
+ case "golf":
382
+ console.log(
383
+ colourS(
384
+ `\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`
385
+ )
386
+ )
387
+ break
388
+ case "generate-type-declaration":
389
+ case "gen-type-declaration":
390
+ case "gen-dts":
391
+ case "gen-types":
392
+ console.log(
393
+ colourS(
394
+ `${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}`
395
+ )
396
+ )
397
+ break
398
+ case "sync-macros":
399
+ console.log(
400
+ colourS(
401
+ `\n${colourJ("Sync macros across all hackmud users")}\n\n${colourA("Options:")}\n${hackmudPathOption}`
402
+ )
403
+ )
404
+ break
405
+ default:
406
+ console.log(
407
+ colourS(
408
+ `\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`
409
+ )
410
+ )
411
+ }
412
+ }
413
+ function logInfo({ path, users, characterCount, error }, hackmudPath) {
414
+ path = relative(".", path)
415
+ error ?
416
+ logError(`Error "${chalk.bold(error.message)}" in ${chalk.bold(path)}`)
417
+ : log(
418
+ `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")}`
419
+ )
420
+ }
421
+ function logError(message) {
422
+ console.error(colourD(message))
423
+ process.exitCode = 1
424
+ }
425
+ function getHackmudPath() {
426
+ const hackmudPathOption = options.get("hackmud-path")
427
+ if (null != hackmudPathOption && "string" != typeof hackmudPathOption) {
428
+ logError(`Option ${colourN("--hackmud-path")} must be a string, got ${colourV(hackmudPathOption)}\n`)
429
+ logHelp()
430
+ process.exit(1)
431
+ }
432
+ return (
433
+ hackmudPathOption ||
434
+ process.env.HSM_HACKMUD_PATH ||
435
+ ("win32" == process.platform ? resolve(process.env.APPDATA, "hackmud") : resolve(homedir(), ".config/hackmud"))
436
+ )
437
+ }