hackmud-script-manager 0.21.1-d4bf990 → 0.21.1-e3e8246
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 +44 -38
- package/bin/hsm.js +252 -245
- package/env.d.ts +301 -244
- package/generateTypeDeclaration.js +1 -1
- package/index.js +2 -2
- package/package.json +26 -26
- package/processScript/index.d.ts +12 -9
- package/processScript/index.js +46 -39
- package/processScript/minify.d.ts +11 -8
- package/processScript/minify.js +10 -10
- package/processScript/preprocess.d.ts +4 -2
- package/processScript/preprocess.js +7 -7
- package/processScript/transform.d.ts +8 -6
- package/processScript/transform.js +32 -32
- package/pull.d.ts +6 -4
- package/pull.js +1 -1
- package/push.d.ts +23 -18
- package/push.js +6 -6
- package/syncMacros.js +14 -15
- package/watch.d.ts +11 -7
- package/watch.js +6 -6
@@ -1,10 +1,10 @@
|
|
1
|
-
import
|
1
|
+
import kwmn7lp0r5s0ul58gd0l3ldw from "@babel/traverse"
|
2
2
|
import t from "@babel/types"
|
3
3
|
import { assert } from "@samual/lib/assert"
|
4
4
|
import { clearObject } from "@samual/lib/clearObject"
|
5
5
|
import { validDBMethods } from "../constants.js"
|
6
6
|
import { getReferencePathsToGlobal } from "./shared.js"
|
7
|
-
const traverse =
|
7
|
+
const traverse = kwmn7lp0r5s0ul58gd0l3ldw.default,
|
8
8
|
globalFunctionsUnder7Characters = [
|
9
9
|
"Map",
|
10
10
|
"Set",
|
@@ -77,30 +77,30 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
77
77
|
const referencePath = FunctionReferencePaths[0]
|
78
78
|
assert(
|
79
79
|
"MemberExpression" == referencePath.parent.type,
|
80
|
-
"src/processScript/transform.ts:
|
80
|
+
"src/processScript/transform.ts:111:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
81
81
|
)
|
82
82
|
assert(
|
83
83
|
"Identifier" == referencePath.parent.property.type,
|
84
|
-
"src/processScript/transform.ts:
|
84
|
+
"src/processScript/transform.ts:116:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
85
85
|
)
|
86
86
|
assert(
|
87
87
|
"prototype" == referencePath.parent.property.name,
|
88
|
-
"src/processScript/transform.ts:
|
88
|
+
"src/processScript/transform.ts:121:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
89
89
|
)
|
90
90
|
referencePath.parentPath.replaceWith(createGetFunctionPrototypeNode())
|
91
91
|
} else {
|
92
92
|
for (const referencePath of FunctionReferencePaths) {
|
93
93
|
assert(
|
94
94
|
"MemberExpression" == referencePath.parent.type,
|
95
|
-
"src/processScript/transform.ts:
|
95
|
+
"src/processScript/transform.ts:129:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
96
96
|
)
|
97
97
|
assert(
|
98
98
|
"Identifier" == referencePath.parent.property.type,
|
99
|
-
"src/processScript/transform.ts:
|
99
|
+
"src/processScript/transform.ts:134:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
100
100
|
)
|
101
101
|
assert(
|
102
102
|
"prototype" == referencePath.parent.property.name,
|
103
|
-
"src/processScript/transform.ts:
|
103
|
+
"src/processScript/transform.ts:139:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
104
104
|
)
|
105
105
|
functionDotPrototypeIsReferencedMultipleTimes = !0
|
106
106
|
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueId}_FUNCTION_DOT_PROTOTYPE_`))
|
@@ -141,12 +141,12 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
141
141
|
const neededDbMethodLets = new Set()
|
142
142
|
if (program.scope.hasGlobal("$db"))
|
143
143
|
for (const referencePath of getReferencePathsToGlobal("$db", program)) {
|
144
|
-
assert("MemberExpression" == referencePath.parentPath.node.type, "src/processScript/transform.ts:
|
145
|
-
assert("Identifier" == referencePath.parentPath.node.property.type, "src/processScript/transform.ts:
|
144
|
+
assert("MemberExpression" == referencePath.parentPath.node.type, "src/processScript/transform.ts:198:69")
|
145
|
+
assert("Identifier" == referencePath.parentPath.node.property.type, "src/processScript/transform.ts:199:72")
|
146
146
|
const databaseOpMethodName = referencePath.parentPath.node.property.name
|
147
147
|
assert(
|
148
148
|
validDBMethods.includes(databaseOpMethodName),
|
149
|
-
`src/processScript/transform.ts:
|
149
|
+
`src/processScript/transform.ts:205:8 invalid db method "${databaseOpMethodName}", valid db methods are "${validDBMethods.join('", "')}"`
|
150
150
|
)
|
151
151
|
if ("CallExpression" == referencePath.parentPath.parentPath?.type)
|
152
152
|
referencePath.parentPath.replaceWith(t.identifier(`$${uniqueId}$DB$${databaseOpMethodName}$`))
|
@@ -181,7 +181,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
181
181
|
if (program.scope.hasGlobal("Object"))
|
182
182
|
for (const referencePath of getReferencePathsToGlobal("Object", program))
|
183
183
|
if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
|
184
|
-
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:
|
184
|
+
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:255:64")
|
185
185
|
if ("getPrototypeOf" == referencePath.parent.property.name) {
|
186
186
|
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueId}_GET_PROTOTYPE_OF_`))
|
187
187
|
needGetPrototypeOf = !0
|
@@ -194,7 +194,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
194
194
|
if (program.scope.hasGlobal("console"))
|
195
195
|
for (const referencePath of getReferencePathsToGlobal("console", program))
|
196
196
|
if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
|
197
|
-
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:
|
197
|
+
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:273:64")
|
198
198
|
referencePath.parentPath.replaceWith(
|
199
199
|
t.identifier(`_${uniqueId}_CONSOLE_METHOD_${referencePath.parent.property.name}_`)
|
200
200
|
)
|
@@ -202,13 +202,13 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
202
202
|
}
|
203
203
|
const lastStatement = program.node.body.at(-1)
|
204
204
|
let exportDefaultName
|
205
|
-
assert(lastStatement, "src/processScript/transform.ts:
|
205
|
+
assert(lastStatement, "src/processScript/transform.ts:287:27 program is empty")
|
206
206
|
if ("ExportNamedDeclaration" == lastStatement.type) {
|
207
207
|
program.node.body.pop()
|
208
208
|
for (const specifier of lastStatement.specifiers) {
|
209
209
|
assert(
|
210
210
|
"ExportSpecifier" == specifier.type,
|
211
|
-
`src/processScript/transform.ts:
|
211
|
+
`src/processScript/transform.ts:293:51 ${specifier.type} is currently unsupported`
|
212
212
|
)
|
213
213
|
if (
|
214
214
|
"default" !=
|
@@ -310,11 +310,11 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
310
310
|
let hoistedGlobalBlockFunctions = 0
|
311
311
|
for (const [globalBlockIndex, globalBlockStatement] of [...globalBlock.body.entries()].reverse())
|
312
312
|
if ("VariableDeclaration" == globalBlockStatement.type) {
|
313
|
-
assert(1 == globalBlockStatement.declarations.length, "src/processScript/transform.ts:
|
313
|
+
assert(1 == globalBlockStatement.declarations.length, "src/processScript/transform.ts:406:59")
|
314
314
|
const declarator = globalBlockStatement.declarations[0]
|
315
315
|
assert(
|
316
316
|
"Identifier" == declarator.id.type,
|
317
|
-
`src/processScript/transform.ts:
|
317
|
+
`src/processScript/transform.ts:410:51 declarator.id.type was "${declarator.id.type}"`
|
318
318
|
)
|
319
319
|
program.scope.crawl()
|
320
320
|
if (program.scope.hasGlobal(declarator.id.name)) {
|
@@ -329,9 +329,9 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
329
329
|
Object.keys(program.scope.globals).some(global => globalBlockVariables.has(global))
|
330
330
|
) {
|
331
331
|
const binding = program.scope.getBinding(declarator.id.name)
|
332
|
-
assert(binding, "src/processScript/transform.ts:
|
332
|
+
assert(binding, "src/processScript/transform.ts:429:23")
|
333
333
|
for (const referencePath of binding.referencePaths) {
|
334
|
-
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:
|
334
|
+
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:432:56")
|
335
335
|
referencePath.replaceWith(
|
336
336
|
t.memberExpression(
|
337
337
|
t.identifier(`_${uniqueId}_G_`),
|
@@ -379,16 +379,16 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
379
379
|
} else globalBlockVariables.add(declarator.id.name)
|
380
380
|
} else if ("ClassDeclaration" == globalBlockStatement.type) {
|
381
381
|
program.scope.crawl()
|
382
|
-
assert(globalBlockStatement.id, "src/processScript/transform.ts:
|
382
|
+
assert(globalBlockStatement.id, "src/processScript/transform.ts:489:37")
|
383
383
|
if (program.scope.hasGlobal(globalBlockStatement.id.name)) {
|
384
384
|
globalBlock.body.splice(globalBlockIndex, 1)
|
385
385
|
const [globalBlockPath] = program.unshiftContainer("body", globalBlock),
|
386
386
|
[globalBlockStatementPath] = program.unshiftContainer("body", globalBlockStatement)
|
387
387
|
program.scope.crawl()
|
388
388
|
const binding = program.scope.getBinding(globalBlockStatement.id.name)
|
389
|
-
assert(binding, "src/processScript/transform.ts:
|
389
|
+
assert(binding, "src/processScript/transform.ts:501:22")
|
390
390
|
for (const referencePath of binding.referencePaths) {
|
391
|
-
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:
|
391
|
+
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:504:55")
|
392
392
|
referencePath.replaceWith(
|
393
393
|
t.memberExpression(t.identifier(`_${uniqueId}_G_`), t.identifier(referencePath.node.name))
|
394
394
|
)
|
@@ -588,9 +588,9 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
588
588
|
"VariableDeclarator" == parent.type &&
|
589
589
|
"VariableDeclaration" == path.parentPath?.parentPath?.node?.type &&
|
590
590
|
"const" == path.parentPath?.parentPath?.node?.kind &&
|
591
|
-
"Identifier" == parent.id.type
|
592
|
-
|
593
|
-
|
591
|
+
"Identifier" == parent.id.type,
|
592
|
+
thisId = reuseDeclaredName ? parent.id.name : `_${evenMoreUniqueId}_THIS_`
|
593
|
+
let thisIsReferenced = !1
|
594
594
|
if ("ObjectExpression" == object.type)
|
595
595
|
for (const property of object.properties)
|
596
596
|
"ObjectMethod" == property.type &&
|
@@ -616,7 +616,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
616
616
|
}
|
617
617
|
currentParent = currentParent.parentPath
|
618
618
|
}
|
619
|
-
assert(null != someBlock, "src/processScript/transform.ts:
|
619
|
+
assert(null != someBlock, "src/processScript/transform.ts:709:29")
|
620
620
|
return someBlock
|
621
621
|
})(path)
|
622
622
|
parentBlock.body.unshift(t.variableDeclaration("let", [t.variableDeclarator(t.identifier(thisId), null)]))
|
@@ -647,7 +647,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
647
647
|
replaceThisInObjectLikeDefinition(path)
|
648
648
|
},
|
649
649
|
ClassBody({ node: classBody, scope, parent }) {
|
650
|
-
assert(t.isClass(parent), "src/processScript/transform.ts:
|
650
|
+
assert(t.isClass(parent), "src/processScript/transform.ts:814:30")
|
651
651
|
let thisIsReferenced = !1
|
652
652
|
for (const classMethod of classBody.body) {
|
653
653
|
if ("ClassMethod" != classMethod.type) continue
|
@@ -759,23 +759,23 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
759
759
|
}
|
760
760
|
function processFakeSubscriptObject(fakeSubscriptObjectName, seclevel) {
|
761
761
|
for (const referencePath of getReferencePathsToGlobal(fakeSubscriptObjectName, program)) {
|
762
|
-
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:
|
762
|
+
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:937:60")
|
763
763
|
assert("Identifier" == referencePath.parent.property.type)
|
764
764
|
assert(
|
765
765
|
"MemberExpression" == referencePath.parentPath.parentPath?.node.type,
|
766
|
-
"src/processScript/transform.ts:
|
766
|
+
"src/processScript/transform.ts:939:81"
|
767
767
|
)
|
768
768
|
assert(
|
769
769
|
"Identifier" == referencePath.parentPath.parentPath.node.property.type,
|
770
|
-
"src/processScript/transform.ts:
|
770
|
+
"src/processScript/transform.ts:940:83"
|
771
771
|
)
|
772
772
|
assert(
|
773
773
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parent.property.name),
|
774
|
-
`src/processScript/transform.ts:
|
774
|
+
`src/processScript/transform.ts:944:8 invalid user "${referencePath.parent.property.name}" in subscript`
|
775
775
|
)
|
776
776
|
assert(
|
777
777
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parentPath.parentPath.node.property.name),
|
778
|
-
`src/processScript/transform.ts:
|
778
|
+
`src/processScript/transform.ts:949:8 invalid script name "${referencePath.parentPath.parentPath.node.property.name}" in subscript`
|
779
779
|
)
|
780
780
|
if ("CallExpression" == referencePath.parentPath.parentPath.parentPath?.type)
|
781
781
|
referencePath.parentPath.parentPath.replaceWith(
|
package/pull.d.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
/**
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
/**
|
2
|
+
* Copies script from hackmud to local source folder.
|
3
|
+
* @param sourceFolderPath path to folder containing source files
|
4
|
+
* @param hackmudPath path to hackmud directory
|
5
|
+
* @param script to pull in `user.name` format
|
6
|
+
*/
|
5
7
|
export declare function pull(sourceFolderPath: string, hackmudPath: string, script: string): Promise<void>;
|
package/pull.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { copyFilePersistent } from "@samual/lib/copyFilePersistent"
|
2
1
|
import { resolve } from "path"
|
2
|
+
import { copyFilePersistent } from "@samual/lib/copyFilePersistent"
|
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')
|
package/push.d.ts
CHANGED
@@ -3,19 +3,22 @@ import type { Info } from ".";
|
|
3
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
|
-
/**
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
/**
|
7
|
+
* array of scripts in the format `foo.bar`
|
8
|
+
*
|
9
|
+
* also accepts wild card (`*`) e.g. `*.bar` or `foo.*`
|
10
|
+
*
|
11
|
+
* pushes everything by default (`*.*`)
|
12
|
+
*/
|
11
13
|
scripts: string[];
|
12
14
|
/** callback called on script push */ onPush: (info: Info) => void;
|
13
|
-
/**
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
/**
|
16
|
+
* when set to `true` forces use of quine cheats
|
17
|
+
*
|
18
|
+
* when set to `false` forces quine cheats not to be used
|
19
|
+
*
|
20
|
+
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
21
|
+
*/
|
19
22
|
forceQuineCheats: boolean;
|
20
23
|
rootFolderPath: string;
|
21
24
|
}>;
|
@@ -27,11 +30,13 @@ export declare class NoUsersError extends Error {
|
|
27
30
|
}
|
28
31
|
export declare class NoScriptsError extends Error {
|
29
32
|
}
|
30
|
-
/**
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
/**
|
34
|
+
* Push scripts from a source directory to the hackmud directory.
|
35
|
+
*
|
36
|
+
* Pushes files directly in the source folder to all users
|
37
|
+
* @param sourcePath directory containing source code
|
38
|
+
* @param hackmudPath directory created by hackmud containing user data including scripts
|
39
|
+
* @param options {@link PushOptions details}
|
40
|
+
* @returns array of info on pushed scripts
|
41
|
+
*/
|
37
42
|
export declare function push(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats, rootFolderPath }?: PushOptions): Promise<MissingSourceFolderError | MissingHackmudFolderError | NoUsersError | NoScriptsError | Info[]>;
|
package/push.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import {
|
1
|
+
import { readFile } from "fs/promises"
|
2
|
+
import { basename, resolve } from "path"
|
2
3
|
import { ensure, assert } from "@samual/lib/assert"
|
4
|
+
import { AutoMap } from "@samual/lib/AutoMap"
|
3
5
|
import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
|
4
6
|
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
5
7
|
import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
|
6
|
-
import { readFile } from "fs/promises"
|
7
|
-
import { basename, resolve } from "path"
|
8
8
|
import { processScript } from "./processScript/index.js"
|
9
9
|
import "@babel/generator"
|
10
10
|
import "@babel/parser"
|
@@ -75,7 +75,7 @@ async function push(
|
|
75
75
|
),
|
76
76
|
allUsers = new Set([
|
77
77
|
...scripts
|
78
|
-
.map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:
|
78
|
+
.map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:94:65"))
|
79
79
|
.filter(name => "*" != name),
|
80
80
|
...sourceFolderFolders.map(({ name }) => name),
|
81
81
|
...hackmudFolder.filter(({ stats }) => stats.isDirectory()).map(({ name }) => name),
|
@@ -91,8 +91,8 @@ async function push(
|
|
91
91
|
scriptNamesToUsers = new AutoMap(_scriptName => new Set())
|
92
92
|
for (const script of scripts) {
|
93
93
|
const [user, scriptName] = script.split(".")
|
94
|
-
assert(user, "src/push.ts:
|
95
|
-
assert(scriptName, "src/push.ts:
|
94
|
+
assert(user, "src/push.ts:117:16")
|
95
|
+
assert(scriptName, "src/push.ts:118:22")
|
96
96
|
"*" == user ? scriptNamesToUsers.set(scriptName, allUsers) : scriptNamesToUsers.get(scriptName).add(user)
|
97
97
|
}
|
98
98
|
const sourceFolderFiles = sourceFolder.filter(({ stats }) => stats.isFile()),
|
package/syncMacros.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
2
1
|
import { readFile, stat, writeFile } from "fs/promises"
|
3
2
|
import { extname, basename, resolve } from "path"
|
3
|
+
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
4
4
|
async function syncMacros(hackmudPath) {
|
5
5
|
const files = await readDirectoryWithStats(hackmudPath),
|
6
6
|
macros = new Map(),
|
@@ -9,22 +9,21 @@ async function syncMacros(hackmudPath) {
|
|
9
9
|
files.map(async file => {
|
10
10
|
if (file.stats.isFile())
|
11
11
|
switch (extname(file.name)) {
|
12
|
-
case ".macros":
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
macros.set(macroName, { date, macro: lines[2 * index + 1] })
|
25
|
-
}
|
12
|
+
case ".macros": {
|
13
|
+
const [lines, date] = await Promise.all([
|
14
|
+
readFile(resolve(hackmudPath, file.name), { encoding: "utf8" }).then(file =>
|
15
|
+
file.split("\n")
|
16
|
+
),
|
17
|
+
stat(resolve(hackmudPath, file.name)).then(({ mtime }) => mtime)
|
18
|
+
])
|
19
|
+
for (let index = 0; index < lines.length / 2 - 1; index++) {
|
20
|
+
const macroName = lines[2 * index],
|
21
|
+
currentMacro = macros.get(macroName)
|
22
|
+
;(!currentMacro || date > currentMacro.date) &&
|
23
|
+
macros.set(macroName, { date, macro: lines[2 * index + 1] })
|
26
24
|
}
|
27
25
|
break
|
26
|
+
}
|
28
27
|
case ".key":
|
29
28
|
users.push(basename(file.name, ".key"))
|
30
29
|
}
|
package/watch.d.ts
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
import type { LaxPartial } from "@samual/lib";
|
2
2
|
import type { PushOptions } from "./push";
|
3
3
|
export type WatchOptions = PushOptions & LaxPartial<{
|
4
|
-
/**
|
5
|
-
|
6
|
-
|
4
|
+
/**
|
5
|
+
* if provided, will write typescript type declarations for all the scripts on every change detected
|
6
|
+
*
|
7
|
+
* writing the type declarations enables interscript type checking and autocompletetes for the args
|
8
|
+
*/
|
7
9
|
typeDeclarationPath: string;
|
8
10
|
onReady: () => void;
|
9
11
|
rootFolderPath: string;
|
10
12
|
}>;
|
11
|
-
/**
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
/**
|
14
|
+
* Watches target file or folder for updates and builds and pushes updated file.
|
15
|
+
* @param sourceDirectory path to folder containing source files
|
16
|
+
* @param hackmudDirectory path to hackmud directory
|
17
|
+
* @param options {@link WatchOptions details} and {@link PushOptions more details}
|
18
|
+
*/
|
15
19
|
export declare function watch(sourceDirectory: string, hackmudDirectory: string, { scripts, onPush, minify, mangleNames, typeDeclarationPath: typeDeclarationPath_, onReady, forceQuineCheats, rootFolderPath }?: WatchOptions): Promise<void>;
|
package/watch.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import {
|
1
|
+
import { stat, readFile, writeFile } from "fs/promises"
|
2
|
+
import { extname, basename, resolve } from "path"
|
2
3
|
import { assert } from "@samual/lib/assert"
|
4
|
+
import { AutoMap } from "@samual/lib/AutoMap"
|
3
5
|
import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
|
4
6
|
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
5
7
|
import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
|
6
8
|
import { watch as watch$1 } from "chokidar"
|
7
|
-
import { stat, readFile, writeFile } from "fs/promises"
|
8
|
-
import { extname, basename, resolve } from "path"
|
9
9
|
import { supportedExtensions } from "./constants.js"
|
10
10
|
import { generateTypeDeclaration } from "./generateTypeDeclaration.js"
|
11
11
|
import { processScript } from "./processScript/index.js"
|
@@ -144,7 +144,7 @@ async function watch(
|
|
144
144
|
}
|
145
145
|
))
|
146
146
|
} catch (error) {
|
147
|
-
assert(error instanceof Error, "src/watch.ts:
|
147
|
+
assert(error instanceof Error, "src/watch.ts:165:36")
|
148
148
|
onPush?.({ path, users: [], characterCount: 0, error, warnings: [] })
|
149
149
|
return
|
150
150
|
}
|
@@ -192,7 +192,7 @@ async function watch(
|
|
192
192
|
rootFolderPath
|
193
193
|
}))
|
194
194
|
} catch (error) {
|
195
|
-
assert(error instanceof Error, "src/watch.ts:
|
195
|
+
assert(error instanceof Error, "src/watch.ts:212:35")
|
196
196
|
onPush?.({ path, users: [], characterCount: 0, error, warnings: [] })
|
197
197
|
return
|
198
198
|
}
|
@@ -207,7 +207,7 @@ async function watch(
|
|
207
207
|
try {
|
208
208
|
await writeFile(typeDeclarationPath, typeDeclaration)
|
209
209
|
} catch (error) {
|
210
|
-
assert(error instanceof Error, "src/watch.ts:
|
210
|
+
assert(error instanceof Error, "src/watch.ts:245:35")
|
211
211
|
if ("EISDIR" != error.code) throw error
|
212
212
|
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
213
213
|
await writeFile(typeDeclarationPath, typeDeclaration)
|