hackmud-script-manager 0.19.1-003b022 → 0.19.1-02bed1a

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/pull.d.ts CHANGED
@@ -1,9 +1,5 @@
1
- /**
2
- * Copies script from hackmud to local source folder.
3
- *
4
- * @param sourceFolderPath path to folder containing source files
5
- * @param hackmudPath path to hackmud directory
6
- * @param script to pull in `user.name` format
7
- */
8
- export declare const pull: (sourceFolderPath: string, hackmudPath: string, script: string) => Promise<void>;
9
- export default pull;
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>;
package/pull.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { copyFilePersistent } from "@samual/lib/copyFilePersistent"
2
2
  import { resolve } from "path"
3
- const pull = async (sourceFolderPath, hackmudPath, script) => {
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(
@@ -8,4 +8,4 @@ const pull = async (sourceFolderPath, hackmudPath, script) => {
8
8
  resolve(sourceFolderPath, user, name + ".js")
9
9
  )
10
10
  }
11
- export { pull as default, pull }
11
+ export { pull }
package/push.d.ts CHANGED
@@ -1,37 +1,28 @@
1
1
  import type { LaxPartial } from "@samual/lib";
2
2
  import type { Info } from ".";
3
- export type PushOptions = {
4
- /** whether to do the minify step (defaults to `true`) */
5
- minify: boolean;
6
- /** whether to mangle function and class names (defaults to `false`) */
7
- mangleNames: boolean;
8
- /**
9
- * array of scripts in the format `foo.bar`
10
- *
11
- * also accepts wild card (`*`) e.g. `*.bar` or `foo.*`
12
- *
13
- * pushes everything by default (`*.*`)
14
- */
3
+ export type PushOptions = LaxPartial<{
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 (`*.*`) */
15
11
  scripts: string[];
16
- /** callback called on script push */
17
- onPush: (info: Info) => void;
18
- /**
19
- * when set to `true` forces use of quine cheats
20
- *
21
- * when set to `false` forces quine cheats not to be used
22
- *
23
- * when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
24
- */
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
+ */
25
19
  forceQuineCheats: boolean;
26
- };
27
- /**
28
- * Push scripts from a source directory to the hackmud directory.
29
- *
30
- * Pushes files directly in the source folder to all users
31
- * @param sourceDirectory directory containing source code
32
- * @param hackmudDirectory directory created by hackmud containing user data including scripts
33
- * @param options {@link PushOptions details}
34
- * @returns array of info on pushed scripts
35
- */
36
- export declare const push: (sourceDirectory: string, hackmudDirectory: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: LaxPartial<PushOptions>) => Promise<Info[]>;
37
- export default push;
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 sourcePath directory containing source code
25
+ * @param hackmudPath 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(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: PushOptions): Promise<Info[]>;
package/push.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Cache } from "@samual/lib/Cache"
2
+ import { ensure, assert } from "@samual/lib/assert"
2
3
  import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
3
4
  import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
4
5
  import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
5
6
  import { readFile } from "fs/promises"
6
- import { basename, resolve, extname } from "path"
7
- import { supportedExtensions } from "./constants.js"
7
+ import { basename, resolve } from "path"
8
8
  import { processScript } from "./processScript/index.js"
9
9
  import "@babel/generator"
10
10
  import "@babel/parser"
@@ -29,9 +29,9 @@ import "@rollup/plugin-babel"
29
29
  import "@rollup/plugin-commonjs"
30
30
  import "@rollup/plugin-json"
31
31
  import "@rollup/plugin-node-resolve"
32
- import "@samual/lib/assert"
33
32
  import "prettier"
34
33
  import "rollup"
34
+ import "./constants.js"
35
35
  import "./processScript/minify.js"
36
36
  import "@samual/lib/spliceString"
37
37
  import "acorn"
@@ -42,228 +42,97 @@ import "./processScript/preprocess.js"
42
42
  import "import-meta-resolve"
43
43
  import "./processScript/transform.js"
44
44
  import "@samual/lib/clearObject"
45
- const push = async (
46
- sourceDirectory,
47
- hackmudDirectory,
45
+ async function push(
46
+ sourcePath,
47
+ hackmudPath,
48
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)
49
+ ) {
50
+ const [sourceFolder, hackmudFolder] = await Promise.all([
51
+ readDirectoryWithStats(sourcePath),
52
+ readDirectoryWithStats(hackmudPath)
53
+ ]),
54
+ sourceFolderFolders = sourceFolder.filter(({ stats }) => stats.isDirectory()),
55
+ allUsers = new Set([
56
+ ...scripts
57
+ .map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:52:65"))
58
+ .filter(name => "*" != name),
59
+ ...sourceFolderFolders.map(({ name }) => name),
60
+ ...hackmudFolder.filter(({ stats }) => stats.isDirectory()).map(({ name }) => name),
61
+ ...hackmudFolder
62
+ .filter(({ stats, name }) => stats.isFile() && name.endsWith(".key"))
63
+ .map(({ name }) => name.slice(0, -4))
64
+ ]),
65
+ usersToScriptsToPush = new Cache(_user => new Map()),
66
+ scriptNamesToUsers = new Cache(_scriptName => new Set())
67
+ for (const script of scripts) {
68
+ const [user, scriptName] = script.split(".")
69
+ assert(user, "src/push.ts:69:16")
70
+ assert(scriptName, "src/push.ts:70:22")
71
+ "*" == user ? scriptNamesToUsers.set(scriptName, allUsers) : scriptNamesToUsers.get(scriptName).add(user)
62
72
  }
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
- }
73
+ const sourceFolderFiles = sourceFolder.filter(({ stats }) => stats.isFile()),
74
+ wildScriptUsers_ = scriptNamesToUsers.get("*")
75
+ scriptNamesToUsers.delete("*")
76
+ for (const { name, path } of [
77
+ ...sourceFolderFiles.filter(({ name }) => name.endsWith(".js")),
78
+ ...sourceFolderFiles.filter(({ name }) => name.endsWith(".ts"))
79
+ ]) {
80
+ const scriptName = name.slice(0, -3)
81
+ for (const user of [...wildScriptUsers_, ...scriptNamesToUsers.get(scriptName)])
82
+ usersToScriptsToPush.get(user).set(scriptName, path)
88
83
  }
89
84
  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
108
- }
109
- ),
110
- info = {
111
- file: `${user}/${name}`,
112
- users: [user],
113
- minLength: countHackmudCharacters(minifiedCode),
114
- error: void 0
115
- }
116
- scriptNamesAlreadyPushedByUser.get(user).add(scriptName)
117
- allInfo.push(info)
118
- await writeFilePersistent(
119
- resolve(hackmudDirectory, user, `scripts/${scriptName}.js`),
120
- minifiedCode
121
- )
122
- onPush(info)
123
- }
124
- })
125
- )
126
- },
127
- error => {
128
- if ("ENOENT" != error.code) throw error
129
- }
130
- )
85
+ sourceFolderFolders.map(async ({ name: user, path }) => {
86
+ const files = (await readDirectoryWithStats(path)).filter(({ stats }) => stats.isFile()),
87
+ scriptFiles = [
88
+ ...files.filter(({ name }) => name.endsWith(".js")),
89
+ ...files.filter(({ name }) => name.endsWith(".ts"))
90
+ ]
91
+ for (const { name, path } of scriptFiles) {
92
+ const scriptName = name.slice(0, -3)
93
+ ;[...wildScriptUsers_, ...scriptNamesToUsers.get(scriptName)].includes(user) &&
94
+ usersToScriptsToPush.get(user).set(scriptName, path)
95
+ }
131
96
  })
