hackmud-script-manager 0.15.0 → 0.16.0-424d2ba

Sign up to get free protection for your applications and to get access to all the features.
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.15.0")}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{push:e}=await import("../push.js"),o=await getConfig();if(!o.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const s=v[1];if(!s){console.error("specify the directory to watch"),help();break}const n=o.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 e(s,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;const{watch:e}=await import("../watch.js");if(!v[1]){console.error("specify the directory to watch"),help();break}const o=await getConfig();if(!o.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const 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"),e(v[1],o.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 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 d}from"../countHackmudCharacters-1e122984.js";const{readFile:u,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-424d2ba")}async function getConfig(){return P||(P=await u($,{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 u(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"),u=Boolean(j.get("mangle-names"));!p&&u&&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:u}),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=d(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)))}})();
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-do-expressions";import"@babel/plugin-proposal-function-bind";import"@babel/plugin-proposal-function-sent";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-partial-application";import"@babel/plugin-proposal-pipeline-operator";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-proposal-record-and-tuple";import"@babel/plugin-proposal-throw-expressions";import"@babel/plugin-transform-exponentiation-operator";import"@babel/plugin-transform-typescript";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{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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hackmud-script-manager",
3
- "version": "0.15.0",
3
+ "version": "0.16.0-424d2ba",
4
4
  "description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
