hackmud-script-manager 0.20.4-769c77c → 0.20.4-9596502
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 +8 -7
- package/env.d.ts +662 -1295
- package/package.json +6 -2
- package/processScript/minify.js +11 -8
- package/processScript/transform.js +8 -6
- package/push.d.ts +5 -1
- package/push.js +26 -10
- package/syncMacros.js +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hackmud-script-manager",
|
3
|
-
"version": "0.20.4-
|
3
|
+
"version": "0.20.4-9596502",
|
4
4
|
"description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
|
5
5
|
"keywords": [
|
6
6
|
"api",
|
@@ -20,7 +20,11 @@
|
|
20
20
|
"homepage": "https://github.com/samualtnorman/hackmud-script-manager#readme",
|
21
21
|
"bugs": "https://github.com/samualtnorman/hackmud-script-manager/issues",
|
22
22
|
"license": "MIT",
|
23
|
-
"author": "Samual Norman",
|
23
|
+
"author": "Samual Norman <me@samual.uk> (https://samual.uk/)",
|
24
|
+
"contributors": [
|
25
|
+
"Daniel Swann (https://github.com/danswann)",
|
26
|
+
"Longboyy"
|
27
|
+
],
|
24
28
|
"main": "index.js",
|
25
29
|
"repository": {
|
26
30
|
"type": "git",
|
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)
|
@@ -220,8 +221,10 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
220
221
|
)
|
221
222
|
},
|
222
223
|
StringLiteral(path) {
|
223
|
-
path.node.value
|
224
|
-
|
224
|
+
if (JSON.stringify(path.node.value).includes("\\u00") || path.toString().length < 4) {
|
225
|
+
path.node.value = replaceUnsafeStrings(uniqueId, path.node.value)
|
226
|
+
return
|
227
|
+
}
|
225
228
|
"key" == path.parentKey && "ObjectProperty" == path.parent.type && (path.parent.computed = !0)
|
226
229
|
let jsonValueIndex = jsonValues.indexOf(path.node.value)
|
227
230
|
;-1 == jsonValueIndex && (jsonValueIndex += jsonValues.push(path.node.value))
|
@@ -244,7 +247,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
244
247
|
})
|
245
248
|
await Promise.all(promises)
|
246
249
|
const functionDeclaration = file.program.body[0]
|
247
|
-
assert("FunctionDeclaration" == functionDeclaration.type, "src/processScript/minify.ts:
|
250
|
+
assert("FunctionDeclaration" == functionDeclaration.type, "src/processScript/minify.ts:366:61")
|
248
251
|
if (jsonValues.length) {
|
249
252
|
hasComment = !0
|
250
253
|
if (1 == jsonValues.length)
|
@@ -361,7 +364,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
361
364
|
)
|
362
365
|
}
|
363
366
|
if (1 == forceQuineCheats) return code
|
364
|
-
assert(scriptBeforeJSONValueReplacement, "src/processScript/minify.ts:
|
367
|
+
assert(scriptBeforeJSONValueReplacement, "src/processScript/minify.ts:497:43")
|
365
368
|
return (
|
366
369
|
countHackmudCharacters(scriptBeforeJSONValueReplacement) <=
|
367
370
|
countHackmudCharacters(code) + Number(hasComment)
|
@@ -377,7 +380,7 @@ function parseObjectExpression(node, o) {
|
|
377
380
|
"Identifier" == property.key.type ||
|
378
381
|
"NumericLiteral" == property.key.type ||
|
379
382
|
"StringLiteral" == property.key.type,
|
380
|
-
"src/processScript/minify.ts:
|
383
|
+
"src/processScript/minify.ts:519:4"
|
381
384
|
)
|
382
385
|
if ("ArrayExpression" == property.value.type) {
|
383
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.d.ts
CHANGED
@@ -18,6 +18,10 @@ export type PushOptions = LaxPartial<{
|
|
18
18
|
*/
|
19
19
|
forceQuineCheats: boolean;
|
20
20
|
}>;
|
21
|
+
export declare class MissingSourceFolderError extends Error {
|
22
|
+
}
|
23
|
+
export declare class MissingHackmudFolderError extends Error {
|
24
|
+
}
|
21
25
|
/** Push scripts from a source directory to the hackmud directory.
|
22
26
|
*
|
23
27
|
* Pushes files directly in the source folder to all users
|
@@ -25,4 +29,4 @@ export type PushOptions = LaxPartial<{
|
|
25
29
|
* @param hackmudPath directory created by hackmud containing user data including scripts
|
26
30
|
* @param options {@link PushOptions details}
|
27
31
|
* @returns array of info on pushed scripts */
|
28
|
-
export declare function push(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: PushOptions): Promise<Info[]>;
|
32
|
+
export declare function push(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: PushOptions): Promise<MissingSourceFolderError | MissingHackmudFolderError | Info[]>;
|
package/push.js
CHANGED
@@ -42,32 +42,48 @@ import "./processScript/preprocess.js"
|
|
42
42
|
import "import-meta-resolve"
|
43
43
|
import "./processScript/transform.js"
|
44
44
|
import "@samual/lib/clearObject"
|
45
|
+
class MissingSourceFolderError extends Error {}
|
46
|
+
Object.defineProperty(MissingSourceFolderError.prototype, "name", { value: "MissingSourceFolderError" })
|
47
|
+
class MissingHackmudFolderError extends Error {}
|
48
|
+
Object.defineProperty(MissingHackmudFolderError.prototype, "name", { value: "MissingHackmudFolderError" })
|
45
49
|
async function push(
|
46
50
|
sourcePath,
|
47
51
|
hackmudPath,
|
48
52
|
{ scripts = ["*.*"], onPush = () => {}, minify = !0, mangleNames = !1, forceQuineCheats } = {}
|
49
53
|
) {
|
50
54
|
const [sourceFolder, hackmudFolder] = await Promise.all([
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
readDirectoryWithStats(sourcePath).catch(error => {
|
56
|
+
if (error && "ENOENT" == error.code)
|
57
|
+
return new MissingSourceFolderError("There is no folder at " + sourcePath)
|
58
|
+
throw error
|
59
|
+
}),
|
60
|
+
readDirectoryWithStats(hackmudPath).catch(error => {
|
61
|
+
if (error && "ENOENT" == error.code)
|
62
|
+
return new MissingHackmudFolderError("There is no folder at " + hackmudPath)
|
63
|
+
throw error
|
64
|
+
})
|
65
|
+
])
|
66
|
+
if (sourceFolder instanceof Error) return sourceFolder
|
67
|
+
if (hackmudFolder instanceof Error) return hackmudFolder
|
68
|
+
const sourceFolderFolders = sourceFolder.filter(({ stats }) => stats.isDirectory()),
|
55
69
|
allUsers = new Set([
|
56
70
|
...scripts
|
57
|
-
.map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:
|
71
|
+
.map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:76:65"))
|
58
72
|
.filter(name => "*" != name),
|
59
73
|
...sourceFolderFolders.map(({ name }) => name),
|
60
74
|
...hackmudFolder.filter(({ stats }) => stats.isDirectory()).map(({ name }) => name),
|
61
75
|
...hackmudFolder
|
62
76
|
.filter(({ stats, name }) => stats.isFile() && name.endsWith(".key"))
|
63
77
|
.map(({ name }) => name.slice(0, -4))
|
64
|
-
])
|
65
|
-
|
78
|
+
])
|
79
|
+
if (!allUsers.size)
|
80
|
+
throw Error("Could not find any users. Either provide the names of your users or log into a user in hackmud.")
|
81
|
+
const usersToScriptsToPush = new Cache(_user => new Map()),
|
66
82
|
scriptNamesToUsers = new Cache(_scriptName => new Set())
|
67
83
|
for (const script of scripts) {
|
68
84
|
const [user, scriptName] = script.split(".")
|
69
|
-
assert(user, "src/push.ts:
|
70
|
-
assert(scriptName, "src/push.ts:
|
85
|
+
assert(user, "src/push.ts:96:16")
|
86
|
+
assert(scriptName, "src/push.ts:97:22")
|
71
87
|
"*" == user ? scriptNamesToUsers.set(scriptName, allUsers) : scriptNamesToUsers.get(scriptName).add(user)
|
72
88
|
}
|
73
89
|
const sourceFolderFiles = sourceFolder.filter(({ stats }) => stats.isFile()),
|
@@ -135,4 +151,4 @@ async function push(
|
|
135
151
|
)
|
136
152
|
return allInfo
|
137
153
|
}
|
138
|
-
export { push }
|
154
|
+
export { MissingHackmudFolderError, MissingSourceFolderError, push }
|
package/syncMacros.js
CHANGED
@@ -37,7 +37,7 @@ async function syncMacros(hackmudPath) {
|
|
37
37
|
macroFile += `${name}\n${macro}\n`
|
38
38
|
macrosSynced++
|
39
39
|
}
|
40
|
-
|
40
|
+
await Promise.all(users.map(async user => writeFile(resolve(hackmudPath, user + ".macros"), macroFile)))
|
41
41
|
return { macrosSynced, usersSynced: users.length }
|
42
42
|
}
|
43
43
|
export { syncMacros }
|