hackmud-script-manager 0.20.0-b71a8be → 0.20.1-503b02c

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1 @@
1
- export declare const generateTypeDeclaration: (sourceDirectory: string, hackmudPath?: string) => Promise<string>;
2
- export default generateTypeDeclaration;
1
+ export declare function generateTypeDeclaration(sourceDirectory: string, hackmudPath?: string): Promise<string>;
@@ -1 +1,68 @@
1
- import{readdir as e}from"fs/promises";import{basename as t,resolve as n}from"path";const generateTypeDeclaration=async(s,i)=>{const a=new Set;if(i)for(const n of await e(i,{withFileTypes:!0}))n.isFile()&&n.name.endsWith(".key")&&a.add(t(n.name,".key"));const r=[],o=[],f={},l={};await Promise.all((await e(s,{withFileTypes:!0})).map((async i=>{if(i.isFile())i.name.endsWith(".ts")?i.name.endsWith(".d.ts")||r.push(t(i.name,".ts")):i.name.endsWith(".js")&&o.push(t(i.name,".js"));else if(i.isDirectory()){const r=[],o=[];f[i.name]=r,l[i.name]=o,a.add(i.name);for(const a of await e(n(s,i.name),{withFileTypes:!0}))a.isFile()&&(a.name.endsWith(".ts")?i.name.endsWith(".d.ts")||r.push(t(a.name,".ts")):a.name.endsWith(".js")&&o.push(t(a.name,".js")))}}))),s=n(s);let c="";for(const e of r)c+=`type $${e}$ = typeof import("${s}/${e}").default\n`;c+="\n";for(const e in f){const t=f[e];for(const n of t)c+=`type $${e}$${n}$ = typeof import("${s}/${e}/${n}").default\n`}c+="\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";for(const e of r)c+=`\t${e}: Subscript<$${e}$>\n`;for(const e of o)c+=`\t${e}: (...args: any) => any\n`;c+="}\n\ninterface PlayerFullsec {";let m=!0;for(const e of a){const t=f[e],n=l[e];if(t&&t.length||n&&n.length){if(m=!0,c+=`\n\t${e}: WildFullsec & {\n`,t)for(const n of t)c+=`\t\t${n}: Subscript<$${e}$${n}$>\n`;if(n)for(const e of n)c+=`\t\t${e}: (...args: any) => any\n`;c+="\t}"}else m&&(c+="\n",m=!1),c+=`\t${e}: WildFullsec`;c+="\n"}return c+="}\n",c};export{generateTypeDeclaration as default,generateTypeDeclaration};
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
- file: string;
9
+ path: string;
10
10
  users: string[];
11
- minLength: number;
11
+ characterCount: number;
12
12
  error: Error | undefined;
13
13
  };
package/index.js CHANGED
@@ -1 +1,51 @@
1
- export{supportedExtensions}from"./constants.js";export{generateTypeDeclaration}from"./generateTypeDeclaration.js";export{processScript}from"./processScript/index.js";export{pull}from"./pull.js";export{push}from"./push.js";export{syncMacros}from"./syncMacros.js";export{watch}from"./watch.js";import"fs/promises";import"path";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-destructuring-private";import"@babel/plugin-proposal-explicit-resource-management";import"@babel/plugin-transform-class-properties";import"@babel/plugin-transform-class-static-block";import"@babel/plugin-transform-exponentiation-operator";import"@babel/plugin-transform-json-strings";import"@babel/plugin-transform-logical-assignment-operators";import"@babel/plugin-transform-nullish-coalescing-operator";import"@babel/plugin-transform-numeric-separator";import"@babel/plugin-transform-object-rest-spread";import"@babel/plugin-transform-optional-catch-binding";import"@babel/plugin-transform-optional-chaining";import"@babel/plugin-transform-private-property-in-object";import"@babel/plugin-transform-unicode-sets-regex";import"@babel/traverse";import"@babel/types";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"@samual/lib/assert";import"prettier";import"rollup";import"./processScript/minify.js";import"@samual/lib/countHackmudCharacters";import"@samual/lib/spliceString";import"acorn";import"terser";import"./processScript/shared.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"import-meta-resolve";import"./processScript/transform.js";import"@samual/lib/clearObject";import"@samual/lib/copyFilePersistent";import"@samual/lib/DynamicMap";import"@samual/lib/writeFilePersistent";import"chokidar";
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.20.0-b71a8be",
3
+ "version": "0.20.1-503b02c",
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
- "javascipt",
15
- "typescipt",
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.23.6",
31
- "@babel/parser": "^7.23.6",
32
- "@babel/plugin-proposal-decorators": "^7.23.7",
33
- "@babel/plugin-proposal-destructuring-private": "^7.23.3",
34
- "@babel/plugin-proposal-do-expressions": "^7.23.3",
35
- "@babel/plugin-proposal-explicit-resource-management": "^7.23.3",
36
- "@babel/plugin-proposal-function-bind": "^7.23.3",
37
- "@babel/plugin-proposal-function-sent": "^7.23.3",
38
- "@babel/plugin-proposal-partial-application": "^7.23.3",
39
- "@babel/plugin-proposal-pipeline-operator": "^7.23.3",
40
- "@babel/plugin-proposal-record-and-tuple": "^7.23.3",
41
- "@babel/plugin-proposal-throw-expressions": "^7.23.3",
42
- "@babel/plugin-transform-class-properties": "^7.23.3",
43
- "@babel/plugin-transform-class-static-block": "^7.23.4",
44
- "@babel/plugin-transform-exponentiation-operator": "^7.23.3",
45
- "@babel/plugin-transform-json-strings": "^7.23.4",
46
- "@babel/plugin-transform-logical-assignment-operators": "^7.23.4",
47
- "@babel/plugin-transform-nullish-coalescing-operator": "^7.23.4",
48
- "@babel/plugin-transform-numeric-separator": "^7.23.4",
49
- "@babel/plugin-transform-object-rest-spread": "^7.23.4",
50
- "@babel/plugin-transform-optional-catch-binding": "^7.23.4",
51
- "@babel/plugin-transform-optional-chaining": "^7.23.4",
52
- "@babel/plugin-transform-private-property-in-object": "^7.23.4",
53
- "@babel/plugin-transform-typescript": "^7.23.6",
54
- "@babel/plugin-transform-unicode-sets-regex": "^7.23.3",
55
- "@babel/traverse": "^7.23.7",
56
- "@babel/types": "^7.23.6",
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": "^0.9.1",
62
+ "@samual/lib": "0.11.0",
63
63
  "acorn": "^8.11.3",
64
64
  "chalk": "^5.3.0",
65
- "chokidar": "^3.5.3",
65
+ "chokidar": "^3.6.0",
66
66
  "import-meta-resolve": "^4.0.0",
67
- "prettier": "^3.2.2",
67
+ "prettier": "^3.2.5",
68
68
  "proxy-polyfill": "^0.3.2",
69
- "rollup": "^4.9.5",
70
- "terser": "^5.26.0"
69
+ "rollup": "^4.16.4",
70
+ "terser": "^5.30.4"
71
71
  },
72
- "engines": {
73
- "node": ">=20"
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
  }
@@ -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
- minify: boolean;
9
- /** 11 a-z 0-9 characters */
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
- mangleNames: boolean;
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
- */
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
- * Minifies a given script
29
- *
30
- * @param code JavaScript or TypeScript code
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;