5
5
  "keywords": [
6
6
  "api",
@@ -1 +1 @@
1
- import e from"@babel/generator";import{parse as r}from"@babel/parser";import o from"@babel/plugin-proposal-class-properties";import t from"@babel/plugin-proposal-class-static-block";import a from"@babel/plugin-proposal-decorators";import s from"@babel/plugin-proposal-do-expressions";import p from"@babel/plugin-proposal-function-bind";import l from"@babel/plugin-proposal-function-sent";import i from"@babel/plugin-proposal-json-strings";import n from"@babel/plugin-proposal-logical-assignment-operators";import m from"@babel/plugin-proposal-nullish-coalescing-operator";import c from"@babel/plugin-proposal-numeric-separator";import f from"@babel/plugin-proposal-object-rest-spread";import u from"@babel/plugin-proposal-optional-catch-binding";import d from"@babel/plugin-proposal-optional-chaining";import b from"@babel/plugin-proposal-partial-application";import g from"@babel/plugin-proposal-pipeline-operator";import y from"@babel/plugin-proposal-private-property-in-object";import h from"@babel/plugin-proposal-record-and-tuple";import w from"@babel/plugin-proposal-throw-expressions";import k from"@babel/plugin-transform-exponentiation-operator";import j from"@babel/plugin-transform-typescript";import x from"@babel/traverse";import v from"@babel/types";import S from"@rollup/plugin-babel";import E from"@rollup/plugin-commonjs";import L from"@rollup/plugin-json";import $ from"@rollup/plugin-node-resolve";import{resolve as C}from"path";import N from"prettier";import{rollup as I}from"rollup";import{s as _}from"../constants-9bb78688.js";import{minify as D}from"./minify.js";export{minify}from"./minify.js";import{postprocess as P}from"./postprocess.js";export{postprocess}from"./postprocess.js";import{preprocess as M}from"./preprocess.js";export{preprocess}from"./preprocess.js";import{includesIllegalString as O,replaceUnsafeStrings as U}from"./shared.js";import{transform as q}from"./transform.js";export{transform}from"./transform.js";import{a as V}from"../assert-1556d989.js";import"acorn";import"terser";import"../spliceString-2c6f214f.js";import"../countHackmudCharacters-1e122984.js";import"import-meta-resolve";const{default:W}=S,{format:H}=N,{default:T}=e,{default:F}=x;async function processScript(e,{minify:x=!0,uniqueID:S=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),scriptUser:N="UNKNOWN",scriptName:K="UNKNOWN",filePath:z,mangleNames:A=!1}={}){V(/^\w{11}$/.exec(S));const B=e;let G,R;const J=/^function\s*\(.+\/\/(?<autocomplete>.+)/.exec(e);if(J)e=`export default ${e}`,({autocomplete:G}=J.groups);else for(const r of e.split("\n")){const e=/^\s*\/\/(?<commentContent>.+)/.exec(r);if(!e)break;const o=e.groups.commentContent.trim();if(o.startsWith("@autocomplete "))G=o.slice(14).trimStart();else if(o.startsWith("@seclevel ")){const e=o.slice(10).trimStart().toLowerCase();switch(e){case"fullsec":case"full":case"fs":case"4s":case"f":case"4":R=4;break;case"highsec":case"high":case"hs":case"3s":case"h":case"3":R=3;break;case"midsec":case"mid":case"ms":case"2s":case"m":case"2":R=2;break;case"lowsec":case"low":case"ls":case"1s":case"l":case"1":R=1;break;case"nullsec":case"null":case"ns":case"0s":case"n":case"0":R=0;break;default:throw new Error(`unrecognised seclevel "${e}"`)}}}V(/^\w{11}$/.exec(S));const Q=z?C(z):`${S}.ts`,X=await I({input:Q,plugins:[{name:"hackmud-script-manager",transform:async e=>(await M(e,{uniqueID:S})).code},W({babelHelpers:"bundled",plugins:[[j.default,{allowDeclareFields:!0,optimizeConstEnums:!0}],[a.default,{decoratorsBeforeExport:!0}],[s.default],[p.default],[l.default],[b.default],[g.default,{proposal:"hack",topicToken:"%"}],[w.default],[h.default,{syntaxType:"hash",importPolyfill:!0}],[o.default],[t.default],[y.default],[n.default],[c.default],[m.default],[d.default],[u.default],[i.default],[f.default],[k.default]],configFile:!1,extensions:_}),E(),$({extensions:_}),L()],treeshake:{moduleSideEffects:!1}}),Y=["NULLSEC","LOWSEC","MIDSEC","HIGHSEC","FULLSEC"];e=(await X.generate({})).output[0].code;const{file:Z,seclevel:ee}=q(r(e,{sourceType:"module"}),B,{uniqueID:S,scriptUser:N,scriptName:K});if(null!=R&&ee<R)throw new Error(`detected seclevel ${Y[ee]} is lower than stated seclevel ${Y[R]}`);if(e=T(Z).code,x?e=await D(Z,G,{uniqueID:S,mangleNames:A}):(F(Z,{MemberExpression({node:e}){e.computed||(V("Identifier"==e.property.type),"prototype"==e.property.name?(e.computed=!0,e.property=v.stringLiteral("prototype")):"__proto__"==e.property.name?(e.computed=!0,e.property=v.stringLiteral("__proto__")):O(e.property.name)&&(e.computed=!0,e.property=v.stringLiteral(U(S,e.property.name))))},VariableDeclarator(e){!function renameVariables(r){switch(r.type){case"Identifier":O(r.name)&&e.scope.rename(r.name,`$${Math.floor(Math.random()*2**52).toString(36).padStart(11,"0")}`);break;case"ObjectPattern":for(const e of r.properties)V("ObjectProperty"==e.type),renameVariables(e.value);break;case"ArrayPattern":for(const e of r.elements)e&&renameVariables(e);break;default:throw new Error(`unknown lValue type "${r.type}"`)}}(e.node.id)},ObjectProperty({node:e}){"Identifier"==e.key.type&&O(e.key.name)&&(e.key=v.stringLiteral(U(S,e.key.name)),e.shorthand=!1)},StringLiteral({node:e}){e.value=U(S,e.value)},TemplateLiteral({node:e}){for(const r of e.quasis)r.value.cooked?(r.value.cooked=U(S,r.value.cooked),r.value.raw=r.value.cooked.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"$\\{")):r.value.raw=U(S,r.value.raw)},RegExpLiteral(e){e.node.pattern=U(S,e.node.pattern),delete e.node.extra}}),e=H(T(Z,{comments:!1}).code,{parser:"babel",arrowParens:"avoid",semi:!1,trailingComma:"none"})),e=P(e,ee,S),O(e))throw new Error('you found a weird edge case where I wasn\'t able to replace illegal strings like "SC$", please report thx');return{script:e,warnings:[]}}export{processScript as default,processScript};
1
+ import e from"@babel/generator";import{parse as o}from"@babel/parser";import r from"@babel/plugin-proposal-class-properties";import t from"@babel/plugin-proposal-class-static-block";import a from"@babel/plugin-proposal-decorators";import p from"@babel/plugin-proposal-json-strings";import s from"@babel/plugin-proposal-logical-assignment-operators";import l from"@babel/plugin-proposal-nullish-coalescing-operator";import i from"@babel/plugin-proposal-numeric-separator";import n from"@babel/plugin-proposal-object-rest-spread";import m from"@babel/plugin-proposal-optional-catch-binding";import c from"@babel/plugin-proposal-optional-chaining";import u from"@babel/plugin-proposal-private-property-in-object";import f from"@babel/plugin-transform-exponentiation-operator";import d from"@babel/traverse";import b from"@babel/types";import g from"@rollup/plugin-babel";import h from"@rollup/plugin-commonjs";import y from"@rollup/plugin-json";import w from"@rollup/plugin-node-resolve";import{resolve as k}from"path";import x from"prettier";import{rollup as j}from"rollup";import{s as v}from"../constants-9bb78688.js";import{minify as S}from"./minify.js";export{minify}from"./minify.js";import{postprocess as E}from"./postprocess.js";export{postprocess}from"./postprocess.js";import{preprocess as C}from"./preprocess.js";export{preprocess}from"./preprocess.js";import{includesIllegalString as L,replaceUnsafeStrings as $}from"./shared.js";import{transform as N}from"./transform.js";export{transform}from"./transform.js";import{a as I}from"../assert-1556d989.js";import"acorn";import"terser";import"../spliceString-2c6f214f.js";import"../countHackmudCharacters-1e122984.js";import"import-meta-resolve";const{default:P}=g,{format:D}=x,{default:_}=e,{default:M}=d;async function processScript(e,{minify:d=!0,uniqueID:g=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),scriptUser:x="UNKNOWN",scriptName:O="UNKNOWN",filePath:T,mangleNames:U=!1}={}){I(/^\w{11}$/.exec(g));const W=e;let q,V;const F=/^function\s*\(.+\/\/(?<autocomplete>.+)/.exec(e);if(F)e=`export default ${e}`,({autocomplete:q}=F.groups);else for(const o of e.split("\n")){const e=/^\s*\/\/(?<commentContent>.+)/.exec(o);if(!e)break;const r=e.groups.commentContent.trim();if(r.startsWith("@autocomplete "))q=r.slice(14).trimStart();else if(r.startsWith("@seclevel ")){const e=r.slice(10).trimStart().toLowerCase();switch(e){case"fullsec":case"full":case"fs":case"4s":case"f":case"4":V=4;break;case"highsec":case"high":case"hs":case"3s":case"h":case"3":V=3;break;case"midsec":case"mid":case"ms":case"2s":case"m":case"2":V=2;break;case"lowsec":case"low":case"ls":case"1s":case"l":case"1":V=1;break;case"nullsec":case"null":case"ns":case"0s":case"n":case"0":V=0;break;default:throw new Error(`unrecognised seclevel "${e}"`)}}}I(/^\w{11}$/.exec(g));const H=[[a.default,{decoratorsBeforeExport:!0}],[r.default],[t.default],[u.default],[s.default],[i.default],[l.default],[c.default],[m.default],[p.default],[n.default],[f.default]];let z;if(T)if(z=k(T),T.endsWith(".ts"))H.push([(await import("@babel/plugin-transform-typescript")).default,{allowDeclareFields:!0,optimizeConstEnums:!0}]);else{const[e,o,r,t,a,p,s]=await Promise.all([import("@babel/plugin-proposal-do-expressions"),import("@babel/plugin-proposal-function-bind"),import("@babel/plugin-proposal-function-sent"),import("@babel/plugin-proposal-partial-application"),import("@babel/plugin-proposal-pipeline-operator"),import("@babel/plugin-proposal-throw-expressions"),import("@babel/plugin-proposal-record-and-tuple")]);H.push([e.default],[o.default],[r.default],[t.default],[a.default,{proposal:"hack",topicToken:"%"}],[p.default],[s.default,{syntaxType:"hash",importPolyfill:!0}])}else{z=`${g}.ts`;const[e,o,r,t,a,p,s,l]=await Promise.all([import("@babel/plugin-transform-typescript"),import("@babel/plugin-proposal-do-expressions"),import("@babel/plugin-proposal-function-bind"),import("@babel/plugin-proposal-function-sent"),import("@babel/plugin-proposal-partial-application"),import("@babel/plugin-proposal-pipeline-operator"),import("@babel/plugin-proposal-throw-expressions"),import("@babel/plugin-proposal-record-and-tuple")]);H.push([e.default,{allowDeclareFields:!0,optimizeConstEnums:!0}],[o.default],[r.default],[t.default],[a.default],[p.default,{proposal:"hack",topicToken:"%"}],[s.default],[l.default,{syntaxType:"hash",importPolyfill:!0}])}const K=await j({input:z,plugins:[{name:"hackmud-script-manager",transform:async e=>(await C(e,{uniqueID:g})).code},P({babelHelpers:"bundled",plugins:H,configFile:!1,extensions:v}),h(),w({extensions:v}),y()],treeshake:{moduleSideEffects:!1}}),A=["NULLSEC","LOWSEC","MIDSEC","HIGHSEC","FULLSEC"];e=(await K.generate({})).output[0].code;const{file:B,seclevel:G}=N(o(e,{sourceType:"module"}),W,{uniqueID:g,scriptUser:x,scriptName:O});if(null!=V&&G<V)throw new Error(`detected seclevel ${A[G]} is lower than stated seclevel ${A[V]}`);if(e=_(B).code,d?e=await S(B,q,{uniqueID:g,mangleNames:U}):(M(B,{MemberExpression({node:e}){e.computed||(I("Identifier"==e.property.type),"prototype"==e.property.name?(e.computed=!0,e.property=b.stringLiteral("prototype")):"__proto__"==e.property.name?(e.computed=!0,e.property=b.stringLiteral("__proto__")):L(e.property.name)&&(e.computed=!0,e.property=b.stringLiteral($(g,e.property.name))))},VariableDeclarator(e){!function renameVariables(o){switch(o.type){case"Identifier":L(o.name)&&e.scope.rename(o.name,`$${Math.floor(Math.random()*2**52).toString(36).padStart(11,"0")}`);break;case"ObjectPattern":for(const e of o.properties)I("ObjectProperty"==e.type),renameVariables(e.value);break;case"ArrayPattern":for(const e of o.elements)e&&renameVariables(e);break;default:throw new Error(`unknown lValue type "${o.type}"`)}}(e.node.id)},ObjectProperty({node:e}){"Identifier"==e.key.type&&L(e.key.name)&&(e.key=b.stringLiteral($(g,e.key.name)),e.shorthand=!1)},StringLiteral({node:e}){e.value=$(g,e.value)},TemplateLiteral({node:e}){for(const o of e.quasis)o.value.cooked?(o.value.cooked=$(g,o.value.cooked),o.value.raw=o.value.cooked.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"$\\{")):o.value.raw=$(g,o.value.raw)},RegExpLiteral(e){e.node.pattern=$(g,e.node.pattern),delete e.node.extra}}),e=D(_(B,{comments:!1}).code,{parser:"babel",arrowParens:"avoid",semi:!1,trailingComma:"none"})),e=E(e,G,g),L(e))throw new Error('you found a weird edge case where I wasn\'t able to replace illegal strings like "SC$", please report thx');return{script:e,warnings:[]}}export{processScript as default,processScript};
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 o}from"./processScript/index.js";import{D as p,w as s}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-do-expressions";import"@babel/plugin-proposal-function-bind";import"@babel/plugin-proposal-function-sent";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-partial-application";import"@babel/plugin-proposal-pipeline-operator";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-proposal-record-and-tuple";import"@babel/plugin-proposal-throw-expressions";import"@babel/plugin-transform-exponentiation-operator";import"@babel/plugin-transform-typescript";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:u=["*.*"],onPush:g=(()=>{}),minify:f=!0,mangleNames:b=!1}={}){const d=new p((e=>new Set)),w=new Set,h=new Set;let $=!1;for(const e of u){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 p((e=>new Set)),S=[],j=new p((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 p=>{await m(i(e,p),{withFileTypes:!0}).then((async m=>{await Promise.all(m.map((async m=>{const u=r(m.name);if(m.isFile()&&a.includes(u)){const r=t(m.name,u),a=i(e,p,m.name),{script:d}=await o(await l(a,{encoding:"utf-8"}),{minify:f,scriptUser:p,scriptName:r,filePath:a,mangleNames:b}),w={file:`${p}/${m.name}`,users:[p],minLength:n(d),error:void 0};j.get(p).add(r),S.push(w),await s(i(c,p,`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 p,m,u;for(const o of a)try{m=`${t}${o}`,p=await l(u=i(e,r,m),{encoding:"utf-8"});break}catch{}if(p){const{script:e}=await o(p,{minify:f,scriptUser:r,scriptName:t,filePath:u,mangleNames:b}),a={file:`${r}/${m}`,users:[r],minLength:n(e),error:void 0};S.push(a),await s(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 p=>{const m=r(p.name);if(!p.isFile()||!a.includes(m))return;const u=t(p.name,m),d=[...w,...y.get(u)].filter((e=>!j.get(e).has(u)));if(!d.length)return;const h=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),$=i(e,p.name),{script:P}=await o(await l($,{encoding:"utf-8"}),{minify:f,scriptUser:!0,scriptName:u,uniqueID:h,filePath:$,mangleNames:b}),N={file:p.name,users:d,minLength:n(P),error:void 0};await Promise.all(d.map((e=>s(i(c,e,`scripts/${u}.js`),P.replace(new RegExp(`\\$${h}\\$SCRIPT_USER\\$`,"g"),e).replace(new RegExp(`\\$${h}\\$FULL_SCRIPT_NAME\\$`,"g"),`${e}.${u}`))))),S.push(N),g(N)}))):Promise.all([...y].map((async([r,t])=>{let p,m,u;for(const t of a)try{m=`${r}${t}`,p=await l(u=i(e,m),{encoding:"utf-8"});break}catch{}if(p){const e=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),{script:a}=await o(p,{minify:f,scriptUser:!0,scriptName:r,uniqueID:e,filePath:u,mangleNames:b}),l={file:m,users:[...t],minLength:n(a),error:void 0};await Promise.all([...t].map((t=>s(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 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};
package/watch.js CHANGED
@@ -1 +1 @@
1
- import{watch as r}from"chokidar";import o from"fs";import{extname as i,basename as t,resolve as e}from"path";import{s}from"./constants-9bb78688.js";import{generateTypings as p}from"./generateTypings.js";import{processScript as a}from"./processScript/index.js";import{D as n,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-do-expressions";import"@babel/plugin-proposal-function-bind";import"@babel/plugin-proposal-function-sent";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-partial-application";import"@babel/plugin-proposal-pipeline-operator";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-proposal-record-and-tuple";import"@babel/plugin-proposal-throw-expressions";import"@babel/plugin-transform-exponentiation-operator";import"@babel/plugin-transform-typescript";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:u,readdir:f}=o.promises;function watch(o,b,{scripts:d=["*.*"],onPush:g,minify:h=!0,mangleNames:w=!1,typeDeclarationPath:y,onReady:j}={}){if(!d.length)throw new Error("scripts option was an empty array");const S=new n((r=>new Set)),$=new Set,v=new Set;let F=!1;for(const r of d){const[o,i]=r.split(".");o&&"*"!=o?i&&"*"!=i?S.get(i).add(o):$.add(o):i&&"*"!=i?v.add(i):F=!0}const P=r("",{depth:1,cwd:o,awaitWriteFinish:{stabilityThreshold:100}}).on("change",(async r=>{const p=i(r);if(!s.includes(p))return;const d=t(r,p);if(r==t(r)){if(!(F||$.size||v.has(d)||S.has(d)))return;const p=new n((r=>[]));await Promise.all((await f(o,{withFileTypes:!0})).map((async r=>{if(r.isDirectory())for(const a of await f(e(o,r.name),{withFileTypes:!0})){if(!a.isFile())continue;const o=i(a.name);s.includes(o)&&p.get(t(a.name,o)).push(r.name)}})));const y=new Set;if(F||v.has(d)){for(const r of await f(e(o),{withFileTypes:!0}))r.isDirectory()&&y.add(r.name);for(const r of await f(e(b),{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(d))y.add(r);const j=[...y].filter((r=>!p.has(r)));if(!j.length)return void(null==g||g({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=e(o,r);let T;try{({script:T}=await a(await u(E,{encoding:"utf-8"}),{minify:h,scriptUser:!0,scriptName:d,uniqueID:P,filePath:E,mangleNames:w}))}catch(o){return c(o instanceof Error),void(null==g||g({file:r,users:[],minLength:0,error:o}))}return await Promise.all(j.map((r=>l(e(b,r,`scripts/${d}.js`),T.replace(new RegExp(`\\$${P}\\$SCRIPT_USER\\$`,"g"),r).replace(new RegExp(`\\$${P}\\$FULL_SCRIPT_NAME\\$`,"g"),`${r}.${d}`))))),void(null==g||g({file:r,users:j,minLength:m(T),error:void 0}))}const y=t(e(r,".."));if(!(F||$.size||v.has(d)||S.get(d).has(y)))return;const j=e(o,r),P=await u(j,{encoding:"utf-8"});let E;try{({script:E}=await a(P,{minify:h,scriptUser:y,scriptName:d,filePath:j,mangleNames:w}))}catch(o){return c(o instanceof Error),void(null==g||g({file:r,users:[],minLength:0,error:o}))}await l(e(b,y,"scripts",`${d}.js`),E),null==g||g({file:r,users:[y],minLength:m(E),error:void 0})}));j&&P.on("ready",j),y&&(p(o,e(o,y),b),P.on("add",(()=>p(o,e(o,y),b))),P.on("unlink",(()=>p(o,e(o,y),b))))}export{watch as default,watch};
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};