hackmud-script-manager 0.19.1-3ef8894 → 0.19.1-531ddb2
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/hsm.js +181 -232
- package/generateTypeDeclaration.js +18 -18
- package/index.js +2 -1
- package/package.json +5 -7
- package/processScript/index.js +257 -240
- package/processScript/minify.js +380 -394
- package/processScript/preprocess.js +93 -93
- package/processScript/shared.js +11 -11
- package/processScript/transform.js +566 -559
- package/pull.js +1 -1
- package/push.js +204 -215
- package/{bin → src/bin}/hsm.d.ts +0 -0
- package/src/generateTypeDeclaration.d.ts +2 -0
- package/src/processScript/index.d.ts +31 -0
- package/src/processScript/minify.d.ts +18 -0
- package/src/processScript/preprocess.d.ts +9 -0
- package/{processScript → src/processScript}/shared.d.ts +1 -1
- package/src/processScript/transform.d.ts +18 -0
- package/src/pull.d.ts +6 -0
- package/src/push.d.ts +29 -0
- package/{syncMacros.d.ts → src/syncMacros.d.ts} +1 -1
- package/src/watch.d.ts +15 -0
- package/syncMacros.js +5 -4
- package/watch.js +21 -22
- package/generateTypeDeclaration.d.ts +0 -2
- package/processScript/index.d.ts +0 -40
- package/processScript/minify.d.ts +0 -24
- package/processScript/preprocess.d.ts +0 -12
- package/processScript/transform.d.ts +0 -24
- package/pull.d.ts +0 -9
- package/push.d.ts +0 -37
- package/tsconfig.tsbuildinfo +0 -1
- package/watch.d.ts +0 -20
- /package/{constants.d.ts → src/constants.d.ts} +0 -0
- /package/{index.d.ts → src/index.d.ts} +0 -0
- /package/{processScript → src/processScript}/postprocess.d.ts +0 -0
package/pull.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { copyFilePersistent } from "@samual/lib/copyFilePersistent"
|
2
2
|
import { resolve } from "path"
|
3
|
-
|
3
|
+
async function pull(sourceFolderPath, hackmudPath, script) {
|
4
4
|
const [user, name] = script.split(".")
|
5
5
|
if (!user || !name) throw Error('`script` argument must be in "user.name" format')
|
6
6
|
await copyFilePersistent(
|
package/push.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
import { Cache } from "@samual/lib/Cache"
|
2
2
|
import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
|
3
|
+
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
3
4
|
import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
|
4
|
-
import { readFile
|
5
|
+
import { readFile } from "fs/promises"
|
5
6
|
import { basename, resolve, extname } from "path"
|
6
7
|
import { supportedExtensions } from "./constants.js"
|
7
8
|
import { processScript } from "./processScript/index.js"
|
@@ -41,240 +42,228 @@ import "./processScript/preprocess.js"
|
|
41
42
|
import "import-meta-resolve"
|
42
43
|
import "./processScript/transform.js"
|
43
44
|
import "@samual/lib/clearObject"
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
),
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
{
|
108
|
-
minify,
|
109
|
-
scriptUser: user,
|
110
|
-
scriptName,
|
111
|
-
filePath: path,
|
112
|
-
mangleNames,
|
113
|
-
forceQuineCheats
|
114
|
-
}
|
115
|
-
),
|
116
|
-
info = {
|
117
|
-
file: `${user}/${name}`,
|
118
|
-
users: [user],
|
119
|
-
minLength: countHackmudCharacters(minifiedCode),
|
120
|
-
error: void 0
|
45
|
+
async function push(
|
46
|
+
sourceDirectory,
|
47
|
+
hackmudDirectory,
|
48
|
+
{ scripts = ["*.*"], onPush = () => {}, minify = !0, mangleNames = !1, forceQuineCheats } = {}
|
49
|
+
) {
|
50
|
+
const scriptNamesByUser = new Cache(_user => new Set()),
|
51
|
+
wildScriptUsers = new Set(),
|
52
|
+
wildUserScripts = new Set()
|
53
|
+
let pushEverything = !1
|
54
|
+
for (const fullScriptName of scripts) {
|
55
|
+
const [user, scriptName] = fullScriptName.split(".")
|
56
|
+
user && "*" != user ?
|
57
|
+
scriptName && "*" != scriptName ?
|
58
|
+
scriptNamesByUser.get(user).add(scriptName)
|
59
|
+
: wildScriptUsers.add(user)
|
60
|
+
: scriptName && "*" != scriptName ? wildUserScripts.add(scriptName)
|
61
|
+
: (pushEverything = !0)
|
62
|
+
}
|
63
|
+
const usersByGlobalScriptsToPush = new Cache(_user => new Set()),
|
64
|
+
allInfo = [],
|
65
|
+
scriptNamesAlreadyPushedByUser = new Cache(_user => new Set())
|
66
|
+
let sourceDirectoryDirents
|
67
|
+
if (wildUserScripts.size || pushEverything) {
|
68
|
+
let hackmudDirectoryEntries
|
69
|
+
;[hackmudDirectoryEntries, sourceDirectoryDirents] = await Promise.all([
|
70
|
+
readDirectoryWithStats(hackmudDirectory),
|
71
|
+
readDirectoryWithStats(sourceDirectory)
|
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
|
+
}
|
88
|
+
}
|
89
|
+
await Promise.all(
|
90
|
+
[...wildScriptUsers].map(async user => {
|
91
|
+
await readDirectoryWithStats(resolve(sourceDirectory, user)).then(
|
92
|
+
async entries => {
|
93
|
+
await Promise.all(
|
94
|
+
entries.map(async ({ stats, name, path }) => {
|
95
|
+
if (name.endsWith(".d.ts")) return
|
96
|
+
const extension = extname(name)
|
97
|
+
if (stats.isFile() && supportedExtensions.includes(extension)) {
|
98
|
+
const scriptName = basename(name, extension),
|
99
|
+
{ script: minifiedCode } = await processScript(
|
100
|
+
await readFile(path, { encoding: "utf-8" }),
|
101
|
+
{
|
102
|
+
minify,
|
103
|
+
scriptUser: user,
|
104
|
+
scriptName,
|
105
|
+
filePath: path,
|
106
|
+
mangleNames,
|
107
|
+
forceQuineCheats
|
121
108
|
}
|
122
|
-
|
123
|
-
allInfo.push(info)
|
124
|
-
await writeFilePersistent(
|
125
|
-
resolve(hackmudDirectory, user, `scripts/${scriptName}.js`),
|
126
|
-
minifiedCode
|
127
|
-
)
|
128
|
-
onPush(info)
|
129
|
-
}
|
130
|
-
})
|
131
|
-
)
|
132
|
-
},
|
133
|
-
error => {
|
134
|
-
if ("ENOENT" != error.code) throw error
|
135
|
-
}
|
136
|
-
)
|
137
|
-
})
|
138
|
-
)
|
139
|
-
await Promise.all(
|
140
|
-
[...scriptNamesByUser].map(async ([user, scripts]) => {
|
141
|
-
wildScriptUsers.has(user) ||
|
142
|
-
(await Promise.all(
|
143
|
-
[...scripts].map(async scriptName => {
|
144
|
-
let code, fileName, filePath
|
145
|
-
for (const extension of supportedExtensions)
|
146
|
-
try {
|
147
|
-
fileName = `${scriptName}${extension}`
|
148
|
-
code = await readFile((filePath = resolve(sourceDirectory, user, fileName)), {
|
149
|
-
encoding: "utf-8"
|
150
|
-
})
|
151
|
-
break
|
152
|
-
} catch {}
|
153
|
-
if (code) {
|
154
|
-
const { script: minifiedCode } = await processScript(code, {
|
155
|
-
minify,
|
156
|
-
scriptUser: user,
|
157
|
-
scriptName,
|
158
|
-
filePath,
|
159
|
-
mangleNames,
|
160
|
-
forceQuineCheats
|
161
|
-
}),
|
109
|
+
),
|
162
110
|
info = {
|
163
|
-
file: `${user}/${
|
111
|
+
file: `${user}/${name}`,
|
164
112
|
users: [user],
|
165
113
|
minLength: countHackmudCharacters(minifiedCode),
|
166
114
|
error: void 0
|
167
115
|
}
|
116
|
+
scriptNamesAlreadyPushedByUser.get(user).add(scriptName)
|
168
117
|
allInfo.push(info)
|
169
118
|
await writeFilePersistent(
|
170
|
-
resolve(hackmudDirectory, user,
|
119
|
+
resolve(hackmudDirectory, user, `scripts/${scriptName}.js`),
|
171
120
|
minifiedCode
|
172
121
|
)
|
173
122
|
onPush(info)
|
174
|
-
}
|
123
|
+
}
|
175
124
|
})
|
176
|
-
)
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
125
|
+
)
|
126
|
+
},
|
127
|
+
error => {
|
128
|
+
if ("ENOENT" != error.code) throw error
|
129
|
+
}
|
130
|
+
)
|
131
|
+
})
|
132
|
+
)
|
133
|
+
await Promise.all(
|
134
|
+
[...scriptNamesByUser].map(async ([user, scripts]) => {
|
135
|
+
wildScriptUsers.has(user) ||
|
136
|
+
(await Promise.all(
|
137
|
+
[...scripts].map(async scriptName => {
|
138
|
+
let code, fileName, filePath
|
139
|
+
for (const extension of supportedExtensions)
|
140
|
+
try {
|
141
|
+
fileName = `${scriptName}${extension}`
|
142
|
+
code = await readFile((filePath = resolve(sourceDirectory, user, fileName)), {
|
143
|
+
encoding: "utf-8"
|
144
|
+
})
|
145
|
+
break
|
146
|
+
} catch {}
|
147
|
+
if (code) {
|
148
|
+
const { script: minifiedCode } = await processScript(code, {
|
197
149
|
minify,
|
198
|
-
scriptUser:
|
150
|
+
scriptUser: user,
|
199
151
|
scriptName,
|
200
|
-
|
201
|
-
filePath: path,
|
152
|
+
filePath,
|
202
153
|
mangleNames,
|
203
154
|
forceQuineCheats
|
155
|
+
}),
|
156
|
+
info = {
|
157
|
+
file: `${user}/${fileName}`,
|
158
|
+
users: [user],
|
159
|
+
minLength: countHackmudCharacters(minifiedCode),
|
160
|
+
error: void 0
|
204
161
|
}
|
205
|
-
)
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
minLength: countHackmudCharacters(minifiedCode),
|
210
|
-
error: void 0
|
211
|
-
}
|
212
|
-
await Promise.all(
|
213
|
-
usersToPushTo.map(user =>
|
214
|
-
writeFilePersistent(
|
215
|
-
resolve(hackmudDirectory, user, `scripts/${scriptName}.js`),
|
216
|
-
minifiedCode
|
217
|
-
.replace(RegExp(`\\$${uniqueID}\\$SCRIPT_USER\\$`, "g"), user)
|
218
|
-
.replace(
|
219
|
-
RegExp(`\\$${uniqueID}\\$FULL_SCRIPT_NAME\\$`, "g"),
|
220
|
-
`${user}.${scriptName}`
|
221
|
-
)
|
222
|
-
)
|
162
|
+
allInfo.push(info)
|
163
|
+
await writeFilePersistent(
|
164
|
+
resolve(hackmudDirectory, user, "scripts", scriptName + ".js"),
|
165
|
+
minifiedCode
|
223
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)
|
224
183
|
)
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
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
|
+
)
|
215
|
+
)
|
216
|
+
allInfo.push(info)
|
217
|
+
onPush(info)
|
218
|
+
}
|
229
219
|
)
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
)
|
270
|
-
)
|
220
|
+
)
|
221
|
+
: Promise.all(
|
222
|
+
[...usersByGlobalScriptsToPush].map(async ([scriptName, users]) => {
|
223
|
+
let code, fileName, filePath
|
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
|
+
)
|
271
259
|
)
|
272
260
|
)
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
}
|
277
|
-
)
|
278
|
-
|
279
|
-
|
261
|
+
)
|
262
|
+
allInfo.push(info)
|
263
|
+
onPush(info)
|
264
|
+
}
|
265
|
+
})
|
266
|
+
))
|
267
|
+
return allInfo
|
268
|
+
}
|
280
269
|
export { push as default, push }
|
package/{bin → src/bin}/hsm.d.ts
RENAMED
File without changes
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import type { LaxPartial } from "@samual/lib";
|
2
|
+
export { minify } from "./minify";
|
3
|
+
export { postprocess } from "./postprocess";
|
4
|
+
export { preprocess } from "./preprocess";
|
5
|
+
export { transform } from "./transform";
|
6
|
+
export type ProcessOptions = {
|
7
|
+
/** whether to minify the given code */ minify: boolean;
|
8
|
+
/** 11 a-z 0-9 characters */ uniqueID: string;
|
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
|
+
filePath: string;
|
12
|
+
/** whether to mangle function and class names (defaults to `false`) */ mangleNames: boolean;
|
13
|
+
/** when set to `true` forces use of quine cheats
|
14
|
+
*
|
15
|
+
* when set to `false` forces quine cheats not to be used
|
16
|
+
*
|
17
|
+
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
18
|
+
*/
|
19
|
+
forceQuineCheats: boolean;
|
20
|
+
};
|
21
|
+
/** Minifies a given script
|
22
|
+
* @param code JavaScript or TypeScript code
|
23
|
+
* @param options {@link ProcessOptions details} */
|
24
|
+
export declare function processScript(code: string, { minify: shouldMinify, uniqueID, scriptUser, scriptName, filePath, mangleNames, forceQuineCheats }?: LaxPartial<ProcessOptions>): Promise<{
|
25
|
+
script: string;
|
26
|
+
warnings: {
|
27
|
+
message: string;
|
28
|
+
line: number;
|
29
|
+
}[];
|
30
|
+
}>;
|
31
|
+
export default processScript;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { File } from "@babel/types";
|
2
|
+
import type { LaxPartial } from "@samual/lib";
|
3
|
+
type MinifyOptions = {
|
4
|
+
/** 11 a-z 0-9 characters */ uniqueID: string;
|
5
|
+
/** whether to mangle function and class names (defaults to `false`) */ mangleNames: boolean;
|
6
|
+
/** when set to `true` forces use of quine cheats
|
7
|
+
*
|
8
|
+
* when set to `false` forces quine cheats not to be used
|
9
|
+
*
|
10
|
+
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
11
|
+
*/
|
12
|
+
forceQuineCheats: boolean;
|
13
|
+
/** the comment inserted after the function signature */ autocomplete: string;
|
14
|
+
};
|
15
|
+
/** @param file babel ast node representing a file containing transformed code
|
16
|
+
* @param options {@link MinifyOptions details} */
|
17
|
+
export declare function minify(file: File, { uniqueID, mangleNames, forceQuineCheats, autocomplete }?: LaxPartial<MinifyOptions>): Promise<string>;
|
18
|
+
export default minify;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export type PreprocessOptions = {
|
2
|
+
/** 11 a-z 0-9 characters */ uniqueID: string;
|
3
|
+
};
|
4
|
+
/** @param code source code for preprocessing
|
5
|
+
* @param options {@link PreprocessOptions details} */
|
6
|
+
export declare function preprocess(code: string, { uniqueID }?: Partial<PreprocessOptions>): Promise<{
|
7
|
+
code: string;
|
8
|
+
}>;
|
9
|
+
export default preprocess;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { NodePath } from "@babel/traverse";
|
2
2
|
import type { Identifier, Program } from "@babel/types";
|
3
|
-
export declare
|
3
|
+
export declare function getReferencePathsToGlobal(name: string, program: NodePath<Program>): NodePath<Identifier>[];
|
4
4
|
export declare const includesIllegalString: (toCheck: string) => boolean;
|
5
5
|
export declare const replaceUnsafeStrings: (uniqueID: string, toReplace: string) => string;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { File } from "@babel/types";
|
2
|
+
export type TransformOptions = {
|
3
|
+
/** 11 a-z 0-9 characters */ uniqueID: string;
|
4
|
+
/** 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
|
+
seclevel: number;
|
7
|
+
};
|
8
|
+
/** transform a given babel `File` to be hackmud compatible
|
9
|
+
*
|
10
|
+
* (returned File will need `postprocess()`ing)
|
11
|
+
* @param file babel ast node representing a file containing preprocessed code
|
12
|
+
* @param sourceCode the original untouched source code
|
13
|
+
* @param options {@link TransformOptions details} */
|
14
|
+
export declare function transform(file: File, sourceCode: string, { uniqueID, scriptUser, scriptName, seclevel }?: Partial<TransformOptions>): {
|
15
|
+
file: File;
|
16
|
+
seclevel: number;
|
17
|
+
};
|
18
|
+
export default transform;
|
package/src/pull.d.ts
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
/** Copies script from hackmud to local source folder.
|
2
|
+
* @param sourceFolderPath path to folder containing source files
|
3
|
+
* @param hackmudPath path to hackmud directory
|
4
|
+
* @param script to pull in `user.name` format */
|
5
|
+
export declare function pull(sourceFolderPath: string, hackmudPath: string, script: string): Promise<void>;
|
6
|
+
export default pull;
|
package/src/push.d.ts
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
import type { LaxPartial } from "@samual/lib";
|
2
|
+
import type { Info } from ".";
|
3
|
+
export type PushOptions = {
|
4
|
+
/** whether to do the minify step (defaults to `true`) */ minify: boolean;
|
5
|
+
/** whether to mangle function and class names (defaults to `false`) */ mangleNames: boolean;
|
6
|
+
/** array of scripts in the format `foo.bar`
|
7
|
+
*
|
8
|
+
* also accepts wild card (`*`) e.g. `*.bar` or `foo.*`
|
9
|
+
*
|
10
|
+
* pushes everything by default (`*.*`) */
|
11
|
+
scripts: string[];
|
12
|
+
/** callback called on script push */ onPush: (info: Info) => void;
|
13
|
+
/** when set to `true` forces use of quine cheats
|
14
|
+
*
|
15
|
+
* when set to `false` forces quine cheats not to be used
|
16
|
+
*
|
17
|
+
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
18
|
+
*/
|
19
|
+
forceQuineCheats: boolean;
|
20
|
+
};
|
21
|
+
/** Push scripts from a source directory to the hackmud directory.
|
22
|
+
*
|
23
|
+
* Pushes files directly in the source folder to all users
|
24
|
+
* @param sourceDirectory directory containing source code
|
25
|
+
* @param hackmudDirectory directory created by hackmud containing user data including scripts
|
26
|
+
* @param options {@link PushOptions details}
|
27
|
+
* @returns array of info on pushed scripts */
|
28
|
+
export declare function push(sourceDirectory: string, hackmudDirectory: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: LaxPartial<PushOptions>): Promise<Info[]>;
|
29
|
+
export default push;
|
package/src/watch.d.ts
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
import type { LaxPartial } from "@samual/lib";
|
2
|
+
import type { PushOptions } from "./push";
|
3
|
+
export type WatchOptions = PushOptions & {
|
4
|
+
/** if provided, will write typescript type declarations for all the scripts on every change detected
|
5
|
+
*
|
6
|
+
* writing the type declarations enables interscript type checking and autocompletetes for the args */
|
7
|
+
typeDeclarationPath: string;
|
8
|
+
onReady: () => void;
|
9
|
+
};
|
10
|
+
/** Watches target file or folder for updates and builds and pushes updated file.
|
11
|
+
* @param sourceDirectory path to folder containing source files
|
12
|
+
* @param hackmudDirectory path to hackmud directory
|
13
|
+
* @param options {@link WatchOptions details} and {@link PushOptions more details} */
|
14
|
+
export declare function watch(sourceDirectory: string, hackmudDirectory: string, { scripts, onPush, minify, mangleNames, typeDeclarationPath: typeDeclarationPath_, onReady, forceQuineCheats }?: LaxPartial<WatchOptions>): Promise<void>;
|
15
|
+
export default watch;
|
package/syncMacros.js
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
import {
|
1
|
+
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
2
|
+
import { readFile, stat, writeFile } from "fs/promises"
|
2
3
|
import { extname, basename, resolve } from "path"
|
3
|
-
|
4
|
-
const files = await
|
4
|
+
async function syncMacros(hackmudPath) {
|
5
|
+
const files = await readDirectoryWithStats(hackmudPath),
|
5
6
|
macros = new Map(),
|
6
7
|
users = []
|
7
8
|
await Promise.all(
|
8
9
|
files.map(async file => {
|
9
|
-
if (file.isFile())
|
10
|
+
if (file.stats.isFile())
|
10
11
|
switch (extname(file.name)) {
|
11
12
|
case ".macros":
|
12
13
|
{
|