hackmud-script-manager 0.16.0 → 0.17.0-df208a9
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +49 -3
- package/bin/hsm.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1,9 +1,55 @@
|
|
1
|
-
#
|
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
|
-
|
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 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.
|
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.17.0-df208a9")}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)))}})();
|
package/package.json
CHANGED