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
@@ -21,11 +21,7 @@ const { default: traverse } = babelTraverse,
|
|
21
21
|
"Symbol",
|
22
22
|
"BigInt"
|
23
23
|
]
|
24
|
-
function transform(
|
25
|
-
file,
|
26
|
-
sourceCode,
|
27
|
-
{ uniqueID = "00000000000", scriptUser = "UNKNOWN", scriptName = "UNKNOWN", seclevel = 4 } = {}
|
28
|
-
) {
|
24
|
+
function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scriptName, seclevel = 4 }) {
|
29
25
|
const topFunctionName = `_${uniqueID}_SCRIPT_`,
|
30
26
|
exports = new Map(),
|
31
27
|
liveExports = new Map()
|
@@ -42,21 +38,31 @@ function transform(
|
|
42
38
|
if (program.scope.hasGlobal("_BUILD_DATE"))
|
43
39
|
for (const referencePath of getReferencePathsToGlobal("_BUILD_DATE", program))
|
44
40
|
referencePath.replaceWith(t.numericLiteral(Date.now()))
|
41
|
+
let uniqueIdScriptUserNeeded = !1
|
45
42
|
if (program.scope.hasGlobal("_SCRIPT_USER"))
|
46
43
|
for (const referencePath of getReferencePathsToGlobal("_SCRIPT_USER", program))
|
47
|
-
|
44
|
+
if (null == scriptUser) {
|
45
|
+
uniqueIdScriptUserNeeded = !0
|
46
|
+
referencePath.replaceWith(t.identifier(`_${uniqueID}_SCRIPT_USER_`))
|
47
|
+
} else
|
48
|
+
referencePath.replaceWith(t.stringLiteral(1 == scriptUser ? `$${uniqueID}$SCRIPT_USER$` : scriptUser))
|
48
49
|
if (program.scope.hasGlobal("_SCRIPT_NAME"))
|
49
50
|
for (const referencePath of getReferencePathsToGlobal("_SCRIPT_NAME", program))
|
50
51
|
referencePath.replaceWith(t.stringLiteral(1 == scriptName ? `$${uniqueID}$SCRIPT_NAME$` : scriptName))
|
51
52
|
if (program.scope.hasGlobal("_FULL_SCRIPT_NAME"))
|
52
53
|
for (const referencePath of getReferencePathsToGlobal("_FULL_SCRIPT_NAME", program))
|
53
|
-
|
54
|
-
t.stringLiteral(
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
if (1 == scriptUser || 1 == scriptName)
|
55
|
+
referencePath.replaceWith(t.stringLiteral(`$${uniqueID}$FULL_SCRIPT_NAME$`))
|
56
|
+
else if (null == scriptUser) {
|
57
|
+
uniqueIdScriptUserNeeded = !0
|
58
|
+
referencePath.replaceWith(
|
59
|
+
t.binaryExpression(
|
60
|
+
"+",
|
61
|
+
t.identifier(`_${uniqueID}_SCRIPT_USER_`),
|
62
|
+
t.stringLiteral("." + scriptName)
|
63
|
+
)
|
58
64
|
)
|
59
|
-
)
|
65
|
+
} else referencePath.replaceWith(t.stringLiteral(`${scriptUser}.${scriptName}`))
|
60
66
|
let functionDotPrototypeIsReferencedMultipleTimes = !1
|
61
67
|
if (program.scope.hasGlobal("Function")) {
|
62
68
|
const FunctionReferencePaths = getReferencePathsToGlobal("Function", program)
|
@@ -64,30 +70,30 @@ function transform(
|
|
64
70
|
const referencePath = FunctionReferencePaths[0]
|
65
71
|
assert(
|
66
72
|
"MemberExpression" == referencePath.parent.type,
|
67
|
-
"src/processScript/transform.ts:
|
73
|
+
"src/processScript/transform.ts:105:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
68
74
|
)
|
69
75
|
assert(
|
70
76
|
"Identifier" == referencePath.parent.property.type,
|
71
|
-
"src/processScript/transform.ts:
|
77
|
+
"src/processScript/transform.ts:110:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
72
78
|
)
|
73
79
|
assert(
|
74
80
|
"prototype" == referencePath.parent.property.name,
|
75
|
-
"src/processScript/transform.ts:
|
81
|
+
"src/processScript/transform.ts:115:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
76
82
|
)
|
77
83
|
referencePath.parentPath.replaceWith(createGetFunctionPrototypeNode())
|
78
84
|
} else {
|
79
85
|
for (const referencePath of FunctionReferencePaths) {
|
80
86
|
assert(
|
81
87
|
"MemberExpression" == referencePath.parent.type,
|
82
|
-
"src/processScript/transform.ts:
|
88
|
+
"src/processScript/transform.ts:123:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
83
89
|
)
|
84
90
|
assert(
|
85
91
|
"Identifier" == referencePath.parent.property.type,
|
86
|
-
"src/processScript/transform.ts:
|
92
|
+
"src/processScript/transform.ts:128:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
87
93
|
)
|
88
94
|
assert(
|
89
95
|
"prototype" == referencePath.parent.property.name,
|
90
|
-
"src/processScript/transform.ts:
|
96
|
+
"src/processScript/transform.ts:133:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
91
97
|
)
|
92
98
|
functionDotPrototypeIsReferencedMultipleTimes = !0
|
93
99
|
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueID}_FUNCTION_DOT_PROTOTYPE_`))
|
@@ -123,12 +129,12 @@ function transform(
|
|
123
129
|
const neededDbMethodLets = new Set()
|
124
130
|
if (program.scope.hasGlobal("$db"))
|
125
131
|
for (const referencePath of getReferencePathsToGlobal("$db", program)) {
|
126
|
-
assert("MemberExpression" == referencePath.parentPath.node.type, "src/processScript/transform.ts:
|
127
|
-
assert("Identifier" == referencePath.parentPath.node.property.type, "src/processScript/transform.ts:
|
132
|
+
assert("MemberExpression" == referencePath.parentPath.node.type, "src/processScript/transform.ts:187:69")
|
133
|
+
assert("Identifier" == referencePath.parentPath.node.property.type, "src/processScript/transform.ts:188:72")
|
128
134
|
const databaseOpMethodName = referencePath.parentPath.node.property.name
|
129
135
|
assert(
|
130
136
|
validDBMethods.includes(databaseOpMethodName),
|
131
|
-
`src/processScript/transform.ts:
|
137
|
+
`src/processScript/transform.ts:194:8 invalid db method "${databaseOpMethodName}", valid db methods are "${validDBMethods.join('", "')}"`
|
132
138
|
)
|
133
139
|
if ("CallExpression" == referencePath.parentPath.parentPath?.type)
|
134
140
|
referencePath.parentPath.replaceWith(t.identifier(`$${uniqueID}$DB$${databaseOpMethodName}$`))
|
@@ -161,7 +167,7 @@ function transform(
|
|
161
167
|
if (program.scope.hasGlobal("Object"))
|
162
168
|
for (const referencePath of getReferencePathsToGlobal("Object", program))
|
163
169
|
if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
|
164
|
-
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:
|
170
|
+
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:241:64")
|
165
171
|
if ("getPrototypeOf" == referencePath.parent.property.name) {
|
166
172
|
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueID}_GET_PROTOTYPE_OF_`))
|
167
173
|
needGetPrototypeOf = !0
|
@@ -171,7 +177,7 @@ function transform(
|
|
171
177
|
if (program.scope.hasGlobal("console"))
|
172
178
|
for (const referencePath of getReferencePathsToGlobal("console", program))
|
173
179
|
if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
|
174
|
-
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:
|
180
|
+
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:256:64")
|
175
181
|
referencePath.parentPath.replaceWith(
|
176
182
|
t.identifier(`_${uniqueID}_CONSOLE_METHOD_${referencePath.parent.property.name}_`)
|
177
183
|
)
|
@@ -179,13 +185,13 @@ function transform(
|
|
179
185
|
}
|
180
186
|
const lastStatement = program.node.body.at(-1)
|
181
187
|
let exportDefaultName
|
182
|
-
assert(lastStatement, "src/processScript/transform.ts:
|
188
|
+
assert(lastStatement, "src/processScript/transform.ts:270:27 program is empty")
|
183
189
|
if ("ExportNamedDeclaration" == lastStatement.type) {
|
184
190
|
program.node.body.pop()
|
185
191
|
for (const specifier of lastStatement.specifiers) {
|
186
192
|
assert(
|
187
193
|
"ExportSpecifier" == specifier.type,
|
188
|
-
`src/processScript/transform.ts:
|
194
|
+
`src/processScript/transform.ts:276:51 ${specifier.type} is currently unsupported`
|
189
195
|
)
|
190
196
|
const exportedName =
|
191
197
|
"Identifier" == specifier.exported.type ? specifier.exported.name : specifier.exported.value
|
@@ -261,6 +267,28 @@ function transform(
|
|
261
267
|
[t.identifier("context"), t.identifier("args")],
|
262
268
|
t.blockStatement([])
|
263
269
|
)
|
270
|
+
if (uniqueIdScriptUserNeeded) {
|
271
|
+
const mainFunctionParams = mainFunction.params
|
272
|
+
mainFunction.params = [t.restElement(t.identifier(`_${uniqueID}_PARAMS_`))]
|
273
|
+
mainFunction.body.body.unshift(
|
274
|
+
t.variableDeclaration("let", [
|
275
|
+
t.variableDeclarator(t.arrayPattern(mainFunctionParams), t.identifier(`_${uniqueID}_PARAMS_`)),
|
276
|
+
t.variableDeclarator(
|
277
|
+
t.arrayPattern([t.identifier(`_${uniqueID}_SCRIPT_USER_`)]),
|
278
|
+
t.callExpression(
|
279
|
+
t.memberExpression(
|
280
|
+
t.memberExpression(
|
281
|
+
t.memberExpression(t.identifier(`_${uniqueID}_PARAMS_`), t.numericLiteral(0), !0),
|
282
|
+
t.identifier("this_script")
|
283
|
+
),
|
284
|
+
t.identifier("split")
|
285
|
+
),
|
286
|
+
[t.stringLiteral(".")]
|
287
|
+
)
|
288
|
+
)
|
289
|
+
])
|
290
|
+
)
|
291
|
+
}
|
264
292
|
program.node.body = [mainFunction]
|
265
293
|
if (globalBlock.body.length) {
|
266
294
|
;(exports.size || liveExports.size) &&
|
@@ -286,11 +314,11 @@ function transform(
|
|
286
314
|
let hoistedGlobalBlockFunctions = 0
|
287
315
|
for (const [globalBlockIndex, globalBlockStatement] of [...globalBlock.body.entries()].reverse())
|
288
316
|
if ("VariableDeclaration" == globalBlockStatement.type) {
|
289
|
-
assert(1 == globalBlockStatement.declarations.length, "src/processScript/transform.ts:
|
317
|
+
assert(1 == globalBlockStatement.declarations.length, "src/processScript/transform.ts:410:59")
|
290
318
|
const declarator = globalBlockStatement.declarations[0]
|
291
319
|
assert(
|
292
320
|
"Identifier" == declarator.id.type,
|
293
|
-
`src/processScript/transform.ts:
|
321
|
+
`src/processScript/transform.ts:414:51 declarator.id.type was "${declarator.id.type}"`
|
294
322
|
)
|
295
323
|
program.scope.crawl()
|
296
324
|
if (program.scope.hasGlobal(declarator.id.name)) {
|
@@ -305,9 +333,9 @@ function transform(
|
|
305
333
|
Object.keys(program.scope.globals).some(global => globalBlockVariables.has(global))
|
306
334
|
) {
|
307
335
|
const binding = program.scope.getBinding(declarator.id.name)
|
308
|
-
assert(binding, "src/processScript/transform.ts:
|
336
|
+
assert(binding, "src/processScript/transform.ts:433:23")
|
309
337
|
for (const referencePath of binding.referencePaths) {
|
310
|
-
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:
|
338
|
+
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:436:56")
|
311
339
|
referencePath.replaceWith(
|
312
340
|
t.memberExpression(
|
313
341
|
t.identifier(`$${uniqueID}$GLOBAL$`),
|
@@ -351,16 +379,16 @@ function transform(
|
|
351
379
|
} else globalBlockVariables.add(declarator.id.name)
|
352
380
|
} else if ("ClassDeclaration" == globalBlockStatement.type) {
|
353
381
|
program.scope.crawl()
|
354
|
-
assert(globalBlockStatement.id, "src/processScript/transform.ts:
|
382
|
+
assert(globalBlockStatement.id, "src/processScript/transform.ts:487:37")
|
355
383
|
if (program.scope.hasGlobal(globalBlockStatement.id.name)) {
|
356
384
|
globalBlock.body.splice(globalBlockIndex, 1)
|
357
385
|
const [globalBlockPath] = program.unshiftContainer("body", globalBlock),
|
358
386
|
[globalBlockStatementPath] = program.unshiftContainer("body", globalBlockStatement)
|
359
387
|
program.scope.crawl()
|
360
388
|
const binding = program.scope.getBinding(globalBlockStatement.id.name)
|
361
|
-
assert(binding, "src/processScript/transform.ts:
|
389
|
+
assert(binding, "src/processScript/transform.ts:499:22")
|
362
390
|
for (const referencePath of binding.referencePaths) {
|
363
|
-
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:
|
391
|
+
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:502:55")
|
364
392
|
referencePath.replaceWith(
|
365
393
|
t.memberExpression(
|
366
394
|
t.identifier(`$${uniqueID}$GLOBAL$`),
|
@@ -527,7 +555,7 @@ function transform(
|
|
527
555
|
}
|
528
556
|
},
|
529
557
|
ClassBody({ node: classBody, scope, parent }) {
|
530
|
-
assert(t.isClass(parent), "src/processScript/transform.ts:
|
558
|
+
assert(t.isClass(parent), "src/processScript/transform.ts:669:30")
|
531
559
|
let thisIsReferenced = !1
|
532
560
|
for (const classMethod of classBody.body) {
|
533
561
|
if ("ClassMethod" != classMethod.type) continue
|
@@ -633,23 +661,23 @@ function transform(
|
|
633
661
|
}
|
634
662
|
function processFakeSubscriptObject(fakeSubscriptObjectName) {
|
635
663
|
for (const referencePath of getReferencePathsToGlobal(fakeSubscriptObjectName, program)) {
|
636
|
-
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:
|
664
|
+
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:783:60")
|
637
665
|
assert("Identifier" == referencePath.parent.property.type)
|
638
666
|
assert(
|
639
667
|
"MemberExpression" == referencePath.parentPath.parentPath?.node.type,
|
640
|
-
"src/processScript/transform.ts:
|
668
|
+
"src/processScript/transform.ts:785:81"
|
641
669
|
)
|
642
670
|
assert(
|
643
671
|
"Identifier" == referencePath.parentPath.parentPath.node.property.type,
|
644
|
-
"src/processScript/transform.ts:
|
672
|
+
"src/processScript/transform.ts:786:83"
|
645
673
|
)
|
646
674
|
assert(
|
647
675
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parent.property.name),
|
648
|
-
`src/processScript/transform.ts:
|
676
|
+
`src/processScript/transform.ts:790:8 invalid user "${referencePath.parent.property.name}" in subscript`
|
649
677
|
)
|
650
678
|
assert(
|
651
679
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parentPath.parentPath.node.property.name),
|
652
|
-
`src/processScript/transform.ts:
|
680
|
+
`src/processScript/transform.ts:795:8 invalid script name "${referencePath.parentPath.parentPath.node.property.name}" in subscript`
|
653
681
|
)
|
654
682
|
if ("CallExpression" == referencePath.parentPath.parentPath.parentPath?.type)
|
655
683
|
referencePath.parentPath.parentPath.replaceWith(
|
@@ -665,4 +693,4 @@ function transform(
|
|
665
693
|
}
|
666
694
|
}
|
667
695
|
}
|
668
|
-
export { transform
|
696
|
+
export { transform }
|
package/pull.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { LaxPartial } from "@samual/lib";
|
2
2
|
import type { Info } from ".";
|
3
|
-
export type PushOptions = {
|
3
|
+
export type PushOptions = LaxPartial<{
|
4
4
|
/** whether to do the minify step (defaults to `true`) */ minify: boolean;
|
5
5
|
/** whether to mangle function and class names (defaults to `false`) */ mangleNames: boolean;
|
6
6
|
/** array of scripts in the format `foo.bar`
|
@@ -17,13 +17,12 @@ export type PushOptions = {
|
|
17
17
|
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
18
18
|
*/
|
19
19
|
forceQuineCheats: boolean;
|
20
|
-
}
|
20
|
+
}>;
|
21
21
|
/** Push scripts from a source directory to the hackmud directory.
|
22
22
|
*
|
23
23
|
* Pushes files directly in the source folder to all users
|
24
|
-
* @param
|
25
|
-
* @param
|
24
|
+
* @param sourcePath directory containing source code
|
25
|
+
* @param hackmudPath directory created by hackmud containing user data including scripts
|
26
26
|
* @param options {@link PushOptions details}
|
27
27
|
* @returns array of info on pushed scripts */
|
28
|
-
export declare function push(
|
29
|
-
export default push;
|
28
|
+
export declare function push(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: PushOptions): Promise<Info[]>;
|
package/push.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
import { Cache } from "@samual/lib/Cache"
|
2
|
+
import { ensure, assert } from "@samual/lib/assert"
|
2
3
|
import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
|
3
4
|
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
4
5
|
import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
|
5
6
|
import { readFile } from "fs/promises"
|
6
|
-
import { basename, resolve
|
7
|
-
import { supportedExtensions } from "./constants.js"
|
7
|
+
import { basename, resolve } from "path"
|
8
8
|
import { processScript } from "./processScript/index.js"
|
9
9
|
import "@babel/generator"
|
10
10
|
import "@babel/parser"
|
@@ -29,9 +29,9 @@ import "@rollup/plugin-babel"
|
|
29
29
|
import "@rollup/plugin-commonjs"
|
30
30
|
import "@rollup/plugin-json"
|
31
31
|
import "@rollup/plugin-node-resolve"
|
32
|
-
import "@samual/lib/assert"
|
33
32
|
import "prettier"
|
34
33
|
import "rollup"
|
34
|
+
import "./constants.js"
|
35
35
|
import "./processScript/minify.js"
|
36
36
|
import "@samual/lib/spliceString"
|
37
37
|
import "acorn"
|
@@ -43,227 +43,96 @@ import "import-meta-resolve"
|
|
43
43
|
import "./processScript/transform.js"
|
44
44
|
import "@samual/lib/clearObject"
|
45
45
|
async function push(
|
46
|
-
|
47
|
-
|
46
|
+
sourcePath,
|
47
|
+
hackmudPath,
|
48
48
|
{ scripts = ["*.*"], onPush = () => {}, minify = !0, mangleNames = !1, forceQuineCheats } = {}
|
49
49
|
) {
|
50
|
-
const
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
50
|
+
const [sourceFolder, hackmudFolder] = await Promise.all([
|
51
|
+
readDirectoryWithStats(sourcePath),
|
52
|
+
readDirectoryWithStats(hackmudPath)
|
53
|
+
]),
|
54
|
+
sourceFolderFolders = sourceFolder.filter(({ stats }) => stats.isDirectory()),
|
55
|
+
allUsers = new Set([
|
56
|
+
...scripts
|
57
|
+
.map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:52:65"))
|
58
|
+
.filter(name => "*" != name),
|
59
|
+
...sourceFolderFolders.map(({ name }) => name),
|
60
|
+
...hackmudFolder.filter(({ stats }) => stats.isDirectory()).map(({ name }) => name),
|
61
|
+
...hackmudFolder
|
62
|
+
.filter(({ stats, name }) => stats.isFile() && name.endsWith(".key"))
|
63
|
+
.map(({ name }) => name.slice(0, -4))
|
64
|
+
]),
|
65
|
+
usersToScriptsToPush = new Cache(_user => new Map()),
|
66
|
+
scriptNamesToUsers = new Cache(_scriptName => new Set())
|
67
|
+
for (const script of scripts) {
|
68
|
+
const [user, scriptName] = script.split(".")
|
69
|
+
assert(user, "src/push.ts:69:16")
|
70
|
+
assert(scriptName, "src/push.ts:70:22")
|
71
|
+
"*" == user ? scriptNamesToUsers.set(scriptName, allUsers) : scriptNamesToUsers.get(scriptName).add(user)
|
62
72
|
}
|
63
|
-
const
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
const allUsers = new Set([
|
74
|
-
...sourceDirectoryDirents.filter(({ stats }) => stats.isDirectory()).map(({ path }) => basename(path)),
|
75
|
-
...hackmudDirectoryEntries.filter(({ stats }) => stats.isDirectory()).map(({ name }) => name),
|
76
|
-
...hackmudDirectoryEntries
|
77
|
-
.filter(({ name, stats }) => stats.isFile() && name.endsWith(".key"))
|
78
|
-
.map(({ name }) => name.slice(0, -4)),
|
79
|
-
...scriptNamesByUser.keys(),
|
80
|
-
...wildScriptUsers
|
81
|
-
])
|
82
|
-
if (pushEverything) for (const user of allUsers) wildScriptUsers.add(user)
|
83
|
-
else
|
84
|
-
for (const user of allUsers) {
|
85
|
-
const scriptNames = scriptNamesByUser.get(user)
|
86
|
-
for (const scriptName of wildUserScripts) scriptNames.add(scriptName)
|
87
|
-
}
|
73
|
+
const sourceFolderFiles = sourceFolder.filter(({ stats }) => stats.isFile()),
|
74
|
+
wildScriptUsers_ = scriptNamesToUsers.get("*")
|
75
|
+
scriptNamesToUsers.delete("*")
|
76
|
+
for (const { name, path } of [
|
77
|
+
...sourceFolderFiles.filter(({ name }) => name.endsWith(".js")),
|
78
|
+
...sourceFolderFiles.filter(({ name }) => name.endsWith(".ts"))
|
79
|
+
]) {
|
80
|
+
const scriptName = name.slice(0, -3)
|
81
|
+
for (const user of [...wildScriptUsers_, ...scriptNamesToUsers.get(scriptName)])
|
82
|
+
usersToScriptsToPush.get(user).set(scriptName, path)
|
88
83
|
}
|
89
84
|
await Promise.all(
|
90
|
-
|
91
|
-
await readDirectoryWithStats(
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
{
|
102
|
-
minify,
|
103
|
-
scriptUser: user,
|
104
|
-
scriptName,
|
105
|
-
filePath: path,
|
106
|
-
mangleNames,
|
107
|
-
forceQuineCheats
|
108
|
-
}
|
109
|
-
),
|
110
|
-
info = {
|
111
|
-
file: `${user}/${name}`,
|
112
|
-
users: [user],
|
113
|
-
minLength: countHackmudCharacters(minifiedCode),
|
114
|
-
error: void 0
|
115
|
-
}
|
116
|
-
scriptNamesAlreadyPushedByUser.get(user).add(scriptName)
|
117
|
-
allInfo.push(info)
|
118
|
-
await writeFilePersistent(
|
119
|
-
resolve(hackmudDirectory, user, `scripts/${scriptName}.js`),
|
120
|
-
minifiedCode
|
121
|
-
)
|
122
|
-
onPush(info)
|
123
|
-
}
|
124
|
-
})
|
125
|
-
)
|
126
|
-
},
|
127
|
-
error => {
|
128
|
-
if ("ENOENT" != error.code) throw error
|
129
|
-
}
|
130
|
-
)
|
85
|
+
sourceFolderFolders.map(async ({ name: user, path }) => {
|
86
|
+
const files = (await readDirectoryWithStats(path)).filter(({ stats }) => stats.isFile()),
|
87
|
+
scriptFiles = [
|
88
|
+
...files.filter(({ name }) => name.endsWith(".js")),
|
89
|
+
...files.filter(({ name }) => name.endsWith(".ts"))
|
90
|
+
]
|
91
|
+
for (const { name, path } of scriptFiles) {
|
92
|
+
const scriptName = name.slice(0, -3)
|
93
|
+
;[...wildScriptUsers_, ...scriptNamesToUsers.get(scriptName)].includes(user) &&
|
94
|
+
usersToScriptsToPush.get(user).set(scriptName, path)
|
95
|
+
}
|
131
96
|
})
|
132
97
|
)
|
98
|
+
for (const [scriptName, users] of scriptNamesToUsers)
|
99
|
+
for (const user of users)
|
100
|
+
if (!usersToScriptsToPush.get(user).has(scriptName))
|
101
|
+
throw Error(`Could not find script ${user}.${scriptName} to push`)
|
102
|
+
const pathsToUsers = new Cache(_path => new Set())
|
103
|
+
for (const [user, scriptsToPush] of usersToScriptsToPush)
|
104
|
+
for (const path of scriptsToPush.values()) pathsToUsers.get(path).add(user)
|
105
|
+
const allInfo = []
|
133
106
|
await Promise.all(
|
134
|
-
[...
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
info = {
|
157
|
-
file: `${user}/${fileName}`,
|
158
|
-
users: [user],
|
159
|
-
minLength: countHackmudCharacters(minifiedCode),
|
160
|
-
error: void 0
|
161
|
-
}
|
162
|
-
allInfo.push(info)
|
163
|
-
await writeFilePersistent(
|
164
|
-
resolve(hackmudDirectory, user, "scripts", scriptName + ".js"),
|
165
|
-
minifiedCode
|
166
|
-
)
|
167
|
-
onPush(info)
|
168
|
-
} else usersByGlobalScriptsToPush.get(scriptName).add(user)
|
169
|
-
})
|
170
|
-
))
|
171
|
-
})
|
172
|
-
)
|
173
|
-
await (wildScriptUsers.size ?
|
174
|
-
Promise.all(
|
175
|
-
(sourceDirectoryDirents || (await readDirectoryWithStats(sourceDirectory))).map(
|
176
|
-
async ({ path, stats, name }) => {
|
177
|
-
if (name.endsWith(".d.ts")) return
|
178
|
-
const extension = extname(name)
|
179
|
-
if (!stats.isFile() || !supportedExtensions.includes(extension)) return
|
180
|
-
const scriptName = basename(name, extension),
|
181
|
-
usersToPushTo = [...wildScriptUsers, ...usersByGlobalScriptsToPush.get(scriptName)].filter(
|
182
|
-
user => !scriptNamesAlreadyPushedByUser.get(user).has(scriptName)
|
183
|
-
)
|
184
|
-
if (!usersToPushTo.length) return
|
185
|
-
const uniqueID = Math.floor(Math.random() * 2 ** 52)
|
186
|
-
.toString(36)
|
187
|
-
.padStart(11, "0"),
|
188
|
-
{ script: minifiedCode } = await processScript(await readFile(path, { encoding: "utf-8" }), {
|
189
|
-
minify,
|
190
|
-
scriptUser: !0,
|
191
|
-
scriptName,
|
192
|
-
uniqueID,
|
193
|
-
filePath: path,
|
194
|
-
mangleNames,
|
195
|
-
forceQuineCheats
|
196
|
-
}),
|
197
|
-
info = {
|
198
|
-
file: name,
|
199
|
-
users: usersToPushTo,
|
200
|
-
minLength: countHackmudCharacters(minifiedCode),
|
201
|
-
error: void 0
|
202
|
-
}
|
203
|
-
await Promise.all(
|
204
|
-
usersToPushTo.map(user =>
|
205
|
-
writeFilePersistent(
|
206
|
-
resolve(hackmudDirectory, user, `scripts/${scriptName}.js`),
|
207
|
-
minifiedCode
|
208
|
-
.replace(RegExp(`\\$${uniqueID}\\$SCRIPT_USER\\$`, "g"), user)
|
209
|
-
.replace(
|
210
|
-
RegExp(`\\$${uniqueID}\\$FULL_SCRIPT_NAME\\$`, "g"),
|
211
|
-
`${user}.${scriptName}`
|
212
|
-
)
|
213
|
-
)
|
214
|
-
)
|
107
|
+
[...pathsToUsers].map(async ([path, [...users]]) => {
|
108
|
+
const scriptName = basename(path.slice(0, -3)),
|
109
|
+
uniqueID = Math.floor(Math.random() * 2 ** 52)
|
110
|
+
.toString(36)
|
111
|
+
.padStart(11, "0"),
|
112
|
+
{ script: minifiedCode } = await processScript(await readFile(path, { encoding: "utf8" }), {
|
113
|
+
minify,
|
114
|
+
scriptUser: !0,
|
115
|
+
scriptName,
|
116
|
+
uniqueID,
|
117
|
+
filePath: path,
|
118
|
+
mangleNames,
|
119
|
+
forceQuineCheats
|
120
|
+
}),
|
121
|
+
info = { path, users, characterCount: countHackmudCharacters(minifiedCode), error: void 0 }
|
122
|
+
await Promise.all(
|
123
|
+
users.map(user =>
|
124
|
+
writeFilePersistent(
|
125
|
+
resolve(hackmudPath, user, `scripts/${scriptName}.js`),
|
126
|
+
minifiedCode
|
127
|
+
.replace(RegExp(`\\$${uniqueID}\\$SCRIPT_USER\\$`, "g"), user)
|
128
|
+
.replace(RegExp(`\\$${uniqueID}\\$FULL_SCRIPT_NAME\\$`, "g"), `${user}.${scriptName}`)
|
215
129
|
)
|
216
|
-
|
217
|
-
onPush(info)
|
218
|
-
}
|
130
|
+
)
|
219
131
|
)
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
for (const extension of supportedExtensions)
|
225
|
-
try {
|
226
|
-
fileName = `${scriptName}${extension}`
|
227
|
-
code = await readFile((filePath = resolve(sourceDirectory, fileName)), { encoding: "utf-8" })
|
228
|
-
break
|
229
|
-
} catch {}
|
230
|
-
if (code) {
|
231
|
-
const uniqueID = Math.floor(Math.random() * 2 ** 52)
|
232
|
-
.toString(36)
|
233
|
-
.padStart(11, "0"),
|
234
|
-
{ script: minifiedCode } = await processScript(code, {
|
235
|
-
minify,
|
236
|
-
scriptUser: !0,
|
237
|
-
scriptName,
|
238
|
-
uniqueID,
|
239
|
-
filePath,
|
240
|
-
mangleNames,
|
241
|
-
forceQuineCheats
|
242
|
-
}),
|
243
|
-
info = {
|
244
|
-
file: fileName,
|
245
|
-
users: [...users],
|
246
|
-
minLength: countHackmudCharacters(minifiedCode),
|
247
|
-
error: void 0
|
248
|
-
}
|
249
|
-
await Promise.all(
|
250
|
-
[...users].map(user =>
|
251
|
-
writeFilePersistent(
|
252
|
-
resolve(hackmudDirectory, user, `scripts/${scriptName}.js`),
|
253
|
-
minifiedCode
|
254
|
-
.replace(RegExp(`\\$${uniqueID}\\$SCRIPT_USER\\$`, "g"), user)
|
255
|
-
.replace(
|
256
|
-
RegExp(`\\$${uniqueID}\\$FULL_SCRIPT_NAME\\$`, "g"),
|
257
|
-
`${user}.${scriptName}`
|
258
|
-
)
|
259
|
-
)
|
260
|
-
)
|
261
|
-
)
|
262
|
-
allInfo.push(info)
|
263
|
-
onPush(info)
|
264
|
-
}
|
265
|
-
})
|
266
|
-
))
|
132
|
+
allInfo.push(info)
|
133
|
+
onPush(info)
|
134
|
+
})
|
135
|
+
)
|
267
136
|
return allInfo
|
268
137
|
}
|
269
|
-
export { push
|
138
|
+
export { push }
|
package/syncMacros.js
CHANGED
@@ -12,7 +12,7 @@ async function syncMacros(hackmudPath) {
|
|
12
12
|
case ".macros":
|
13
13
|
{
|
14
14
|
const [lines, date] = await Promise.all([
|
15
|
-
readFile(resolve(hackmudPath, file.name), { encoding: "
|
15
|
+
readFile(resolve(hackmudPath, file.name), { encoding: "utf8" }).then(file =>
|
16
16
|
file.split("\n")
|
17
17
|
),
|
18
18
|
stat(resolve(hackmudPath, file.name)).then(({ mtime }) => mtime)
|
@@ -40,4 +40,4 @@ async function syncMacros(hackmudPath) {
|
|
40
40
|
for (const user of users) writeFile(resolve(hackmudPath, user + ".macros"), macroFile)
|
41
41
|
return { macrosSynced, usersSynced: users.length }
|
42
42
|
}
|
43
|
-
export { syncMacros
|
43
|
+
export { syncMacros }
|