hackmud-script-manager 0.21.1-ea9322a → 0.21.1-ef961a0

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/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 formatOption = name => colourN(`-${1 == name.length ? "" : "-"}${name}`),
17
- options = new Map(),
18
- commands = [],
19
- userColours = new AutoMap(user => {
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
- } else commands.push(argument)
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,7 +52,23 @@ 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)
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
+ }
58
72
  if (process.version.startsWith("v21.")) {
59
73
  process.exitCode = 1
60
74
  console.warn(
@@ -64,7 +78,7 @@ if (process.version.startsWith("v21.")) {
64
78
  )
65
79
  }
66
80
  if ("v" == commands[0] || "version" == commands[0] || popOption("version", "v")?.value) {
67
- console.log("0.21.1-ea9322a")
81
+ console.log("0.21.1-ef961a0")
68
82
  process.exit()
69
83
  }
70
84
  let warnedDeprecatedEmitDtsAlias = !1
@@ -78,275 +92,267 @@ switch (commands[0]) {
78
92
  case "dev":
79
93
  case "watch":
80
94
  case "golf":
81
- case "minify":
82
- {
83
- const noMinifyOption = popOption("no-minify", "skip-minify")
84
- if (noMinifyOption && "no-minify" != noMinifyOption.name) {
85
- process.exitCode = 1
86
- console.warn(
87
- colourF(
88
- `${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
- )
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`
90
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)
91
136
  }
92
- const mangleNamesOption = popOption("mangle-names"),
93
- forceQuineCheatsOption = popOption("force-quine-cheats"),
94
- noQuineCheatsOptions = popOption("no-quine-cheats"),
95
- noMinifyIncompatibleOption = mangleNamesOption || forceQuineCheatsOption || noQuineCheatsOptions
96
- if (noMinifyOption && noMinifyIncompatibleOption) {
137
+ const fileExtension = extname(target)
138
+ if (!supportedExtensions.includes(fileExtension)) {
97
139
  logError(
98
- `Options ${formatOption(noMinifyOption.name)} and ${formatOption(noMinifyIncompatibleOption.name)} are incompatible\n`
140
+ `Unsupported file extension "${chalk.bold(fileExtension)}"\nSupported extensions are "${supportedExtensions.map(extension => chalk.bold(extension)).join('", "')}"`
99
141
  )
100
- logHelp()
101
142
  process.exit(1)
102
143
  }
103
- if (forceQuineCheatsOption && noQuineCheatsOptions) {
104
- logError(
105
- `Options ${formatOption(forceQuineCheatsOption.name)} and ${formatOption(noQuineCheatsOptions.name)} are incompatible\n`
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"
106
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`)
107
202
  logHelp()
108
203
  process.exit(1)
109
204
  }
110
- noMinifyOption && assertOptionIsBoolean(noMinifyOption)
111
- mangleNamesOption && assertOptionIsBoolean(mangleNamesOption)
112
- forceQuineCheatsOption && assertOptionIsBoolean(forceQuineCheatsOption)
113
- noQuineCheatsOptions && assertOptionIsBoolean(noQuineCheatsOptions)
114
- const rootFolderPathOption = popOption("root-folder-path"),
115
- rootFolderPath = rootFolderPathOption && resolve(rootFolderPathOption.value + "")
116
- if ("golf" == commands[0] || "minify" == commands[0]) {
117
- const watchOption = popOption("watch"),
118
- target = commands[1]
119
- if (!target) {
120
- 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`)
121
212
  logHelp()
122
213
  process.exit(1)
123
214
  }
124
- const fileExtension = extname(target)
125
- if (!supportedExtensions.includes(fileExtension)) {
126
- logError(
127
- `Unsupported file extension "${chalk.bold(fileExtension)}"\nSupported extensions are "${supportedExtensions.map(extension => chalk.bold(extension)).join('", "')}"`
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
+ )
128
235
  )
129
- process.exit(1)
130
236
  }
131
237
  complainAboutUnrecognisedOptions()
132
- const { processScript } = await processScriptModule,
133
- fileBaseName = basename(target, fileExtension),
134
- fileBaseNameEndsWithDotSrc = fileBaseName.endsWith(".src"),
135
- scriptName = fileBaseNameEndsWithDotSrc ? fileBaseName.slice(0, -4) : fileBaseName,
136
- scriptUser =
137
- "scripts" == basename(resolve(target, "..")) &&
138
- "hackmud" == basename(resolve(target, "../../.."))
139
- ? basename(resolve(target, "../.."))
140
- : void 0
141
- let outputPath =
142
- commands[2] ||
143
- resolve(
144
- dirname(target),
145
- fileBaseNameEndsWithDotSrc
146
- ? scriptName + ".js"
147
- : ".js" == fileExtension
148
- ? fileBaseName + ".min.js"
149
- : fileBaseName + ".js"
150
- )
151
- const golfFile = () =>
152
- readFile(target, { encoding: "utf8" }).then(async source => {
153
- const timeStart = performance.now(),
154
- { script, warnings } = await processScript(source, {
155
- minify: noMinifyOption && !noMinifyOption.value,
156
- scriptUser,
157
- scriptName,
158
- filePath: target,
159
- mangleNames: mangleNamesOption?.value,
160
- forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
161
- rootFolderPath
162
- }),
163
- timeTook = performance.now() - timeStart
164
- warnings.length && (process.exitCode = 1)
165
- for (const { message } of warnings)
166
- console.warn(colourF(`${chalk.bold("Warning:")} ${message}`))
167
- await writeFilePersistent(outputPath, script)
168
- .catch(error => {
169
- if (!commands[2] || "EISDIR" != error.code) throw error
170
- outputPath = resolve(outputPath, basename(target, fileExtension) + ".js")
171
- return writeFilePersistent(outputPath, script)
172
- })
173
- .then(() =>
174
- log(
175
- `Wrote ${chalk.bold(countHackmudCharacters(script))} chars to ${chalk.bold(relative(".", outputPath))} | took ${Math.round(100 * timeTook) / 100}ms`
176
- )
177
- )
178
- })
179
- if (watchOption) {
180
- const { watch: watchFile } = await chokidarModule
181
- watchFile(target, { awaitWriteFinish: { stabilityThreshold: 100 } })
182
- .on("ready", () => log("Watching " + target))
183
- .on("change", golfFile)
184
- autoExit = !1
185
- } 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
186
250
  } else {
187
- const hackmudPath = getHackmudPath(),
188
- sourcePath = commands[1]
189
- if (!sourcePath) {
190
- logError(`Must provide the directory to ${"push" == commands[0] ? "push from" : "watch"}\n`)
191
- logHelp()
192
- process.exit(1)
193
- }
194
- const scripts = commands.slice(2)
195
- if (scripts.length) {
196
- const invalidScript = scripts.find(
197
- script => !/^(?:[a-z_][a-z\d_]{0,24}|\*)\.(?:[a-z_][a-z\d_]{0,24}|\*)$/.test(script)
198
- )
199
- if (invalidScript) {
200
- 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
+ )
201
259
  logHelp()
202
260
  process.exit(1)
203
261
  }
204
- } else scripts.push("*.*")
205
- const watchOption = popOption("watch")
206
- if ("push" != commands[0] || watchOption?.value) {
207
- const dtsPathOption = popOption(
208
- "dts-path",
209
- "type-declaration-path",
210
- "type-declaration",
211
- "dts",
212
- "gen-types"
213
- )
214
- if (
215
- dtsPathOption &&
216
- "dts-path" != dtsPathOption.name &&
217
- "type-declaration-path" != dtsPathOption.name
218
- ) {
219
- process.exitCode = 1
220
- console.warn(
221
- colourF(
222
- `${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`
223
- )
224
- )
225
- }
226
- complainAboutUnrecognisedOptions()
227
- const { watch } = await watchModule
228
- 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, {
229
275
  scripts,
230
276
  onPush: info => logInfo(info, hackmudPath),
231
- typeDeclarationPath: dtsPathOption?.value.toString(),
232
277
  minify: noMinifyOption && !noMinifyOption.value,
233
278
  mangleNames: mangleNamesOption?.value,
234
- onReady: () => log("Watching"),
235
279
  forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
236
280
  rootFolderPath
237
281
  })
238
- autoExit = !1
239
- } else {
240
- const dtsPathOption = popOption("dts-path")
241
- complainAboutUnrecognisedOptions()
242
- let declarationPathPromise
243
- if (dtsPathOption) {
244
- if ("string" != typeof dtsPathOption.value) {
245
- logError(
246
- `Option ${formatOption(dtsPathOption.name)} must be a string, got ${colourV(dtsPathOption.value)}\n`
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`
247
291
  )
248
- logHelp()
249
- process.exit(1)
250
- }
251
- let typeDeclarationPath = resolve(dtsPathOption.value)
252
- const typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
253
- declarationPathPromise = writeFile(typeDeclarationPath, typeDeclaration)
254
- .catch(error => {
255
- assert(error instanceof Error, "src/bin/hsm.ts:299:38")
256
- if ("EISDIR" != error.code) throw error
257
- typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
258
- return writeFile(typeDeclarationPath, typeDeclaration)
259
- })
260
- .then(() => typeDeclarationPath)
261
- }
262
- const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } =
263
- await pushModule,
264
- infos = await push(sourcePath, hackmudPath, {
265
- scripts,
266
- onPush: info => logInfo(info, hackmudPath),
267
- minify: noMinifyOption && !noMinifyOption.value,
268
- mangleNames: mangleNamesOption?.value,
269
- forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
270
- rootFolderPath
271
- })
272
- if (infos instanceof Error) {
273
- logError(infos.message)
274
- if (infos instanceof MissingSourceFolderError || infos instanceof NoUsersError) {
275
- console.log()
276
- logHelp()
277
- } else
278
- infos instanceof MissingHackmudFolderError &&
279
- log(
280
- `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`
281
- )
282
- } else infos.length || logError("Could not find any scripts to push")
283
- declarationPathPromise &&
284
- log("Wrote type declaration to " + chalk.bold(await declarationPathPromise))
285
- }
292
+ } else infos.length || logError("Could not find any scripts to push")
293
+ declarationPathPromise && log("Wrote type declaration to " + chalk.bold(await declarationPathPromise))
286
294
  }
287
295
  }
288
296
  break
289
- case "pull":
290
- {
291
- const hackmudPath = getHackmudPath(),
292
- script = commands[1]
293
- if (!script) {
294
- logError("Must provide the script to pull\n")
295
- logHelp()
296
- process.exit(1)
297
- }
298
- complainAboutUnrecognisedOptions()
299
- const sourcePath = commands[2] || "."
300
- await pull(sourcePath, hackmudPath, script).catch(error => {
301
- console.error(error)
302
- logError(`Something went wrong, did you forget to ${colourC("#down")} the script?`)
303
- })
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)
304
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
+ })
305
312
  break
306
- case "sync-macros":
307
- {
308
- const hackmudPath = getHackmudPath()
309
- complainAboutUnrecognisedOptions()
310
- const { macrosSynced, usersSynced } = await syncMacros(hackmudPath)
311
- log(`Synced ${macrosSynced} macros to ${usersSynced} users`)
312
- }
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`)
313
319
  break
320
+ }
314
321
  case "generate-type-declaration":
315
322
  case "gen-type-declaration":
316
323
  case "gen-dts":
317
324
  case "gen-types":
318
- case "emit-dts":
319
- {
320
- if ("emit-dts" != commands[0] && "gen-dts" != commands[0]) {
321
- warnedDeprecatedEmitDtsAlias = !0
322
- process.exitCode = 1
323
- console.warn(
324
- colourF(
325
- `${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
- )
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`
327
332
  )
328
- }
329
- const hackmudPath = getHackmudPath(),
330
- target = commands[1]
331
- if (!target) {
332
- logError("Must provide target directory\n")
333
- logHelp()
334
- process.exit(1)
335
- }
336
- complainAboutUnrecognisedOptions()
337
- const sourcePath = resolve(target),
338
- outputPath = commands[2] || "./player.d.ts",
339
- typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
340
- let typeDeclarationPath = resolve(outputPath)
341
- await writeFile(typeDeclarationPath, typeDeclaration).catch(error => {
342
- assert(error instanceof Error, "src/bin/hsm.ts:438:35")
343
- if ("EISDIR" != error.code) throw error
344
- typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
345
- return writeFile(typeDeclarationPath, typeDeclaration)
346
- })
347
- log("Wrote type declaration to " + chalk.bold(typeDeclarationPath))
333
+ )
348
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))
349
354
  break
355
+ }
350
356
  case "help":
351
357
  logHelp()
352
358
  break
@@ -412,7 +418,7 @@ function logHelp() {
412
418
  default:
413
419
  console.log(
414
420
  colourS(
415
- `${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.1-ea9322a")}\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`
421
+ `${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.1-ef961a0")}\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`
416
422
  )
417
423
  )
418
424
  }