hackmud-script-manager 0.21.1-7aac667 → 0.21.1-7b1c428
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 +46 -38
- package/bin/hsm.js +236 -245
- package/env.d.ts +302 -245
- package/generateTypeDeclaration.js +24 -23
- package/index.js +2 -3
- package/package.json +26 -25
- package/processScript/index.d.ts +12 -9
- package/processScript/index.js +86 -71
- 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 +101 -24
- 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 -7
package/bin/hsm.js
CHANGED
@@ -1,27 +1,19 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
import { AutoMap } from "@samual/lib/AutoMap"
|
3
|
-
import { assert } from "@samual/lib/assert"
|
4
|
-
import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
|
5
|
-
import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
|
6
2
|
import { writeFile, readFile } from "fs/promises"
|
7
3
|
import { homedir } from "os"
|
8
4
|
import { resolve, extname, basename, dirname, relative } from "path"
|
5
|
+
import { assert } from "@samual/lib/assert"
|
6
|
+
import { AutoMap } from "@samual/lib/AutoMap"
|
7
|
+
import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
|
8
|
+
import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
|
9
9
|
import { supportedExtensions } from "../constants.js"
|
10
10
|
import { generateTypeDeclaration } from "../generateTypeDeclaration.js"
|
11
11
|
import { pull } from "../pull.js"
|
12
12
|
import { syncMacros } from "../syncMacros.js"
|
13
13
|
import "@samual/lib/readDirectoryWithStats"
|
14
|
-
import "path/posix"
|
15
14
|
import "@samual/lib/copyFilePersistent"
|
16
|
-
const
|
17
|
-
|
18
|
-
commands = [],
|
19
|
-
userColours = new AutoMap(user => {
|
20
|
-
let hash = 0
|
21
|
-
for (const char of user) hash += (hash >> 1) + hash + "xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(char) + 1
|
22
|
-
return [colourJ, colourK, colourM, colourW, colourL, colourB][hash % 6](user)
|
23
|
-
}),
|
24
|
-
log = message => console.log(colourS(message))
|
15
|
+
const options = new Map(),
|
16
|
+
commands = []
|
25
17
|
for (const argument of process.argv.slice(2))
|
26
18
|
if ("-" == argument[0]) {
|
27
19
|
const argumentEqualsIndex = argument.indexOf("=")
|
@@ -54,7 +46,14 @@ const pushModule = import("../push.js"),
|
|
54
46
|
colourN = chalk.rgb(0, 255, 255),
|
55
47
|
colourS = chalk.rgb(122, 178, 244),
|
56
48
|
colourV = chalk.rgb(255, 0, 236),
|
57
|
-
colourW = chalk.rgb(255, 150, 224)
|
49
|
+
colourW = chalk.rgb(255, 150, 224),
|
50
|
+
formatOption = name => colourN(`-${1 == name.length ? "" : "-"}${name}`),
|
51
|
+
userColours = new AutoMap(user => {
|
52
|
+
let hash = 0
|
53
|
+
for (const char of user) hash += (hash >> 1) + hash + "xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(char) + 1
|
54
|
+
return [colourJ, colourK, colourM, colourW, colourL, colourB][hash % 6](user)
|
55
|
+
}),
|
56
|
+
log = message => console.log(colourS(message))
|
58
57
|
if (process.version.startsWith("v21.")) {
|
59
58
|
process.exitCode = 1
|
60
59
|
console.warn(
|
@@ -64,7 +63,7 @@ if (process.version.startsWith("v21.")) {
|
|
64
63
|
)
|
65
64
|
}
|
66
65
|
if ("v" == commands[0] || "version" == commands[0] || popOption("version", "v")?.value) {
|
67
|
-
console.log("0.21.1-
|
66
|
+
console.log("0.21.1-7b1c428")
|
68
67
|
process.exit()
|
69
68
|
}
|
70
69
|
let warnedDeprecatedEmitDtsAlias = !1
|
@@ -78,275 +77,267 @@ switch (commands[0]) {
|
|
78
77
|
case "dev":
|
79
78
|
case "watch":
|
80
79
|
case "golf":
|
81
|
-
case "minify":
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
`${chalk.bold("Warning:")} ${formatOption(noMinifyOption.name)} is deprecated and will be removed in the next minor\n release of HSM\n You should switch to using its alias ${colourN("--no-minify")}\n`
|
89
|
-
)
|
80
|
+
case "minify": {
|
81
|
+
const noMinifyOption = popOption("no-minify", "skip-minify")
|
82
|
+
if (noMinifyOption && "no-minify" != noMinifyOption.name) {
|
83
|
+
process.exitCode = 1
|
84
|
+
console.warn(
|
85
|
+
colourF(
|
86
|
+
`${chalk.bold("Warning:")} ${formatOption(noMinifyOption.name)} is deprecated and will be removed in the next minor\n release of HSM\n You should switch to using its alias ${colourN("--no-minify")}\n`
|
90
87
|
)
|
88
|
+
)
|
89
|
+
}
|
90
|
+
const mangleNamesOption = popOption("mangle-names"),
|
91
|
+
forceQuineCheatsOption = popOption("force-quine-cheats"),
|
92
|
+
noQuineCheatsOptions = popOption("no-quine-cheats"),
|
93
|
+
noMinifyIncompatibleOption = mangleNamesOption || forceQuineCheatsOption || noQuineCheatsOptions
|
94
|
+
if (noMinifyOption && noMinifyIncompatibleOption) {
|
95
|
+
logError(
|
96
|
+
`Options ${formatOption(noMinifyOption.name)} and ${formatOption(noMinifyIncompatibleOption.name)} are incompatible\n`
|
97
|
+
)
|
98
|
+
logHelp()
|
99
|
+
process.exit(1)
|
100
|
+
}
|
101
|
+
if (forceQuineCheatsOption && noQuineCheatsOptions) {
|
102
|
+
logError(
|
103
|
+
`Options ${formatOption(forceQuineCheatsOption.name)} and ${formatOption(noQuineCheatsOptions.name)} are incompatible\n`
|
104
|
+
)
|
105
|
+
logHelp()
|
106
|
+
process.exit(1)
|
107
|
+
}
|
108
|
+
noMinifyOption && assertOptionIsBoolean(noMinifyOption)
|
109
|
+
mangleNamesOption && assertOptionIsBoolean(mangleNamesOption)
|
110
|
+
forceQuineCheatsOption && assertOptionIsBoolean(forceQuineCheatsOption)
|
111
|
+
noQuineCheatsOptions && assertOptionIsBoolean(noQuineCheatsOptions)
|
112
|
+
const rootFolderPathOption = popOption("root-folder-path"),
|
113
|
+
rootFolderPath = rootFolderPathOption && resolve(rootFolderPathOption.value + "")
|
114
|
+
if ("golf" == commands[0] || "minify" == commands[0]) {
|
115
|
+
const watchOption = popOption("watch"),
|
116
|
+
target = commands[1]
|
117
|
+
if (!target) {
|
118
|
+
logError("Must provide target\n")
|
119
|
+
logHelp()
|
120
|
+
process.exit(1)
|
91
121
|
}
|
92
|
-
const
|
93
|
-
|
94
|
-
noQuineCheatsOptions = popOption("no-quine-cheats"),
|
95
|
-
noMinifyIncompatibleOption = mangleNamesOption || forceQuineCheatsOption || noQuineCheatsOptions
|
96
|
-
if (noMinifyOption && noMinifyIncompatibleOption) {
|
122
|
+
const fileExtension = extname(target)
|
123
|
+
if (!supportedExtensions.includes(fileExtension)) {
|
97
124
|
logError(
|
98
|
-
`
|
125
|
+
`Unsupported file extension "${chalk.bold(fileExtension)}"\nSupported extensions are "${supportedExtensions.map(extension => chalk.bold(extension)).join('", "')}"`
|
99
126
|
)
|
100
|
-
logHelp()
|
101
127
|
process.exit(1)
|
102
128
|
}
|
103
|
-
|
104
|
-
|
105
|
-
|
129
|
+
complainAboutUnrecognisedOptions()
|
130
|
+
const { processScript } = await processScriptModule,
|
131
|
+
fileBaseName = basename(target, fileExtension),
|
132
|
+
fileBaseNameEndsWithDotSrc = fileBaseName.endsWith(".src"),
|
133
|
+
scriptName = fileBaseNameEndsWithDotSrc ? fileBaseName.slice(0, -4) : fileBaseName,
|
134
|
+
scriptUser =
|
135
|
+
"scripts" == basename(resolve(target, "..")) && "hackmud" == basename(resolve(target, "../../.."))
|
136
|
+
? basename(resolve(target, "../.."))
|
137
|
+
: void 0
|
138
|
+
let outputPath =
|
139
|
+
commands[2] ||
|
140
|
+
resolve(
|
141
|
+
dirname(target),
|
142
|
+
fileBaseNameEndsWithDotSrc
|
143
|
+
? scriptName + ".js"
|
144
|
+
: ".js" == fileExtension
|
145
|
+
? fileBaseName + ".min.js"
|
146
|
+
: fileBaseName + ".js"
|
106
147
|
)
|
148
|
+
const golfFile = () =>
|
149
|
+
readFile(target, { encoding: "utf8" }).then(async source => {
|
150
|
+
const timeStart = performance.now(),
|
151
|
+
{ script, warnings } = await processScript(source, {
|
152
|
+
minify: noMinifyOption && !noMinifyOption.value,
|
153
|
+
scriptUser,
|
154
|
+
scriptName,
|
155
|
+
filePath: target,
|
156
|
+
mangleNames: mangleNamesOption?.value,
|
157
|
+
forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
|
158
|
+
rootFolderPath
|
159
|
+
}),
|
160
|
+
timeTook = performance.now() - timeStart
|
161
|
+
warnings.length && (process.exitCode = 1)
|
162
|
+
for (const { message } of warnings) console.warn(colourF(`${chalk.bold("Warning:")} ${message}`))
|
163
|
+
await writeFilePersistent(outputPath, script)
|
164
|
+
.catch(error => {
|
165
|
+
if (!commands[2] || "EISDIR" != error.code) throw error
|
166
|
+
outputPath = resolve(outputPath, basename(target, fileExtension) + ".js")
|
167
|
+
return writeFilePersistent(outputPath, script)
|
168
|
+
})
|
169
|
+
.then(() =>
|
170
|
+
log(
|
171
|
+
`Wrote ${chalk.bold(countHackmudCharacters(script))} chars to ${chalk.bold(relative(".", outputPath))} | took ${Math.round(100 * timeTook) / 100}ms`
|
172
|
+
)
|
173
|
+
)
|
174
|
+
})
|
175
|
+
if (watchOption) {
|
176
|
+
const { watch: watchFile } = await chokidarModule
|
177
|
+
watchFile(target, { awaitWriteFinish: { stabilityThreshold: 100 } })
|
178
|
+
.on("ready", () => log("Watching " + target))
|
179
|
+
.on("change", golfFile)
|
180
|
+
autoExit = !1
|
181
|
+
} else await golfFile()
|
182
|
+
} else {
|
183
|
+
const hackmudPath = getHackmudPath(),
|
184
|
+
sourcePath = commands[1]
|
185
|
+
if (!sourcePath) {
|
186
|
+
logError(`Must provide the directory to ${"push" == commands[0] ? "push from" : "watch"}\n`)
|
107
187
|
logHelp()
|
108
188
|
process.exit(1)
|
109
189
|
}
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
const watchOption = popOption("watch"),
|
118
|
-
target = commands[1]
|
119
|
-
if (!target) {
|
120
|
-
logError("Must provide target\n")
|
190
|
+
const scripts = commands.slice(2)
|
191
|
+
if (scripts.length) {
|
192
|
+
const invalidScript = scripts.find(
|
193
|
+
script => !/^(?:[a-z_][a-z\d_]{0,24}|\*)\.(?:[a-z_][a-z\d_]{0,24}|\*)$/.test(script)
|
194
|
+
)
|
195
|
+
if (invalidScript) {
|
196
|
+
logError(`Invalid script name: ${JSON.stringify(invalidScript)}\n`)
|
121
197
|
logHelp()
|
122
198
|
process.exit(1)
|
123
199
|
}
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
200
|
+
} else scripts.push("*.*")
|
201
|
+
const watchOption = popOption("watch")
|
202
|
+
if ("push" != commands[0] || watchOption?.value) {
|
203
|
+
const dtsPathOption = popOption(
|
204
|
+
"dts-path",
|
205
|
+
"type-declaration-path",
|
206
|
+
"type-declaration",
|
207
|
+
"dts",
|
208
|
+
"gen-types"
|
209
|
+
)
|
210
|
+
if (
|
211
|
+
dtsPathOption &&
|
212
|
+
"dts-path" != dtsPathOption.name &&
|
213
|
+
"type-declaration-path" != dtsPathOption.name
|
214
|
+
) {
|
215
|
+
process.exitCode = 1
|
216
|
+
console.warn(
|
217
|
+
colourF(
|
218
|
+
`${chalk.bold("Warning:")} ${formatOption(dtsPathOption.name)} is deprecated and will be removed in the\n next minor release of HSM\n You should switch to using its alias ${colourN("--dts-path")}\n`
|
219
|
+
)
|
128
220
|
)
|
129
|
-
process.exit(1)
|
130
221
|
}
|
131
222
|
complainAboutUnrecognisedOptions()
|
132
|
-
const {
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
dirname(target),
|
145
|
-
fileBaseNameEndsWithDotSrc
|
146
|
-
? scriptName + ".js"
|
147
|
-
: ".js" == fileExtension
|
148
|
-
? fileBaseName + ".min.js"
|
149
|
-
: fileBaseName + ".js"
|
150
|
-
)
|
151
|
-
const golfFile = () =>
|
152
|
-
readFile(target, { encoding: "utf8" }).then(async source => {
|
153
|
-
const timeStart = performance.now(),
|
154
|
-
{ script, warnings } = await processScript(source, {
|
155
|
-
minify: noMinifyOption && !noMinifyOption.value,
|
156
|
-
scriptUser,
|
157
|
-
scriptName,
|
158
|
-
filePath: target,
|
159
|
-
mangleNames: mangleNamesOption?.value,
|
160
|
-
forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
|
161
|
-
rootFolderPath
|
162
|
-
}),
|
163
|
-
timeTook = performance.now() - timeStart
|
164
|
-
warnings.length && (process.exitCode = 1)
|
165
|
-
for (const { message } of warnings)
|
166
|
-
console.warn(colourF(`${chalk.bold("Warning:")} ${message}`))
|
167
|
-
await writeFilePersistent(outputPath, script)
|
168
|
-
.catch(error => {
|
169
|
-
if (!commands[2] || "EISDIR" != error.code) throw error
|
170
|
-
outputPath = resolve(outputPath, basename(target, fileExtension) + ".js")
|
171
|
-
return writeFilePersistent(outputPath, script)
|
172
|
-
})
|
173
|
-
.then(() =>
|
174
|
-
log(
|
175
|
-
`Wrote ${chalk.bold(countHackmudCharacters(script))} chars to ${chalk.bold(relative(".", outputPath))} | took ${Math.round(100 * timeTook) / 100}ms`
|
176
|
-
)
|
177
|
-
)
|
178
|
-
})
|
179
|
-
if (watchOption) {
|
180
|
-
const { watch: watchFile } = await chokidarModule
|
181
|
-
watchFile(target, { awaitWriteFinish: { stabilityThreshold: 100 } })
|
182
|
-
.on("ready", () => log("Watching " + target))
|
183
|
-
.on("change", golfFile)
|
184
|
-
autoExit = !1
|
185
|
-
} else await golfFile()
|
223
|
+
const { watch } = await watchModule
|
224
|
+
watch(sourcePath, hackmudPath, {
|
225
|
+
scripts,
|
226
|
+
onPush: info => logInfo(info, hackmudPath),
|
227
|
+
typeDeclarationPath: dtsPathOption?.value.toString(),
|
228
|
+
minify: noMinifyOption && !noMinifyOption.value,
|
229
|
+
mangleNames: mangleNamesOption?.value,
|
230
|
+
onReady: () => log("Watching"),
|
231
|
+
forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
|
232
|
+
rootFolderPath
|
233
|
+
})
|
234
|
+
autoExit = !1
|
186
235
|
} else {
|
187
|
-
const
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
if (scripts.length) {
|
196
|
-
const invalidScript = scripts.find(
|
197
|
-
script => !/^(?:[a-z_][a-z\d_]{0,24}|\*)\.(?:[a-z_][a-z\d_]{0,24}|\*)$/.test(script)
|
198
|
-
)
|
199
|
-
if (invalidScript) {
|
200
|
-
logError(`Invalid script name: ${JSON.stringify(invalidScript)}\n`)
|
236
|
+
const dtsPathOption = popOption("dts-path")
|
237
|
+
complainAboutUnrecognisedOptions()
|
238
|
+
let declarationPathPromise
|
239
|
+
if (dtsPathOption) {
|
240
|
+
if ("string" != typeof dtsPathOption.value) {
|
241
|
+
logError(
|
242
|
+
`Option ${formatOption(dtsPathOption.name)} must be a string, got ${colourV(dtsPathOption.value)}\n`
|
243
|
+
)
|
201
244
|
logHelp()
|
202
245
|
process.exit(1)
|
203
246
|
}
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
"type-declaration-path" != dtsPathOption.name
|
218
|
-
) {
|
219
|
-
process.exitCode = 1
|
220
|
-
console.warn(
|
221
|
-
colourF(
|
222
|
-
`${chalk.bold("Warning:")} ${formatOption(dtsPathOption.name)} is deprecated and will be removed in the\n next minor release of HSM\n You should switch to using its alias ${colourN("--dts-path")}\n`
|
223
|
-
)
|
224
|
-
)
|
225
|
-
}
|
226
|
-
complainAboutUnrecognisedOptions()
|
227
|
-
const { watch } = await watchModule
|
228
|
-
watch(sourcePath, hackmudPath, {
|
247
|
+
let typeDeclarationPath = resolve(dtsPathOption.value)
|
248
|
+
const typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
|
249
|
+
declarationPathPromise = writeFile(typeDeclarationPath, typeDeclaration)
|
250
|
+
.catch(error => {
|
251
|
+
assert(error instanceof Error, "src/bin/hsm.ts:300:38")
|
252
|
+
if ("EISDIR" != error.code) throw error
|
253
|
+
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
254
|
+
return writeFile(typeDeclarationPath, typeDeclaration)
|
255
|
+
})
|
256
|
+
.then(() => typeDeclarationPath)
|
257
|
+
}
|
258
|
+
const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } = await pushModule,
|
259
|
+
infos = await push(sourcePath, hackmudPath, {
|
229
260
|
scripts,
|
230
261
|
onPush: info => logInfo(info, hackmudPath),
|
231
|
-
typeDeclarationPath: dtsPathOption?.value.toString(),
|
232
262
|
minify: noMinifyOption && !noMinifyOption.value,
|
233
263
|
mangleNames: mangleNamesOption?.value,
|
234
|
-
onReady: () => log("Watching"),
|
235
264
|
forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
|
236
265
|
rootFolderPath
|
237
266
|
})
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
`
|
267
|
+
if (infos instanceof Error) {
|
268
|
+
logError(infos.message)
|
269
|
+
if (infos instanceof MissingSourceFolderError || infos instanceof NoUsersError) {
|
270
|
+
console.log()
|
271
|
+
logHelp()
|
272
|
+
} else
|
273
|
+
infos instanceof MissingHackmudFolderError &&
|
274
|
+
log(
|
275
|
+
`If this is not where your hackmud folder is, you can specify it with the\n${colourN("--hackmud-path")}=${colourB("<path>")} option or ${colourN("HSM_HACKMUD_PATH")} environment variable`
|
247
276
|
)
|
248
|
-
|
249
|
-
|
250
|
-
}
|
251
|
-
let typeDeclarationPath = resolve(dtsPathOption.value)
|
252
|
-
const typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
|
253
|
-
declarationPathPromise = writeFile(typeDeclarationPath, typeDeclaration)
|
254
|
-
.catch(error => {
|
255
|
-
assert(error instanceof Error, "src/bin/hsm.ts:299:38")
|
256
|
-
if ("EISDIR" != error.code) throw error
|
257
|
-
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
258
|
-
return writeFile(typeDeclarationPath, typeDeclaration)
|
259
|
-
})
|
260
|
-
.then(() => typeDeclarationPath)
|
261
|
-
}
|
262
|
-
const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } =
|
263
|
-
await pushModule,
|
264
|
-
infos = await push(sourcePath, hackmudPath, {
|
265
|
-
scripts,
|
266
|
-
onPush: info => logInfo(info, hackmudPath),
|
267
|
-
minify: noMinifyOption && !noMinifyOption.value,
|
268
|
-
mangleNames: mangleNamesOption?.value,
|
269
|
-
forceQuineCheats: forceQuineCheatsOption?.value ?? !noQuineCheatsOptions?.value,
|
270
|
-
rootFolderPath
|
271
|
-
})
|
272
|
-
if (infos instanceof Error) {
|
273
|
-
logError(infos.message)
|
274
|
-
if (infos instanceof MissingSourceFolderError || infos instanceof NoUsersError) {
|
275
|
-
console.log()
|
276
|
-
logHelp()
|
277
|
-
} else
|
278
|
-
infos instanceof MissingHackmudFolderError &&
|
279
|
-
log(
|
280
|
-
`If this is not where your hackmud folder is, you can specify it with the\n${colourN("--hackmud-path")}=${colourB("<path>")} option or ${colourN("HSM_HACKMUD_PATH")} environment variable`
|
281
|
-
)
|
282
|
-
} else infos.length || logError("Could not find any scripts to push")
|
283
|
-
declarationPathPromise &&
|
284
|
-
log("Wrote type declaration to " + chalk.bold(await declarationPathPromise))
|
285
|
-
}
|
277
|
+
} else infos.length || logError("Could not find any scripts to push")
|
278
|
+
declarationPathPromise && log("Wrote type declaration to " + chalk.bold(await declarationPathPromise))
|
286
279
|
}
|
287
280
|
}
|
288
281
|
break
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
}
|
298
|
-
complainAboutUnrecognisedOptions()
|
299
|
-
const sourcePath = commands[2] || "."
|
300
|
-
await pull(sourcePath, hackmudPath, script).catch(error => {
|
301
|
-
console.error(error)
|
302
|
-
logError(`Something went wrong, did you forget to ${colourC("#down")} the script?`)
|
303
|
-
})
|
282
|
+
}
|
283
|
+
case "pull": {
|
284
|
+
const hackmudPath = getHackmudPath(),
|
285
|
+
script = commands[1]
|
286
|
+
if (!script) {
|
287
|
+
logError("Must provide the script to pull\n")
|
288
|
+
logHelp()
|
289
|
+
process.exit(1)
|
304
290
|
}
|
291
|
+
complainAboutUnrecognisedOptions()
|
292
|
+
const sourcePath = commands[2] || "."
|
293
|
+
await pull(sourcePath, hackmudPath, script).catch(error => {
|
294
|
+
console.error(error)
|
295
|
+
logError(`Something went wrong, did you forget to ${colourC("#down")} the script?`)
|
296
|
+
})
|
305
297
|
break
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
}
|
298
|
+
}
|
299
|
+
case "sync-macros": {
|
300
|
+
const hackmudPath = getHackmudPath()
|
301
|
+
complainAboutUnrecognisedOptions()
|
302
|
+
const { macrosSynced, usersSynced } = await syncMacros(hackmudPath)
|
303
|
+
log(`Synced ${macrosSynced} macros to ${usersSynced} users`)
|
313
304
|
break
|
305
|
+
}
|
314
306
|
case "generate-type-declaration":
|
315
307
|
case "gen-type-declaration":
|
316
308
|
case "gen-dts":
|
317
309
|
case "gen-types":
|
318
|
-
case "emit-dts":
|
319
|
-
{
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
`${chalk.bold("Warning:")} ${colourC("hsm")} ${colourL(commands[0])} is deprecated and will be removed\n in the next minor release of HSM\n You should switch to using its alias ${colourC("hsm")} ${colourL("emit-dts")}\n`
|
326
|
-
)
|
310
|
+
case "emit-dts": {
|
311
|
+
if ("emit-dts" != commands[0] && "gen-dts" != commands[0]) {
|
312
|
+
warnedDeprecatedEmitDtsAlias = !0
|
313
|
+
process.exitCode = 1
|
314
|
+
console.warn(
|
315
|
+
colourF(
|
316
|
+
`${chalk.bold("Warning:")} ${colourC("hsm")} ${colourL(commands[0])} is deprecated and will be removed\n in the next minor release of HSM\n You should switch to using its alias ${colourC("hsm")} ${colourL("emit-dts")}\n`
|
327
317
|
)
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
complainAboutUnrecognisedOptions()
|
337
|
-
const sourcePath = resolve(target),
|
338
|
-
outputPath = commands[2] || "./player.d.ts",
|
339
|
-
typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
|
340
|
-
let typeDeclarationPath = resolve(outputPath)
|
341
|
-
await writeFile(typeDeclarationPath, typeDeclaration).catch(error => {
|
342
|
-
assert(error instanceof Error, "src/bin/hsm.ts:438:35")
|
343
|
-
if ("EISDIR" != error.code) throw error
|
344
|
-
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
345
|
-
return writeFile(typeDeclarationPath, typeDeclaration)
|
346
|
-
})
|
347
|
-
log("Wrote type declaration to " + chalk.bold(typeDeclarationPath))
|
318
|
+
)
|
319
|
+
}
|
320
|
+
const hackmudPath = getHackmudPath(),
|
321
|
+
target = commands[1]
|
322
|
+
if (!target) {
|
323
|
+
logError("Must provide target directory\n")
|
324
|
+
logHelp()
|
325
|
+
process.exit(1)
|
348
326
|
}
|
327
|
+
complainAboutUnrecognisedOptions()
|
328
|
+
const sourcePath = resolve(target),
|
329
|
+
outputPath = commands[2] || "./player.d.ts",
|
330
|
+
typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
|
331
|
+
let typeDeclarationPath = resolve(outputPath)
|
332
|
+
await writeFile(typeDeclarationPath, typeDeclaration).catch(error => {
|
333
|
+
assert(error instanceof Error, "src/bin/hsm.ts:444:35")
|
334
|
+
if ("EISDIR" != error.code) throw error
|
335
|
+
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
336
|
+
return writeFile(typeDeclarationPath, typeDeclaration)
|
337
|
+
})
|
338
|
+
log("Wrote type declaration to " + chalk.bold(typeDeclarationPath))
|
349
339
|
break
|
340
|
+
}
|
350
341
|
case "help":
|
351
342
|
logHelp()
|
352
343
|
break
|
@@ -412,7 +403,7 @@ function logHelp() {
|
|
412
403
|
default:
|
413
404
|
console.log(
|
414
405
|
colourS(
|
415
|
-
`${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.1-
|
406
|
+
`${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.1-7b1c428")}\n\n${colourA("Commands:")}\n${colourL("push")}\n ${pushCommandDescription}\n${colourL("minify")}\n Minify a script file on the spot\n${colourL("emit-dts")}\n Generate a type declaration file for a directory of scripts\n${colourL("sync-macros")}\n Sync macros across all hackmud users\n${colourL("pull")}\n Pull a script a from a hackmud user's script directory\n\n${colourA("Options:")}\n${colourN("--help")}\n Can be used on any command e.g. ${colourC("hsm")} ${colourL("push")} ${colourN("--help")} to show helpful information`
|
416
407
|
)
|
417
408
|
)
|
418
409
|
}
|