hackmud-script-manager 0.18.0-6155ebe → 0.18.0-7338c14

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 +3 -3
package/bin/hsm.js CHANGED
@@ -1 +1 @@
1
- import e from"chalk";import{watch as o}from"chokidar";import s from"fs";import{homedir as t}from"os";import{resolve as a,basename as n,extname as i,dirname as r,relative as l}from"path";import{s as c}from"../transform-eee68ce3.js";import{g as p}from"../generateTypeDeclaration-8dd67882.js";import{a as g}from"../assert-22a7ef8a.js";import{p as f}from"../pull-9b44f235.js";import"../push-3c3e0dfc.js";import{s as m}from"../syncMacros-0bf3ed91.js";import"../watch-e580a6f9.js";import{D as h,w as u}from"../writeFilePersistent-0476afeb.js";import{c as d}from"../minify-fba250e4.js";import"@babel/traverse";import"@babel/types";import"../shared-eace5bd5.js";import"../index-73f8f8aa.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"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"../postprocess-164b44d3.js";import"../preprocess-67d17495.js";import"import-meta-resolve";import"../spliceString-0e6b5d6d.js";import"acorn";import"terser";const{readFile:b,rmdir:w,writeFile:y,mkdir:k}=s.promises,j=a(t(),".config"),v=a(j,"hsm.json"),$=new Map,P=[];let C;const S=e.rgb(255,244,4),N=e.rgb(243,249,152),x=e.rgb(179,255,155),q=e.rgb(255,150,224),F=e.rgb(30,255,0),O=e.rgb(202,202,202),B=new h((e=>{let o=0;for(const s of e)o+=(o>>1)+o+"xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(s)+1;return[S,N,x,q,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])$.set(o.slice(2),t);else for(const e of o.slice(1))$.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(`${n(process.argv[1])} ${P[0]} <target> [output]`);break;default:console.log("hsm <push, watch, pull, config, golf>")}}function version(){console.log("0.18.0-6155ebe")}async function getConfig(){return C||(C=await b(v,{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 ${v}`),{}))))}function exploreObject(e,o,s=!1){for(const a of o){var t;e=s?"object"==typeof e[a]?e[a]:e[a]={}:null===(t=e)||void 0===t?void 0:t[a]}return e}function updateConfig(){if(C){const e=JSON.stringify(C,void 0,"\t");y(v,e).catch((async o=>{switch(o.code){case"EISDIR":await w(v);break;case"ENOENT":await k(j);break;default:throw o}y(v,e)}))}}function onPushLogger({file:o,users:s,minLength:t,error:r}){r?console.log(`error "${e.bold(r.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(`${a(C.hackmudPath,s[0],"scripts",n(o,i(o)))}.js`)}`)}(async()=>{if($.get("version")||$.get("v"))version();else if($.get("help")||$.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-3c3e0dfc.js"),t=e.hackmudPath,a=P.slice(2);a.length||a.push("*.*"),$.has("skip-minify")&&$.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names");let n=$.get("force-quine-cheats");null!=n&&"boolean"!=typeof n&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),n=Boolean(n));(await s(o,t,{scripts:a,onPush:onPushLogger,minify:!$.get("skip-minify"),mangleNames:Boolean($.get("mangle-names")),forceQuineCheats:n})).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-e580a6f9.js"),t=P.slice(2);t.length||t.push("*.*"),$.has("skip-minify")&&$.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names");let a=$.get("force-quine-cheats");null!=a&&"boolean"!=typeof a&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),a=Boolean(a)),o(P[1],e.hackmudPath,{scripts:t,onPush:onPushLogger,typeDeclarationPath:null===(s=$.get("type-declaration-path")||$.get("type-declaration")||$.get("dts")||$.get("gen-types"))||void 0===s?void 0:s.toString(),minify:!$.get("skip-minify"),mangleNames:Boolean($.get("mangle-names")),onReady:()=>console.log("watching"),forceQuineCheats:a})}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 f(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 m(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=a(P[1]||"."),s=p(o,(await getConfig()).hackmudPath);let t=a(P[2]||"./player.d.ts");try{await y(t,s)}catch(e){if(g(e instanceof Error),"EISDIR"!=e.code)throw e;t=a(t,"player.d.ts"),await y(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=a(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: ${n(process.argv[1])} ${P[0]} <target> [output]`);break}const t=i(s);if(!c.includes(t)){console.log(`Unsupported file extension "${e.bold(t)}"\nSupported extensions are "${c.map((o=>e.bold(o))).join('", "')}"`);break}$.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("../index-73f8f8aa.js");await b(o,{encoding:"utf-8"}).then((async i=>{const c=n(o,s),p=c.endsWith(".src"),g=p?c.slice(0,-4):c;let f="UNKNOWN";"scripts"==n(a(o,".."))&&"hackmud"==n(a(o,"../../.."))&&(f=n(a(o,"../..")));const m=!$.get("skip-minify"),h=Boolean($.get("mangle-names"));!m&&h&&console.warn("warning: `--mangle-names` has no effect while `--skip-minify` is active");let b=$.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:y,warnings:k}=await t(i,{minify:m,scriptUser:f,scriptName:g,filePath:o,mangleNames:h,forceQuineCheats:b}),j=performance.now()-w;for(const{message:o,line:s}of k)console.log(`warning "${e.bold(o)}" on line ${e.bold(String(s))}`);let v;v=P[2]?P[2]:a(r(o),p?`${g}.js`:".js"==s?`${c}.min.js`:`${c}.js`);const C=d(y);await u(v,y).catch((async e=>{if(!P[2]||"EISDIR"!=e.code)throw e;v=a(v,`${n(o,s)}.js`),await u(v,y)})).then((()=>console.log(`wrote ${e.bold(C)} chars to ${e.bold(l(".",v))} | took ${Math.round(100*j)/100}ms`)),(e=>console.log(e.message)))}),(e=>console.log(e.message)))}})();
1
+ import e from"chalk";import{watch as o}from"chokidar";import s from"fs";import{homedir as t}from"os";import{resolve as a,basename as n,extname as i,dirname as r,relative as l}from"path";import{s as c}from"../transform-eee68ce3.js";import{g as p}from"../generateTypeDeclaration-8dd67882.js";import{a as g}from"../assert-22a7ef8a.js";import{p as f}from"../pull-9b44f235.js";import"../push-3c3e0dfc.js";import{s as m}from"../syncMacros-0bf3ed91.js";import"../watch-e580a6f9.js";import{D as h,w as u}from"../writeFilePersistent-0476afeb.js";import{c as d}from"../minify-fba250e4.js";import"@babel/traverse";import"@babel/types";import"../shared-eace5bd5.js";import"../index-73f8f8aa.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"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"../postprocess-164b44d3.js";import"../preprocess-67d17495.js";import"import-meta-resolve";import"../spliceString-0e6b5d6d.js";import"acorn";import"terser";const{readFile:b,rmdir:w,writeFile:y,mkdir:k}=s.promises,j=a(t(),".config"),v=a(j,"hsm.json"),$=new Map,P=[];let C;const S=e.rgb(255,244,4),N=e.rgb(243,249,152),x=e.rgb(179,255,155),q=e.rgb(255,150,224),F=e.rgb(30,255,0),O=e.rgb(202,202,202),B=new h((e=>{let o=0;for(const s of e)o+=(o>>1)+o+"xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(s)+1;return[S,N,x,q,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])$.set(o.slice(2),t);else for(const e of o.slice(1))$.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(`${n(process.argv[1])} ${P[0]} <target> [output]`);break;default:console.log("hsm <push, watch, pull, config, golf>")}}function version(){console.log("0.18.0-7338c14")}async function getConfig(){return C||(C=await b(v,{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 ${v}`),{}))))}function exploreObject(e,o,s=!1){for(const a of o){var t;e=s?"object"==typeof e[a]?e[a]:e[a]={}:null===(t=e)||void 0===t?void 0:t[a]}return e}function updateConfig(){if(C){const e=JSON.stringify(C,void 0,"\t");y(v,e).catch((async o=>{switch(o.code){case"EISDIR":await w(v);break;case"ENOENT":await k(j);break;default:throw o}y(v,e)}))}}function onPushLogger({file:o,users:s,minLength:t,error:r}){r?console.log(`error "${e.bold(r.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(`${a(C.hackmudPath,s[0],"scripts",n(o,i(o)))}.js`)}`)}(async()=>{if($.get("version")||$.get("v"))version();else if($.get("help")||$.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-3c3e0dfc.js"),t=e.hackmudPath,a=P.slice(2);a.length||a.push("*.*"),$.has("skip-minify")&&$.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names");let n=$.get("force-quine-cheats");null!=n&&"boolean"!=typeof n&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),n=Boolean(n));(await s(o,t,{scripts:a,onPush:onPushLogger,minify:!$.get("skip-minify"),mangleNames:Boolean($.get("mangle-names")),forceQuineCheats:n})).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-e580a6f9.js"),t=P.slice(2);t.length||t.push("*.*"),$.has("skip-minify")&&$.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names");let a=$.get("force-quine-cheats");null!=a&&"boolean"!=typeof a&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),a=Boolean(a)),o(P[1],e.hackmudPath,{scripts:t,onPush:onPushLogger,typeDeclarationPath:null===(s=$.get("type-declaration-path")||$.get("type-declaration")||$.get("dts")||$.get("gen-types"))||void 0===s?void 0:s.toString(),minify:!$.get("skip-minify"),mangleNames:Boolean($.get("mangle-names")),onReady:()=>console.log("watching"),forceQuineCheats:a})}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 f(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 m(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=a(P[1]||"."),s=await p(o,(await getConfig()).hackmudPath);let t=a(P[2]||"./player.d.ts");try{await y(t,s)}catch(e){if(g(e instanceof Error),"EISDIR"!=e.code)throw e;t=a(t,"player.d.ts"),await y(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=a(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: ${n(process.argv[1])} ${P[0]} <target> [output]`);break}const t=i(s);if(!c.includes(t)){console.log(`Unsupported file extension "${e.bold(t)}"\nSupported extensions are "${c.map((o=>e.bold(o))).join('", "')}"`);break}$.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("../index-73f8f8aa.js");await b(o,{encoding:"utf-8"}).then((async i=>{const c=n(o,s),p=c.endsWith(".src"),g=p?c.slice(0,-4):c;let f="UNKNOWN";"scripts"==n(a(o,".."))&&"hackmud"==n(a(o,"../../.."))&&(f=n(a(o,"../..")));const m=!$.get("skip-minify"),h=Boolean($.get("mangle-names"));!m&&h&&console.warn("warning: `--mangle-names` has no effect while `--skip-minify` is active");let b=$.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:y,warnings:k}=await t(i,{minify:m,scriptUser:f,scriptName:g,filePath:o,mangleNames:h,forceQuineCheats:b}),j=performance.now()-w;for(const{message:o,line:s}of k)console.log(`warning "${e.bold(o)}" on line ${e.bold(String(s))}`);let v;v=P[2]?P[2]:a(r(o),p?`${g}.js`:".js"==s?`${c}.min.js`:`${c}.js`);const C=d(y);await u(v,y).catch((async e=>{if(!P[2]||"EISDIR"!=e.code)throw e;v=a(v,`${n(o,s)}.js`),await u(v,y)})).then((()=>console.log(`wrote ${e.bold(C)} chars to ${e.bold(l(".",v))} | took ${Math.round(100*j)/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.18.0-6155ebe",
3
+ "version": "0.18.0-7338c14",
4
4
  "description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
5
5
  "keywords": [
6
6
  "api",
@@ -73,7 +73,7 @@
73
73
  "@types/babel__core": "^7.1.16",
74
74
  "@types/babel__generator": "^7.6.4",
75
75
  "@types/babel__traverse": "^7.17.1",
76
- "@types/node": "^12.20.37",
76
+ "@types/node": "14",
77
77
  "@types/prettier": "^2.4.2",
78
78
  "@types/semver": "^7.3.9",
79
79
  "@typescript-eslint/eslint-plugin": "^5.8.0",
@@ -94,7 +94,7 @@
94
94
  "deasync": "^0.1.24"
95
95
  },
96
96
  "engines": {
97
- "node": "^12.20 || >=14"
97
+ "node": ">=14"
98
98
  },
99
99
  "types": "index.d.ts",
100
100
  "type": "module",