132
97
  )
98
+ for (const [scriptName, users] of scriptNamesToUsers)
99
+ for (const user of users)
100
+ if (!usersToScriptsToPush.get(user).has(scriptName))
101
+ throw Error(`Could not find script ${user}.${scriptName} to push`)
102
+ const pathsToUsers = new Cache(_path => new Set())
103
+ for (const [user, scriptsToPush] of usersToScriptsToPush)
104
+ for (const path of scriptsToPush.values()) pathsToUsers.get(path).add(user)
105
+ const allInfo = []
133
106
  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, {
149
- minify,
150
- scriptUser: user,
151
- scriptName,
152
- filePath,
153
- mangleNames,
154
- forceQuineCheats
155
- }),
156
- info = {
157
- file: `${user}/${fileName}`,
158
- users: [user],
159
- minLength: countHackmudCharacters(minifiedCode),
160
- error: void 0
161
- }
162
- allInfo.push(info)
163
- await writeFilePersistent(
164
- resolve(hackmudDirectory, user, "scripts", scriptName + ".js"),
165
- minifiedCode
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)
183
- )
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
- )
107
+ [...pathsToUsers].map(async ([path, [...users]]) => {
108
+ const scriptName = basename(path.slice(0, -3)),
109
+ uniqueId = Math.floor(Math.random() * 2 ** 52)
110
+ .toString(36)
111
+ .padStart(11, "0"),
112
+ { script: minifiedCode } = await processScript(await readFile(path, { encoding: "utf8" }), {
113
+ minify,
114
+ scriptUser: !0,
115
+ scriptName,
116
+ uniqueId,
117
+ filePath: path,
118
+ mangleNames,
119
+ forceQuineCheats
120
+ }),
121
+ info = { path, users, characterCount: countHackmudCharacters(minifiedCode), error: void 0 }
122
+ await Promise.all(
123
+ users.map(user =>
124
+ writeFilePersistent(
125
+ resolve(hackmudPath, user, `scripts/${scriptName}.js`),
126
+ minifiedCode
127
+ .replace(RegExp(`\\$${uniqueId}\\$SCRIPT_USER\\$`, "g"), user)
128
+ .replace(RegExp(`\\$${uniqueId}\\$FULL_SCRIPT_NAME\\$`, "g"), `${user}.${scriptName}`)
215
129
  )
216
- allInfo.push(info)
217
- onPush(info)
218
- }
130
+ )
219
131
  )
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
- )
259
- )
260
- )
261
- )
262
- allInfo.push(info)
263
- onPush(info)
264
- }
265
- })
266
- ))
132
+ allInfo.push(info)
133
+ onPush(info)
134
+ })
135
+ )
267
136
  return allInfo
