hackmud-script-manager 0.20.4-e675c94 → 0.20.5-97101bc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/hsm.js +1 -1
- package/env.d.ts +5 -20
- package/package.json +1 -1
- package/processScript/minify.js +7 -6
- package/processScript/transform.js +8 -6
- package/push.js +6 -4
package/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Hackmud Script Manager
|
2
|
-
Command made for [
|
2
|
+
Command made for [Hackmud Scripting Environment](https://github.com/samualtnorman/hackmud-environment), which is a scripting environment for hackmud with minification, autocompletes / intellisense, and TypeScript support.
|
3
3
|
|
4
4
|
[](https://ko-fi.com/R6R0XN5CX)
|
5
5
|
|
package/bin/hsm.js
CHANGED
@@ -12,7 +12,7 @@ import { pull } from "../pull.js"
|
|
12
12
|
import { syncMacros } from "../syncMacros.js"
|
13
13
|
import "@samual/lib/readDirectoryWithStats"
|
14
14
|
import "@samual/lib/copyFilePersistent"
|
15
|
-
const version = "0.20.
|
15
|
+
const version = "0.20.5-97101bc",
|
16
16
|
options = new Map(),
|
17
17
|
commands = [],
|
18
18
|
userColours = new Cache(user => {
|
package/env.d.ts
CHANGED
@@ -1,20 +1,9 @@
|
|
1
|
-
type Replace<
|
1
|
+
type Replace<A, B> = Omit<A, keyof B> & B
|
2
2
|
type ScriptSuccess<T = object> = { ok: true } & T
|
3
3
|
type ScriptFailure = { ok: false, msg?: string }
|
4
4
|
type ScriptResponse<T = object> = ScriptSuccess<T> | ScriptFailure
|
5
5
|
type ErrorScripts = Record<string, () => ScriptFailure>
|
6
6
|
|
7
|
-
type AllOptional<T> = {
|
8
|
-
[K in keyof T]-?: {} extends Pick<T, K> ? true : false
|
9
|
-
}[keyof T]
|
10
|
-
|
11
|
-
type Scriptor<Args = unknown, Ret = unknown> = {
|
12
|
-
name: string,
|
13
|
-
call: AllOptional<Args> extends true
|
14
|
-
? (args?: Args) => Ret
|
15
|
-
: (args: Args) => Ret
|
16
|
-
}
|
17
|
-
|
18
7
|
type Subscripts = Record<string, Record<string, (...args: any) => any>> & {
|
19
8
|
accts: ErrorScripts
|
20
9
|
autos: ErrorScripts
|
@@ -37,16 +26,12 @@ interface PlayerMidsec {}
|
|
37
26
|
interface PlayerLowsec {}
|
38
27
|
interface PlayerNullsec {}
|
39
28
|
|
40
|
-
type UpgradeRarityString = "`0noob`" | "`1kiddie`" | "`2h4x0r`" | "`3h4rdc0r3`" | "`4|_|b3|2`" | "`531337`"
|
41
|
-
type UpgradeRarityNumber = 0 | 1 | 2 | 3 | 4 | 5;
|
42
|
-
type UpgradeRarity = UpgradeRarityString | UpgradeRarityNumber;
|
43
|
-
|
44
29
|
type UpgradeCore = {
|
45
30
|
name: string
|
46
31
|
type: "lock" | "script_space" | "chat" | "script" | "tool" | "bot_brain" | "glam"
|
47
32
|
up_class?: -1 | 0 | 1 | 2 | 3
|
48
33
|
tier: 1 | 2 | 3 | 4
|
49
|
-
rarity:
|
34
|
+
rarity: 0 | 1 | 2 | 3 | 4 | 5
|
50
35
|
i: number
|
51
36
|
loaded: boolean
|
52
37
|
sn: string
|
@@ -57,7 +42,7 @@ type Upgrade = UpgradeCore & Record<string, null | boolean | number | string>
|
|
57
42
|
|
58
43
|
type CLIUpgrade = Omit<UpgradeCore, `rarity`> & {
|
59
44
|
[x: string]: null | boolean | number | string
|
60
|
-
rarity:
|
45
|
+
rarity: "`0noob`" | "`1kiddie`" | "`2h4x0r`" | "`3h4rdc0r3`" | "`4|_|b3|2`" | "`531337`"
|
61
46
|
}
|
62
47
|
|
63
48
|
type UsersTopItem<R> = { rank: R, name: string, last_activity: string, balance: string }
|
@@ -357,7 +342,7 @@ type Fullsec = Subscripts & PlayerFullsec & {
|
|
357
342
|
* const arr = [ 1, 2, 2, 3, 2 ]
|
358
343
|
*
|
359
344
|
* $D(uniq(arr)) // [ 1, 2, 3, 2 ] */
|
360
|
-
uniq: (array: T[]) => T[]
|
345
|
+
uniq: <T>(array: T[]) => T[]
|
361
346
|
|
362
347
|
/** Sorts an array of numbers or number-coercible strings in descending order. */
|
363
348
|
u_sort_num_arr_desc: <T>(array: T[]) => T[]
|
@@ -534,7 +519,7 @@ type Highsec = Fullsec & PlayerHighsec & {
|
|
534
519
|
args?: { filter?: F, is_script: false, full: true }
|
535
520
|
): (Omit<UpgradeCore, keyof F | `rarity`> & F & {
|
536
521
|
[x: string]: null | boolean | number | string
|
537
|
-
rarity:
|
522
|
+
rarity: "`0noob`" | "`1kiddie`" | "`2h4x0r`" | "`3h4rdc0r3`" | "`4|_|b3|2`" | "`531337`"
|
538
523
|
})[] | ScriptFailure
|
539
524
|
}
|
540
525
|
}
|
package/package.json
CHANGED
package/processScript/minify.js
CHANGED
@@ -136,7 +136,8 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
136
136
|
const promises = []
|
137
137
|
traverse(file, {
|
138
138
|
FunctionDeclaration(path) {
|
139
|
-
path.
|
139
|
+
const body = path.get("body")
|
140
|
+
body.traverse({
|
140
141
|
Function(path) {
|
141
142
|
"CallExpression" != path.parent.type && "callee" != path.parentKey && path.skip()
|
142
143
|
},
|
@@ -152,7 +153,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
152
153
|
path.replaceWith(t.identifier(`_${uniqueId}_JSON_VALUE_${jsonValues.push(o) - 1}_`))
|
153
154
|
}
|
154
155
|
})
|
155
|
-
|
156
|
+
body.traverse({
|
156
157
|
TemplateLiteral(path) {
|
157
158
|
if ("TaggedTemplateExpression" == path.parent.type) return
|
158
159
|
const templateLiteral = path.node
|
@@ -172,7 +173,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
172
173
|
},
|
173
174
|
MemberExpression({ node: memberExpression }) {
|
174
175
|
if (!memberExpression.computed) {
|
175
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:
|
176
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:261:62")
|
176
177
|
if (!(memberExpression.property.name.length < 3)) {
|
177
178
|
memberExpression.computed = !0
|
178
179
|
memberExpression.property = t.stringLiteral(memberExpression.property.name)
|
@@ -246,7 +247,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
246
247
|
})
|
247
248
|
await Promise.all(promises)
|
248
249
|
const functionDeclaration = file.program.body[0]
|
249
|
-
assert("FunctionDeclaration" == functionDeclaration.type, "src/processScript/minify.ts:
|
250
|
+
assert("FunctionDeclaration" == functionDeclaration.type, "src/processScript/minify.ts:366:61")
|
250
251
|
if (jsonValues.length) {
|
251
252
|
hasComment = !0
|
252
253
|
if (1 == jsonValues.length)
|
@@ -363,7 +364,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
363
364
|
)
|
364
365
|
}
|
365
366
|
if (1 == forceQuineCheats) return code
|
366
|
-
assert(scriptBeforeJSONValueReplacement, "src/processScript/minify.ts:
|
367
|
+
assert(scriptBeforeJSONValueReplacement, "src/processScript/minify.ts:497:43")
|
367
368
|
return (
|
368
369
|
countHackmudCharacters(scriptBeforeJSONValueReplacement) <=
|
369
370
|
countHackmudCharacters(code) + Number(hasComment)
|
@@ -379,7 +380,7 @@ function parseObjectExpression(node, o) {
|
|
379
380
|
"Identifier" == property.key.type ||
|
380
381
|
"NumericLiteral" == property.key.type ||
|
381
382
|
"StringLiteral" == property.key.type,
|
382
|
-
"src/processScript/minify.ts:
|
383
|
+
"src/processScript/minify.ts:519:4"
|
383
384
|
)
|
384
385
|
if ("ArrayExpression" == property.value.type) {
|
385
386
|
const childArray = []
|
@@ -631,7 +631,9 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
631
631
|
VariableDeclaration({ node: variableDeclaration }) {
|
632
632
|
"const" == variableDeclaration.kind && (variableDeclaration.kind = "let")
|
633
633
|
},
|
634
|
-
ThisExpression: path =>
|
634
|
+
ThisExpression: path => {
|
635
|
+
path.replaceWith(t.identifier("undefined"))
|
636
|
+
},
|
635
637
|
BigIntLiteral(path) {
|
636
638
|
const bigIntAsNumber = Number(path.node.value)
|
637
639
|
path.replaceWith(
|
@@ -661,23 +663,23 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
661
663
|
}
|
662
664
|
function processFakeSubscriptObject(fakeSubscriptObjectName) {
|
663
665
|
for (const referencePath of getReferencePathsToGlobal(fakeSubscriptObjectName, program)) {
|
664
|
-
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:
|
666
|
+
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:785:60")
|
665
667
|
assert("Identifier" == referencePath.parent.property.type)
|
666
668
|
assert(
|
667
669
|
"MemberExpression" == referencePath.parentPath.parentPath?.node.type,
|
668
|
-
"src/processScript/transform.ts:
|
670
|
+
"src/processScript/transform.ts:787:81"
|
669
671
|
)
|
670
672
|
assert(
|
671
673
|
"Identifier" == referencePath.parentPath.parentPath.node.property.type,
|
672
|
-
"src/processScript/transform.ts:
|
674
|
+
"src/processScript/transform.ts:788:83"
|
673
675
|
)
|
674
676
|
assert(
|
675
677
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parent.property.name),
|
676
|
-
`src/processScript/transform.ts:
|
678
|
+
`src/processScript/transform.ts:792:8 invalid user "${referencePath.parent.property.name}" in subscript`
|
677
679
|
)
|
678
680
|
assert(
|
679
681
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parentPath.parentPath.node.property.name),
|
680
|
-
`src/processScript/transform.ts:
|
682
|
+
`src/processScript/transform.ts:797:8 invalid script name "${referencePath.parentPath.parentPath.node.property.name}" in subscript`
|
681
683
|
)
|
682
684
|
if ("CallExpression" == referencePath.parentPath.parentPath.parentPath?.type)
|
683
685
|
referencePath.parentPath.parentPath.replaceWith(
|
package/push.js
CHANGED
@@ -61,13 +61,15 @@ async function push(
|
|
61
61
|
...hackmudFolder
|
62
62
|
.filter(({ stats, name }) => stats.isFile() && name.endsWith(".key"))
|
63
63
|
.map(({ name }) => name.slice(0, -4))
|
64
|
-
])
|
65
|
-
|
64
|
+
])
|
65
|
+
if (!allUsers.size)
|
66
|
+
throw Error("Could not find any users. Either provide the names of your users or log into a user in hackmud.")
|
67
|
+
const usersToScriptsToPush = new Cache(_user => new Map()),
|
66
68
|
scriptNamesToUsers = new Cache(_scriptName => new Set())
|
67
69
|
for (const script of scripts) {
|
68
70
|
const [user, scriptName] = script.split(".")
|
69
|
-
assert(user, "src/push.ts:
|
70
|
-
assert(scriptName, "src/push.ts:
|
71
|
+
assert(user, "src/push.ts:72:16")
|
72
|
+
assert(scriptName, "src/push.ts:73:22")
|
71
73
|
"*" == user ? scriptNamesToUsers.set(scriptName, allUsers) : scriptNamesToUsers.get(scriptName).add(user)
|
72
74
|
}
|
73
75
|
const sourceFolderFiles = sourceFolder.filter(({ stats }) => stats.isFile()),
|