hackmud-script-manager 0.19.0 → 0.19.1-01c1752
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -3
- package/bin/hsm.d.ts +0 -0
- package/bin/hsm.js +436 -1
- package/constants.js +3 -1
- package/env.d.ts +1657 -0
- package/generateTypeDeclaration.d.ts +1 -2
- package/generateTypeDeclaration.js +68 -1
- package/index.d.ts +2 -2
- package/index.js +51 -1
- package/package.json +41 -38
- package/processScript/index.d.ts +17 -26
- package/processScript/index.js +333 -1
- package/processScript/minify.d.ts +15 -21
- package/processScript/minify.js +444 -1
- package/processScript/postprocess.d.ts +1 -2
- package/processScript/postprocess.js +20 -1
- package/processScript/preprocess.d.ts +7 -10
- package/processScript/preprocess.js +105 -1
- package/processScript/shared.d.ts +2 -2
- package/processScript/shared.js +32 -1
- package/processScript/transform.d.ts +13 -18
- package/processScript/transform.js +696 -1
- package/pull.d.ts +5 -9
- package/pull.js +11 -1
- package/push.d.ts +24 -33
- package/push.js +138 -1
- package/syncMacros.d.ts +1 -2
- package/syncMacros.js +43 -1
- package/watch.d.ts +10 -16
- package/watch.js +208 -1
- package/tsconfig.tsbuildinfo +0 -1
@@ -1,2 +1 @@
|
|
1
|
-
export declare
|
2
|
-
export default generateTypeDeclaration;
|
1
|
+
export declare function generateTypeDeclaration(sourceDirectory: string, hackmudPath?: string): Promise<string>;
|
@@ -1 +1,68 @@
|
|
1
|
-
import{
|
1
|
+
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
2
|
+
import { basename, resolve } from "path"
|
3
|
+
async function generateTypeDeclaration(sourceDirectory, hackmudPath) {
|
4
|
+
const users = new Set()
|
5
|
+
if (hackmudPath)
|
6
|
+
for (const { stats, name } of await readDirectoryWithStats(hackmudPath))
|
7
|
+
stats.isFile() && name.endsWith(".key") && users.add(basename(name, ".key"))
|
8
|
+
const wildScripts = [],
|
9
|
+
wildAnyScripts = [],
|
10
|
+
allScripts = {},
|
11
|
+
allAnyScripts = {}
|
12
|
+
await Promise.all(
|
13
|
+
(await readDirectoryWithStats(sourceDirectory)).map(async ({ stats, name }) => {
|
14
|
+
if (stats.isFile())
|
15
|
+
name.endsWith(".ts") ?
|
16
|
+
name.endsWith(".d.ts") || wildScripts.push(basename(name, ".ts"))
|
17
|
+
: name.endsWith(".js") && wildAnyScripts.push(basename(name, ".js"))
|
18
|
+
else if (stats.isDirectory()) {
|
19
|
+
const scripts = [],
|
20
|
+
anyScripts = []
|
21
|
+
allScripts[name] = scripts
|
22
|
+
allAnyScripts[name] = anyScripts
|
23
|
+
users.add(name)
|
24
|
+
for (const child of await readDirectoryWithStats(resolve(sourceDirectory, name)))
|
25
|
+
child.stats.isFile() &&
|
26
|
+
(child.name.endsWith(".ts") ?
|
27
|
+
name.endsWith(".d.ts") || scripts.push(basename(child.name, ".ts"))
|
28
|
+
: child.name.endsWith(".js") && anyScripts.push(basename(child.name, ".js")))
|
29
|
+
}
|
30
|
+
})
|
31
|
+
)
|
32
|
+
sourceDirectory = resolve(sourceDirectory)
|
33
|
+
let o = ""
|
34
|
+
for (const script of wildScripts) o += `type $${script}$ = typeof import("${sourceDirectory}/${script}").default\n`
|
35
|
+
o += "\n"
|
36
|
+
for (const user in allScripts) {
|
37
|
+
const scripts = allScripts[user]
|
38
|
+
for (const script of scripts)
|
39
|
+
o += `type $${user}$${script}$ = typeof import("${sourceDirectory}/${user}/${script}").default\n`
|
40
|
+
}
|
41
|
+
o +=
|
42
|
+
"\ntype ArrayRemoveFirst<A> = A extends [ infer FirstItem, ...infer Rest ] ? Rest : never\n\ntype Subscript<T extends (...args: any) => any> =\n\t(...args: ArrayRemoveFirst<Parameters<T>>) => ReturnType<T> | ScriptFailure\n\ntype WildFullsec = Record<string, () => ScriptFailure> & {\n"
|
43
|
+
for (const script of wildScripts) o += `\t${script}: Subscript<$${script}$>\n`
|
44
|
+
for (const script of wildAnyScripts) o += `\t${script}: (...args: any) => any\n`
|
45
|
+
o += "}\n\ninterface PlayerFullsec {"
|
46
|
+
let lastWasMultiLine = !0
|
47
|
+
for (const user of users) {
|
48
|
+
const scripts = allScripts[user],
|
49
|
+
anyScripts = allAnyScripts[user]
|
50
|
+
if ((scripts && scripts.length) || (anyScripts && anyScripts.length)) {
|
51
|
+
lastWasMultiLine = !0
|
52
|
+
o += `\n\t${user}: WildFullsec & {\n`
|
53
|
+
if (scripts) for (const script of scripts) o += `\t\t${script}: Subscript<$${user}$${script}$>\n`
|
54
|
+
if (anyScripts) for (const script of anyScripts) o += `\t\t${script}: (...args: any) => any\n`
|
55
|
+
o += "\t}"
|
56
|
+
} else {
|
57
|
+
if (lastWasMultiLine) {
|
58
|
+
o += "\n"
|
59
|
+
lastWasMultiLine = !1
|
60
|
+
}
|
61
|
+
o += `\t${user}: WildFullsec`
|
62
|
+
}
|
63
|
+
o += "\n"
|
64
|
+
}
|
65
|
+
o += "}\n"
|
66
|
+
return o
|
67
|
+
}
|
68
|
+
export { generateTypeDeclaration }
|
package/index.d.ts
CHANGED
@@ -6,8 +6,8 @@ export { push } from "./push";
|
|
6
6
|
export { syncMacros } from "./syncMacros";
|
7
7
|
export { watch } from "./watch";
|
8
8
|
export type Info = {
|
9
|
-
|
9
|
+
path: string;
|
10
10
|
users: string[];
|
11
|
-
|
11
|
+
characterCount: number;
|
12
12
|
error: Error | undefined;
|
13
13
|
};
|
package/index.js
CHANGED
@@ -1 +1,51 @@
|
|
1
|
-
export{supportedExtensions}from"./constants.js"
|
1
|
+
export { supportedExtensions } from "./constants.js"
|
2
|
+
export { generateTypeDeclaration } from "./generateTypeDeclaration.js"
|
3
|
+
export { processScript } from "./processScript/index.js"
|
4
|
+
export { pull } from "./pull.js"
|
5
|
+
export { push } from "./push.js"
|
6
|
+
export { syncMacros } from "./syncMacros.js"
|
7
|
+
export { watch } from "./watch.js"
|
8
|
+
import "@samual/lib/readDirectoryWithStats"
|
9
|
+
import "path"
|
10
|
+
import "@babel/generator"
|
11
|
+
import "@babel/parser"
|
12
|
+
import "@babel/plugin-proposal-decorators"
|
13
|
+
import "@babel/plugin-proposal-destructuring-private"
|
14
|
+
import "@babel/plugin-proposal-explicit-resource-management"
|
15
|
+
import "@babel/plugin-transform-class-properties"
|
16
|
+
import "@babel/plugin-transform-class-static-block"
|
17
|
+
import "@babel/plugin-transform-exponentiation-operator"
|
18
|
+
import "@babel/plugin-transform-json-strings"
|
19
|
+
import "@babel/plugin-transform-logical-assignment-operators"
|
20
|
+
import "@babel/plugin-transform-nullish-coalescing-operator"
|
21
|
+
import "@babel/plugin-transform-numeric-separator"
|
22
|
+
import "@babel/plugin-transform-object-rest-spread"
|
23
|
+
import "@babel/plugin-transform-optional-catch-binding"
|
24
|
+
import "@babel/plugin-transform-optional-chaining"
|
25
|
+
import "@babel/plugin-transform-private-property-in-object"
|
26
|
+
import "@babel/plugin-transform-unicode-sets-regex"
|
27
|
+
import "@babel/traverse"
|
28
|
+
import "@babel/types"
|
29
|
+
import "@rollup/plugin-babel"
|
30
|
+
import "@rollup/plugin-commonjs"
|
31
|
+
import "@rollup/plugin-json"
|
32
|
+
import "@rollup/plugin-node-resolve"
|
33
|
+
import "@samual/lib/assert"
|
34
|
+
import "prettier"
|
35
|
+
import "rollup"
|
36
|
+
import "./processScript/minify.js"
|
37
|
+
import "@samual/lib/countHackmudCharacters"
|
38
|
+
import "@samual/lib/spliceString"
|
39
|
+
import "acorn"
|
40
|
+
import "terser"
|
41
|
+
import "./processScript/shared.js"
|
42
|
+
import "./processScript/postprocess.js"
|
43
|
+
import "./processScript/preprocess.js"
|
44
|
+
import "import-meta-resolve"
|
45
|
+
import "./processScript/transform.js"
|
46
|
+
import "@samual/lib/clearObject"
|
47
|
+
import "@samual/lib/copyFilePersistent"
|
48
|
+
import "@samual/lib/Cache"
|
49
|
+
import "@samual/lib/writeFilePersistent"
|
50
|
+
import "fs/promises"
|
51
|
+
import "chokidar"
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hackmud-script-manager",
|
3
|
-
"version": "0.19.
|
3
|
+
"version": "0.19.1-01c1752",
|
4
4
|
"description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
|
5
5
|
"keywords": [
|
6
6
|
"api",
|
@@ -11,8 +11,8 @@
|
|
11
11
|
"minifier",
|
12
12
|
"hackmd",
|
13
13
|
"hackmud",
|
14
|
-
"
|
15
|
-
"
|
14
|
+
"javascript",
|
15
|
+
"typescript",
|
16
16
|
"typescript-support",
|
17
17
|
"golf",
|
18
18
|
"golfer"
|
@@ -27,58 +27,61 @@
|
|
27
27
|
"url": "https://github.com/samualtnorman/hackmud-script-manager.git"
|
28
28
|
},
|
29
29
|
"dependencies": {
|
30
|
-
"@babel/generator": "^7.
|
31
|
-
"@babel/parser": "^7.
|
32
|
-
"@babel/plugin-proposal-decorators": "^7.
|
33
|
-
"@babel/plugin-proposal-destructuring-private": "^7.
|
34
|
-
"@babel/plugin-proposal-do-expressions": "^7.
|
35
|
-
"@babel/plugin-proposal-explicit-resource-management": "^7.
|
36
|
-
"@babel/plugin-proposal-function-bind": "^7.
|
37
|
-
"@babel/plugin-proposal-function-sent": "^7.
|
38
|
-
"@babel/plugin-proposal-partial-application": "^7.
|
39
|
-
"@babel/plugin-proposal-pipeline-operator": "^7.
|
40
|
-
"@babel/plugin-proposal-record-and-tuple": "^7.
|
41
|
-
"@babel/plugin-proposal-throw-expressions": "^7.
|
42
|
-
"@babel/plugin-transform-class-properties": "^7.
|
43
|
-
"@babel/plugin-transform-class-static-block": "^7.
|
44
|
-
"@babel/plugin-transform-exponentiation-operator": "^7.
|
45
|
-
"@babel/plugin-transform-json-strings": "^7.
|
46
|
-
"@babel/plugin-transform-logical-assignment-operators": "^7.
|
47
|
-
"@babel/plugin-transform-nullish-coalescing-operator": "^7.
|
48
|
-
"@babel/plugin-transform-numeric-separator": "^7.
|
49
|
-
"@babel/plugin-transform-object-rest-spread": "^7.
|
50
|
-
"@babel/plugin-transform-optional-catch-binding": "^7.
|
51
|
-
"@babel/plugin-transform-optional-chaining": "^7.
|
52
|
-
"@babel/plugin-transform-private-property-in-object": "^7.
|
53
|
-
"@babel/plugin-transform-typescript": "^7.
|
54
|
-
"@babel/plugin-transform-unicode-sets-regex": "^7.
|
55
|
-
"@babel/traverse": "^7.
|
56
|
-
"@babel/types": "^7.
|
30
|
+
"@babel/generator": "^7.24.4",
|
31
|
+
"@babel/parser": "^7.24.4",
|
32
|
+
"@babel/plugin-proposal-decorators": "^7.24.1",
|
33
|
+
"@babel/plugin-proposal-destructuring-private": "^7.24.1",
|
34
|
+
"@babel/plugin-proposal-do-expressions": "^7.24.1",
|
35
|
+
"@babel/plugin-proposal-explicit-resource-management": "^7.24.1",
|
36
|
+
"@babel/plugin-proposal-function-bind": "^7.24.1",
|
37
|
+
"@babel/plugin-proposal-function-sent": "^7.24.1",
|
38
|
+
"@babel/plugin-proposal-partial-application": "^7.24.1",
|
39
|
+
"@babel/plugin-proposal-pipeline-operator": "^7.24.1",
|
40
|
+
"@babel/plugin-proposal-record-and-tuple": "^7.24.1",
|
41
|
+
"@babel/plugin-proposal-throw-expressions": "^7.24.1",
|
42
|
+
"@babel/plugin-transform-class-properties": "^7.24.1",
|
43
|
+
"@babel/plugin-transform-class-static-block": "^7.24.4",
|
44
|
+
"@babel/plugin-transform-exponentiation-operator": "^7.24.1",
|
45
|
+
"@babel/plugin-transform-json-strings": "^7.24.1",
|
46
|
+
"@babel/plugin-transform-logical-assignment-operators": "^7.24.1",
|
47
|
+
"@babel/plugin-transform-nullish-coalescing-operator": "^7.24.1",
|
48
|
+
"@babel/plugin-transform-numeric-separator": "^7.24.1",
|
49
|
+
"@babel/plugin-transform-object-rest-spread": "^7.24.1",
|
50
|
+
"@babel/plugin-transform-optional-catch-binding": "^7.24.1",
|
51
|
+
"@babel/plugin-transform-optional-chaining": "^7.24.1",
|
52
|
+
"@babel/plugin-transform-private-property-in-object": "^7.24.1",
|
53
|
+
"@babel/plugin-transform-typescript": "^7.24.4",
|
54
|
+
"@babel/plugin-transform-unicode-sets-regex": "^7.24.1",
|
55
|
+
"@babel/traverse": "^7.24.1",
|
56
|
+
"@babel/types": "^7.24.0",
|
57
57
|
"@bloomberg/record-tuple-polyfill": "^0.0.4",
|
58
58
|
"@rollup/plugin-babel": "^6.0.4",
|
59
59
|
"@rollup/plugin-commonjs": "^25.0.7",
|
60
60
|
"@rollup/plugin-json": "^6.1.0",
|
61
61
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
62
|
-
"@samual/lib": "
|
62
|
+
"@samual/lib": "0.10.2-e64c5bc",
|
63
63
|
"acorn": "^8.11.3",
|
64
64
|
"chalk": "^5.3.0",
|
65
|
-
"chokidar": "^3.
|
65
|
+
"chokidar": "^3.6.0",
|
66
66
|
"import-meta-resolve": "^4.0.0",
|
67
|
-
"prettier": "^3.2.
|
67
|
+
"prettier": "^3.2.5",
|
68
68
|
"proxy-polyfill": "^0.3.2",
|
69
|
-
"rollup": "^4.
|
70
|
-
"terser": "^5.
|
69
|
+
"rollup": "^4.14.2",
|
70
|
+
"terser": "^5.30.3"
|
71
71
|
},
|
72
|
-
"
|
73
|
-
"
|
72
|
+
"peerDependencies": {
|
73
|
+
"typescript": "5.4.5"
|
74
74
|
},
|
75
75
|
"type": "module",
|
76
76
|
"exports": {
|
77
|
+
".": "./index.js",
|
77
78
|
"./*": "./*.js",
|
78
79
|
"./*.js": "./*.js"
|
79
80
|
},
|
80
81
|
"bin": {
|
81
|
-
"hsm.d": "bin/hsm.d.ts",
|
82
82
|
"hsm": "bin/hsm.js"
|
83
|
+
},
|
84
|
+
"engines": {
|
85
|
+
"node": "^18 || >=20"
|
83
86
|
}
|
84
87
|
}
|
package/processScript/index.d.ts
CHANGED
@@ -3,38 +3,29 @@ export { minify } from "./minify";
|
|
3
3
|
export { postprocess } from "./postprocess";
|
4
4
|
export { preprocess } from "./preprocess";
|
5
5
|
export { transform } from "./transform";
|
6
|
-
export type ProcessOptions = {
|
7
|
-
/** whether to minify the given code */
|
8
|
-
|
9
|
-
/**
|
10
|
-
uniqueID: string;
|
11
|
-
/** the user going to be hosting this script (or set to `true` if not yet known) */
|
12
|
-
scriptUser: string | true;
|
13
|
-
/** the name of this script (or set to `true` if not yet known) */
|
14
|
-
scriptName: string | true;
|
6
|
+
export type ProcessOptions = LaxPartial<{
|
7
|
+
/** whether to minify the given code */ minify: boolean;
|
8
|
+
/** 11 a-z 0-9 characters */ uniqueId: string;
|
9
|
+
/** the user going to be hosting this script (or set to `true` if not yet known) */ scriptUser: string | true;
|
15
10
|
filePath: string;
|
16
|
-
/** whether to mangle function and class names (defaults to `false`) */
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
24
|
-
*/
|
11
|
+
/** whether to mangle function and class names (defaults to `false`) */ mangleNames: boolean;
|
12
|
+
/** when set to `true` forces use of quine cheats
|
13
|
+
*
|
14
|
+
* when set to `false` forces quine cheats not to be used
|
15
|
+
*
|
16
|
+
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
17
|
+
*/
|
25
18
|
forceQuineCheats: boolean;
|
19
|
+
}> & {
|
20
|
+
scriptName: string | true;
|
26
21
|
};
|
27
|
-
/**
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
* @param options {@link ProcessOptions details}
|
32
|
-
*/
|
33
|
-
export declare const processScript: (code: string, { minify: shouldMinify, uniqueID, scriptUser, scriptName, filePath, mangleNames, forceQuineCheats }?: LaxPartial<ProcessOptions>) => Promise<{
|
22
|
+
/** Minifies a given script
|
23
|
+
* @param code JavaScript or TypeScript code
|
24
|
+
* @param options {@link ProcessOptions details} */
|
25
|
+
export declare function processScript(code: string, { minify: shouldMinify, uniqueId, scriptUser, scriptName, filePath, mangleNames, forceQuineCheats }: ProcessOptions): Promise<{
|
34
26
|
script: string;
|
35
27
|
warnings: {
|
36
28
|
message: string;
|
37
29
|
line: number;
|
38
30
|
}[];
|
39
31
|
}>;
|
40
|
-
export default processScript;
|