hackmud-script-manager 0.19.0-43367ba → 0.19.0-7c69a3b

Sign up to get free protection for your applications and to get access to all the features.
package/constants.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const supportedExtensions: string[];
2
+ export declare const validDBMethods: string[];
package/constants.js ADDED
@@ -0,0 +1,4 @@
1
+ const supportedExtensions = [`.js`, `.ts`];
2
+ const validDBMethods = [`i`, `r`, `f`, `u`, `u1`, `us`, `ObjectId`];
3
+
4
+ export { supportedExtensions, validDBMethods };
@@ -1 +1,94 @@
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 { readdir } from 'fs/promises';
2
+ import { basename, resolve } from 'path';
3
+
4
+ const generateTypeDeclaration = async (sourceDirectory, hackmudPath) => {
5
+ const users = new Set();
6
+ if (hackmudPath) {
7
+ for (const dirent of await readdir(hackmudPath, {
8
+ withFileTypes: true
9
+ })) {
10
+ if (dirent.isFile() && dirent.name.endsWith(`.key`)) users.add(basename(dirent.name, `.key`));
11
+ }
12
+ }
13
+ const wildScripts = [];
14
+ const wildAnyScripts = [];
15
+ const allScripts = {};
16
+ const allAnyScripts = {};
17
+ await Promise.all((await readdir(sourceDirectory, {
18
+ withFileTypes: true
19
+ })).map(async dirent => {
20
+ if (dirent.isFile()) {
21
+ if (dirent.name.endsWith(`.ts`)) {
22
+ if (!dirent.name.endsWith(`.d.ts`)) wildScripts.push(basename(dirent.name, `.ts`));
23
+ } else if (dirent.name.endsWith(`.js`)) wildAnyScripts.push(basename(dirent.name, `.js`));
24
+ } else if (dirent.isDirectory()) {
25
+ const scripts = [];
26
+ const anyScripts = [];
27
+ allScripts[dirent.name] = scripts;
28
+ allAnyScripts[dirent.name] = anyScripts;
29
+ users.add(dirent.name);
30
+ for (const file of await readdir(resolve(sourceDirectory, dirent.name), {
31
+ withFileTypes: true
32
+ })) {
33
+ if (file.isFile()) {
34
+ if (file.name.endsWith(`.ts`)) {
35
+ if (!dirent.name.endsWith(`.d.ts`)) scripts.push(basename(file.name, `.ts`));
36
+ } else if (file.name.endsWith(`.js`)) anyScripts.push(basename(file.name, `.js`));
37
+ }
38
+ }
39
+ }
40
+ }));
41
+ sourceDirectory = resolve(sourceDirectory);
42
+ let o = ``;
43
+ for (const script of wildScripts) o += `type $${script}$ = typeof import("${sourceDirectory}/${script}").default\n`;
44
+ o += `\n`;
45
+ for (const user in allScripts) {
46
+ const scripts = allScripts[user];
47
+ for (const script of scripts) o += `type $${user}$${script}$ = typeof import("${sourceDirectory}/${user}/${script}").default\n`;
48
+ }
49
+
50
+ // TODO detect security level and generate apropriate code
51
+
52
+ // TODO accurate function signatures
53
+ // I lose the generic-ness of my functions when I wrap them
54
+ // regexing isn't enough and it looks like I'm going to need to parse the files in TypeScript to extract the signature
55
+
56
+ o += `
57
+ type ArrayRemoveFirst<A> = A extends [ infer FirstItem, ...infer Rest ] ? Rest : never
58
+
59
+ type Subscript<T extends (...args: any) => any> =
60
+ (...args: ArrayRemoveFirst<Parameters<T>>) => ReturnType<T> | ScriptFailure
61
+
62
+ type WildFullsec = Record<string, () => ScriptFailure> & {
63
+ `;
64
+ for (const script of wildScripts) o += `\t${script}: Subscript<$${script}$>\n`;
65
+ for (const script of wildAnyScripts) o += `\t${script}: (...args: any) => any\n`;
66
+ o += `}\n\ninterface PlayerFullsec {`;
67
+ let lastWasMultiLine = true;
68
+ for (const user of users) {
69
+ const scripts = allScripts[user];
70
+ const anyScripts = allAnyScripts[user];
71
+ if (scripts && scripts.length || anyScripts && anyScripts.length) {
72
+ lastWasMultiLine = true;
73
+ o += `\n\t${user}: WildFullsec & {\n`;
74
+ if (scripts) {
75
+ for (const script of scripts) o += `\t\t${script}: Subscript<$${user}$${script}$>\n`;
76
+ }
77
+ if (anyScripts) {
78
+ for (const script of anyScripts) o += `\t\t${script}: (...args: any) => any\n`;
79
+ }
80
+ o += `\t}`;
81
+ } else {
82
+ if (lastWasMultiLine) {
83
+ o += `\n`;
84
+ lastWasMultiLine = false;
85
+ }
86
+ o += `\t${user}: WildFullsec`;
87
+ }
88
+ o += `\n`;
89
+ }
90
+ o += `}\n`;
91
+ return o;
92
+ };
93
+
94
+ export { generateTypeDeclaration as default, generateTypeDeclaration };
package/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- export { supportedExtensions } from "./constants.json";
1
+ export { supportedExtensions } from "./constants";
2
2
  export { generateTypeDeclaration } from "./generateTypeDeclaration";
