hackmud-script-manager 0.21.1-2f94c60 → 0.21.1-3adcfa2

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,19 @@
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 = []
25
17
  for (const argument of process.argv.slice(2))
26
18
  if ("-" == argument[0]) {
27
19
  const argumentEqualsIndex = argument.indexOf("=")
@@ -54,7 +46,14 @@ const pushModule = import("../push.js"),
54
46
  colourN = chalk.rgb(0, 255, 255),
55
47
  colourS = chalk.rgb(122, 178, 244),
56
48
  colourV = chalk.rgb(255, 0, 236),
57
- colourW = chalk.rgb(255, 150, 224)
49
+ colourW = chalk.rgb(255, 150, 224),
50
+ formatOption = name => colourN(`-${1 == name.length ? "" : "-"}${name}`),
51
+ userColours = new AutoMap(user => {
52
+ let hash = 0
53
+ for (const char of user) hash += (hash >> 1) + hash + "xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(char) + 1
54
+ return [colourJ, colourK, colourM, colourW, colourL, colourB][hash % 6](user)
55
+ }),
56
+ log = message => console.log(colourS(message))
58
57
  if (process.version.startsWith("v21.")) {
59
58
  process.exitCode = 1
60
59
  console.warn(
@@ -64,7 +63,7 @@ if (process.version.startsWith("v21.")) {
64
63
  )
65
64
  }
66
65
  if ("v" == commands[0] || "version" == commands[0] || popOption("version", "v")?.value) {
67
- console.log("0.21.1-2f94c60")
66
+ console.log("0.21.1-3adcfa2")
68
67
  process.exit()
69
68
  }
70
69
  let warnedDeprecatedEmitDtsAlias = !1
@@ -78,275 +77,267 @@ switch (commands[0]) {
78
77
  case "dev":
79
78
  case "watch":
80
79
  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
- )
80
+ case "minify": {
81
+ const noMinifyOption = popOption("no-minify", "skip-minify")
82
+ if (noMinifyOption && "no-minify" != noMinifyOption.name) {
83
+ process.exitCode = 1
84
+ console.warn(
85
+ colourF(
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`
90
87
  )
88
+ )
89
+ }
90
+ const mangleNamesOption = popOption("mangle-names"),
91
+ forceQuineCheatsOption = popOption("force-quine-cheats"),
92
+ noQuineCheatsOptions = popOption("no-quine-cheats"),
93
+ noMinifyIncompatibleOption = mangleNamesOption || forceQuineCheatsOption || noQuineCheatsOptions
94
+ if (noMinifyOption && noMinifyIncompatibleOption) {
95
+ logError(
96
+ `Options ${formatOption(noMinifyOption.name)} and ${formatOption(noMinifyIncompatibleOption.name)} are incompatible\n`
97
+ )
98
+ logHelp()
99
+ process.exit(1)
100
+ }
101
+ if (forceQuineCheatsOption && noQuineCheatsOptions) {
102
+ logError(
103
+ `Options ${formatOption(forceQuineCheatsOption.name)} and ${formatOption(noQuineCheatsOptions.name)} are incompatible\n`
104
+ )
105
+ logHelp()
106
+ process.exit(1)
107
+ }
108
+ noMinifyOption && assertOptionIsBoolean(noMinifyOption)
109
+ mangleNamesOption && assertOptionIsBoolean(mangleNamesOption)
110
+ forceQuineCheatsOption && assertOptionIsBoolean(forceQuineCheatsOption)
111
+ noQuineCheatsOptions && assertOptionIsBoolean(noQuineCheatsOptions)
112
+ const rootFolderPathOption = popOption("root-folder-path"),
113
+ rootFolderPath = rootFolderPathOption && resolve(rootFolderPathOption.value + "")
114
+ if ("golf" == commands[0] || "minify" == commands[0]) {
115
+ const watchOption = popOption("watch"),
116
+ target = commands[1]
117
+ if (!target) {
118
+ logError("Must provide target\n")
119
+ logHelp()
120
+ process.exit(1)
91
121
  }
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) {
122
+ const fileExtension = extname(target)
123
+ if (!supportedExtensions.includes(fileExtension)) {
97
124
  logError(
98
- `Options ${formatOption(noMinifyOption.name)} and ${formatOption(noMinifyIncompatibleOption.name)} are incompatible\n`
125
+ `Unsupported file extension "${chalk.bold(fileExtension)}"\nSupported extensions are "${supportedExtensions.map(extension => chalk.bold(extension)).join('", "')}"`
99
126
  )
100
- logHelp()
101
127
  process.exit(1)
102
128
  }
103
- if (forceQuineCheatsOption && noQuineCheatsOptions) {
104
- logError(
105
- `Options ${formatOption(forceQuineCheatsOption.name)} and ${formatOption(noQuineCheatsOptions.name)} are incompatible\n`
129
+ complainAboutUnrecognisedOptions()
130
+ const { processScript } = await processScriptModule,
131
+ fileBaseName = basename(target, fileExtension),
132
+ fileBaseNameEndsWithDotSrc = fileBaseName.endsWith(".src"),
133
+ scriptName = fileBaseNameEndsWithDotSrc ? fileBaseName.slice(0, -4) : fileBaseName,
134
+ scriptUser =
135
+ "scripts" == basename(resolve(target, "..")) && "hackmud" == basename(resolve(target, "../../.."))
136
+ ? basename(resolve(target, "../.."))
137
+ : void 0
138
+ let outputPath =
139
+ commands[2] ||
140
+ resolve(
141
+ dirname(target),
142
+ fileBaseNameEndsWithDotSrc
143
+ ? scriptName + ".js"
144
+ : ".js" == fileExtension
145
+ ? fileBaseName + ".min.js"
146
+ : fileBaseName + ".js"
106
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
+ warnings.length && (process.exitCode = 1)
162
+ for (const { message } of warnings) 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()
182
+ } else {
183
+ const hackmudPath = getHackmudPath(),
184
+ sourcePath = commands[1]
185
+ if (!sourcePath) {
186
+ logError(`Must provide the directory to ${"push" == commands[0] ? "push from" : "watch"}\n`)
107
187
  logHelp()
108
188
  process.exit(1)
109
189
  }
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")
190
+ const scripts = commands.slice(2)
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`)
121
197
  logHelp()
122
198
  process.exit(1)
123
199
  }
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('", "')}"`
200
+ } else scripts.push("*.*")
201
+ const watchOption = popOption("watch")
202
+ if ("push" != commands[0] || watchOption?.value) {
203
+ const dtsPathOption = popOption(
204
+ "dts-path",
205
+ "type-declaration-path",
206
+ "type-declaration",
207
+ "dts",
208
+ "gen-types"
209
+ )
210
+ if (
211
+ dtsPathOption &&
212
+ "dts-path" != dtsPathOption.name &&
213
+ "type-declaration-path" != dtsPathOption.name
214
+ ) {
215
+ process.exitCode = 1
216
+ console.warn(
217
+ colourF(
218
+ `${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`
219
+ )
128
220
  )
129
- process.exit(1)
130
221
  }
131
222
  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()
223
+ const { watch } = await watchModule
224
+ watch(sourcePath, hackmudPath, {
225
+ scripts,
226
+ onPush: info => logInfo(info, hackmudPath),
227
+ typeDeclarationPath: dtsPathOption?.value.toString(),
228
+ minify: noMinifyOption && !noMinifyOption.value,
229
+ mangleNames: mangleNamesOption?.value,
230
+ onReady: () => log("Watching"),
231
+ forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
232
+ rootFolderPath
233
+ })
234
+ autoExit = !1
186
235
  } 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`)
236
+ const dtsPathOption = popOption("dts-path")
237
+ complainAboutUnrecognisedOptions()
238
+ let declarationPathPromise
239
+ if (dtsPathOption) {
240
+ if ("string" != typeof dtsPathOption.value) {
241
+ logError(
242
+ `Option ${formatOption(dtsPathOption.name)} must be a string, got ${colourV(dtsPathOption.value)}\n`
243
+ )
201
244
  logHelp()
202
245
  process.exit(1)
203
246
  }
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, {
247
+ let typeDeclarationPath = resolve(dtsPathOption.value)
248
+ const typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
249
+ declarationPathPromise = writeFile(typeDeclarationPath, typeDeclaration)
250
+ .catch(error => {
251
+ assert(error instanceof Error, "src/bin/hsm.ts:300:38")
252
+ if ("EISDIR" != error.code) throw error
253
+ typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
254
+ return writeFile(typeDeclarationPath, typeDeclaration)
255
+ })
256
+ .then(() => typeDeclarationPath)
257
+ }
258
+ const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } = await pushModule,
259
+ infos = await push(sourcePath, hackmudPath, {
229
260
  scripts,
230
261
  onPush: info => logInfo(info, hackmudPath),
231
- typeDeclarationPath: dtsPathOption?.value.toString(),
232
262
  minify: noMinifyOption && !noMinifyOption.value,
233
263
  mangleNames: mangleNamesOption?.value,
234
- onReady: () => log("Watching"),
235
264
  forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
236
265
  rootFolderPath
237
266
  })
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`
267
+ if (infos instanceof Error) {
268
+ logError(infos.message)
269
+ if (infos instanceof MissingSourceFolderError || infos instanceof NoUsersError) {
270
+ console.log()
271
+ logHelp()
272
+ } else
273
+ infos instanceof MissingHackmudFolderError &&
274
+ log(
275
+ `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
276
  )
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
- }
277
+ } else infos.length || logError("Could not find any scripts to push")
278
+ declarationPathPromise && log("Wrote type declaration to " + chalk.bold(await declarationPathPromise))
286
279
  }
287
280
  }
288
281
  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
- })
282
+ }
283
+ case "pull": {
284
+ const hackmudPath = getHackmudPath(),
285
+ script = commands[1]
286
+ if (!script) {
287
+ logError("Must provide the script to pull\n")
288
+ logHelp()
289
+ process.exit(1)
304
290
  }
291
+ complainAboutUnrecognisedOptions()
292
+ const sourcePath = commands[2] || "."
293
+ await pull(sourcePath, hackmudPath, script).catch(error => {
294
+ console.error(error)
295
+ logError(`Something went wrong, did you forget to ${colourC("#down")} the script?`)
296
+ })
305
297
  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
- }
298
+ }
299
+ case "sync-macros": {
300
+ const hackmudPath = getHackmudPath()
301
+ complainAboutUnrecognisedOptions()
302
+ const { macrosSynced, usersSynced } = await syncMacros(hackmudPath)
303
+ log(`Synced ${macrosSynced} macros to ${usersSynced} users`)
313
304
  break
305
+ }
314
306
  case "generate-type-declaration":
315
307
  case "gen-type-declaration":
316
308
  case "gen-dts":
317
309
  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
- )
310
+ case "emit-dts": {
311
+ if ("emit-dts" != commands[0] && "gen-dts" != commands[0]) {
312
+ warnedDeprecatedEmitDtsAlias = !0
313
+ process.exitCode = 1
314
+ console.warn(
315
+ colourF(
316
+ `${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
317
  )
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))
318
+ )
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)
348
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:444: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))
349
339
  break
340
+ }
350
341
  case "help":
351
342
  logHelp()
352
343
  break
@@ -412,7 +403,7 @@ function logHelp() {
412
403
  default:
413
404
  console.log(
414
405
  colourS(
415
- `${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.1-2f94c60")}\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`
406
+ `${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.1-3adcfa2")}\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
407
  )
417
408
  )
418
409
  }