hackmud-script-manager 0.17.0-f0377d6 → 0.18.0-b0e9141

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/bin/hsm.js +1 -1
  2. package/package.json +1 -1
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 t}from"os";import{resolve as n,basename as a,extname as c,dirname as i,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{generateTypeDeclaration as h}from"../generateTypeDeclaration.js";import{a as m}from"../assert-1556d989.js";import{syncMacros as p}from"../syncMacros.js";import{pull as u}from"../pull.js";import{c as d}from"../countHackmudCharacters-1e122984.js";const{readFile:b,rmdir:w,writeFile:k,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),q=e.rgb(179,255,155),x=e.rgb(255,150,224),F=e.rgb(30,255,0),O=e.rgb(202,202,202),B=new g((e=>{let o=0;for(const s of e)o+=(o>>1)+o+"xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(s)+1;return[S,N,q,x,F,O][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.17.0-f0377d6")}async function getConfig(){return C||(C=await b(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");k(j,e).catch((async o=>{switch(o.code){case"EISDIR":await w(j);break;case"ENOENT":await y($);break;default:throw o}k(j,e)}))}}function onPushLogger({file:o,users:s,minLength:t,error:i}){i?console.log(`error "${e.bold(i.message)}" in ${e.bold(o)}`):console.log(`pushed ${e.bold(o)} to ${s.map((o=>e.bold(B.get(o)))).join(", ")} | ${e.bold(String(t))} chars | ${e.bold(`${n(C.hackmudPath,s[0],"scripts",a(o,c(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");let a=v.get("force-quine-cheats");null!=a&&"boolean"!=typeof a&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),a=Boolean(a));(await s(o,t,{scripts:n,onPush:onPushLogger,minify:!v.get("skip-minify"),mangleNames:Boolean(v.get("mangle-names")),forceQuineCheats:a})).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");let n=v.get("force-quine-cheats");null!=n&&"boolean"!=typeof n&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),n=Boolean(n)),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"),forceQuineCheats:n})}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 u(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 k(t,s)}catch(e){if(m(e instanceof Error),"EISDIR"!=e.code)throw e;t=n(t,"player.d.ts"),await k(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=c(s);if(!r.includes(t)){console.log(`Unsupported file extension "${e.bold(t)}"\nSupported extensions are "${r.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 b(o,{encoding:"utf-8"}).then((async c=>{const r=a(o,s),g=r.endsWith(".src"),h=g?r.slice(0,-4):r;let m="UNKNOWN";"scripts"==a(n(o,".."))&&"hackmud"==a(n(o,"../../.."))&&(m=a(n(o,"../..")));const p=!v.get("skip-minify"),u=Boolean(v.get("mangle-names"));!p&&u&&console.warn("warning: `--mangle-names` has no effect while `--skip-minify` is active");let b=v.get("force-quine-cheats");null!=b&&"boolean"!=typeof b&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),b=Boolean(b));const w=performance.now(),{script:k,warnings:y}=await t(c,{minify:p,scriptUser:m,scriptName:h,filePath:o,mangleNames:u,forceQuineCheats:b}),$=performance.now()-w;for(const{message:o,line:s}of y)console.log(`warning "${e.bold(o)}" on line ${e.bold(String(s))}`);let j;j=P[2]?P[2]:n(i(o),g?`${h}.js`:".js"==s?`${r}.min.js`:`${r}.js`);const C=d(k);await f(j,k).catch((async e=>{if(!P[2]||"EISDIR"!=e.code)throw e;j=n(j,`${a(o,s)}.js`),await f(j,k)})).then((()=>console.log(`wrote ${e.bold(C)} chars to ${e.bold(l(".",j))} | took ${Math.round(100*$)/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 c,dirname as i,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{generateTypeDeclaration as h}from"../generateTypeDeclaration.js";import{a as m}from"../assert-1556d989.js";import{syncMacros as p}from"../syncMacros.js";import{pull as u}from"../pull.js";import{c as d}from"../countHackmudCharacters-1e122984.js";const{readFile:b,rmdir:w,writeFile:k,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),q=e.rgb(179,255,155),x=e.rgb(255,150,224),F=e.rgb(30,255,0),O=e.rgb(202,202,202),B=new g((e=>{let o=0;for(const s of e)o+=(o>>1)+o+"xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(s)+1;return[S,N,q,x,F,O][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.18.0-b0e9141")}async function getConfig(){return C||(C=await b(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");k(j,e).catch((async o=>{switch(o.code){case"EISDIR":await w(j);break;case"ENOENT":await y($);break;default:throw o}k(j,e)}))}}function onPushLogger({file:o,users:s,minLength:t,error:i}){i?console.log(`error "${e.bold(i.message)}" in ${e.bold(o)}`):console.log(`pushed ${e.bold(o)} to ${s.map((o=>e.bold(B.get(o)))).join(", ")} | ${e.bold(String(t))} chars | ${e.bold(`${n(C.hackmudPath,s[0],"scripts",a(o,c(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");let a=v.get("force-quine-cheats");null!=a&&"boolean"!=typeof a&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),a=Boolean(a));(await s(o,t,{scripts:n,onPush:onPushLogger,minify:!v.get("skip-minify"),mangleNames:Boolean(v.get("mangle-names")),forceQuineCheats:a})).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");let n=v.get("force-quine-cheats");null!=n&&"boolean"!=typeof n&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),n=Boolean(n)),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"),forceQuineCheats:n})}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 u(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 k(t,s)}catch(e){if(m(e instanceof Error),"EISDIR"!=e.code)throw e;t=n(t,"player.d.ts"),await k(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=c(s);if(!r.includes(t)){console.log(`Unsupported file extension "${e.bold(t)}"\nSupported extensions are "${r.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 b(o,{encoding:"utf-8"}).then((async c=>{const r=a(o,s),g=r.endsWith(".src"),h=g?r.slice(0,-4):r;let m="UNKNOWN";"scripts"==a(n(o,".."))&&"hackmud"==a(n(o,"../../.."))&&(m=a(n(o,"../..")));const p=!v.get("skip-minify"),u=Boolean(v.get("mangle-names"));!p&&u&&console.warn("warning: `--mangle-names` has no effect while `--skip-minify` is active");let b=v.get("force-quine-cheats");null!=b&&"boolean"!=typeof b&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),b=Boolean(b));const w=performance.now(),{script:k,warnings:y}=await t(c,{minify:p,scriptUser:m,scriptName:h,filePath:o,mangleNames:u,forceQuineCheats:b}),$=performance.now()-w;for(const{message:o,line:s}of y)console.log(`warning "${e.bold(o)}" on line ${e.bold(String(s))}`);let j;j=P[2]?P[2]:n(i(o),g?`${h}.js`:".js"==s?`${r}.min.js`:`${r}.js`);const C=d(k);await f(j,k).catch((async e=>{if(!P[2]||"EISDIR"!=e.code)throw e;j=n(j,`${a(o,s)}.js`),await f(j,k)})).then((()=>console.log(`wrote ${e.bold(C)} chars to ${e.bold(l(".",j))} | took ${Math.round(100*$)/100}ms`)),(e=>console.log(e.message)))}),(e=>console.log(e.message)))}})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hackmud-script-manager",
3
- "version": "0.17.0-f0377d6",
3
+ "version": "0.18.0-b0e9141",
4
4
  "description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
5
5
  "keywords": [
6
6
  "api",