hackmud-script-manager 0.20.4-9596502 → 0.20.4-a5e6bcd
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/hsm.js +13 -5
- package/env.d.ts +51 -2
- package/package.json +1 -1
- package/processScript/index.js +1 -1
- package/processScript/minify.js +6 -3
- package/processScript/postprocess.d.ts +1 -1
- package/processScript/postprocess.js +3 -3
- package/processScript/transform.js +12 -11
- package/push.d.ts +5 -1
- package/push.js +12 -6
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.4-
|
15
|
+
const version = "0.20.4-a5e6bcd",
|
16
16
|
options = new Map(),
|
17
17
|
commands = [],
|
18
18
|
userColours = new Cache(user => {
|
@@ -119,7 +119,7 @@ switch (commands[0]) {
|
|
119
119
|
logHelp()
|
120
120
|
break
|
121
121
|
}
|
122
|
-
const { push } = await pushModule,
|
122
|
+
const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } = await pushModule,
|
123
123
|
infos = await push(sourcePath, hackmudPath, {
|
124
124
|
scripts,
|
125
125
|
onPush: info => logInfo(info, hackmudPath),
|
@@ -127,9 +127,17 @@ switch (commands[0]) {
|
|
127
127
|
mangleNames: shouldMangleNames,
|
128
128
|
forceQuineCheats: shouldforceQuineCheats
|
129
129
|
})
|
130
|
-
infos instanceof Error
|
130
|
+
if (infos instanceof Error) {
|
131
131
|
logError(infos.message)
|
132
|
-
|
132
|
+
if (infos instanceof MissingSourceFolderError || infos instanceof NoUsersError) {
|
133
|
+
console.log()
|
134
|
+
logHelp()
|
135
|
+
} else
|
136
|
+
infos instanceof MissingHackmudFolderError &&
|
137
|
+
log(
|
138
|
+
`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`
|
139
|
+
)
|
140
|
+
} else infos.length || logError("Could not find any scripts to push")
|
133
141
|
}
|
134
142
|
break
|
135
143
|
case "dev":
|
@@ -246,7 +254,7 @@ switch (commands[0]) {
|
|
246
254
|
typeDeclaration = await generateTypeDeclaration(sourcePath, getHackmudPath())
|
247
255
|
let typeDeclarationPath = resolve(outputPath)
|
248
256
|
await writeFile(typeDeclarationPath, typeDeclaration).catch(error => {
|
249
|
-
assert(error instanceof Error, "src/bin/hsm.ts:
|
257
|
+
assert(error instanceof Error, "src/bin/hsm.ts:340:35")
|
250
258
|
if ("EISDIR" != error.code) throw error
|
251
259
|
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
252
260
|
return writeFile(typeDeclarationPath, typeDeclaration)
|
package/env.d.ts
CHANGED
@@ -151,7 +151,16 @@ type Fullsec = Subscripts & PlayerFullsec & {
|
|
151
151
|
market: {
|
152
152
|
/** **FULLSEC** */ browse: {
|
153
153
|
(args:
|
154
|
-
Partial<{
|
154
|
+
Partial<{
|
155
|
+
seller: string | MongoQuerySelector<string>,
|
156
|
+
listed_before: number | MongoQuerySelector<number>,
|
157
|
+
listed_after: number,
|
158
|
+
cost: number | MongoQuerySelector<number> | string,
|
159
|
+
rarity: UpgradeRarityNumber | MongoQuerySelector<UpgradeRarityNumber>,
|
160
|
+
name: string | MongoQuerySelector<string>
|
161
|
+
} & Omit<{
|
162
|
+
[k in keyof CliUpgrade]: CliUpgrade[k] | MongoQuerySelector<CliUpgrade[k]>
|
163
|
+
}, "rarity">>
|
155
164
|
): { i: string, name: string, rarity: Upgrade["rarity"], cost: number }[] | ScriptFailure
|
156
165
|
|
157
166
|
<I extends string>(args: { i: I }): {
|
@@ -710,10 +719,50 @@ type Nullsec = Lowsec & PlayerNullsec & {
|
|
710
719
|
}
|
711
720
|
}
|
712
721
|
|
722
|
+
type MongoTypeString = "minKey" | "double" | "string" | "object" | "array" | "binData" | "undefined" | "objectId" |
|
723
|
+
"bool" | "date" | "null" | "regex" | "dbPointer" | "javascript" | "symbol" | "int" | "timestamp" | "long" | "decimal" | "maxKey";
|
724
|
+
type MongoTypeNumber = -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 127;
|
725
|
+
|
713
726
|
type MongoValue = string | number | boolean | Date | MongoValue[] | { [key: string]: MongoValue } | null
|
714
727
|
|
715
728
|
type MongoCommandValue = string | number | boolean | Date | MongoCommandValue[] | { [key: string]: MongoCommandValue } |
|
716
|
-
|
729
|
+
null | undefined
|
730
|
+
|
731
|
+
/**
|
732
|
+
* Currently unused
|
733
|
+
*/
|
734
|
+
type MongoLogicalSelectors<T extends MongoValue = MongoValue> = {
|
735
|
+
$not: T | MongoComparisonSelectors<T> | MongoLogicalSelectors<T>
|
736
|
+
$nor: T[]
|
737
|
+
$or: T[]
|
738
|
+
$and: T[]
|
739
|
+
}
|
740
|
+
|
741
|
+
type MongoArraySelectors<T extends Array<MongoValue> = Array<MongoValue>> = {
|
742
|
+
$all: T
|
743
|
+
$elemMatch: T
|
744
|
+
$size: number
|
745
|
+
}
|
746
|
+
|
747
|
+
type MongoComparisonSelectors<T extends MongoValue = MongoValue> = {
|
748
|
+
$eq: T
|
749
|
+
$gt: T
|
750
|
+
$gte: T
|
751
|
+
$in: T[]
|
752
|
+
$lt: T
|
753
|
+
$lte: T
|
754
|
+
$ne: T
|
755
|
+
$nin: T[]
|
756
|
+
}
|
757
|
+
|
758
|
+
type MongoElementSelectors = {
|
759
|
+
$exists: boolean
|
760
|
+
$type: MongoTypeNumber | MongoTypeString
|
761
|
+
}
|
762
|
+
|
763
|
+
type MongoQuerySelector<T extends MongoValue = MongoValue> = Partial<T extends MongoValue[] ?
|
764
|
+
(MongoArraySelectors<T> & MongoElementSelectors & MongoComparisonSelectors<T>) :
|
765
|
+
(MongoElementSelectors & MongoComparisonSelectors<T>)>
|
717
766
|
|
718
767
|
type Query = { [key: string]: MongoValue | Query } & { _id?: Id, $in?: MongoValue[] }
|
719
768
|
type Projection = Record<string, boolean | 0 | 1>
|
package/package.json
CHANGED
package/processScript/index.js
CHANGED
@@ -323,7 +323,7 @@ async function processScript(
|
|
323
323
|
trailingComma: "none"
|
324
324
|
})
|
325
325
|
}
|
326
|
-
code = postprocess(code,
|
326
|
+
code = postprocess(code, uniqueId)
|
327
327
|
if (includesIllegalString(code))
|
328
328
|
throw Error(
|
329
329
|
'you found a weird edge case where I wasn\'t able to replace illegal strings like "SC$", please report thx'
|
package/processScript/minify.js
CHANGED
@@ -259,7 +259,10 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
259
259
|
t.memberExpression(
|
260
260
|
t.taggedTemplateExpression(
|
261
261
|
t.memberExpression(
|
262
|
-
t.callExpression(
|
262
|
+
t.callExpression(
|
263
|
+
t.identifier(`$${uniqueId}$4$SUBSCRIPT$scripts$quine$`),
|
264
|
+
[]
|
265
|
+
),
|
263
266
|
t.identifier("split")
|
264
267
|
),
|
265
268
|
t.templateLiteral([t.templateElement({ raw: "\t", cooked: "\t" }, !0)], [])
|
@@ -283,7 +286,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
283
286
|
t.memberExpression(
|
284
287
|
t.taggedTemplateExpression(
|
285
288
|
t.memberExpression(
|
286
|
-
t.callExpression(t.identifier(`$${uniqueId}$SUBSCRIPT$scripts$quine$`), []),
|
289
|
+
t.callExpression(t.identifier(`$${uniqueId}$4$SUBSCRIPT$scripts$quine$`), []),
|
287
290
|
t.identifier("split")
|
288
291
|
),
|
289
292
|
t.templateLiteral([t.templateElement({ raw: "\t", cooked: "\t" }, !0)], [])
|
@@ -308,7 +311,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
308
311
|
t.memberExpression(
|
309
312
|
t.taggedTemplateExpression(
|
310
313
|
t.memberExpression(
|
311
|
-
t.callExpression(t.identifier(`$${uniqueId}$SUBSCRIPT$scripts$quine$`), []),
|
314
|
+
t.callExpression(t.identifier(`$${uniqueId}$4$SUBSCRIPT$scripts$quine$`), []),
|
312
315
|
t.identifier("split")
|
313
316
|
),
|
314
317
|
t.templateLiteral([t.templateElement({ raw: "\t", cooked: "\t" }, !0)], [])
|
@@ -1 +1 @@
|
|
1
|
-
export declare const postprocess: (code: string,
|
1
|
+
export declare const postprocess: (code: string, uniqueId: string) => string;
|
@@ -1,12 +1,12 @@
|
|
1
|
-
const postprocess = (code,
|
1
|
+
const postprocess = (code, uniqueId) =>
|
2
2
|
code
|
3
|
-
.replace(/^function\s
|
3
|
+
.replace(/^function\s*[\w$]+\(/, "function(")
|
4
4
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$SC_DOLLAR\\$`, "g"), "S\\C$")
|
5
5
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$DB_DOLLAR\\$`, "g"), "D\\B$")
|
6
6
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$D\\$`, "g"), "_\\_D_S")
|
7
7
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$FMCL\\$`, "g"), "_\\_FMCL_")
|
8
8
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$G\\$`, "g"), "_\\_G_")
|
9
|
-
.replace(RegExp(`\\$${uniqueId}\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)\\$`, "g"),
|
9
|
+
.replace(RegExp(`\\$${uniqueId}\\$(\\d)\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)\\$`, "g"), "#$1s.$2.$3")
|
10
10
|
.replace(RegExp(`\\$${uniqueId}\\$DEBUG\\$`, "g"), "#D")
|
11
11
|
.replace(RegExp(`\\$${uniqueId}\\$FMCL\\$`, "g"), "#FMCL")
|
12
12
|
.replace(RegExp(`\\$${uniqueId}\\$GLOBAL\\$`, "g"), "#G")
|
@@ -101,29 +101,29 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
101
101
|
functionDotPrototypeIsReferencedMultipleTimes = !0
|
102
102
|
}
|
103
103
|
}
|
104
|
-
const neededSubscriptLets = new
|
104
|
+
const neededSubscriptLets = new Map()
|
105
105
|
let detectedSeclevel = 4
|
106
106
|
for (const fakeSubscriptObjectName of ["$fs", "$4s", "$s"])
|
107
|
-
program.scope.hasGlobal(fakeSubscriptObjectName) && processFakeSubscriptObject(fakeSubscriptObjectName)
|
107
|
+
program.scope.hasGlobal(fakeSubscriptObjectName) && processFakeSubscriptObject(fakeSubscriptObjectName, 4)
|
108
108
|
for (const fakeSubscriptObjectName of ["$hs", "$3s"])
|
109
109
|
if (program.scope.hasGlobal(fakeSubscriptObjectName)) {
|
110
110
|
detectedSeclevel = 3
|
111
|
-
processFakeSubscriptObject(fakeSubscriptObjectName)
|
111
|
+
processFakeSubscriptObject(fakeSubscriptObjectName, 3)
|
112
112
|
}
|
113
113
|
for (const fakeSubscriptObjectName of ["$ms", "$2s"])
|
114
114
|
if (program.scope.hasGlobal(fakeSubscriptObjectName)) {
|
115
115
|
detectedSeclevel = 2
|
116
|
-
processFakeSubscriptObject(fakeSubscriptObjectName)
|
116
|
+
processFakeSubscriptObject(fakeSubscriptObjectName, 2)
|
117
117
|
}
|
118
118
|
for (const fakeSubscriptObjectName of ["$ls", "$1s"])
|
119
119
|
if (program.scope.hasGlobal(fakeSubscriptObjectName)) {
|
120
120
|
detectedSeclevel = 1
|
121
|
-
processFakeSubscriptObject(fakeSubscriptObjectName)
|
121
|
+
processFakeSubscriptObject(fakeSubscriptObjectName, 1)
|
122
122
|
}
|
123
123
|
for (const fakeSubscriptObjectName of ["$ns", "$0s"])
|
124
124
|
if (program.scope.hasGlobal(fakeSubscriptObjectName)) {
|
125
125
|
detectedSeclevel = 0
|
126
|
-
processFakeSubscriptObject(fakeSubscriptObjectName)
|
126
|
+
processFakeSubscriptObject(fakeSubscriptObjectName, 0)
|
127
127
|
}
|
128
128
|
seclevel = Math.min(seclevel, detectedSeclevel)
|
129
129
|
const neededDbMethodLets = new Set()
|
@@ -522,12 +522,12 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
522
522
|
mainFunction.body.body.unshift(
|
523
523
|
t.variableDeclaration(
|
524
524
|
"let",
|
525
|
-
[...neededSubscriptLets].map(name =>
|
525
|
+
[...neededSubscriptLets].map(([name, seclevel]) =>
|
526
526
|
t.variableDeclarator(
|
527
527
|
t.identifier(`_${uniqueId}_SUBSCRIPT_${name}_`),
|
528
528
|
t.arrowFunctionExpression(
|
529
529
|
[t.restElement(t.identifier("args"))],
|
530
|
-
t.callExpression(t.identifier(`$${uniqueId}$SUBSCRIPT$${name}$`), [
|
530
|
+
t.callExpression(t.identifier(`$${uniqueId}$${seclevel}$SUBSCRIPT$${name}$`), [
|
531
531
|
t.spreadElement(t.identifier("args"))
|
532
532
|
])
|
533
533
|
)
|
@@ -661,7 +661,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
661
661
|
t.identifier("prototype")
|
662
662
|
)
|
663
663
|
}
|
664
|
-
function processFakeSubscriptObject(fakeSubscriptObjectName) {
|
664
|
+
function processFakeSubscriptObject(fakeSubscriptObjectName, seclevel) {
|
665
665
|
for (const referencePath of getReferencePathsToGlobal(fakeSubscriptObjectName, program)) {
|
666
666
|
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:785:60")
|
667
667
|
assert("Identifier" == referencePath.parent.property.type)
|
@@ -684,13 +684,14 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
684
684
|
if ("CallExpression" == referencePath.parentPath.parentPath.parentPath?.type)
|
685
685
|
referencePath.parentPath.parentPath.replaceWith(
|
686
686
|
t.identifier(
|
687
|
-
`$${uniqueId}$SUBSCRIPT$${referencePath.parent.property.name}$${referencePath.parentPath.parentPath.node.property.name}$`
|
687
|
+
`$${uniqueId}$${seclevel}$SUBSCRIPT$${referencePath.parent.property.name}$${referencePath.parentPath.parentPath.node.property.name}$`
|
688
688
|
)
|
689
689
|
)
|
690
690
|
else {
|
691
691
|
const name = `${referencePath.parent.property.name}$${referencePath.parentPath.parentPath.node.property.name}`
|
692
692
|
referencePath.parentPath.parentPath.replaceWith(t.identifier(`_${uniqueId}_SUBSCRIPT_${name}_`))
|
693
|
-
neededSubscriptLets.
|
693
|
+
const maxSecLevel = Math.max(neededSubscriptLets.get(name) || 0, seclevel)
|
694
|
+
neededSubscriptLets.set(name, maxSecLevel)
|
694
695
|
}
|
695
696
|
}
|
696
697
|
}
|
package/push.d.ts
CHANGED
@@ -22,6 +22,10 @@ export declare class MissingSourceFolderError extends Error {
|
|
22
22
|
}
|
23
23
|
export declare class MissingHackmudFolderError extends Error {
|
24
24
|
}
|
25
|
+
export declare class NoUsersError extends Error {
|
26
|
+
}
|
27
|
+
export declare class NoScriptsError extends Error {
|
28
|
+
}
|
25
29
|
/** Push scripts from a source directory to the hackmud directory.
|
26
30
|
*
|
27
31
|
* Pushes files directly in the source folder to all users
|
@@ -29,4 +33,4 @@ export declare class MissingHackmudFolderError extends Error {
|
|
29
33
|
* @param hackmudPath directory created by hackmud containing user data including scripts
|
30
34
|
* @param options {@link PushOptions details}
|
31
35
|
* @returns array of info on pushed scripts */
|
32
|
-
export declare function push(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: PushOptions): Promise<MissingSourceFolderError | MissingHackmudFolderError | Info[]>;
|
36
|
+
export declare function push(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: PushOptions): Promise<MissingSourceFolderError | MissingHackmudFolderError | NoUsersError | NoScriptsError | Info[]>;
|
package/push.js
CHANGED
@@ -46,6 +46,10 @@ class MissingSourceFolderError extends Error {}
|
|
46
46
|
Object.defineProperty(MissingSourceFolderError.prototype, "name", { value: "MissingSourceFolderError" })
|
47
47
|
class MissingHackmudFolderError extends Error {}
|
48
48
|
Object.defineProperty(MissingHackmudFolderError.prototype, "name", { value: "MissingHackmudFolderError" })
|
49
|
+
class NoUsersError extends Error {}
|
50
|
+
Object.defineProperty(NoUsersError.prototype, "name", { value: "NoUsersError" })
|
51
|
+
class NoScriptsError extends Error {}
|
52
|
+
Object.defineProperty(NoScriptsError.prototype, "name", { value: "NoScriptsError" })
|
49
53
|
async function push(
|
50
54
|
sourcePath,
|
51
55
|
hackmudPath,
|
@@ -68,7 +72,7 @@ async function push(
|
|
68
72
|
const sourceFolderFolders = sourceFolder.filter(({ stats }) => stats.isDirectory()),
|
69
73
|
allUsers = new Set([
|
70
74
|
...scripts
|
71
|
-
.map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:
|
75
|
+
.map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:82:65"))
|
72
76
|
.filter(name => "*" != name),
|
73
77
|
...sourceFolderFolders.map(({ name }) => name),
|
74
78
|
...hackmudFolder.filter(({ stats }) => stats.isDirectory()).map(({ name }) => name),
|
@@ -77,13 +81,15 @@ async function push(
|
|
77
81
|
.map(({ name }) => name.slice(0, -4))
|
78
82
|
])
|
79
83
|
if (!allUsers.size)
|
80
|
-
|
84
|
+
return new NoUsersError(
|
85
|
+
"Could not find any users. Either provide the names of your users or log into a user in hackmud"
|
86
|
+
)
|
81
87
|
const usersToScriptsToPush = new Cache(_user => new Map()),
|
82
88
|
scriptNamesToUsers = new Cache(_scriptName => new Set())
|
83
89
|
for (const script of scripts) {
|
84
90
|
const [user, scriptName] = script.split(".")
|
85
|
-
assert(user, "src/push.ts:
|
86
|
-
assert(scriptName, "src/push.ts:
|
91
|
+
assert(user, "src/push.ts:105:16")
|
92
|
+
assert(scriptName, "src/push.ts:106:22")
|
87
93
|
"*" == user ? scriptNamesToUsers.set(scriptName, allUsers) : scriptNamesToUsers.get(scriptName).add(user)
|
88
94
|
}
|
89
95
|
const sourceFolderFiles = sourceFolder.filter(({ stats }) => stats.isFile()),
|
@@ -114,7 +120,7 @@ async function push(
|
|
114
120
|
for (const [scriptName, users] of scriptNamesToUsers)
|
115
121
|
for (const user of users)
|
116
122
|
if (!usersToScriptsToPush.get(user).has(scriptName))
|
117
|
-
|
123
|
+
return new NoScriptsError(`Could not find script ${user}.${scriptName} to push`)
|
118
124
|
const pathsToUsers = new Cache(_path => new Set())
|
119
125
|
for (const [user, scriptsToPush] of usersToScriptsToPush)
|
120
126
|
for (const path of scriptsToPush.values()) pathsToUsers.get(path).add(user)
|
@@ -151,4 +157,4 @@ async function push(
|
|
151
157
|
)
|
152
158
|
return allInfo
|
153
159
|
}
|
154
|
-
export { MissingHackmudFolderError, MissingSourceFolderError, push }
|
160
|
+
export { MissingHackmudFolderError, MissingSourceFolderError, NoScriptsError, NoUsersError, push }
|