hackmud-script-manager 0.20.3 → 0.20.4-0dd1d9b
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +9 -1
- package/bin/hsm.js +193 -236
- package/env.d.ts +704 -1294
- package/generateTypeDeclaration.js +2 -1
- package/index.js +1 -0
- package/package.json +6 -2
- package/processScript/index.js +3 -3
- package/processScript/minify.js +18 -21
- package/processScript/postprocess.d.ts +1 -1
- package/processScript/postprocess.js +3 -3
- package/processScript/preprocess.js +5 -3
- package/processScript/transform.js +68 -91
- package/push.d.ts +9 -1
- package/push.js +33 -11
- package/syncMacros.js +1 -1
- package/watch.js +6 -4
package/push.js
CHANGED
@@ -42,32 +42,54 @@ import "./processScript/preprocess.js"
|
|
42
42
|
import "import-meta-resolve"
|
43
43
|
import "./processScript/transform.js"
|
44
44
|
import "@samual/lib/clearObject"
|
45
|
+
class MissingSourceFolderError extends Error {}
|
46
|
+
Object.defineProperty(MissingSourceFolderError.prototype, "name", { value: "MissingSourceFolderError" })
|
47
|
+
class MissingHackmudFolderError extends Error {}
|
48
|
+
Object.defineProperty(MissingHackmudFolderError.prototype, "name", { value: "MissingHackmudFolderError" })
|
49
|
+
class NoUsersError extends Error {}
|
50
|
+
Object.defineProperty(NoUsersError.prototype, "name", { value: "NoUsersError" })
|
51
|
+
class NoScriptsError extends Error {}
|
52
|
+
Object.defineProperty(NoScriptsError.prototype, "name", { value: "NoScriptsError" })
|
45
53
|
async function push(
|
46
54
|
sourcePath,
|
47
55
|
hackmudPath,
|
48
56
|
{ scripts = ["*.*"], onPush = () => {}, minify = !0, mangleNames = !1, forceQuineCheats } = {}
|
49
57
|
) {
|
50
58
|
const [sourceFolder, hackmudFolder] = await Promise.all([
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
59
|
+
readDirectoryWithStats(sourcePath).catch(error => {
|
60
|
+
if (error && "ENOENT" == error.code)
|
61
|
+
return new MissingSourceFolderError("There is no folder at " + sourcePath)
|
62
|
+
throw error
|
63
|
+
}),
|
64
|
+
readDirectoryWithStats(hackmudPath).catch(error => {
|
65
|
+
if (error && "ENOENT" == error.code)
|
66
|
+
return new MissingHackmudFolderError("There is no folder at " + hackmudPath)
|
67
|
+
throw error
|
68
|
+
})
|
69
|
+
])
|
70
|
+
if (sourceFolder instanceof Error) return sourceFolder
|
71
|
+
if (hackmudFolder instanceof Error) return hackmudFolder
|
72
|
+
const sourceFolderFolders = sourceFolder.filter(({ stats }) => stats.isDirectory()),
|
55
73
|
allUsers = new Set([
|
56
74
|
...scripts
|
57
|
-
.map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:
|
75
|
+
.map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:82:65"))
|
58
76
|
.filter(name => "*" != name),
|
59
77
|
...sourceFolderFolders.map(({ name }) => name),
|
60
78
|
...hackmudFolder.filter(({ stats }) => stats.isDirectory()).map(({ name }) => name),
|
61
79
|
...hackmudFolder
|
62
80
|
.filter(({ stats, name }) => stats.isFile() && name.endsWith(".key"))
|
63
81
|
.map(({ name }) => name.slice(0, -4))
|
64
|
-
])
|
65
|
-
|
82
|
+
])
|
83
|
+
if (!allUsers.size)
|
84
|
+
return new NoUsersError(
|
85
|
+
"Could not find any users. Either provide the names of your users or log into a user in hackmud"
|
86
|
+
)
|
87
|
+
const usersToScriptsToPush = new Cache(_user => new Map()),
|
66
88
|
scriptNamesToUsers = new Cache(_scriptName => new Set())
|
67
89
|
for (const script of scripts) {
|
68
90
|
const [user, scriptName] = script.split(".")
|
69
|
-
assert(user, "src/push.ts:
|
70
|
-
assert(scriptName, "src/push.ts:
|
91
|
+
assert(user, "src/push.ts:105:16")
|
92
|
+
assert(scriptName, "src/push.ts:106:22")
|
71
93
|
"*" == user ? scriptNamesToUsers.set(scriptName, allUsers) : scriptNamesToUsers.get(scriptName).add(user)
|
72
94
|
}
|
73
95
|
const sourceFolderFiles = sourceFolder.filter(({ stats }) => stats.isFile()),
|
@@ -98,7 +120,7 @@ async function push(
|
|
98
120
|
for (const [scriptName, users] of scriptNamesToUsers)
|
99
121
|
for (const user of users)
|
100
122
|
if (!usersToScriptsToPush.get(user).has(scriptName))
|
101
|
-
|
123
|
+
return new NoScriptsError(`Could not find script ${user}.${scriptName} to push`)
|
102
124
|
const pathsToUsers = new Cache(_path => new Set())
|
103
125
|
for (const [user, scriptsToPush] of usersToScriptsToPush)
|
104
126
|
for (const path of scriptsToPush.values()) pathsToUsers.get(path).add(user)
|
@@ -135,4 +157,4 @@ async function push(
|
|
135
157
|
)
|
136
158
|
return allInfo
|
137
159
|
}
|
138
|
-
export { push }
|
160
|
+
export { MissingHackmudFolderError, MissingSourceFolderError, NoScriptsError, NoUsersError, push }
|
package/syncMacros.js
CHANGED
@@ -37,7 +37,7 @@ async function syncMacros(hackmudPath) {
|
|
37
37
|
macroFile += `${name}\n${macro}\n`
|
38
38
|
macrosSynced++
|
39
39
|
}
|
40
|
-
|
40
|
+
await Promise.all(users.map(async user => writeFile(resolve(hackmudPath, user + ".macros"), macroFile)))
|
41
41
|
return { macrosSynced, usersSynced: users.length }
|
42
42
|
}
|
43
43
|
export { syncMacros }
|
package/watch.js
CHANGED
@@ -4,11 +4,12 @@ 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"
|
@@ -58,6 +59,7 @@ async function watch(
|
|
58
59
|
} = {}
|
59
60
|
) {
|
60
61
|
if (!scripts.length) throw Error("scripts option was an empty array")
|
62
|
+
if (!(await stat(sourceDirectory)).isDirectory()) throw Error("Target folder must be a folder")
|
61
63
|
const scriptNamesToUsers = new Cache(_scriptName => new Set()),
|
62
64
|
wildScriptUsers = new Set(),
|
63
65
|
wildUserScripts = new Set()
|
@@ -135,7 +137,7 @@ async function watch(
|
|
135
137
|
forceQuineCheats
|
136
138
|
}))
|
137
139
|
} catch (error) {
|
138
|
-
assert(error instanceof Error, "src/watch.ts:
|
140
|
+
assert(error instanceof Error, "src/watch.ts:146:36")
|
139
141
|
onPush?.({ path, users: [], characterCount: 0, error })
|
140
142
|
return
|
141
143
|
}
|
@@ -180,7 +182,7 @@ async function watch(
|
|
180
182
|
forceQuineCheats
|
181
183
|
}))
|
182
184
|
} catch (error) {
|
183
|
-
assert(error instanceof Error, "src/watch.ts:
|
185
|
+
assert(error instanceof Error, "src/watch.ts:182:35")
|
184
186
|
onPush?.({ path, users: [], characterCount: 0, error })
|
185
187
|
return
|
186
188
|
}
|
@@ -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:215:35")
|
199
201
|
if ("EISDIR" != error.code) throw error
|
200
202
|
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
201
203
|
await writeFile(typeDeclarationPath, typeDeclaration)
|