268
137
  }
269
- export { push as default, push }
138
+ export { push }
package/syncMacros.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- export declare const syncMacros: (hackmudPath: string) => Promise<{
1
+ export declare function syncMacros(hackmudPath: string): Promise<{
2
2
  macrosSynced: number;
3
3
  usersSynced: number;
4
4
  }>;
5
- export default syncMacros;
package/syncMacros.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
2
2
  import { readFile, stat, writeFile } from "fs/promises"
3
3
  import { extname, basename, resolve } from "path"
4
- const syncMacros = async hackmudPath => {
4
+ async function syncMacros(hackmudPath) {
5
5
  const files = await readDirectoryWithStats(hackmudPath),
6
6
  macros = new Map(),
7
7
  users = []
@@ -12,7 +12,7 @@ const syncMacros = async hackmudPath => {
12
12
  case ".macros":
13
13
  {
14
14
  const [lines, date] = await Promise.all([
15
- readFile(resolve(hackmudPath, file.name), { encoding: "utf-8" }).then(file =>
15
+ readFile(resolve(hackmudPath, file.name), { encoding: "utf8" }).then(file =>
16
16
  file.split("\n")
17
17
  ),
18
18
  stat(resolve(hackmudPath, file.name)).then(({ mtime }) => mtime)
@@ -40,4 +40,4 @@ const syncMacros = async hackmudPath => {
40
40
  for (const user of users) writeFile(resolve(hackmudPath, user + ".macros"), macroFile)
41
41
  return { macrosSynced, usersSynced: users.length }
42
42
  }
43
- export { syncMacros as default, syncMacros }
43
+ export { syncMacros }
package/watch.d.ts CHANGED
@@ -1,20 +1,14 @@
1
1
  import type { LaxPartial } from "@samual/lib";
2
2
  import type { PushOptions } from "./push";
3
- export type WatchOptions = PushOptions & {
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
- */
3
+ export type WatchOptions = PushOptions & LaxPartial<{
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 */
9
7
  typeDeclarationPath: string;
10
8
  onReady: () => void;
11
- };
12
- /**
13
- * Watches target file or folder for updates and builds and pushes updated file.
14
- *
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
- */
19
- export declare const watch: (sourceDirectory: string, hackmudDirectory: string, { scripts, onPush, minify, mangleNames, typeDeclarationPath: typeDeclarationPath_, onReady, forceQuineCheats }?: LaxPartial<WatchOptions>) => Promise<void>;
20
- export default watch;
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 }?: WatchOptions): Promise<void>;
package/watch.js CHANGED
@@ -44,7 +44,7 @@ import "./processScript/preprocess.js"
44
44
  import "import-meta-resolve"
45
45
  import "./processScript/transform.js"
46
46
  import "@samual/lib/clearObject"
47
- const watch = async (
47
+ async function watch(
48
48
  sourceDirectory,
49
49
  hackmudDirectory,
50
50
  {
@@ -56,7 +56,7 @@ const watch = async (
56
56
  onReady,
57
57
  forceQuineCheats
58
58
  } = {}
59
- ) => {
59
+ ) {
60
60
  if (!scripts.length) throw Error("scripts option was an empty array")
61
61
  const scriptNamesToUsers = new Cache(_scriptName => new Set()),
62
62
  wildScriptUsers = new Set(),
@@ -94,12 +94,12 @@ const watch = async (
94
94
  await Promise.all(
95
95
  (await readDirectoryWithStats(sourceDirectory)).map(async ({ stats, name, path }) => {
96
96
  if (stats.isDirectory())
97
- for (const child of await readDirectoryWithStats(path)) {
98
- if (!child.stats.isFile()) continue
99
- const fileExtension = extname(child.name)
100
- supportedExtensions.includes(fileExtension) &&
101
- scriptNamesToUsersToSkip.get(basename(child.name, fileExtension)).push(name)
102
- }
97
+ for (const child of await readDirectoryWithStats(path))
98
+ if (child.stats.isFile()) {
99
+ const fileExtension = extname(child.name)
100
+ supportedExtensions.includes(fileExtension) &&
101
+ scriptNamesToUsersToSkip.get(basename(child.name, fileExtension)).push(name)
102
+ }
103
103
  })
104
104
  )
105
105
  const usersToPushToSet = new Set()
@@ -116,27 +116,27 @@ const watch = async (
116
116
  for (const user of scriptNamesToUsers.get(scriptName)) usersToPushToSet.add(user)
117
117
  const usersToPushTo = [...usersToPushToSet].filter(user => !scriptNamesToUsersToSkip.has(user))
118
118
  if (!usersToPushTo.length) {
119
- onPush?.({ file: path, users: [], minLength: 0, error: Error("no users to push to") })
119
+ onPush?.({ path, users: [], characterCount: 0, error: Error("no users to push to") })
120
120
  return
121
121
  }
122
- const uniqueID = Math.floor(Math.random() * 2 ** 52)
122
+ const uniqueId = Math.floor(Math.random() * 2 ** 52)
123
123
  .toString(36)
124
124
  .padStart(11, "0"),
125
125
  filePath = resolve(sourceDirectory, path)
126
126
  let minifiedCode
127
127
  try {
128
- ;({ script: minifiedCode } = await processScript(await readFile(filePath, { encoding: "utf-8" }), {
128
+ ;({ script: minifiedCode } = await processScript(await readFile(filePath, { encoding: "utf8" }), {
129
129
  minify,
130
130
  scriptUser: !0,
131
131
  scriptName,
132
- uniqueID,
132
+ uniqueId,
133
133
  filePath,
134
134
  mangleNames,
135
135
  forceQuineCheats
136
136
  }))
137
137
  } catch (error) {
138
- assert(error instanceof Error)
139
- onPush?.({ file: path, users: [], minLength: 0, error })
138
+ assert(error instanceof Error, "src/watch.ts:141:36")
139
+ onPush?.({ path, users: [], characterCount: 0, error })
140
140
  return
141
141
  }
142
142
  await Promise.all(
@@ -144,15 +144,15 @@ const watch = async (
144
144
  writeFilePersistent(
145
145
  resolve(hackmudDirectory, user, `scripts/${scriptName}.js`),
146
146
  minifiedCode
147
- .replace(RegExp(`\\$${uniqueID}\\$SCRIPT_USER\\$`, "g"), user)
148
- .replace(RegExp(`\\$${uniqueID}\\$FULL_SCRIPT_NAME\\$`, "g"), `${user}.${scriptName}`)
147
+ .replace(RegExp(`\\$${uniqueId}\\$SCRIPT_USER\\$`, "g"), user)
148
+ .replace(RegExp(`\\$${uniqueId}\\$FULL_SCRIPT_NAME\\$`, "g"), `${user}.${scriptName}`)
149
149
  )
150
150
  )
151
151
  )
152
152
  onPush?.({
153
- file: path,
153
+ path,
154
154
  users: usersToPushTo,
155
- minLength: countHackmudCharacters(minifiedCode),
155
+ characterCount: countHackmudCharacters(minifiedCode),
156
156
  error: void 0
157
157
  })
158
158
  return
@@ -168,7 +168,7 @@ const watch = async (
168
168
  )
169
169
  return
170
170
  const filePath = resolve(sourceDirectory, path),
171
- sourceCode = await readFile(filePath, { encoding: "utf-8" })
171
+ sourceCode = await readFile(filePath, { encoding: "utf8" })
172
172
  let script
173
173
  try {
174
174
  ;({ script } = await processScript(sourceCode, {
@@ -180,12 +180,12 @@ const watch = async (
180
180
  forceQuineCheats
181
181
  }))
182
182
  } catch (error) {
183
- assert(error instanceof Error)
184
- onPush?.({ file: path, users: [], minLength: 0, error })
183
+ assert(error instanceof Error, "src/watch.ts:177:35")
184
+ onPush?.({ path, users: [], characterCount: 0, error })
185
185
  return
186
186
  }
187
187
  await writeFilePersistent(resolve(hackmudDirectory, user, "scripts", scriptName + ".js"), script)
188
- onPush?.({ file: path, users: [user], minLength: countHackmudCharacters(script), error: void 0 })
188
+ onPush?.({ path, users: [user], characterCount: countHackmudCharacters(script), error: void 0 })
189
189
  })
190
190
  onReady && watcher.on("ready", onReady)
191
191
  if (!typeDeclarationPath_) return
@@ -195,7 +195,7 @@ const watch = async (
195
195
  try {
196
196
  await writeFile(typeDeclarationPath, typeDeclaration)
197
197
  } catch (error) {
198
- assert(error instanceof Error)
198
+ assert(error instanceof Error, "src/watch.ts:210:35")
199
199
  if ("EISDIR" != error.code) throw error
200
200
  typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
201
201
  await writeFile(typeDeclarationPath, typeDeclaration)
@@ -205,4 +205,4 @@ const watch = async (
205
205
  watcher.on("add", writeTypeDeclaration)
206
206
  watcher.on("unlink", writeTypeDeclaration)
207
207
  }
208
- export { watch as default, watch }
208
+ export { watch }