hackmud-script-manager 0.21.1-5970667 → 0.21.1-698970b
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 +23 -26
- package/processScript/index.d.ts +12 -9
- package/processScript/index.js +94 -72
- 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 +99 -22
- 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 gpiwud5ibbmji5fxkev1yx1i 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
|
7
|
+
const traverse = gpiwud5ibbmji5fxkev1yx1i.default,
|
8
8
|
globalFunctionsUnder7Characters = [
|
9
9
|
"Map",
|
10
10
|
"Set",
|
@@ -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
|
)
|
@@ -562,6 +562,65 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
562
562
|
t.variableDeclarator(t.identifier(`_${uniqueId}_G_`), t.identifier(`$${uniqueId}$GLOBAL$`))
|
563
563
|
])
|
564
564
|
)
|
565
|
+
const replaceAllThisWith = (node, scope, thisId) => {
|
566
|
+
let thisIsReferenced = !1
|
567
|
+
traverse(
|
568
|
+
node,
|
569
|
+
{
|
570
|
+
ThisExpression(path) {
|
571
|
+
thisIsReferenced = !0
|
572
|
+
path.replaceWith(t.identifier(thisId))
|
573
|
+
},
|
574
|
+
Function(path) {
|
575
|
+
"ArrowFunctionExpression" != path.node.type && path.skip()
|
576
|
+
}
|
577
|
+
},
|
578
|
+
scope
|
579
|
+
)
|
580
|
+
return thisIsReferenced
|
581
|
+
},
|
582
|
+
replaceThisInObjectLikeDefinition = path => {
|
583
|
+
const { node: object, scope, parent } = path,
|
584
|
+
evenMoreUniqueId = Math.floor(Math.random() * 2 ** 52)
|
585
|
+
.toString(36)
|
586
|
+
.padStart(11, "0"),
|
587
|
+
reuseDeclaredName =
|
588
|
+
"VariableDeclarator" == parent.type &&
|
589
|
+
"VariableDeclaration" == path.parentPath?.parentPath?.node?.type &&
|
590
|
+
"const" == path.parentPath?.parentPath?.node?.kind &&
|
591
|
+
"Identifier" == parent.id.type,
|
592
|
+
thisId = reuseDeclaredName ? parent.id.name : `_${evenMoreUniqueId}_THIS_`
|
593
|
+
let thisIsReferenced = !1
|
594
|
+
if ("ObjectExpression" == object.type)
|
595
|
+
for (const property of object.properties)
|
596
|
+
"ObjectMethod" == property.type &&
|
597
|
+
(thisIsReferenced ||= replaceAllThisWith(property, scope, thisId))
|
598
|
+
else
|
599
|
+
for (const element of object.elements)
|
600
|
+
null != element && (thisIsReferenced ||= replaceAllThisWith(element, scope, thisId))
|
601
|
+
if (!thisIsReferenced) return
|
602
|
+
if (reuseDeclaredName) return
|
603
|
+
path.replaceWith(t.assignmentExpression("=", t.identifier(thisId), object))
|
604
|
+
const parentBlock = (path => {
|
605
|
+
let someBlock = null,
|
606
|
+
currentParent = path
|
607
|
+
for (; currentParent && currentParent && currentParent.node; ) {
|
608
|
+
if (t.isBlock(currentParent.node)) {
|
609
|
+
someBlock = currentParent.node
|
610
|
+
break
|
611
|
+
}
|
612
|
+
if (t.isArrowFunctionExpression(currentParent.parentPath?.node)) {
|
613
|
+
currentParent.replaceWith(t.blockStatement([t.returnStatement(currentParent.node)]))
|
614
|
+
someBlock = currentParent.node
|
615
|
+
break
|
616
|
+
}
|
617
|
+
currentParent = currentParent.parentPath
|
618
|
+
}
|
619
|
+
assert(null != someBlock, "src/processScript/transform.ts:709:29")
|
620
|
+
return someBlock
|
621
|
+
})(path)
|
622
|
+
parentBlock.body.unshift(t.variableDeclaration("let", [t.variableDeclarator(t.identifier(thisId), null)]))
|
623
|
+
}
|
565
624
|
traverse(file, {
|
566
625
|
BlockStatement({ node: blockStatement }) {
|
567
626
|
for (const [index, functionDeclaration] of blockStatement.body.entries())
|
@@ -581,12 +640,30 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
581
640
|
)
|
582
641
|
}
|
583
642
|
},
|
643
|
+
ObjectExpression(path) {
|
644
|
+
replaceThisInObjectLikeDefinition(path)
|
645
|
+
},
|
646
|
+
ArrayExpression(path) {
|
647
|
+
replaceThisInObjectLikeDefinition(path)
|
648
|
+
},
|
584
649
|
ClassBody({ node: classBody, scope, parent }) {
|
585
|
-
assert(t.isClass(parent), "src/processScript/transform.ts:
|
650
|
+
assert(t.isClass(parent), "src/processScript/transform.ts:814:30")
|
586
651
|
let thisIsReferenced = !1
|
587
652
|
for (const classMethod of classBody.body) {
|
588
653
|
if ("ClassMethod" != classMethod.type) continue
|
589
654
|
let methodReferencesThis = !1
|
655
|
+
for (const param of classMethod.params)
|
656
|
+
traverse(
|
657
|
+
param,
|
658
|
+
{
|
659
|
+
ThisExpression(path) {
|
660
|
+
path.replaceWith(
|
661
|
+
t.callExpression(t.memberExpression(t.super(), t.identifier("valueOf")), [])
|
662
|
+
)
|
663
|
+
}
|
664
|
+
},
|
665
|
+
scope
|
666
|
+
)
|
590
667
|
traverse(
|
591
668
|
classMethod.body,
|
592
669
|
{
|
@@ -684,23 +761,23 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
684
761
|
}
|
685
762
|
function processFakeSubscriptObject(fakeSubscriptObjectName, seclevel) {
|
686
763
|
for (const referencePath of getReferencePathsToGlobal(fakeSubscriptObjectName, program)) {
|
687
|
-
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:
|
764
|
+
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:937:60")
|
688
765
|
assert("Identifier" == referencePath.parent.property.type)
|
689
766
|
assert(
|
690
767
|
"MemberExpression" == referencePath.parentPath.parentPath?.node.type,
|
691
|
-
"src/processScript/transform.ts:
|
768
|
+
"src/processScript/transform.ts:939:81"
|
692
769
|
)
|
693
770
|
assert(
|
694
771
|
"Identifier" == referencePath.parentPath.parentPath.node.property.type,
|
695
|
-
"src/processScript/transform.ts:
|
772
|
+
"src/processScript/transform.ts:940:83"
|
696
773
|
)
|
697
774
|
assert(
|
698
775
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parent.property.name),
|
699
|
-
`src/processScript/transform.ts:
|
776
|
+
`src/processScript/transform.ts:944:8 invalid user "${referencePath.parent.property.name}" in subscript`
|
700
777
|
)
|
701
778
|
assert(
|
702
779
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parentPath.parentPath.node.property.name),
|
703
|
-
`src/processScript/transform.ts:
|
780
|
+
`src/processScript/transform.ts:949:8 invalid script name "${referencePath.parentPath.parentPath.node.property.name}" in subscript`
|
704
781
|
)
|
705
782
|
if ("CallExpression" == referencePath.parentPath.parentPath.parentPath?.type)
|
706
783
|
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)
|