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