hackmud-script-manager 0.16.0-8448068 → 0.16.1

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,9 +1,55 @@
1
- # hackmud-script-manager
1
+ # Hackmud Script Manager
2
2
  ![Test](https://github.com/samualtnorman/hackmud-script-manager/workflows/Test/badge.svg)
3
3
 
4
4
  Command made for [hackmud-environment](https://github.com/samualtnorman/hackmud-environment), which is a scripting environment for hackmud with minification, autocompletes / intellisense, and TypeScript support.
5
5
 
6
6
  Install with `npm install hackmud-script-manager -g` to make the `hsm` command available everywhere.
7
- Or use `npm install hackmud-script-manager` without the `-g` option if you are using the API, or only need the command in your project.
8
7
 
9
- The internal API is also exposed for programmatic use.
8
+ ## Features
9
+ - Minification
10
+ - This includes auto quine cheating.
11
+ - Supported types are null, numbers, strings, and JSON compatible objects and arrays.
12
+ - Non JSON compatible object keys are quine cheated.
13
+ - Member expressions are converted to index notation so the index string can be quine cheated.
14
+ - And template literals are converted to string concatenation so the strings can be quine cheated.
15
+ - Global variable aliasing.
16
+ - Converting `function foo() { ... }` format to `let foo = () => ...` format.
17
+ - Converting references to `_START` and `_TIMEOUT` to `_ST` and `_TO`.
18
+ - Removing unused parameters from main function expression.
19
+ - Modern Javascript Syntax and Features
20
+ - [Exponentiation Operator](https://babeljs.io/docs/en/babel-plugin-transform-exponentiation-operator), [Object Rest Spread](https://babeljs.io/docs/en/babel-plugin-proposal-object-rest-spread), [Optional Catch Binding](https://babeljs.io/docs/en/babel-plugin-proposal-optional-catch-binding), [JSON strings](https://babeljs.io/docs/en/babel-plugin-proposal-json-strings), [Nullish Coalescing Operator](https://babeljs.io/docs/en/babel-plugin-proposal-nullish-coalescing-operator), [Optional Chaining](https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining), [Logical Assignment Operators](https://babeljs.io/docs/en/babel-plugin-proposal-logical-assignment-operators), [Numeric Seperators](https://babeljs.io/docs/en/babel-plugin-proposal-numeric-separator), [Class Properties](https://babeljs.io/docs/en/babel-plugin-proposal-class-properties), [Class Static Block](https://babeljs.io/docs/en/babel-plugin-proposal-class-static-block), [Private Property `in` Object](https://babeljs.io/docs/en/babel-plugin-proposal-private-property-in-object).
21
+ - And bigint literals (hackmud has `BigInt()`).
22
+ - Hackmud already supports all modern regular expression features.
23
+ - Future JavaScript Syntax and Features
24
+ - Warning: TypeScript doesn't support any of these features and these features may change or not actually make it into JavaScript.
25
+ - [Decorators](https://babeljs.io/docs/en/babel-plugin-proposal-decorators), [Do Expressions](https://babeljs.io/docs/en/babel-plugin-proposal-do-expressions), [Function Bind](https://babeljs.io/docs/en/babel-plugin-proposal-function-bind), [Function Sent](https://babeljs.io/docs/en/babel-plugin-proposal-function-sent), [Partial Application](https://babeljs.io/docs/en/babel-plugin-proposal-partial-application), [Pipeline Operator](https://babeljs.io/docs/en/babel-plugin-proposal-pipeline-operator) (hack proposal and `%` topic token), [Throw Expression](https://babeljs.io/docs/en/babel-plugin-proposal-throw-expressions), [Record and Tuple](https://babeljs.io/docs/en/babel-plugin-proposal-record-and-tuple) (hash `#` syntax type).
26
+ - TypeScript Support
27
+ - This command/module doesn't actually do any type checking so you'll need to run `tsc` seperatly with `noEmit`.
28
+ - And “Cool” Unnecessary Features.
29
+ - Variables declared outside the main function expression automatically become `#G` global variables.
30
+ - Any code outside the function expression will only run once per top level script execution (`#FMCL`).
31
+ - Basic seclevel verification.
32
+ - Declaring `// @seclevel HIGHSEC` or any other seclevel stops you from accidentally using `#ls.` or `#ns.`.
33
+ - Importing modules into your script.
34
+ - `_SOURCE` is replaced with string of source code of the script it's in.
35
+ - `_BUILD_DATE` is replaced with a unix timestamp (`Date.now()`) of the build date of the script.
36
+ - `_SCRIPT_USER` is replaced with a string of the user the script was pushed to.
37
+ - This saves characters compared to `context.this_script.split(".")[0]`.
38
+ - `_SCRIPT_NAME` is like `_SCRIPT_USER` but the name of the script.
39
+ - Saves characters compared to `context.this_script.split(".")[1]`.
40
+ - `_FULL_SCRIPT_NAME` is replaced with what would be `context.this_script` but saves characters.
41
+ - `#s.` can be used and it'll automatically have the seclevel inserted.
42
+ - Subscript names and db methods are verified.
43
+ - All references to preprocessor syntax functions not being called are turned into arrow function wrappers e.g. `let debug = #D;` -> `let debug = v => #D(v);`.
44
+ - `_SECLEVEL` is replaced with a number (`0` to `4`) representing the seclevel of the script.
45
+ - When `export`s are present in the script, it becomes a script that returns an object of the `export`ed values.
46
+ - `_EXPORTS` becomes an array of the names of the exported values.
47
+ - And Other Weird Fixes
48
+ - Like `.__proto__` and `.prototype` are converted to `["__proto__"]` and `["prototype"]`.
49
+ - Illegal and unsafe strings.
50
+ - Appearences of `_SC` and friends are either renamed or have an escape inserted so that script is legal.
51
+ - Preprocessor syntax in strings are escaped so hackmud doesn't recognise them as preprocessor syntax.
52
+ - And appearences of `//` in strings and regexes have a backslash inserted between to stop hackmud's overagressive comment remove from removing half the line of code.
53
+ - Classes are actually usable now, this module replaces instances of `this` to a variable referencing what would be `this`.
54
+ - `Function.prototype` can be referenced (but only the `.prototype` property, nothing else).
55
+ - `Object.getPrototypeOf` and `Object.setPrototypeOf` are replaced with equivalent functions.
package/bin/hsm.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import e from"chalk";import{watch as o}from"chokidar";import s from"fs";import{homedir as n}from"os";import{resolve as t,basename as a,extname as i,dirname as c,relative as l}from"path";import{s as r}from"../constants-9bb78688.js";import{D as g,w as f}from"../writeFilePersistent-72dc81a3.js";import{generateTypings as h}from"../generateTypings.js";import{syncMacros as m}from"../syncMacros.js";import{pull as p}from"../pull.js";import{c as u}from"../countHackmudCharacters-1e122984.js";const{readFile:d,rmdir:k,writeFile:b,mkdir:w}=s.promises,y=t(n(),".config"),$=t(y,"hsm.json"),j=new Map,v=[];let P;const C=e.rgb(255,244,4),N=e.rgb(243,249,152),S=e.rgb(179,255,155),x=e.rgb(255,150,224),F=e.rgb(30,255,0),O=e.rgb(202,202,202),U=new g((e=>{let o=0;for(const s of e)o+=(o>>1)+o+"xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(s)+1;return[C,N,S,x,F,O][o%6](e)}));for(const e of process.argv.slice(2))if("-"==e[0]){const[o,s]=e.split("=");let n=s;if(n)if("true"==n)n=!0;else if("false"==n)n=!1;else{const e=Number(n);isFinite(e)&&(n=e)}else n=!0;if("-"==e[1])j.set(o.slice(2),n);else for(const e of o.slice(1))j.set(e,n)}else v.push(e);function help(){switch(v[0]){case"config":switch(v[1]){case"get":console.log("hsm config get <key>");break;case"set":console.log("hsm config set <key> <value>");break;case"delete":console.log("hsm config delete <key>");break;default:console.log("hsm config <get, delete, set>")}break;case"push":console.log('hsm push <dir> [..."<script user>.<script name>"] [--skip-minify] [--mangle-names]');break;case"dev":case"watch":console.log(`hsm ${v[0]} <dir> [..."<script user>.<script name>"] [--skip-minify] [--mangle-names]`);break;case"pull":console.log("hsm pull <script user>.<script name>");break;case"minify":case"golf":console.log(`${a(process.argv[1])} ${v[0]} <target> [output]`);break;default:console.log("hsm <push, watch, pull, config, golf>")}}function version(){console.log("0.16.0-8448068")}async function getConfig(){return P||(P=await d($,{encoding:"utf-8"}).then((e=>{let o;try{o=JSON.parse(e)}catch{return console.log("config file was corrupted, resetting"),{}}return o&&"object"==typeof o?o:(console.log("config file was corrupted, resetting"),{})}),(()=>(console.log(`creating config file at ${$}`),{}))))}function exploreObject(e,o,s=!1){for(const t of o){var n;e=s?"object"==typeof e[t]?e[t]:e[t]={}:null===(n=e)||void 0===n?void 0:n[t]}return e}function updateConfig(){if(P){const e=JSON.stringify(P,void 0,"\t");b($,e).catch((async o=>{switch(o.code){case"EISDIR":await k($);break;case"ENOENT":await w(y);break;default:throw o}b($,e)}))}}function onPushLogger({file:o,users:s,minLength:n,error:c}){c?console.log(`error "${e.bold(c.message)}" in ${e.bold(o)}`):console.log(`pushed ${e.bold(o)} to ${s.map((o=>e.bold(U.get(o)))).join(", ")} | ${e.bold(String(n))} chars | ${e.bold(`${t(P.hackmudPath,s[0],"scripts",a(o,i(o)))}.js`)}`)}(async()=>{if(j.get("version")||j.get("v"))version();else if(j.get("help")||j.get("h"))help();else{switch(v[0]){case"push":{const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const o=v[1];if(!o){console.error("specify the directory to watch"),help();break}const{push:s}=await import("../push.js"),n=e.hackmudPath,t=v.slice(2);t.length||t.push("*.*"),j.has("skip-minify")&&j.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names");(await s(o,n,{scripts:t,onPush:onPushLogger,minify:!j.get("skip-minify"),mangleNames:Boolean(j.get("mangle-names"))})).length||console.warn("couldn't find any scripts to push"),updateConfig()}break;case"dev":case"watch":{var s;if(!v[1]){console.error("specify the directory to watch"),help();break}const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const{watch:o}=await import("../watch.js"),n=v.slice(2);n.length||n.push("*.*"),j.has("skip-minify")&&j.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names"),o(v[1],e.hackmudPath,{scripts:n,onPush:onPushLogger,typeDeclarationPath:null===(s=j.get("type-declaration-path"))||void 0===s?void 0:s.toString(),minify:!j.get("skip-minify"),mangleNames:Boolean(j.get("mangle-names")),onReady:()=>console.log("watching")})}break;case"pull":{const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const o=v[1];if(!o){help();break}const s=v[2]||".",n=e.hackmudPath;try{await p(s,n,o)}catch{console.log("something went wrong, did you forget to #down the script?")}}break;case"sync-macros":{const{hackmudPath:e}=await getConfig();if(!e){console.log("you need to set hackmudPath in config before you can use this command");break}const{macrosSynced:o,usersSynced:s}=await m(e);console.log(`synced ${o} macros to ${s} users`)}break;case"gen-types":{const e=t(v[1]||".");h(e,v[2]?t(v[2]):t(e,"../player.d.ts"),(await getConfig()).hackmudPath)}break;case"config":switch(v[1]){case"get":v[2]?console.log(exploreObject(await getConfig(),v[2].split("."))):console.log(await getConfig());break;case"delete":if(v[2]){var n;const e=v[2].split("."),o=e.pop();if(!e.length){help();break}const s=await getConfig();null===(n=exploreObject(s,e))||void 0===n||delete n[o],console.log(s)}else console.log("Usage:\nhsm config delete <key>");break;case"set":if(v[2]&&v[3]){const e=v[2].split(".");if(!e.length){help();break}const o=e.pop(),s=await getConfig();if(e.length||"hackmudPath"!=o){let n=s;for(const o of e)"object"==typeof n[o]||(n[o]={}),n=n[o];n[o]=v[3]}else s.hackmudPath=t(v[3]);console.log(s)}else console.log("Usage:\nhsm config set <key> <value>");break;default:v[1]&&console.log("unknown command"),help()}break;case"help":case"h":help();break;case"version":case"v":version();break;case"golf":case"minify":{const s=v[1];if(!s){console.log(`Target required\nUsage: ${a(process.argv[1])} ${v[0]} <target> [output]`);break}const n=i(s);if(!r.includes(n)){console.log(`Unsupported file extension "${e.bold(n)}"\nSupported extensions are "${r.map((o=>e.bold(o))).join('", "')}"`);break}j.get("watch")?o(s,{awaitWriteFinish:{stabilityThreshold:100}}).on("ready",(()=>console.log(`watching ${s}`))).on("change",(()=>golfFile(s,n))):await golfFile(s,n)}break;default:v[0]&&console.log("unknown command"),help()}updateConfig()}async function golfFile(o,s){const{processScript:n}=await import("../processScript/index.js");await d(o,{encoding:"utf-8"}).then((async i=>{const r=a(o,s),g=r.endsWith(".src"),h=g?r.slice(0,-4):r;let m="UNKNOWN";"scripts"==a(t(o,".."))&&"hackmud"==a(t(o,"../../.."))&&(m=a(t(o,"../..")));const p=!j.get("skip-minify"),d=Boolean(j.get("mangle-names"));!p&&d&&console.warn("warning: `--mangle-names` has no effect while `--skip-minify` is active");const k=performance.now(),{script:b,warnings:w}=await n(i,{minify:p,scriptUser:m,scriptName:h,filePath:o,mangleNames:d}),y=performance.now()-k;for(const{message:o,line:s}of w)console.log(`warning "${e.bold(o)}" on line ${e.bold(String(s))}`);let $;$=v[2]?v[2]:t(c(o),g?`${h}.js`:".js"==s?`${r}.min.js`:`${r}.js`);const P=u(b);await f($,b).catch((async e=>{if(!v[2]||"EISDIR"!=e.code)throw e;$=t($,`${a(o,s)}.js`),await f($,b)})).then((()=>console.log(`wrote ${e.bold(P)} chars to ${e.bold(l(".",$))} | took ${Math.round(100*y)/100}ms`)),(e=>console.log(e.message)))}),(e=>console.log(e.message)))}})();
2
+ import e from"chalk";import{watch as o}from"chokidar";import s from"fs";import{homedir as t}from"os";import{resolve as n,basename as a,extname as i,dirname as c,relative as r}from"path";import{s as l}from"../constants-9bb78688.js";import{D as g,w as f}from"../writeFilePersistent-72dc81a3.js";import{generateTypeDeclaration as h}from"../generateTypeDeclaration.js";import{a as m}from"../assert-1556d989.js";import{syncMacros as p}from"../syncMacros.js";import{pull as d}from"../pull.js";import{c as u}from"../countHackmudCharacters-1e122984.js";const{readFile:k,rmdir:b,writeFile:w,mkdir:y}=s.promises,$=n(t(),".config"),j=n($,"hsm.json"),v=new Map,P=[];let C;const S=e.rgb(255,244,4),N=e.rgb(243,249,152),x=e.rgb(179,255,155),F=e.rgb(255,150,224),O=e.rgb(30,255,0),D=e.rgb(202,202,202),E=new g((e=>{let o=0;for(const s of e)o+=(o>>1)+o+"xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(s)+1;return[S,N,x,F,O,D][o%6](e)}));for(const e of process.argv.slice(2))if("-"==e[0]){const[o,s]=e.split("=");let t=s;if(t)if("true"==t)t=!0;else if("false"==t)t=!1;else{const e=Number(t);isFinite(e)&&(t=e)}else t=!0;if("-"==e[1])v.set(o.slice(2),t);else for(const e of o.slice(1))v.set(e,t)}else P.push(e);function help(){switch(P[0]){case"config":switch(P[1]){case"get":console.log("hsm config get <key>");break;case"set":console.log("hsm config set <key> <value>");break;case"delete":console.log("hsm config delete <key>");break;default:console.log("hsm config <get, delete, set>")}break;case"push":console.log('hsm push <dir> [..."<script user>.<script name>"] [--skip-minify] [--mangle-names]');break;case"dev":case"watch":console.log(`hsm ${P[0]} <dir> [..."<script user>.<script name>"] [--skip-minify] [--mangle-names]`);break;case"pull":console.log("hsm pull <script user>.<script name>");break;case"minify":case"golf":console.log(`${a(process.argv[1])} ${P[0]} <target> [output]`);break;default:console.log("hsm <push, watch, pull, config, golf>")}}function version(){console.log("0.16.1")}async function getConfig(){return C||(C=await k(j,{encoding:"utf-8"}).then((e=>{let o;try{o=JSON.parse(e)}catch{return console.log("config file was corrupted, resetting"),{}}return o&&"object"==typeof o?o:(console.log("config file was corrupted, resetting"),{})}),(()=>(console.log(`creating config file at ${j}`),{}))))}function exploreObject(e,o,s=!1){for(const n of o){var t;e=s?"object"==typeof e[n]?e[n]:e[n]={}:null===(t=e)||void 0===t?void 0:t[n]}return e}function updateConfig(){if(C){const e=JSON.stringify(C,void 0,"\t");w(j,e).catch((async o=>{switch(o.code){case"EISDIR":await b(j);break;case"ENOENT":await y($);break;default:throw o}w(j,e)}))}}function onPushLogger({file:o,users:s,minLength:t,error:c}){c?console.log(`error "${e.bold(c.message)}" in ${e.bold(o)}`):console.log(`pushed ${e.bold(o)} to ${s.map((o=>e.bold(E.get(o)))).join(", ")} | ${e.bold(String(t))} chars | ${e.bold(`${n(C.hackmudPath,s[0],"scripts",a(o,i(o)))}.js`)}`)}(async()=>{if(v.get("version")||v.get("v"))version();else if(v.get("help")||v.get("h"))help();else{switch(P[0]){case"push":{const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const o=P[1];if(!o){console.error("specify the directory to watch"),help();break}const{push:s}=await import("../push.js"),t=e.hackmudPath,n=P.slice(2);n.length||n.push("*.*"),v.has("skip-minify")&&v.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names");(await s(o,t,{scripts:n,onPush:onPushLogger,minify:!v.get("skip-minify"),mangleNames:Boolean(v.get("mangle-names"))})).length||console.warn("couldn't find any scripts to push"),updateConfig()}break;case"dev":case"watch":{var s;if(!P[1]){console.error("specify the directory to watch"),help();break}const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const{watch:o}=await import("../watch.js"),t=P.slice(2);t.length||t.push("*.*"),v.has("skip-minify")&&v.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names"),o(P[1],e.hackmudPath,{scripts:t,onPush:onPushLogger,typeDeclarationPath:null===(s=v.get("type-declaration-path")||v.get("type-declaration")||v.get("dts")||v.get("gen-types"))||void 0===s?void 0:s.toString(),minify:!v.get("skip-minify"),mangleNames:Boolean(v.get("mangle-names")),onReady:()=>console.log("watching")})}break;case"pull":{const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const o=P[1];if(!o){help();break}const s=P[2]||".",t=e.hackmudPath;try{await d(s,t,o)}catch{console.log("something went wrong, did you forget to #down the script?")}}break;case"sync-macros":{const{hackmudPath:e}=await getConfig();if(!e){console.log("you need to set hackmudPath in config before you can use this command");break}const{macrosSynced:o,usersSynced:s}=await p(e);console.log(`synced ${o} macros to ${s} users`)}break;case"generate-type-declaration":case"gen-type-declaration":case"gen-dts":case"gen-types":{const o=n(P[1]||"."),s=h(o,(await getConfig()).hackmudPath);let t=n(P[2]||"./player.d.ts");try{await w(t,s)}catch(e){if(m(e instanceof Error),"EISDIR"!=e.code)throw e;t=n(t,"player.d.ts"),await w(t,s)}console.log(`wrote type declaration to ${e.bold(t)}`)}break;case"config":switch(P[1]){case"get":P[2]?console.log(exploreObject(await getConfig(),P[2].split("."))):console.log(await getConfig());break;case"delete":if(P[2]){var t;const e=P[2].split("."),o=e.pop();if(!e.length){help();break}const s=await getConfig();null===(t=exploreObject(s,e))||void 0===t||delete t[o],console.log(s)}else console.log("Usage:\nhsm config delete <key>");break;case"set":if(P[2]&&P[3]){const e=P[2].split(".");if(!e.length){help();break}const o=e.pop(),s=await getConfig();if(e.length||"hackmudPath"!=o){let t=s;for(const o of e)"object"==typeof t[o]||(t[o]={}),t=t[o];t[o]=P[3]}else s.hackmudPath=n(P[3]);console.log(s)}else console.log("Usage:\nhsm config set <key> <value>");break;default:P[1]&&console.log("unknown command"),help()}break;case"help":case"h":help();break;case"version":case"v":version();break;case"golf":case"minify":{const s=P[1];if(!s){console.log(`Target required\nUsage: ${a(process.argv[1])} ${P[0]} <target> [output]`);break}const t=i(s);if(!l.includes(t)){console.log(`Unsupported file extension "${e.bold(t)}"\nSupported extensions are "${l.map((o=>e.bold(o))).join('", "')}"`);break}v.get("watch")?o(s,{awaitWriteFinish:{stabilityThreshold:100}}).on("ready",(()=>console.log(`watching ${s}`))).on("change",(()=>golfFile(s,t))):await golfFile(s,t)}break;default:P[0]&&console.log("unknown command"),help()}updateConfig()}async function golfFile(o,s){const{processScript:t}=await import("../processScript/index.js");await k(o,{encoding:"utf-8"}).then((async i=>{const l=a(o,s),g=l.endsWith(".src"),h=g?l.slice(0,-4):l;let m="UNKNOWN";"scripts"==a(n(o,".."))&&"hackmud"==a(n(o,"../../.."))&&(m=a(n(o,"../..")));const p=!v.get("skip-minify"),d=Boolean(v.get("mangle-names"));!p&&d&&console.warn("warning: `--mangle-names` has no effect while `--skip-minify` is active");const k=performance.now(),{script:b,warnings:w}=await t(i,{minify:p,scriptUser:m,scriptName:h,filePath:o,mangleNames:d}),y=performance.now()-k;for(const{message:o,line:s}of w)console.log(`warning "${e.bold(o)}" on line ${e.bold(String(s))}`);let $;$=P[2]?P[2]:n(c(o),g?`${h}.js`:".js"==s?`${l}.min.js`:`${l}.js`);const j=u(b);await f($,b).catch((async e=>{if(!P[2]||"EISDIR"!=e.code)throw e;$=n($,`${a(o,s)}.js`),await f($,b)})).then((()=>console.log(`wrote ${e.bold(j)} chars to ${e.bold(r(".",$))} | took ${Math.round(100*y)/100}ms`)),(e=>console.log(e.message)))}),(e=>console.log(e.message)))}})();
@@ -0,0 +1,2 @@
1
+ export declare function generateTypeDeclaration(sourceDirectory: string, hackmudPath?: string): Promise<string>;
2
+ export default generateTypeDeclaration;
@@ -0,0 +1 @@
1
+ import e from"fs";import{basename as t,resolve as n}from"path";const{readdir:s}=e.promises;async function generateTypeDeclaration(e,a){const i=new Set;if(a)for(const e of await s(a,{withFileTypes:!0}))e.isFile()&&e.name.endsWith(".key")&&i.add(t(e.name,".key"));const r=[],o=[],f={},c={};await Promise.all((await s(e,{withFileTypes:!0})).map((async a=>{if(a.isFile())a.name.endsWith(".ts")?a.name.endsWith(".d.ts")||r.push(t(a.name,".ts")):a.name.endsWith(".js")&&o.push(t(a.name,".js"));else if(a.isDirectory()){const r=[],o=[];f[a.name]=r,c[a.name]=o,i.add(a.name);for(const i of await s(n(e,a.name),{withFileTypes:!0}))i.isFile()&&(i.name.endsWith(".ts")?a.name.endsWith(".d.ts")||r.push(t(i.name,".ts")):i.name.endsWith(".js")&&o.push(t(i.name,".js")))}}))),e=n(e);let l="";for(const t of r)l+=`type $${t}$ = typeof import("${e}/${t}").default\n`;l+="\n";for(const t in f){const n=f[t];for(const s of n)l+=`type $${t}$${s}$ = typeof import("${e}/${t}/${s}").default\n`}l+="\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)l+=`\t${e}: Subscript<$${e}$>\n`;for(const e of o)l+=`\t${e}: (...args: any) => any\n`;l+="}\n\ninterface PlayerFullsec {";let p=!0;for(const e of i){const t=f[e],n=c[e];if(t&&t.length||n&&n.length){if(p=!0,l+=`\n\t${e}: WildFullsec & {\n`,t)for(const n of t)l+=`\t\t${n}: Subscript<$${e}$${n}$>\n`;if(n)for(const e of n)l+=`\t\t${e}: (...args: any) => any\n`;l+="\t}"}else p&&(l+="\n",p=!1),l+=`\t${e}: WildFullsec`;l+="\n"}return l+="}\n",l}export{generateTypeDeclaration as default,generateTypeDeclaration};
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { supportedExtensions } from "./constants.json";
2
- export { generateTypings } from "./generateTypings";
2
+ export { generateTypeDeclaration } from "./generateTypeDeclaration";
3
3
  export { processScript } from "./processScript";
4
4
  export { pull } from "./pull";
5
5
  export { push } from "./push";
package/index.js CHANGED
@@ -1 +1 @@
1
- export{s as supportedExtensions}from"./constants-9bb78688.js";export{generateTypings}from"./generateTypings.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";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-1556d989.js";import"./spliceString-2c6f214f.js";import"./countHackmudCharacters-1e122984.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"import-meta-resolve";import"./processScript/transform.js";import"./writeFilePersistent-72dc81a3.js";import"chokidar";
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";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-1556d989.js";import"./spliceString-2c6f214f.js";import"./countHackmudCharacters-1e122984.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"import-meta-resolve";import"./processScript/transform.js";import"./writeFilePersistent-72dc81a3.js";import"chokidar";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hackmud-script-manager",
3
- "version": "0.16.0-8448068",
3
+ "version": "0.16.1",
4
4
  "description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
5
5
  "keywords": [
6
6
  "api",
@@ -81,7 +81,7 @@
81
81
  "eslint-plugin-eslint-comments": "^3.2.0",
82
82
  "eslint-plugin-optimize-regex": "^1.2.1",
83
83
  "eslint-plugin-regexp": "^1.5.1",
84
- "eslint-plugin-unicorn": "^40.1.0",
84
+ "eslint-plugin-unicorn": "^41.0.0",
85
85
  "eslint-plugin-write-good-comments": "^0.1.3",
86
86
  "latest-version": "^6.0.0",
87
87
  "rollup-plugin-preserve-shebang": "^1.0.1",
@@ -103,7 +103,7 @@
103
103
  "require": "./index.cjs"
104
104
  },
105
105
  "./*": "./*",
106
- "./generateTypings": "./generateTypings.js",
106
+ "./generateTypeDeclaration": "./generateTypeDeclaration.js",
107
107
  "./index": "./index.js",
108
108
  "./pull": "./pull.js",
109
109
  "./push": "./push.js",
package/push.js CHANGED
@@ -1 +1 @@
1
- import e from"fs";import{resolve as i,extname as r,basename as t}from"path";import{s as a}from"./constants-9bb78688.js";import{processScript as s}from"./processScript/index.js";import{D as o,w as p}from"./writeFilePersistent-72dc81a3.js";import{c as n}from"./countHackmudCharacters-1e122984.js";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-1556d989.js";import"./spliceString-2c6f214f.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"import-meta-resolve";import"./processScript/transform.js";const{readFile:l,readdir:m}=e.promises;async function push(e,c,{scripts:f=["*.*"],onPush:g=(()=>{}),minify:u=!0,mangleNames:b=!1}={}){const d=new o((e=>new Set)),w=new Set,h=new Set;let $=!1;for(const e of f){const[i,r]=e.split(".");i&&"*"!=i?r&&"*"!=r?d.get(i).add(r):w.add(i):r&&"*"!=r?h.add(r):$=!0}const y=new o((e=>new Set)),S=[],j=new o((e=>new Set));let P;if(h.size||$){const t=await m(i(c),{withFileTypes:!0}),a=new Set([...(P=await m(i(e),{withFileTypes:!0})).filter((e=>e.isDirectory())).map((e=>e.name)),...t.filter((e=>e.isDirectory())).map((e=>e.name)),...t.filter((e=>e.isFile()&&".key"==r(e.name))).map((e=>e.name.slice(0,-4))),...d.keys(),...w]);if($)for(const e of a)w.add(e);else for(const e of a){const i=d.get(e);for(const e of h)i.add(e)}}return await Promise.all([...w].map((async o=>{await m(i(e,o),{withFileTypes:!0}).then((async m=>{await Promise.all(m.map((async m=>{const f=r(m.name);if(m.isFile()&&a.includes(f)){const r=t(m.name,f),a=i(e,o,m.name),{script:d}=await s(await l(a,{encoding:"utf-8"}),{minify:u,scriptUser:o,scriptName:r,filePath:a,mangleNames:b}),w={file:`${o}/${m.name}`,users:[o],minLength:n(d),error:void 0};j.get(o).add(r),S.push(w),await p(i(c,o,`scripts/${r}.js`),d),g(w)}})))}),(e=>{if("ENOENT"!=e.code)throw e}))}))),await Promise.all([...d].map((async([r,t])=>{w.has(r)||await Promise.all([...t].map((async t=>{let o,m,f;for(const s of a)try{m=`${t}${s}`,o=await l(f=i(e,r,m),{encoding:"utf-8"});break}catch{}if(o){const{script:e}=await s(o,{minify:u,scriptUser:r,scriptName:t,filePath:f,mangleNames:b}),a={file:`${r}/${m}`,users:[r],minLength:n(e),error:void 0};S.push(a),await p(i(c,r,"scripts",`${t}.js`),e),g(a)}else y.get(t).add(r)})))}))),await(w.size?Promise.all((P||await m(i(e),{withFileTypes:!0})).map((async o=>{const m=r(o.name);if(!o.isFile()||!a.includes(m))return;const f=t(o.name,m),d=[...w,...y.get(f)].filter((e=>!j.get(e).has(f)));if(!d.length)return;const h=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),$=i(e,o.name),{script:P}=await s(await l($,{encoding:"utf-8"}),{minify:u,scriptUser:!0,scriptName:f,uniqueID:h,filePath:$,mangleNames:b}),N={file:o.name,users:d,minLength:n(P),error:void 0};await Promise.all(d.map((e=>p(i(c,e,`scripts/${f}.js`),P.replace(new RegExp(`\\$${h}\\$SCRIPT_USER\\$`,"g"),e).replace(new RegExp(`\\$${h}\\$FULL_SCRIPT_NAME\\$`,"g"),`${e}.${f}`))))),S.push(N),g(N)}))):Promise.all([...y].map((async([r,t])=>{let o,m,f;for(const t of a)try{m=`${r}${t}`,o=await l(f=i(e,m),{encoding:"utf-8"});break}catch{}if(o){const e=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),{script:a}=await s(o,{minify:u,scriptUser:!0,scriptName:r,uniqueID:e,filePath:f,mangleNames:b}),l={file:m,users:[...t],minLength:n(a),error:void 0};await Promise.all([...t].map((t=>p(i(c,t,`scripts/${r}.js`),a.replace(new RegExp(`\\$${e}\\$SCRIPT_USER\\$`,"g"),t).replace(new RegExp(`\\$${e}\\$FULL_SCRIPT_NAME\\$`,"g"),`${t}.${r}`))))),S.push(l),g(l)}})))),S}export{push as default,push};
1
+ import e from"fs";import{resolve as i,extname as t,basename as r}from"path";import{s as a}from"./constants-9bb78688.js";import{processScript as s}from"./processScript/index.js";import{D as o,w as p}from"./writeFilePersistent-72dc81a3.js";import{c as n}from"./countHackmudCharacters-1e122984.js";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-1556d989.js";import"./spliceString-2c6f214f.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"import-meta-resolve";import"./processScript/transform.js";const{readFile:l,readdir:m}=e.promises;async function push(e,c,{scripts:f=["*.*"],onPush:g=(()=>{}),minify:u=!0,mangleNames:d=!1}={}){const b=new o((e=>new Set)),w=new Set,h=new Set;let $=!1;for(const e of f){const[i,t]=e.split(".");i&&"*"!=i?t&&"*"!=t?b.get(i).add(t):w.add(i):t&&"*"!=t?h.add(t):$=!0}const y=new o((e=>new Set)),S=[],j=new o((e=>new Set));let P;if(h.size||$){const t=await m(i(c),{withFileTypes:!0}),r=new Set([...(P=await m(i(e),{withFileTypes:!0})).filter((e=>e.isDirectory())).map((e=>e.name)),...t.filter((e=>e.isDirectory())).map((e=>e.name)),...t.filter((e=>e.isFile()&&e.name.endsWith(".key"))).map((e=>e.name.slice(0,-4))),...b.keys(),...w]);if($)for(const e of r)w.add(e);else for(const e of r){const i=b.get(e);for(const e of h)i.add(e)}}return await Promise.all([...w].map((async o=>{await m(i(e,o),{withFileTypes:!0}).then((async m=>{await Promise.all(m.map((async m=>{if(m.name.endsWith(".d.ts"))return;const f=t(m.name);if(m.isFile()&&a.includes(f)){const t=r(m.name,f),a=i(e,o,m.name),{script:b}=await s(await l(a,{encoding:"utf-8"}),{minify:u,scriptUser:o,scriptName:t,filePath:a,mangleNames:d}),w={file:`${o}/${m.name}`,users:[o],minLength:n(b),error:void 0};j.get(o).add(t),S.push(w),await p(i(c,o,`scripts/${t}.js`),b),g(w)}})))}),(e=>{if("ENOENT"!=e.code)throw e}))}))),await Promise.all([...b].map((async([t,r])=>{w.has(t)||await Promise.all([...r].map((async r=>{let o,m,f;for(const s of a)try{m=`${r}${s}`,o=await l(f=i(e,t,m),{encoding:"utf-8"});break}catch{}if(o){const{script:e}=await s(o,{minify:u,scriptUser:t,scriptName:r,filePath:f,mangleNames:d}),a={file:`${t}/${m}`,users:[t],minLength:n(e),error:void 0};S.push(a),await p(i(c,t,"scripts",`${r}.js`),e),g(a)}else y.get(r).add(t)})))}))),await(w.size?Promise.all((P||await m(i(e),{withFileTypes:!0})).map((async o=>{if(o.name.endsWith(".d.ts"))return;const m=t(o.name);if(!o.isFile()||!a.includes(m))return;const f=r(o.name,m),b=[...w,...y.get(f)].filter((e=>!j.get(e).has(f)));if(!b.length)return;const h=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),$=i(e,o.name),{script:P}=await s(await l($,{encoding:"utf-8"}),{minify:u,scriptUser:!0,scriptName:f,uniqueID:h,filePath:$,mangleNames:d}),N={file:o.name,users:b,minLength:n(P),error:void 0};await Promise.all(b.map((e=>p(i(c,e,`scripts/${f}.js`),P.replace(new RegExp(`\\$${h}\\$SCRIPT_USER\\$`,"g"),e).replace(new RegExp(`\\$${h}\\$FULL_SCRIPT_NAME\\$`,"g"),`${e}.${f}`))))),S.push(N),g(N)}))):Promise.all([...y].map((async([t,r])=>{let o,m,f;for(const r of a)try{m=`${t}${r}`,o=await l(f=i(e,m),{encoding:"utf-8"});break}catch{}if(o){const e=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),{script:a}=await s(o,{minify:u,scriptUser:!0,scriptName:t,uniqueID:e,filePath:f,mangleNames:d}),l={file:m,users:[...r],minLength:n(a),error:void 0};await Promise.all([...r].map((r=>p(i(c,r,`scripts/${t}.js`),a.replace(new RegExp(`\\$${e}\\$SCRIPT_USER\\$`,"g"),r).replace(new RegExp(`\\$${e}\\$FULL_SCRIPT_NAME\\$`,"g"),`${r}.${t}`))))),S.push(l),g(l)}})))),S}export{push as default,push};
package/watch.d.ts CHANGED
@@ -18,5 +18,5 @@ export declare type WatchOptions = PushOptions & {
18
18
  * @param scripts to push from (pushes from all if empty)
19
19
  * @param onPush function that's called on each script push
20
20
  */
21
- export declare function watch(sourceDirectory: string, hackmudDirectory: string, { scripts, onPush, minify, mangleNames, typeDeclarationPath, onReady }?: LaxPartial<WatchOptions>): void;
21
+ export declare function watch(sourceDirectory: string, hackmudDirectory: string, { scripts, onPush, minify, mangleNames, typeDeclarationPath: typeDeclarationPath_, onReady }?: LaxPartial<WatchOptions>): Promise<void>;
22
22
  export default watch;
package/watch.js CHANGED
@@ -1 +1 @@
1
- import{watch as r}from"chokidar";import o from"fs";import{extname as t,basename as e,resolve as i}from"path";import{s}from"./constants-9bb78688.js";import{generateTypings as a}from"./generateTypings.js";import{processScript as n}from"./processScript/index.js";import{D as p,w as l}from"./writeFilePersistent-72dc81a3.js";import{a as c}from"./assert-1556d989.js";import{c as m}from"./countHackmudCharacters-1e122984.js";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"./spliceString-2c6f214f.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"import-meta-resolve";import"./processScript/transform.js";const{readFile:f,readdir:u}=o.promises;function watch(o,d,{scripts:g=["*.*"],onPush:h,minify:b=!0,mangleNames:w=!1,typeDeclarationPath:y,onReady:j}={}){if(!g.length)throw new Error("scripts option was an empty array");const S=new p((r=>new Set)),$=new Set,v=new Set;let F=!1;for(const r of g){const[o,t]=r.split(".");o&&"*"!=o?t&&"*"!=t?S.get(t).add(o):$.add(o):t&&"*"!=t?v.add(t):F=!0}const P=r("",{depth:1,cwd:o,awaitWriteFinish:{stabilityThreshold:100}}).on("change",(async r=>{const a=t(r);if(!s.includes(a))return;const g=e(r,a);if(r==e(r)){if(!(F||$.size||v.has(g)||S.has(g)))return;const a=new p((r=>[]));await Promise.all((await u(o,{withFileTypes:!0})).map((async r=>{if(r.isDirectory())for(const n of await u(i(o,r.name),{withFileTypes:!0})){if(!n.isFile())continue;const o=t(n.name);s.includes(o)&&a.get(e(n.name,o)).push(r.name)}})));const y=new Set;if(F||v.has(g)){for(const r of await u(i(o),{withFileTypes:!0}))r.isDirectory()&&y.add(r.name);for(const r of await u(i(d),{withFileTypes:!0}))r.isDirectory()?y.add(r.name):r.isFile()&&r.name.endsWith(".key")&&y.add(r.name.slice(0,-4));for(const r of S.values())for(const o of r)y.add(o)}for(const r of $)y.add(r);for(const r of S.get(g))y.add(r);const j=[...y].filter((r=>!a.has(r)));if(!j.length)return void(null==h||h({file:r,users:[],minLength:0,error:new Error("no users to push to")}));const P=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),E=i(o,r);let T;try{({script:T}=await n(await f(E,{encoding:"utf-8"}),{minify:b,scriptUser:!0,scriptName:g,uniqueID:P,filePath:E,mangleNames:w}))}catch(o){return c(o instanceof Error),void(null==h||h({file:r,users:[],minLength:0,error:o}))}return await Promise.all(j.map((r=>l(i(d,r,`scripts/${g}.js`),T.replace(new RegExp(`\\$${P}\\$SCRIPT_USER\\$`,"g"),r).replace(new RegExp(`\\$${P}\\$FULL_SCRIPT_NAME\\$`,"g"),`${r}.${g}`))))),void(null==h||h({file:r,users:j,minLength:m(T),error:void 0}))}const y=e(i(r,".."));if(!(F||$.size||v.has(g)||S.get(g).has(y)))return;const j=i(o,r),P=await f(j,{encoding:"utf-8"});let E;try{({script:E}=await n(P,{minify:b,scriptUser:y,scriptName:g,filePath:j,mangleNames:w}))}catch(o){return c(o instanceof Error),void(null==h||h({file:r,users:[],minLength:0,error:o}))}await l(i(d,y,"scripts",`${g}.js`),E),null==h||h({file:r,users:[y],minLength:m(E),error:void 0})}));j&&P.on("ready",j),y&&(a(o,i(o,y),d),P.on("add",(()=>a(o,i(o,y),d))),P.on("unlink",(()=>a(o,i(o,y),d))))}export{watch as default,watch};
1
+ import{watch as r}from"chokidar";import t from"fs";import{extname as e,basename as o,resolve as i}from"path";import{s as a}from"./constants-9bb78688.js";import{generateTypeDeclaration as s}from"./generateTypeDeclaration.js";import{processScript as n}from"./processScript/index.js";import{D as p,w as l}from"./writeFilePersistent-72dc81a3.js";import{a as c}from"./assert-1556d989.js";import{c as m}from"./countHackmudCharacters-1e122984.js";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"./spliceString-2c6f214f.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"import-meta-resolve";import"./processScript/transform.js";const{readFile:f,readdir:u,writeFile:d}=t.promises;async function watch(t,g,{scripts:h=["*.*"],onPush:w,minify:b=!0,mangleNames:y=!1,typeDeclarationPath:j,onReady:S}={}){if(!h.length)throw new Error("scripts option was an empty array");const D=new p((r=>new Set)),T=new Set,$=new Set;let v=!1;for(const r of h){const[t,e]=r.split(".");t&&"*"!=t?e&&"*"!=e?D.get(e).add(t):T.add(t):e&&"*"!=e?$.add(e):v=!0}const F=r(["*.ts","*.js"],{depth:1,cwd:t,awaitWriteFinish:{stabilityThreshold:100},ignored:"*.d.ts"}).on("change",(async r=>{if(r.endsWith(".d.ts"))return;const s=e(r);if(!a.includes(s))return;const d=o(r,s);if(r==o(r)){if(!(v||T.size||$.has(d)||D.has(d)))return;const s=new p((r=>[]));await Promise.all((await u(t,{withFileTypes:!0})).map((async r=>{if(r.isDirectory())for(const n of await u(i(t,r.name),{withFileTypes:!0})){if(!n.isFile())continue;const t=e(n.name);a.includes(t)&&s.get(o(n.name,t)).push(r.name)}})));const h=new Set;if(v||$.has(d)){for(const r of await u(i(t),{withFileTypes:!0}))r.isDirectory()&&h.add(r.name);for(const r of await u(i(g),{withFileTypes:!0}))r.isDirectory()?h.add(r.name):r.isFile()&&r.name.endsWith(".key")&&h.add(r.name.slice(0,-4));for(const r of D.values())for(const t of r)h.add(t)}for(const r of T)h.add(r);for(const r of D.get(d))h.add(r);const j=[...h].filter((r=>!s.has(r)));if(!j.length)return void(null==w||w({file:r,users:[],minLength:0,error:new Error("no users to push to")}));const S=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),F=i(t,r);let E;try{({script:E}=await n(await f(F,{encoding:"utf-8"}),{minify:b,scriptUser:!0,scriptName:d,uniqueID:S,filePath:F,mangleNames:y}))}catch(t){return c(t instanceof Error),void(null==w||w({file:r,users:[],minLength:0,error:t}))}return await Promise.all(j.map((r=>l(i(g,r,`scripts/${d}.js`),E.replace(new RegExp(`\\$${S}\\$SCRIPT_USER\\$`,"g"),r).replace(new RegExp(`\\$${S}\\$FULL_SCRIPT_NAME\\$`,"g"),`${r}.${d}`))))),void(null==w||w({file:r,users:j,minLength:m(E),error:void 0}))}const h=o(i(r,".."));if(!(v||T.size||$.has(d)||D.get(d).has(h)))return;const j=i(t,r),S=await f(j,{encoding:"utf-8"});let F;try{({script:F}=await n(S,{minify:b,scriptUser:h,scriptName:d,filePath:j,mangleNames:y}))}catch(t){return c(t instanceof Error),void(null==w||w({file:r,users:[],minLength:0,error:t}))}await l(i(g,h,"scripts",`${d}.js`),F),null==w||w({file:r,users:[h],minLength:m(F),error:void 0})}));if(S&&F.on("ready",S),!j)return;let E=j;async function writeTypeDeclaration(){const r=await s(t,g);try{await d(E,r)}catch(t){if(c(t instanceof Error),"EISDIR"!=t.code)throw t;E=i(E,"player.d.ts"),await d(E,r)}}await writeTypeDeclaration(),F.on("add",writeTypeDeclaration),F.on("unlink",writeTypeDeclaration)}export{watch as default,watch};
@@ -1,2 +0,0 @@
1
- export declare function generateTypings(sourceDirectory: string, target: string, hackmudPath?: string): Promise<void>;
2
- export default generateTypings;
@@ -1 +0,0 @@
1
- import e from"fs";import{extname as n,basename as t,resolve as s,relative as r}from"path";const{readdir:i,writeFile:a}=e.promises;async function generateTypings(e,o,f){const c=new Set;if(f)for(const e of await i(f,{withFileTypes:!0}))e.isFile()&&".key"==n(e.name)&&c.add(t(e.name,".key"));const l=[],m=[],p={},$={};await Promise.all((await i(e,{withFileTypes:!0})).map((async r=>{if(r.isFile())".ts"==n(r.name)?l.push(t(r.name,".ts")):".js"==n(r.name)&&m.push(t(r.name,".js"));else if(r.isDirectory()){const a=[],o=[];p[r.name]=a,$[r.name]=o,c.add(r.name);for(const f of await i(s(e,r.name),{withFileTypes:!0}))f.isFile()&&(".ts"==n(f.name)?a.push(t(f.name,".ts")):".js"==n(f.name)&&o.push(t(f.name,".js")))}}))),e=r(".",e);let y="";for(const n of l)y+=`import $${n}$ from "./${e}/${n}"\n`;y+="\n";for(const n in p){const t=p[n];for(const s of t)y+=`import $${n}$${s}$ from "./${e}/${n}/${s}"\n`}y+="\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 l)y+=`\t${e}: Subscript<typeof $${e}$>\n`;for(const e of m)y+=`\t${e}: (...args: any) => any\n`;y+="}\n\ninterface PlayerFullsec {";let u=!0;for(const e of c){const n=p[e],t=$[e];if(n&&n.length||t&&t.length){if(u=!0,y+=`\n\t${e}: WildFullsec & {\n`,n)for(const t of n)y+=`\t\t${t}: Subscript<typeof $${e}$${t}$>\n`;if(t)for(const e of t)y+=`\t\t${e}: (...args: any) => any\n`;y+="\t}"}else u&&(y+="\n",u=!1),y+=`\t${e}: WildFullsec`;y+="\n"}y+="}\n",await a(o,y)}export{generateTypings as default,generateTypings};