hackmud-script-manager 0.19.1-cb8d65f → 0.19.1-d57be2a
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/bin/hsm.js +43 -155
- package/{src/generateTypeDeclaration.d.ts → generateTypeDeclaration.d.ts} +0 -1
- package/generateTypeDeclaration.js +1 -1
- package/{src/index.d.ts → index.d.ts} +2 -2
- package/package.json +5 -1
- package/{src/processScript → processScript}/index.d.ts +4 -4
- package/processScript/index.js +8 -8
- package/{src/processScript → processScript}/minify.d.ts +4 -4
- package/processScript/minify.js +6 -6
- package/{src/processScript → processScript}/postprocess.d.ts +0 -1
- package/processScript/postprocess.js +1 -1
- package/{src/processScript → processScript}/preprocess.d.ts +5 -5
- package/processScript/preprocess.js +3 -3
- package/{src/processScript → processScript}/transform.d.ts +5 -4
- package/processScript/transform.js +67 -39
- package/{src/pull.d.ts → pull.d.ts} +0 -1
- package/pull.js +1 -1
- package/{src/push.d.ts → push.d.ts} +5 -6
- package/push.js +84 -215
- package/{src/syncMacros.d.ts → syncMacros.d.ts} +0 -1
- package/syncMacros.js +2 -2
- package/{src/watch.d.ts → watch.d.ts} +3 -4
- package/watch.js +9 -9
- /package/{src/bin → bin}/hsm.d.ts +0 -0
- /package/{src/constants.d.ts → constants.d.ts} +0 -0
- /package/{src/processScript → processScript}/shared.d.ts +0 -0
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
|
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.js
CHANGED
@@ -1,23 +1,18 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
import { Cache } from "@samual/lib/Cache"
|
3
3
|
import { assert } from "@samual/lib/assert"
|
4
|
-
import { catchError } from "@samual/lib/catchError"
|
5
4
|
import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
|
6
|
-
import { getDeepObjectProperty } from "@samual/lib/getDeepObjectProperty"
|
7
|
-
import { isRecord } from "@samual/lib/isRecord"
|
8
|
-
import { setDeepObjectProperty } from "@samual/lib/setDeepObjectProperty"
|
9
5
|
import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
|
10
|
-
import {
|
6
|
+
import { writeFile, readFile } from "fs/promises"
|
11
7
|
import { homedir } from "os"
|
12
|
-
import {
|
8
|
+
import { extname, basename, resolve, dirname, relative } from "path"
|
13
9
|
import { supportedExtensions } from "../constants.js"
|
14
10
|
import { generateTypeDeclaration } from "../generateTypeDeclaration.js"
|
15
11
|
import { pull } from "../pull.js"
|
16
12
|
import { syncMacros } from "../syncMacros.js"
|
17
13
|
import "@samual/lib/readDirectoryWithStats"
|
18
14
|
import "@samual/lib/copyFilePersistent"
|
19
|
-
const
|
20
|
-
configFilePath = resolve(configDirectoryPath, "hsm.json"),
|
15
|
+
const version = "0.19.1-d57be2a",
|
21
16
|
options = new Map(),
|
22
17
|
commands = [],
|
23
18
|
userColours = new Cache(user => {
|
@@ -42,29 +37,10 @@ for (const argument of process.argv.slice(2))
|
|
42
37
|
else for (const option of key.slice(1)) options.set(option, value)
|
43
38
|
} else commands.push(argument)
|
44
39
|
if ("v" == commands[0] || "version" == commands[0] || options.get("version") || options.get("v")) {
|
45
|
-
console.log(
|
40
|
+
console.log(version)
|
46
41
|
process.exit()
|
47
42
|
}
|
48
|
-
|
49
|
-
const configPromise = readFile(configFilePath, { encoding: "utf-8" }).then(
|
50
|
-
configFile => {
|
51
|
-
const [temporaryConfig, error] = catchError(() => JSON.parse(configFile))
|
52
|
-
if (error || !isRecord(temporaryConfig)) {
|
53
|
-
log("Config file was corrupted, resetting")
|
54
|
-
return {}
|
55
|
-
}
|
56
|
-
if ("hackmudPath" in temporaryConfig && "string" != typeof temporaryConfig.hackmudPath) {
|
57
|
-
log('Property "hackmudPath" of config file was corrupted, removing')
|
58
|
-
delete temporaryConfig.hackmudPath
|
59
|
-
}
|
60
|
-
return temporaryConfig
|
61
|
-
},
|
62
|
-
() => {
|
63
|
-
configDidNotExist = !0
|
64
|
-
return {}
|
65
|
-
}
|
66
|
-
),
|
67
|
-
pushModule = import("../push.js"),
|
43
|
+
const pushModule = import("../push.js"),
|
68
44
|
processScriptModule = import("../processScript/index.js"),
|
69
45
|
watchModule = import("../watch.js"),
|
70
46
|
chokidarModule = import("chokidar"),
|
@@ -86,12 +62,10 @@ if (options.get("help") || options.get("h")) {
|
|
86
62
|
process.exit()
|
87
63
|
}
|
88
64
|
let autoExit = !0
|
89
|
-
const getDefaultHackmudPath = () =>
|
90
|
-
"win32" == process.platform ? resolve(process.env.APPDATA, "hackmud") : resolve(homedir(), ".config/hackmud")
|
91
65
|
switch (commands[0]) {
|
92
66
|
case "push":
|
93
67
|
{
|
94
|
-
const
|
68
|
+
const hackmudPath = getHackmudPath(),
|
95
69
|
sourcePath = commands[1]
|
96
70
|
if (!sourcePath) {
|
97
71
|
logError("Must provide the directory to push from\n")
|
@@ -160,7 +134,7 @@ switch (commands[0]) {
|
|
160
134
|
case "dev":
|
161
135
|
case "watch":
|
162
136
|
{
|
163
|
-
const
|
137
|
+
const hackmudPath = getHackmudPath(),
|
164
138
|
sourcePath = commands[1]
|
165
139
|
if (!sourcePath) {
|
166
140
|
logError("Must provide the directory to watch\n")
|
@@ -234,7 +208,7 @@ switch (commands[0]) {
|
|
234
208
|
break
|
235
209
|
case "pull":
|
236
210
|
{
|
237
|
-
const
|
211
|
+
const hackmudPath = getHackmudPath(),
|
238
212
|
script = commands[1]
|
239
213
|
if (!script) {
|
240
214
|
logError("Must provide the script to pull\n")
|
@@ -250,7 +224,7 @@ switch (commands[0]) {
|
|
250
224
|
break
|
251
225
|
case "sync-macros":
|
252
226
|
{
|
253
|
-
const
|
227
|
+
const hackmudPath = getHackmudPath(),
|
254
228
|
{ macrosSynced, usersSynced } = await syncMacros(hackmudPath)
|
255
229
|
log(`Synced ${macrosSynced} macros to ${usersSynced} users`)
|
256
230
|
}
|
@@ -268,13 +242,10 @@ switch (commands[0]) {
|
|
268
242
|
}
|
269
243
|
const sourcePath = resolve(target),
|
270
244
|
outputPath = commands[2] || "./player.d.ts",
|
271
|
-
typeDeclaration = await generateTypeDeclaration(
|
272
|
-
sourcePath,
|
273
|
-
(await configPromise).hackmudPath || getDefaultHackmudPath()
|
274
|
-
)
|
245
|
+
typeDeclaration = await generateTypeDeclaration(sourcePath, getHackmudPath())
|
275
246
|
let typeDeclarationPath = resolve(outputPath)
|
276
247
|
await writeFile(typeDeclarationPath, typeDeclaration).catch(error => {
|
277
|
-
assert(error instanceof Error, "src/bin/hsm.ts:
|
248
|
+
assert(error instanceof Error, "src/bin/hsm.ts:327:35")
|
278
249
|
if ("EISDIR" != error.code) throw error
|
279
250
|
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
280
251
|
return writeFile(typeDeclarationPath, typeDeclaration)
|
@@ -282,66 +253,6 @@ switch (commands[0]) {
|
|
282
253
|
log("Wrote type declaration to " + chalk.bold(typeDeclarationPath))
|
283
254
|
}
|
284
255
|
break
|
285
|
-
case "config":
|
286
|
-
switch (commands[1]) {
|
287
|
-
case "get":
|
288
|
-
{
|
289
|
-
const key = commands[2],
|
290
|
-
config = await configPromise
|
291
|
-
if (key) {
|
292
|
-
const [value, error] = catchError(() => getDeepObjectProperty(config, key.split(".")))
|
293
|
-
error ? logError("Could not get key " + colourV(key))
|
294
|
-
: "string" == typeof value ? log(value)
|
295
|
-
: console.log(value)
|
296
|
-
} else console.log(config)
|
297
|
-
}
|
298
|
-
break
|
299
|
-
case "delete":
|
300
|
-
{
|
301
|
-
const key = commands[2]
|
302
|
-
if (!key) {
|
303
|
-
logError("Must provide a key to delete\n")
|
304
|
-
logHelp()
|
305
|
-
break
|
306
|
-
}
|
307
|
-
const keys = key.split("."),
|
308
|
-
lastKey = keys.pop(),
|
309
|
-
config = await configPromise,
|
310
|
-
object = getDeepObjectProperty(config, keys)
|
311
|
-
if (isRecord(object)) {
|
312
|
-
delete object[lastKey]
|
313
|
-
await updateConfig(config)
|
314
|
-
log(`Removed ${colourV(key)} from config file:`)
|
315
|
-
console.log(config)
|
316
|
-
} else log("Could not delete " + colourV(key))
|
317
|
-
}
|
318
|
-
break
|
319
|
-
case "set":
|
320
|
-
{
|
321
|
-
const key = commands[2],
|
322
|
-
value = commands[3]
|
323
|
-
if (!key) {
|
324
|
-
logError("Must provide a key and value\n")
|
325
|
-
logHelp()
|
326
|
-
break
|
327
|
-
}
|
328
|
-
if (!value) {
|
329
|
-
logError(`Must provide a value for the key ${colourV(key)}\n`)
|
330
|
-
logHelp()
|
331
|
-
break
|
332
|
-
}
|
333
|
-
const config = await configPromise
|
334
|
-
setDeepObjectProperty(config, key.split("."), value)
|
335
|
-
log(`Set ${colourV(key)} to ${colourV(value)}:`)
|
336
|
-
console.log(config)
|
337
|
-
await updateConfig(config)
|
338
|
-
}
|
339
|
-
break
|
340
|
-
default:
|
341
|
-
commands[1] && logError(`Unknown command: ${colourL(commands[1])}\n`)
|
342
|
-
logHelp()
|
343
|
-
}
|
344
|
-
break
|
345
256
|
case "help":
|
346
257
|
case "h":
|
347
258
|
logHelp()
|
@@ -369,7 +280,7 @@ switch (commands[0]) {
|
|
369
280
|
scriptUser =
|
370
281
|
"scripts" == basename(resolve(target, "..")) && "hackmud" == basename(resolve(target, "../../..")) ?
|
371
282
|
basename(resolve(target, "../.."))
|
372
|
-
:
|
283
|
+
: void 0,
|
373
284
|
optionsHasNoMinify = options.has("no-minify")
|
374
285
|
if ((optionsHasNoMinify || options.has("skip-minify")) && options.has("mangle-names")) {
|
375
286
|
logError(
|
@@ -405,7 +316,7 @@ switch (commands[0]) {
|
|
405
316
|
: fileBaseName + ".js"
|
406
317
|
)
|
407
318
|
const golfFile = () =>
|
408
|
-
readFile(target, { encoding: "
|
319
|
+
readFile(target, { encoding: "utf8" }).then(async source => {
|
409
320
|
const timeStart = performance.now(),
|
410
321
|
{ script, warnings } = await processScript(source, {
|
411
322
|
minify: !(options.get("no-minify") || options.get("skip-minify")),
|
@@ -446,47 +357,23 @@ switch (commands[0]) {
|
|
446
357
|
autoExit && process.exit()
|
447
358
|
function logHelp() {
|
448
359
|
const pushCommandDescription = "Push scripts from a directory to hackmud user's scripts directories",
|
449
|
-
forceQuineCheatsOptionDescription = `Force quine cheats on. Use ${colourN("--force-quine-cheats")}=${colourV("false")} to force off
|
450
|
-
|
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))
|
451
363
|
switch (commands[0]) {
|
452
|
-
case "config":
|
453
|
-
switch (commands[1]) {
|
454
|
-
case "get":
|
455
|
-
console.log(
|
456
|
-
`\n${colourJ("Retrieve a value from the config file")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(`${commands[0]} ${commands[1]}`)} ${colourB("<key>")}`
|
457
|
-
)
|
458
|
-
break
|
459
|
-
case "set":
|
460
|
-
console.log(
|
461
|
-
`\n${colourJ("Assign a value to the config file")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(`${commands[0]} ${commands[1]}`)} ${colourB("<key> <value>")}`
|
462
|
-
)
|
463
|
-
break
|
464
|
-
case "delete":
|
465
|
-
console.log(
|
466
|
-
`\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>")}`
|
467
|
-
)
|
468
|
-
break
|
469
|
-
default:
|
470
|
-
console.log(
|
471
|
-
colourS(
|
472
|
-
`${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`
|
473
|
-
)
|
474
|
-
)
|
475
|
-
}
|
476
|
-
break
|
477
364
|
case "dev":
|
478
365
|
case "watch":
|
479
366
|
case "push":
|
480
367
|
console.log(
|
481
368
|
colourS(
|
482
|
-
`\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${"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
|
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`
|
483
370
|
)
|
484
371
|
)
|
485
372
|
break
|
486
373
|
case "pull":
|
487
374
|
console.log(
|
488
375
|
colourS(
|
489
|
-
`\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>")}`
|
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}`
|
490
377
|
)
|
491
378
|
)
|
492
379
|
break
|
@@ -504,46 +391,47 @@ function logHelp() {
|
|
504
391
|
case "gen-types":
|
505
392
|
console.log(
|
506
393
|
colourS(
|
507
|
-
`${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]")}`
|
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}`
|
508
395
|
)
|
509
396
|
)
|
510
397
|
break
|
511
398
|
case "sync-macros":
|
512
|
-
console.log(
|
399
|
+
console.log(
|
400
|
+
colourS(
|
401
|
+
`\n${colourJ("Sync macros across all hackmud users")}\n\n${colourA("Options:")}\n${hackmudPathOption}`
|
402
|
+
)
|
403
|
+
)
|
513
404
|
break
|
514
405
|
default:
|
515
406
|
console.log(
|
516
407
|
colourS(
|
517
|
-
`\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("
|
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`
|
518
409
|
)
|
519
410
|
)
|
520
411
|
}
|
521
412
|
}
|
522
|
-
|
523
|
-
|
524
|
-
configDidNotExist && log("Creating config file at " + configFilePath)
|
525
|
-
await writeFile(configFilePath, json).catch(async error => {
|
526
|
-
switch (error.code) {
|
527
|
-
case "EISDIR":
|
528
|
-
await rmdir(configFilePath)
|
529
|
-
break
|
530
|
-
case "ENOENT":
|
531
|
-
await mkdir(configDirectoryPath)
|
532
|
-
break
|
533
|
-
default:
|
534
|
-
throw error
|
535
|
-
}
|
536
|
-
await writeFile(configFilePath, json)
|
537
|
-
})
|
538
|
-
}
|
539
|
-
function logInfo({ file, users, minLength, error }, hackmudPath) {
|
413
|
+
function logInfo({ path, users, characterCount, error }, hackmudPath) {
|
414
|
+
path = relative(".", path)
|
540
415
|
error ?
|
541
|
-
logError(`
|
542
|
-
:
|
543
|
-
`
|
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")}`
|
544
419
|
)
|
545
420
|
}
|
546
421
|
function logError(message) {
|
547
422
|
console.error(colourD(message))
|
548
423
|
process.exitCode = 1
|
549
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
|
+
}
|
@@ -6,8 +6,8 @@ export { push } from "./push";
|
|
6
6
|
export { syncMacros } from "./syncMacros";
|
7
7
|
export { watch } from "./watch";
|
8
8
|
export type Info = {
|
9
|
-
|
9
|
+
path: string;
|
10
10
|
users: string[];
|
11
|
-
|
11
|
+
characterCount: number;
|
12
12
|
error: Error | undefined;
|
13
13
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hackmud-script-manager",
|
3
|
-
"version": "0.19.1-
|
3
|
+
"version": "0.19.1-d57be2a",
|
4
4
|
"description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
|
5
5
|
"keywords": [
|
6
6
|
"api",
|
@@ -71,9 +71,13 @@
|
|
71
71
|
},
|
72
72
|
"type": "module",
|
73
73
|
"exports": {
|
74
|
+
".": "./index.js",
|
74
75
|
"./*": "./*.js",
|
75
76
|
"./*.js": "./*.js"
|
76
77
|
},
|
78
|
+
"bin": {
|
79
|
+
"hsm": "bin/hsm.js"
|
80
|
+
},
|
77
81
|
"engines": {
|
78
82
|
"node": "^18 || >=20"
|
79
83
|
}
|
@@ -3,11 +3,10 @@ export { minify } from "./minify";
|
|
3
3
|
export { postprocess } from "./postprocess";
|
4
4
|
export { preprocess } from "./preprocess";
|
5
5
|
export { transform } from "./transform";
|
6
|
-
export type ProcessOptions = {
|
6
|
+
export type ProcessOptions = LaxPartial<{
|
7
7
|
/** whether to minify the given code */ minify: boolean;
|
8
8
|
/** 11 a-z 0-9 characters */ uniqueID: string;
|
9
9
|
/** the user going to be hosting this script (or set to `true` if not yet known) */ scriptUser: string | true;
|
10
|
-
/** the name of this script (or set to `true` if not yet known) */ scriptName: string | true;
|
11
10
|
filePath: string;
|
12
11
|
/** whether to mangle function and class names (defaults to `false`) */ mangleNames: boolean;
|
13
12
|
/** when set to `true` forces use of quine cheats
|
@@ -17,15 +16,16 @@ export type ProcessOptions = {
|
|
17
16
|
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
18
17
|
*/
|
19
18
|
forceQuineCheats: boolean;
|
19
|
+
}> & {
|
20
|
+
scriptName: string | true;
|
20
21
|
};
|
21
22
|
/** Minifies a given script
|
22
23
|
* @param code JavaScript or TypeScript code
|
23
24
|
* @param options {@link ProcessOptions details} */
|
24
|
-
export declare function processScript(code: string, { minify: shouldMinify, uniqueID, scriptUser, scriptName, filePath, mangleNames, forceQuineCheats }
|
25
|
+
export declare function processScript(code: string, { minify: shouldMinify, uniqueID, scriptUser, scriptName, filePath, mangleNames, forceQuineCheats }: ProcessOptions): Promise<{
|
25
26
|
script: string;
|
26
27
|
warnings: {
|
27
28
|
message: string;
|
28
29
|
line: number;
|
29
30
|
}[];
|
30
31
|
}>;
|
31
|
-
export default processScript;
|
package/processScript/index.js
CHANGED
@@ -47,14 +47,14 @@ async function processScript(
|
|
47
47
|
uniqueID = Math.floor(Math.random() * 2 ** 52)
|
48
48
|
.toString(36)
|
49
49
|
.padStart(11, "0"),
|
50
|
-
scriptUser
|
51
|
-
scriptName
|
50
|
+
scriptUser,
|
51
|
+
scriptName,
|
52
52
|
filePath,
|
53
53
|
mangleNames = !1,
|
54
54
|
forceQuineCheats
|
55
|
-
}
|
55
|
+
}
|
56
56
|
) {
|
57
|
-
assert(/^\w{11}$/.exec(uniqueID), "src/processScript/index.ts:
|
57
|
+
assert(/^\w{11}$/.exec(uniqueID), "src/processScript/index.ts:77:36")
|
58
58
|
const sourceCode = code
|
59
59
|
let autocomplete, statedSeclevel
|
60
60
|
const autocompleteMatch = /^function\s*\(.+\/\/(?<autocomplete>.+)/.exec(code)
|
@@ -115,7 +115,7 @@ async function processScript(
|
|
115
115
|
}
|
116
116
|
}
|
117
117
|
}
|
118
|
-
assert(/^\w{11}$/.exec(uniqueID), "src/processScript/index.ts:
|
118
|
+
assert(/^\w{11}$/.exec(uniqueID), "src/processScript/index.ts:158:36")
|
119
119
|
const plugins = [
|
120
120
|
[babelPluginProposalDecorators.default, { decoratorsBeforeExport: !0 }],
|
121
121
|
[babelPluginTransformClassProperties.default],
|
@@ -249,7 +249,7 @@ async function processScript(
|
|
249
249
|
traverse(file, {
|
250
250
|
MemberExpression({ node: memberExpression }) {
|
251
251
|
if (!memberExpression.computed) {
|
252
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/index.ts:
|
252
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/index.ts:321:60")
|
253
253
|
if ("prototype" == memberExpression.property.name) {
|
254
254
|
memberExpression.computed = !0
|
255
255
|
memberExpression.property = t.stringLiteral("prototype")
|
@@ -279,7 +279,7 @@ async function processScript(
|
|
279
279
|
break
|
280
280
|
case "ObjectPattern":
|
281
281
|
for (const property of lValue.properties) {
|
282
|
-
assert("ObjectProperty" == property.type, "src/processScript/index.ts:
|
282
|
+
assert("ObjectProperty" == property.type, "src/processScript/index.ts:351:51")
|
283
283
|
renameVariables(property.value)
|
284
284
|
}
|
285
285
|
break
|
@@ -330,4 +330,4 @@ async function processScript(
|
|
330
330
|
)
|
331
331
|
return { script: code, warnings: [] }
|
332
332
|
}
|
333
|
-
export {
|
333
|
+
export { minify, postprocess, preprocess, processScript, transform }
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { File } from "@babel/types";
|
2
2
|
import type { LaxPartial } from "@samual/lib";
|
3
|
-
type MinifyOptions = {
|
3
|
+
type MinifyOptions = LaxPartial<{
|
4
4
|
/** 11 a-z 0-9 characters */ uniqueID: string;
|
5
5
|
/** whether to mangle function and class names (defaults to `false`) */ mangleNames: boolean;
|
6
6
|
/** when set to `true` forces use of quine cheats
|
@@ -11,8 +11,8 @@ type MinifyOptions = {
|
|
11
11
|
*/
|
12
12
|
forceQuineCheats: boolean;
|
13
13
|
/** the comment inserted after the function signature */ autocomplete: string;
|
14
|
-
}
|
14
|
+
}>;
|
15
15
|
/** @param file babel ast node representing a file containing transformed code
|
16
16
|
* @param options {@link MinifyOptions details} */
|
17
|
-
export declare function minify(file: File, { uniqueID, mangleNames, forceQuineCheats, autocomplete }?:
|
18
|
-
export
|
17
|
+
export declare function minify(file: File, { uniqueID, mangleNames, forceQuineCheats, autocomplete }?: MinifyOptions): Promise<string>;
|
18
|
+
export {};
|
package/processScript/minify.js
CHANGED
@@ -377,15 +377,15 @@ function parseObjectExpression(node, o) {
|
|
377
377
|
"Identifier" == property.key.type ||
|
378
378
|
"NumericLiteral" == property.key.type ||
|
379
379
|
"StringLiteral" == property.key.type,
|
380
|
-
"src/processScript/minify.ts:
|
380
|
+
"src/processScript/minify.ts:516:4"
|
381
381
|
)
|
382
382
|
if ("ArrayExpression" == property.value.type) {
|
383
383
|
const childArray = []
|
384
|
-
if (!parseArrayExpression(property.value, childArray)) return !1
|
384
|
+
if (property.value.elements.length && !parseArrayExpression(property.value, childArray)) return !1
|
385
385
|
o["Identifier" == property.key.type ? property.key.name : property.key.value] = childArray
|
386
386
|
} else if ("ObjectExpression" == property.value.type) {
|
387
387
|
const childObject = {}
|
388
|
-
if (!parseObjectExpression(property.value, childObject)) return !1
|
388
|
+
if (property.value.properties.length && !parseObjectExpression(property.value, childObject)) return !1
|
389
389
|
o["Identifier" == property.key.type ? property.key.name : property.key.value] = childObject
|
390
390
|
} else if ("NullLiteral" == property.value.type)
|
391
391
|
o["Identifier" == property.key.type ? property.key.name : property.key.value] = null
|
@@ -409,11 +409,11 @@ function parseArrayExpression(node, o) {
|
|
409
409
|
if (!element) return !1
|
410
410
|
if ("ArrayExpression" == element.type) {
|
411
411
|
const childArray = []
|
412
|
-
if (!parseArrayExpression(element, childArray)) return !1
|
412
|
+
if (!element.elements.length && parseArrayExpression(element, childArray)) return !1
|
413
413
|
o.push(childArray)
|
414
414
|
} else if ("ObjectExpression" == element.type) {
|
415
415
|
const childObject = {}
|
416
|
-
if (!parseObjectExpression(element, childObject)) return !1
|
416
|
+
if (element.properties.length && !parseObjectExpression(element, childObject)) return !1
|
417
417
|
o.push(childObject)
|
418
418
|
} else if ("NullLiteral" == element.type) o.push(null)
|
419
419
|
else if (
|
@@ -441,4 +441,4 @@ function getFunctionBodyStart(code) {
|
|
441
441
|
}
|
442
442
|
return tokens.getToken().start
|
443
443
|
}
|
444
|
-
export { minify
|
444
|
+
export { minify }
|
@@ -17,4 +17,4 @@ const postprocess = (code, seclevel, uniqueID) =>
|
|
17
17
|
.replace(RegExp(`\\$${uniqueID}\\$NOT_A_DEBUG_CALL\\$`, "g"), "#D\\(")
|
18
18
|
.replace(RegExp(`\\$${uniqueID}\\$NOT_FMCL\\$`, "g"), "#\\FMCL")
|
19
19
|
.replace(RegExp(`\\$${uniqueID}\\$NOT_G\\$`, "g"), "#\\G")
|
20
|
-
export { postprocess
|
20
|
+
export { postprocess }
|
@@ -1,9 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
import type { LaxPartial } from "@samual/lib";
|
2
|
+
export type PreprocessOptions = LaxPartial<{
|
3
|
+
uniqueID: string;
|
4
|
+
}>;
|
4
5
|
/** @param code source code for preprocessing
|
5
6
|
* @param options {@link PreprocessOptions details} */
|
6
|
-
export declare function preprocess(code: string, { uniqueID }?:
|
7
|
+
export declare function preprocess(code: string, { uniqueID }?: PreprocessOptions): Promise<{
|
7
8
|
code: string;
|
8
9
|
}>;
|
9
|
-
export default preprocess;
|
@@ -8,7 +8,7 @@ import { resolve } from "import-meta-resolve"
|
|
8
8
|
const { default: traverse } = babelTraverse,
|
9
9
|
{ default: generate } = babelGenerator
|
10
10
|
async function preprocess(code, { uniqueID = "00000000000" } = {}) {
|
11
|
-
assert(/^\w{11}$/.test(uniqueID), "src/processScript/preprocess.ts:
|
11
|
+
assert(/^\w{11}$/.test(uniqueID), "src/processScript/preprocess.ts:22:36")
|
12
12
|
const sourceCode = code
|
13
13
|
let lengthBefore, file, program
|
14
14
|
do {
|
@@ -47,7 +47,7 @@ async function preprocess(code, { uniqueID = "00000000000" } = {}) {
|
|
47
47
|
})
|
48
48
|
break
|
49
49
|
} catch (error_) {
|
50
|
-
assert(error_ instanceof SyntaxError, "src/processScript/preprocess.ts:
|
50
|
+
assert(error_ instanceof SyntaxError, "src/processScript/preprocess.ts:66:42")
|
51
51
|
error = error_
|
52
52
|
}
|
53
53
|
if ("BABEL_PARSER_SYNTAX_ERROR" != error.code || "PrivateInExpectedIn" != error.reasonCode) {
|
@@ -102,4 +102,4 @@ async function preprocess(code, { uniqueID = "00000000000" } = {}) {
|
|
102
102
|
{ code: "export default " + generate(file).code }
|
103
103
|
: { code: generate(file).code }
|
104
104
|
}
|
105
|
-
export { preprocess
|
105
|
+
export { preprocess }
|
@@ -1,9 +1,11 @@
|
|
1
1
|
import type { File } from "@babel/types";
|
2
|
-
|
2
|
+
import type { LaxPartial } from "@samual/lib";
|
3
|
+
export type TransformOptions = LaxPartial<{
|
3
4
|
/** 11 a-z 0-9 characters */ uniqueID: string;
|
4
5
|
/** the user going to be hosting this script (or set to `true` if not yet known) */ scriptUser: string | true;
|
5
|
-
/** the name of this script (or set to `true` if not yet known) */ scriptName: string | true;
|
6
6
|
seclevel: number;
|
7
|
+
}> & {
|
8
|
+
scriptName: string | true;
|
7
9
|
};
|
8
10
|
/** transform a given babel `File` to be hackmud compatible
|
9
11
|
*
|
@@ -11,8 +13,7 @@ export type TransformOptions = {
|
|
11
13
|
* @param file babel ast node representing a file containing preprocessed code
|
12
14
|
* @param sourceCode the original untouched source code
|
13
15
|
* @param options {@link TransformOptions details} */
|
14
|
-
export declare function transform(file: File, sourceCode: string, { uniqueID, scriptUser, scriptName, seclevel }
|
16
|
+
export declare function transform(file: File, sourceCode: string, { uniqueID, scriptUser, scriptName, seclevel }: TransformOptions): {
|
15
17
|
file: File;
|
16
18
|
seclevel: number;
|
17
19
|
};
|
18
|
-
export default transform;
|