3
3
  export { processScript } from "./processScript";
4
4
  export { pull } from "./pull";
5
5
  export { push } from "./push";
6
6
  export { syncMacros } from "./syncMacros";
7
7
  export { watch } from "./watch";
8
- export declare type Info = {
8
+ export type Info = {
9
9
  file: string;
10
10
  users: string[];
11
11
  minLength: number;
package/index.js CHANGED
@@ -1 +1,50 @@
1
- export{s as supportedExtensions}from"./constants-9bb78688.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-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-transform-exponentiation-operator";import"@babel/traverse";import"@babel/types";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"./processScript/minify.js";import"acorn";import"terser";import"./processScript/shared.js";import"./assert-22a7ef8a.js";import"./spliceString-0e6b5d6d.js";import"./countHackmudCharacters-a08a265f.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"import-meta-resolve";import"./processScript/transform.js";import"fs";import"./writeFilePersistent-ee9c9bfd.js";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 'fs/promises';
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/DynamicMap';
49
+ import '@samual/lib/writeFilePersistent';
50
+ import 'chokidar';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hackmud-script-manager",
3
- "version": "0.19.0-43367ba",
3
+ "version": "0.19.0-7c69a3b",
4
4
  "description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
5
5
  "keywords": [
6
6
  "api",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "homepage": "https://github.com/samualtnorman/hackmud-script-manager#readme",
21
21
  "bugs": "https://github.com/samualtnorman/hackmud-script-manager/issues",
22
- "license": "GPL-3.0-or-later",
22
+ "license": "MIT",
23
23
  "author": "Samual Norman",
24
24
  "main": "index.js",
25
25
  "repository": {
@@ -27,98 +27,58 @@
27
27
  "url": "https://github.com/samualtnorman/hackmud-script-manager.git"
28
28
  },
29
29
  "dependencies": {
30
- "@babel/core": "^7.18.9",
31
- "@babel/generator": "^7.18.9",
32
- "@babel/parser": "^7.18.9",
33
- "@babel/plugin-proposal-class-properties": "^7.18.6",
34
- "@babel/plugin-proposal-class-static-block": "^7.18.6",
35
- "@babel/plugin-proposal-decorators": "^7.18.9",
36
- "@babel/plugin-proposal-do-expressions": "^7.18.6",
37
- "@babel/plugin-proposal-function-bind": "^7.18.9",
38
- "@babel/plugin-proposal-function-sent": "^7.18.6",
39
- "@babel/plugin-proposal-json-strings": "^7.18.6",
40
- "@babel/plugin-proposal-logical-assignment-operators": "^7.18.9",
41
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
42
- "@babel/plugin-proposal-numeric-separator": "^7.18.6",
43
- "@babel/plugin-proposal-object-rest-spread": "^7.18.9",
44
- "@babel/plugin-proposal-optional-catch-binding": "^7.18.6",
45
- "@babel/plugin-proposal-optional-chaining": "^7.18.9",
46
- "@babel/plugin-proposal-partial-application": "^7.18.9",
47
- "@babel/plugin-proposal-pipeline-operator": "^7.18.9",
48
- "@babel/plugin-proposal-private-property-in-object": "^7.18.6",
49
- "@babel/plugin-proposal-record-and-tuple": "^7.18.6",
50
- "@babel/plugin-proposal-throw-expressions": "^7.18.6",
51
- "@babel/plugin-transform-exponentiation-operator": "^7.18.6",
52
- "@babel/plugin-transform-typescript": "^7.18.8",
53
- "@babel/traverse": "^7.18.9",
54
- "@babel/types": "^7.18.9",
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",
55
57
  "@bloomberg/record-tuple-polyfill": "^0.0.4",
56
- "@rollup/plugin-babel": "^5.3.1",
57
- "@rollup/plugin-commonjs": "^22.0.1",
58
- "@rollup/plugin-json": "^4.1.0",
59
- "@rollup/plugin-node-resolve": "^13.3.0",
60
- "acorn": "^8.7.1",
61
- "chalk": "^5.0.1",
58
+ "@rollup/plugin-babel": "^6.0.4",
59
+ "@rollup/plugin-commonjs": "^25.0.7",
60
+ "@rollup/plugin-json": "^6.1.0",
61
+ "@rollup/plugin-node-resolve": "^15.2.3",
62
+ "@samual/lib": "^0.9.1",
63
+ "acorn": "^8.11.3",
64
+ "chalk": "^5.3.0",
62
65
  "chokidar": "^3.5.3",
63
- "import-meta-resolve": "^2.0.3",
64
- "prettier": "^2.7.1",
66
+ "import-meta-resolve": "^4.0.0",
67
+ "prettier": "^3.2.2",
65
68
  "proxy-polyfill": "^0.3.2",
66
- "rollup": "^2.77.0",
67
- "terser": "^5.14.2"
68
- },
69
- "devDependencies": {
70
- "@babel/preset-env": "^7.18.9",
71
- "@babel/preset-typescript": "^7.18.6",
72
- "@samual/lib": "^0.3.4",
73
- "@types/babel__core": "^7.1.19",
74
- "@types/babel__generator": "^7.6.4",
75
- "@types/babel__traverse": "^7.17.1",
76
- "@types/node": "^14.18.22",
77
- "@types/prettier": "^2.6.3",
78
- "@types/semver": "^7.3.10",
79
- "@typescript-eslint/eslint-plugin": "^5.30.7",
80
- "@typescript-eslint/parser": "^5.30.7",
81
- "eslint": "^8.20.0",
82
- "eslint-plugin-array-func": "^3.1.7",
83
- "eslint-plugin-eslint-comments": "^3.2.0",
84
- "eslint-plugin-regexp": "^1.7.0",
85
- "eslint-plugin-unicorn": "^43.0.2",
86
- "latest-version": "^7.0.0",
87
- "rollup-plugin-preserve-shebang": "^1.0.1",
88
- "rollup-plugin-terser": "^7.0.2",
89
- "semver": "^7.3.7",
90
- "typescript": "^4.7.4"
91
- },
92
- "optionalDependencies": {
93
- "deasync": "^0.1.27"
69
+ "rollup": "^4.9.5",
70
+ "terser": "^5.26.0"
94
71
  },
95
72
  "engines": {
96
- "node": ">=14"
73
+ "node": ">=20"
97
74
  },
98
- "types": "index.d.ts",
99
75
  "type": "module",
100
76
  "exports": {
101
- ".": {
102
- "import": "./index.js",
103
- "require": "./index.cjs"
104
- },
105
- "./*": "./*",
106
- "./generateTypeDeclaration": "./generateTypeDeclaration.js",
107
- "./index": "./index.js",
108
- "./pull": "./pull.js",
109
- "./push": "./push.js",
110
- "./syncMacros": "./syncMacros.js",
111
- "./watch": "./watch.js",
112
- "./bin/hsm": "./bin/hsm.js",
113
- "./processScript/index": "./processScript/index.js",
114
- "./processScript": "./processScript/index.js",
115
- "./processScript/minify": "./processScript/minify.js",
116
- "./processScript/postprocess": "./processScript/postprocess.js",
117
- "./processScript/preprocess": "./processScript/preprocess.js",
118
- "./processScript/shared": "./processScript/shared.js",
119
- "./processScript/transform": "./processScript/transform.js"
77
+ "./*": "./*.js",
78
+ "./*.js": "./*.js"
120
79
  },
121
80
  "bin": {
122
- "hsm": "./bin/hsm.js"
81
+ "hsm.d": "bin/hsm.d.ts",
82
+ "hsm": "bin/hsm.js"
123
83
  }
124
84
  }
@@ -1,9 +1,9 @@
1
- import { LaxPartial } from "@samual/lib";
1
+ import type { LaxPartial } from "@samual/lib";
2
2
  export { minify } from "./minify";
3
3
  export { postprocess } from "./postprocess";
4
4
  export { preprocess } from "./preprocess";
5
5
  export { transform } from "./transform";
6
- export declare type ProcessOptions = {
6
+ export type ProcessOptions = {
7
7
  /** whether to minify the given code */
8
8
  minify: boolean;
9
9
  /** 11 a-z 0-9 characters */