hackmud-script-manager 0.20.4-03d5600 → 0.20.4-06a037b

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -20,6 +20,10 @@ You can read about how HSM works [in my blog post](https://samual.uk/blog/js-cod
20
20
  > ```
21
21
  > You will need to run `Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser` in PowerShell as an administrator. For more information, see [Microsoft's page about Execution Policies](https://learn.microsoft.com/en-gb/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.4).
22
22
 
23
+ ![image](https://github.com/samualtnorman/hackmud-script-manager/assets/18307063/69a371fe-f8c8-43fe-b3c7-39f3735ce6fb)
24
+ ![image](https://github.com/samualtnorman/hackmud-script-manager/assets/18307063/08103f9e-74fa-4a56-a739-94858ba8c139)
25
+ ![image](https://github.com/samualtnorman/hackmud-script-manager/assets/18307063/25ccb86d-1fe3-4632-b703-ac47f5b32c9c)
26
+
23
27
  ## Features
24
28
  - Minification
25
29
  - This includes auto quine cheating.
package/bin/hsm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { Cache } from "@samual/lib/Cache"
2
+ import { AutoMap } from "@samual/lib/AutoMap"
3
3
  import { assert } from "@samual/lib/assert"
4
4
  import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
5
5
  import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
@@ -13,10 +13,10 @@ import { syncMacros } from "../syncMacros.js"
13
13
  import "@samual/lib/readDirectoryWithStats"
14
14
  import "path/posix"
15
15
  import "@samual/lib/copyFilePersistent"
16
- const version = "0.20.4-03d5600",
16
+ const formatOption = name => colourN(`-${1 == name.length ? "" : "-"}${name}`),
17
17
  options = new Map(),
18
18
  commands = [],
19
- userColours = new Cache(user => {
19
+ userColours = new AutoMap(user => {
20
20
  let hash = 0
21
21
  for (const char of user) hash += (hash >> 1) + hash + "xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(char) + 1
22
22
  return [colourJ, colourK, colourM, colourW, colourL, colourB][hash % 6](user)
@@ -46,6 +46,7 @@ const pushModule = import("../push.js"),
46
46
  colourB = chalk.rgb(202, 202, 202),
47
47
  colourC = chalk.rgb(155, 155, 155),
48
48
  colourD = chalk.rgb(255, 0, 0),
49
+ colourF = chalk.rgb(255, 128, 0),
49
50
  colourJ = chalk.rgb(255, 244, 4),
50
51
  colourK = chalk.rgb(243, 249, 152),
51
52
  colourL = chalk.rgb(30, 255, 0),
@@ -54,8 +55,14 @@ const pushModule = import("../push.js"),
54
55
  colourS = chalk.rgb(122, 178, 244),
55
56
  colourV = chalk.rgb(255, 0, 236),
56
57
  colourW = chalk.rgb(255, 150, 224)
58
+ process.version.startsWith("v21.") &&
59
+ console.warn(
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"
62
+ )
63
+ )
57
64
  if ("v" == commands[0] || "version" == commands[0] || popOption("version", "v")?.value) {
58
- console.log(version)
65
+ console.log("0.20.4-06a037b")
59
66
  process.exit()
60
67
  }
61
68
  if (popOption("help", "h")?.value) {
@@ -76,7 +83,7 @@ switch (commands[0]) {
76
83
  noMinifyIncompatibleOption = mangleNamesOption || forceQuineCheatsOption
77
84
  if (noMinifyOption && noMinifyIncompatibleOption) {
78
85
  logError(
79
- `Options ${colourN(noMinifyOption.name)} and ${colourN(noMinifyIncompatibleOption.name)} are incompatible\n`
86
+ `Options ${formatOption(noMinifyOption.name)} and ${formatOption(noMinifyIncompatibleOption.name)} are incompatible\n`
80
87
  )
81
88
  logHelp()
82
89
  process.exit(1)
@@ -99,6 +106,7 @@ switch (commands[0]) {
99
106
  )
100
107
  process.exit(1)
101
108
  }
109
+ complainAboutUnrecognisedOptions()
102
110
  const { processScript } = await processScriptModule,
103
111
  fileBaseName = basename(target, fileExtension),
104
112
  fileBaseNameEndsWithDotSrc = fileBaseName.endsWith(".src"),
@@ -171,15 +179,15 @@ switch (commands[0]) {
171
179
  }
172
180
  } else scripts.push("*.*")
173
181
  if ("push" == commands[0]) {
174
- const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } =
175
- await pushModule,
176
- infos = await push(sourcePath, hackmudPath, {
177
- scripts,
178
- onPush: info => logInfo(info, hackmudPath),
179
- minify: noMinifyOption && !noMinifyOption.value,
180
- mangleNames: mangleNamesOption?.value,
181
- forceQuineCheats: forceQuineCheatsOption?.value
182
- })
182
+ const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } = await pushModule
183
+ complainAboutUnrecognisedOptions()
184
+ const infos = await push(sourcePath, hackmudPath, {
185
+ scripts,
186
+ onPush: info => logInfo(info, hackmudPath),
187
+ minify: noMinifyOption && !noMinifyOption.value,
188
+ mangleNames: mangleNamesOption?.value,
189
+ forceQuineCheats: forceQuineCheatsOption?.value
190
+ })
183
191
  if (infos instanceof Error) {
184
192
  logError(infos.message)
185
193
  if (infos instanceof MissingSourceFolderError || infos instanceof NoUsersError) {
@@ -193,12 +201,13 @@ switch (commands[0]) {
193
201
  } else infos.length || logError("Could not find any scripts to push")
194
202
  } else {
195
203
  const typeDeclarationPathOption = popOption(
196
- "type-declaration-path",
197
- "type-declaration",
198
- "dts",
199
- "gen-types"
200
- ),
201
- { watch } = await watchModule
204
+ "type-declaration-path",
205
+ "type-declaration",
206
+ "dts",
207
+ "gen-types"
208
+ )
209
+ complainAboutUnrecognisedOptions()
210
+ const { watch } = await watchModule
202
211
  watch(sourcePath, hackmudPath, {
203
212
  scripts,
204
213
  onPush: info => logInfo(info, hackmudPath),
@@ -222,6 +231,7 @@ switch (commands[0]) {
222
231
  logHelp()
223
232
  process.exit(1)
224
233
  }
234
+ complainAboutUnrecognisedOptions()
225
235
  const sourcePath = commands[2] || "."
226
236
  await pull(sourcePath, hackmudPath, script).catch(error => {
227
237
  console.error(error)
@@ -231,8 +241,9 @@ switch (commands[0]) {
231
241
  break
232
242
  case "sync-macros":
233
243
  {
234
- const hackmudPath = getHackmudPath(),
235
- { macrosSynced, usersSynced } = await syncMacros(hackmudPath)
244
+ const hackmudPath = getHackmudPath()
245
+ complainAboutUnrecognisedOptions()
246
+ const { macrosSynced, usersSynced } = await syncMacros(hackmudPath)
236
247
  log(`Synced ${macrosSynced} macros to ${usersSynced} users`)
237
248
  }
238
249
  break
@@ -248,12 +259,13 @@ switch (commands[0]) {
248
259
  logHelp()
249
260
  process.exit(1)
250
261
  }
262
+ complainAboutUnrecognisedOptions()
251
263
  const sourcePath = resolve(target),
252
264
  outputPath = commands[2] || "./player.d.ts",
253
265
  typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
254
266
  let typeDeclarationPath = resolve(outputPath)
255
267
  await writeFile(typeDeclarationPath, typeDeclaration).catch(error => {
256
- assert(error instanceof Error, "src/bin/hsm.ts:321:35")
268
+ assert(error instanceof Error, "src/bin/hsm.ts:343:35")
257
269
  if ("EISDIR" != error.code) throw error
258
270
  typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
259
271
  return writeFile(typeDeclarationPath, typeDeclaration)
@@ -274,7 +286,7 @@ function logHelp() {
274
286
  const pushCommandDescription = "Push scripts from a directory to hackmud user's scripts directories",
275
287
  forceQuineCheatsOptionDescription = `Force quine cheats on. Use ${colourN("--force-quine-cheats")}=${colourV("false")} to force off`,
276
288
  hackmudPathOption = `${colourN("--hackmud-path")}=${colourB("<path>")}\n Override hackmud path`
277
- console.log(colourN("Version") + colourS(": ") + colourV(version))
289
+ console.log(colourN("Version") + colourS(": ") + colourV("0.20.4-06a037b"))
278
290
  switch (commands[0]) {
279
291
  case "dev":
280
292
  case "watch":
@@ -352,7 +364,7 @@ function getHackmudPath() {
352
364
  }
353
365
  function assertOptionIsBoolean(option) {
354
366
  if ("boolean" != typeof option.value) {
355
- logError(`The value for ${colourN(option.name)} must be ${colourV("true")} or ${colourV("false")}\n`)
367
+ logError(`The value for ${formatOption(option.name)} must be ${colourV("true")} or ${colourV("false")}\n`)
356
368
  logHelp()
357
369
  process.exit(1)
358
370
  }
@@ -360,9 +372,7 @@ function assertOptionIsBoolean(option) {
360
372
  function popOption(...names) {
361
373
  const presentOptionNames = names.filter(name => options.has(name))
362
374
  if (!presentOptionNames.length) return
363
- const presentOptionNamesWithDashDash = presentOptionNames.map(name =>
364
- colourN(`-${1 == name.length ? "" : "-"}${name}`)
365
- )
375
+ const presentOptionNamesWithDashDash = presentOptionNames.map(formatOption)
366
376
  if (presentOptionNames.length > 1) {
367
377
  logError(
368
378
  `The options ${presentOptionNamesWithDashDash.join(", ")} are aliases for each other. Please only specify one`
@@ -373,3 +383,11 @@ function popOption(...names) {
373
383
  options.delete(presentOptionNames[0])
374
384
  return { name: presentOptionNamesWithDashDash[0], value }
375
385
  }
386
+ function complainAboutUnrecognisedOptions() {
387
+ if (options.size) {
388
+ logError(
389
+ `Unrecognised option${options.size > 1 ? "s" : ""}: ${[...options.keys()].map(formatOption).join(", ")}`
390
+ )
391
+ process.exit(1)
392
+ }
393
+ }