hackmud-script-manager 0.20.4-550e28d → 0.20.4-66e0e13
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 +4 -0
- package/bin/hsm.js +161 -72
- package/env.d.ts +325 -317
- package/index.d.ts +3 -0
- package/index.js +2 -1
- package/package.json +39 -38
- package/processScript/index.d.ts +2 -2
- package/processScript/index.js +14 -10
- package/processScript/preprocess.js +2 -2
- package/processScript/transform.d.ts +3 -0
- package/processScript/transform.js +71 -41
- package/push.js +12 -9
- package/watch.js +29 -28
package/watch.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import {
|
1
|
+
import { AutoMap } from "@samual/lib/AutoMap"
|
2
2
|
import { assert } from "@samual/lib/assert"
|
3
3
|
import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
|
4
4
|
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
5
5
|
import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
|
6
6
|
import { watch as watch$1 } from "chokidar"
|
7
|
-
import { readFile, writeFile } from "fs/promises"
|
7
|
+
import { stat, readFile, writeFile } from "fs/promises"
|
8
8
|
import { extname, basename, resolve } from "path"
|
9
9
|
import { supportedExtensions } from "./constants.js"
|
10
10
|
import { generateTypeDeclaration } from "./generateTypeDeclaration.js"
|
@@ -29,6 +29,7 @@ import "@babel/plugin-transform-private-property-in-object"
|
|
29
29
|
import "@babel/plugin-transform-unicode-sets-regex"
|
30
30
|
import "@babel/traverse"
|
31
31
|
import "@babel/types"
|
32
|
+
import "@rollup/plugin-alias"
|
32
33
|
import "@rollup/plugin-babel"
|
33
34
|
import "@rollup/plugin-commonjs"
|
34
35
|
import "@rollup/plugin-json"
|
@@ -59,7 +60,8 @@ async function watch(
|
|
59
60
|
} = {}
|
60
61
|
) {
|
61
62
|
if (!scripts.length) throw Error("scripts option was an empty array")
|
62
|
-
|
63
|
+
if (!(await stat(sourceDirectory)).isDirectory()) throw Error("Target folder must be a folder")
|
64
|
+
const scriptNamesToUsers = new AutoMap(_scriptName => new Set()),
|
63
65
|
wildScriptUsers = new Set(),
|
64
66
|
wildUserScripts = new Set()
|
65
67
|
let pushEverything = !1
|
@@ -72,10 +74,11 @@ async function watch(
|
|
72
74
|
: scriptName && "*" != scriptName ? wildUserScripts.add(scriptName)
|
73
75
|
: (pushEverything = !0)
|
74
76
|
}
|
75
|
-
const watcher = watch$1(
|
77
|
+
const watcher = watch$1(".", {
|
76
78
|
cwd: sourceDirectory,
|
77
79
|
awaitWriteFinish: { stabilityThreshold: 100 },
|
78
|
-
ignored:
|
80
|
+
ignored: (path, stats) =>
|
81
|
+
!!stats?.isFile() && !(path.endsWith(".js") || (path.endsWith(".ts") && !path.endsWith(".d.ts")))
|
79
82
|
}).on("change", async path => {
|
80
83
|
if (path.endsWith(".d.ts")) return
|
81
84
|
const extension = extname(path)
|
@@ -91,7 +94,7 @@ async function watch(
|
|
91
94
|
)
|
92
95
|
)
|
93
96
|
return
|
94
|
-
const scriptNamesToUsersToSkip = new
|
97
|
+
const scriptNamesToUsersToSkip = new AutoMap(_scriptName => [])
|
95
98
|
await Promise.all(
|
96
99
|
(await readDirectoryWithStats(sourceDirectory)).map(async ({ stats, name, path }) => {
|
97
100
|
if (stats.isDirectory())
|
@@ -117,27 +120,22 @@ async function watch(
|
|
117
120
|
for (const user of scriptNamesToUsers.get(scriptName)) usersToPushToSet.add(user)
|
118
121
|
const usersToPushTo = [...usersToPushToSet].filter(user => !scriptNamesToUsersToSkip.has(user))
|
119
122
|
if (!usersToPushTo.length) {
|
120
|
-
onPush?.({ path, users: [], characterCount: 0, error: Error("no users to push to") })
|
123
|
+
onPush?.({ path, users: [], characterCount: 0, error: Error("no users to push to"), warnings: [] })
|
121
124
|
return
|
122
125
|
}
|
123
126
|
const uniqueId = Math.floor(Math.random() * 2 ** 52)
|
124
127
|
.toString(36)
|
125
128
|
.padStart(11, "0"),
|
126
129
|
filePath = resolve(sourceDirectory, path)
|
127
|
-
let minifiedCode
|
130
|
+
let minifiedCode, warnings
|
128
131
|
try {
|
129
|
-
;({ script: minifiedCode } = await processScript(
|
130
|
-
|
131
|
-
scriptUser: !0,
|
132
|
-
|
133
|
-
uniqueId,
|
134
|
-
filePath,
|
135
|
-
mangleNames,
|
136
|
-
forceQuineCheats
|
137
|
-
}))
|
132
|
+
;({ script: minifiedCode, warnings } = await processScript(
|
133
|
+
await readFile(filePath, { encoding: "utf8" }),
|
134
|
+
{ minify, scriptUser: !0, scriptName, uniqueId, filePath, mangleNames, forceQuineCheats }
|
135
|
+
))
|
138
136
|
} catch (error) {
|
139
|
-
assert(error instanceof Error, "src/watch.ts:
|
140
|
-
onPush?.({ path, users: [], characterCount: 0, error })
|
137
|
+
assert(error instanceof Error, "src/watch.ts:149:36")
|
138
|
+
onPush?.({ path, users: [], characterCount: 0, error, warnings: [] })
|
141
139
|
return
|
142
140
|
}
|
143
141
|
await Promise.all(
|
@@ -154,7 +152,8 @@ async function watch(
|
|
154
152
|
path,
|
155
153
|
users: usersToPushTo,
|
156
154
|
characterCount: countHackmudCharacters(minifiedCode),
|
157
|
-
error: void 0
|
155
|
+
error: void 0,
|
156
|
+
warnings
|
158
157
|
})
|
159
158
|
return
|
160
159
|
}
|
@@ -168,25 +167,27 @@ async function watch(
|
|
168
167
|
)
|
169
168
|
)
|
170
169
|
return
|
171
|
-
const
|
170
|
+
const sourceDirectoryResolved = resolve(sourceDirectory),
|
171
|
+
filePath = resolve(sourceDirectoryResolved, path),
|
172
172
|
sourceCode = await readFile(filePath, { encoding: "utf8" })
|
173
|
-
let script
|
173
|
+
let script, warnings
|
174
174
|
try {
|
175
|
-
;({ script } = await processScript(sourceCode, {
|
175
|
+
;({ script, warnings } = await processScript(sourceCode, {
|
176
176
|
minify,
|
177
177
|
scriptUser: user,
|
178
178
|
scriptName,
|
179
179
|
filePath,
|
180
180
|
mangleNames,
|
181
|
-
forceQuineCheats
|
181
|
+
forceQuineCheats,
|
182
|
+
rootFolderPath: sourceDirectoryResolved
|
182
183
|
}))
|
183
184
|
} catch (error) {
|
184
|
-
assert(error instanceof Error, "src/watch.ts:
|
185
|
-
onPush?.({ path, users: [], characterCount: 0, error })
|
185
|
+
assert(error instanceof Error, "src/watch.ts:196:35")
|
186
|
+
onPush?.({ path, users: [], characterCount: 0, error, warnings: [] })
|
186
187
|
return
|
187
188
|
}
|
188
189
|
await writeFilePersistent(resolve(hackmudDirectory, user, "scripts", scriptName + ".js"), script)
|
189
|
-
onPush?.({ path, users: [user], characterCount: countHackmudCharacters(script), error: void 0 })
|
190
|
+
onPush?.({ path, users: [user], characterCount: countHackmudCharacters(script), error: void 0, warnings })
|
190
191
|
})
|
191
192
|
onReady && watcher.on("ready", onReady)
|
192
193
|
if (!typeDeclarationPath_) return
|
@@ -196,7 +197,7 @@ async function watch(
|
|
196
197
|
try {
|
197
198
|
await writeFile(typeDeclarationPath, typeDeclaration)
|
198
199
|
} catch (error) {
|
199
|
-
assert(error instanceof Error, "src/watch.ts:
|
200
|
+
assert(error instanceof Error, "src/watch.ts:229:35")
|
200
201
|
if ("EISDIR" != error.code) throw error
|
201
202
|
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
202
203
|
await writeFile(typeDeclarationPath, typeDeclaration)
|