hackmud-script-manager 0.19.0-50a29ed → 0.19.0-cd5548c

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/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,47 @@
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-class-properties';
13
+ import '@babel/plugin-proposal-class-static-block';
14
+ import '@babel/plugin-proposal-decorators';
15
+ import '@babel/plugin-proposal-json-strings';
16
+ import '@babel/plugin-proposal-logical-assignment-operators';
17
+ import '@babel/plugin-proposal-nullish-coalescing-operator';
18
+ import '@babel/plugin-proposal-numeric-separator';
19
+ import '@babel/plugin-proposal-object-rest-spread';
20
+ import '@babel/plugin-proposal-optional-catch-binding';
21
+ import '@babel/plugin-proposal-optional-chaining';
22
+ import '@babel/plugin-proposal-private-property-in-object';
23
+ import '@babel/plugin-transform-exponentiation-operator';
24
+ import '@babel/traverse';
25
+ import '@babel/types';
26
+ import '@rollup/plugin-babel';
27
+ import '@rollup/plugin-commonjs';
28
+ import '@rollup/plugin-json';
29
+ import '@rollup/plugin-node-resolve';
30
+ import '@samual/lib/assert';
31
+ import 'prettier';
32
+ import 'rollup';
33
+ import './processScript/minify.js';
34
+ import '@samual/lib/countHackmudCharacters';
35
+ import '@samual/lib/spliceString';
36
+ import 'acorn';
37
+ import 'terser';
38
+ import './processScript/shared.js';
39
+ import './processScript/postprocess.js';
40
+ import './processScript/preprocess.js';
41
+ import 'import-meta-resolve';
42
+ import './processScript/transform.js';
43
+ import '@samual/lib/clearObject';
44
+ import '@samual/lib/copyFilePersistent';
45
+ import '@samual/lib/DynamicMap';
46
+ import '@samual/lib/writeFilePersistent';
47
+ import 'chokidar';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hackmud-script-manager",
3
- "version": "0.19.0-50a29ed",
3
+ "version": "0.19.0-cd5548c",
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,56 @@
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",
30
+ "@babel/generator": "^7.22.9",
31
+ "@babel/parser": "^7.22.7",
33
32
  "@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",
33
+ "@babel/plugin-proposal-class-static-block": "^7.21.0",
34
+ "@babel/plugin-proposal-decorators": "^7.22.7",
35
+ "@babel/plugin-proposal-do-expressions": "^7.22.5",
36
+ "@babel/plugin-proposal-function-bind": "^7.22.5",
37
+ "@babel/plugin-proposal-function-sent": "^7.22.5",
39
38
  "@babel/plugin-proposal-json-strings": "^7.18.6",
40
- "@babel/plugin-proposal-logical-assignment-operators": "^7.18.9",
39
+ "@babel/plugin-proposal-logical-assignment-operators": "^7.20.7",
41
40
  "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
42
41
  "@babel/plugin-proposal-numeric-separator": "^7.18.6",
43
- "@babel/plugin-proposal-object-rest-spread": "^7.18.9",
42
+ "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
44
43
  "@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",
44
+ "@babel/plugin-proposal-optional-chaining": "^7.21.0",
45
+ "@babel/plugin-proposal-partial-application": "^7.22.5",
46
+ "@babel/plugin-proposal-pipeline-operator": "^7.22.5",
47
+ "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
48
+ "@babel/plugin-proposal-record-and-tuple": "^7.22.5",
49
+ "@babel/plugin-proposal-throw-expressions": "^7.22.5",
50
+ "@babel/plugin-transform-exponentiation-operator": "^7.22.5",
51
+ "@babel/plugin-transform-typescript": "^7.22.9",
52
+ "@babel/traverse": "^7.22.8",
53
+ "@babel/types": "^7.22.5",
55
54
  "@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",
55
+ "@rollup/plugin-babel": "^6.0.3",
56
+ "@rollup/plugin-commonjs": "^25.0.2",
57
+ "@rollup/plugin-json": "^6.0.0",
58
+ "@rollup/plugin-node-resolve": "^15.1.0",
59
+ "@samual/lib": "^0.8.1",
60
+ "acorn": "^8.10.0",
61
+ "chalk": "^5.3.0",
62
62
  "chokidar": "^3.5.3",
63
- "import-meta-resolve": "^2.0.3",
64
- "prettier": "^2.7.1",
63
+ "import-meta-resolve": "^3.0.0",
64
+ "prettier": "^3.0.0",
65
65
  "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"
66
+ "rollup": "^3.26.2",
67
+ "terser": "^5.19.0"
94
68
  },
95
69
  "engines": {
96
- "node": ">=14"
70
+ "node": ">=16"
97
71
  },
98
72
  "types": "index.d.ts",
99
73
  "type": "module",
100
74
  "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"
75
+ "./*": "./*.js",
76
+ "./*.js": "./*.js"
120
77
  },
121
78
  "bin": {
122
- "hsm": "./bin/hsm.js"
79
+ "hsm.d": "bin/hsm.d.ts",
80
+ "hsm": "bin/hsm.js"
123
81
  }
124
82
  }
@@ -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 */