hackmud-script-manager 0.15.0 → 0.17.0-3de4ad4
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/hsm.js +1 -1
- package/generateTypeDeclaration.d.ts +2 -0
- package/generateTypeDeclaration.js +1 -0
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +2 -2
- package/processScript/index.js +1 -1
- package/push.js +1 -1
- package/watch.d.ts +1 -1
- package/watch.js +1 -1
- package/generateTypings.d.ts +0 -2
- package/generateTypings.js +0 -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
|
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-3de4ad4")}async function getConfig(){return C||(C=await k(j,{encoding:"utf-8"}).then((e=>{let o;try{o=JSON.parse(e)}catch{return console.log("config file was corrupted, resetting"),{}}return o&&"object"==typeof o?o:(console.log("config file was corrupted, resetting"),{})}),(()=>(console.log(`creating config file at ${j}`),{}))))}function exploreObject(e,o,s=!1){for(const n of o){var t;e=s?"object"==typeof e[n]?e[n]:e[n]={}:null===(t=e)||void 0===t?void 0:t[n]}return e}function updateConfig(){if(C){const e=JSON.stringify(C,void 0,"\t");w(j,e).catch((async o=>{switch(o.code){case"EISDIR":await b(j);break;case"ENOENT":await y($);break;default:throw o}w(j,e)}))}}function onPushLogger({file:o,users:s,minLength:t,error:c}){c?console.log(`error "${e.bold(c.message)}" in ${e.bold(o)}`):console.log(`pushed ${e.bold(o)} to ${s.map((o=>e.bold(E.get(o)))).join(", ")} | ${e.bold(String(t))} chars | ${e.bold(`${n(C.hackmudPath,s[0],"scripts",a(o,i(o)))}.js`)}`)}(async()=>{if(v.get("version")||v.get("v"))version();else if(v.get("help")||v.get("h"))help();else{switch(P[0]){case"push":{const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const o=P[1];if(!o){console.error("specify the directory to watch"),help();break}const{push:s}=await import("../push.js"),t=e.hackmudPath,n=P.slice(2);n.length||n.push("*.*"),v.has("skip-minify")&&v.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names");(await s(o,t,{scripts:n,onPush:onPushLogger,minify:!v.get("skip-minify"),mangleNames:Boolean(v.get("mangle-names"))})).length||console.warn("couldn't find any scripts to push"),updateConfig()}break;case"dev":case"watch":{var s;if(!P[1]){console.error("specify the directory to watch"),help();break}const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const{watch:o}=await import("../watch.js"),t=P.slice(2);t.length||t.push("*.*"),v.has("skip-minify")&&v.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names"),o(P[1],e.hackmudPath,{scripts:t,onPush:onPushLogger,typeDeclarationPath:null===(s=v.get("type-declaration-path")||v.get("type-declaration")||v.get("dts")||v.get("gen-types"))||void 0===s?void 0:s.toString(),minify:!v.get("skip-minify"),mangleNames:Boolean(v.get("mangle-names")),onReady:()=>console.log("watching")})}break;case"pull":{const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const o=P[1];if(!o){help();break}const s=P[2]||".",t=e.hackmudPath;try{await d(s,t,o)}catch{console.log("something went wrong, did you forget to #down the script?")}}break;case"sync-macros":{const{hackmudPath:e}=await getConfig();if(!e){console.log("you need to set hackmudPath in config before you can use this command");break}const{macrosSynced:o,usersSynced:s}=await p(e);console.log(`synced ${o} macros to ${s} users`)}break;case"generate-type-declaration":case"gen-type-declaration":case"gen-dts":case"gen-types":{const o=n(P[1]||"."),s=h(o,(await getConfig()).hackmudPath);let t=n(P[2]||"./player.d.ts");try{await w(t,s)}catch(e){if(m(e instanceof Error),"EISDIR"!=e.code)throw e;t=n(t,"player.d.ts"),await w(t,s)}console.log(`wrote type declaration to ${e.bold(t)}`)}break;case"config":switch(P[1]){case"get":P[2]?console.log(exploreObject(await getConfig(),P[2].split("."))):console.log(await getConfig());break;case"delete":if(P[2]){var t;const e=P[2].split("."),o=e.pop();if(!e.length){help();break}const s=await getConfig();null===(t=exploreObject(s,e))||void 0===t||delete t[o],console.log(s)}else console.log("Usage:\nhsm config delete <key>");break;case"set":if(P[2]&&P[3]){const e=P[2].split(".");if(!e.length){help();break}const o=e.pop(),s=await getConfig();if(e.length||"hackmudPath"!=o){let t=s;for(const o of e)"object"==typeof t[o]||(t[o]={}),t=t[o];t[o]=P[3]}else s.hackmudPath=n(P[3]);console.log(s)}else console.log("Usage:\nhsm config set <key> <value>");break;default:P[1]&&console.log("unknown command"),help()}break;case"help":case"h":help();break;case"version":case"v":version();break;case"golf":case"minify":{const s=P[1];if(!s){console.log(`Target required\nUsage: ${a(process.argv[1])} ${P[0]} <target> [output]`);break}const t=i(s);if(!l.includes(t)){console.log(`Unsupported file extension "${e.bold(t)}"\nSupported extensions are "${l.map((o=>e.bold(o))).join('", "')}"`);break}v.get("watch")?o(s,{awaitWriteFinish:{stabilityThreshold:100}}).on("ready",(()=>console.log(`watching ${s}`))).on("change",(()=>golfFile(s,t))):await golfFile(s,t)}break;default:P[0]&&console.log("unknown command"),help()}updateConfig()}async function golfFile(o,s){const{processScript:t}=await import("../processScript/index.js");await k(o,{encoding:"utf-8"}).then((async i=>{const l=a(o,s),g=l.endsWith(".src"),h=g?l.slice(0,-4):l;let m="UNKNOWN";"scripts"==a(n(o,".."))&&"hackmud"==a(n(o,"../../.."))&&(m=a(n(o,"../..")));const p=!v.get("skip-minify"),d=Boolean(v.get("mangle-names"));!p&&d&&console.warn("warning: `--mangle-names` has no effect while `--skip-minify` is active");const k=performance.now(),{script:b,warnings:w}=await t(i,{minify:p,scriptUser:m,scriptName:h,filePath:o,mangleNames:d}),y=performance.now()-k;for(const{message:o,line:s}of w)console.log(`warning "${e.bold(o)}" on line ${e.bold(String(s))}`);let $;$=P[2]?P[2]:n(c(o),g?`${h}.js`:".js"==s?`${l}.min.js`:`${l}.js`);const j=u(b);await f($,b).catch((async e=>{if(!P[2]||"EISDIR"!=e.code)throw e;$=n($,`${a(o,s)}.js`),await f($,b)})).then((()=>console.log(`wrote ${e.bold(j)} chars to ${e.bold(r(".",$))} | took ${Math.round(100*y)/100}ms`)),(e=>console.log(e.message)))}),(e=>console.log(e.message)))}})();
|
@@ -0,0 +1 @@
|
|
1
|
+
import e from"fs";import{basename as t,resolve as n}from"path";const{readdir:s}=e.promises;async function generateTypeDeclaration(e,a){const i=new Set;if(a)for(const e of await s(a,{withFileTypes:!0}))e.isFile()&&e.name.endsWith(".key")&&i.add(t(e.name,".key"));const r=[],o=[],f={},c={};await Promise.all((await s(e,{withFileTypes:!0})).map((async a=>{if(a.isFile())a.name.endsWith(".ts")?a.name.endsWith(".d.ts")||r.push(t(a.name,".ts")):a.name.endsWith(".js")&&o.push(t(a.name,".js"));else if(a.isDirectory()){const r=[],o=[];f[a.name]=r,c[a.name]=o,i.add(a.name);for(const i of await s(n(e,a.name),{withFileTypes:!0}))i.isFile()&&(i.name.endsWith(".ts")?a.name.endsWith(".d.ts")||r.push(t(i.name,".ts")):i.name.endsWith(".js")&&o.push(t(i.name,".js")))}}))),e=n(e);let l="";for(const t of r)l+=`type $${t}$ = typeof import("${e}/${t}").default\n`;l+="\n";for(const t in f){const n=f[t];for(const s of n)l+=`type $${t}$${s}$ = typeof import("${e}/${t}/${s}").default\n`}l+="\ntype ArrayRemoveFirst<A> = A extends [ infer FirstItem, ...infer Rest ] ? Rest : never\n\ntype Subscript<T extends (...args: any) => any> =\n\t(...args: ArrayRemoveFirst<Parameters<T>>) => ReturnType<T> | ScriptFailure\n\ntype WildFullsec = Record<string, () => ScriptFailure> & {\n";for(const e of r)l+=`\t${e}: Subscript<$${e}$>\n`;for(const e of o)l+=`\t${e}: (...args: any) => any\n`;l+="}\n\ninterface PlayerFullsec {";let p=!0;for(const e of i){const t=f[e],n=c[e];if(t&&t.length||n&&n.length){if(p=!0,l+=`\n\t${e}: WildFullsec & {\n`,t)for(const n of t)l+=`\t\t${n}: Subscript<$${e}$${n}$>\n`;if(n)for(const e of n)l+=`\t\t${e}: (...args: any) => any\n`;l+="\t}"}else p&&(l+="\n",p=!1),l+=`\t${e}: WildFullsec`;l+="\n"}return l+="}\n",l}export{generateTypeDeclaration as default,generateTypeDeclaration};
|
package/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
export { supportedExtensions } from "./constants.json";
|
2
|
-
export {
|
2
|
+
export { generateTypeDeclaration } from "./generateTypeDeclaration";
|
3
3
|
export { processScript } from "./processScript";
|
4
4
|
export { pull } from "./pull";
|
5
5
|
export { push } from "./push";
|
package/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export{s as supportedExtensions}from"./constants-9bb78688.js";export{
|
1
|
+
export{s as supportedExtensions}from"./constants-9bb78688.js";export{generateTypeDeclaration}from"./generateTypeDeclaration.js";export{processScript}from"./processScript/index.js";export{pull}from"./pull.js";export{push}from"./push.js";export{syncMacros}from"./syncMacros.js";export{watch}from"./watch.js";import"fs";import"path";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-transform-exponentiation-operator";import"@babel/traverse";import"@babel/types";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"./processScript/minify.js";import"acorn";import"terser";import"./processScript/shared.js";import"./assert-1556d989.js";import"./spliceString-2c6f214f.js";import"./countHackmudCharacters-1e122984.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"import-meta-resolve";import"./processScript/transform.js";import"./writeFilePersistent-72dc81a3.js";import"chokidar";
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hackmud-script-manager",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.17.0-3de4ad4",
|
4
4
|
"description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
|
5
5
|
"keywords": [
|
6
6
|
"api",
|
@@ -103,7 +103,7 @@
|
|
103
103
|
"require": "./index.cjs"
|
104
104
|
},
|
105
105
|
"./*": "./*",
|
106
|
-
"./
|
106
|
+
"./generateTypeDeclaration": "./generateTypeDeclaration.js",
|
107
107
|
"./index": "./index.js",
|
108
108
|
"./pull": "./pull.js",
|
109
109
|
"./push": "./push.js",
|
package/processScript/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
import e from"@babel/generator";import{parse as
|
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
|
1
|
+
import e from"fs";import{resolve as i,extname as t,basename as r}from"path";import{s as a}from"./constants-9bb78688.js";import{processScript as s}from"./processScript/index.js";import{D as o,w as p}from"./writeFilePersistent-72dc81a3.js";import{c as n}from"./countHackmudCharacters-1e122984.js";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-transform-exponentiation-operator";import"@babel/traverse";import"@babel/types";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"./processScript/minify.js";import"acorn";import"terser";import"./processScript/shared.js";import"./assert-1556d989.js";import"./spliceString-2c6f214f.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"import-meta-resolve";import"./processScript/transform.js";const{readFile:l,readdir:m}=e.promises;async function push(e,c,{scripts:f=["*.*"],onPush:g=(()=>{}),minify:u=!0,mangleNames:d=!1}={}){const b=new o((e=>new Set)),w=new Set,h=new Set;let $=!1;for(const e of f){const[i,t]=e.split(".");i&&"*"!=i?t&&"*"!=t?b.get(i).add(t):w.add(i):t&&"*"!=t?h.add(t):$=!0}const y=new o((e=>new Set)),S=[],j=new o((e=>new Set));let P;if(h.size||$){const t=await m(i(c),{withFileTypes:!0}),r=new Set([...(P=await m(i(e),{withFileTypes:!0})).filter((e=>e.isDirectory())).map((e=>e.name)),...t.filter((e=>e.isDirectory())).map((e=>e.name)),...t.filter((e=>e.isFile()&&e.name.endsWith(".key"))).map((e=>e.name.slice(0,-4))),...b.keys(),...w]);if($)for(const e of r)w.add(e);else for(const e of r){const i=b.get(e);for(const e of h)i.add(e)}}return await Promise.all([...w].map((async o=>{await m(i(e,o),{withFileTypes:!0}).then((async m=>{await Promise.all(m.map((async m=>{if(m.name.endsWith(".d.ts"))return;const f=t(m.name);if(m.isFile()&&a.includes(f)){const t=r(m.name,f),a=i(e,o,m.name),{script:b}=await s(await l(a,{encoding:"utf-8"}),{minify:u,scriptUser:o,scriptName:t,filePath:a,mangleNames:d}),w={file:`${o}/${m.name}`,users:[o],minLength:n(b),error:void 0};j.get(o).add(t),S.push(w),await p(i(c,o,`scripts/${t}.js`),b),g(w)}})))}),(e=>{if("ENOENT"!=e.code)throw e}))}))),await Promise.all([...b].map((async([t,r])=>{w.has(t)||await Promise.all([...r].map((async r=>{let o,m,f;for(const s of a)try{m=`${r}${s}`,o=await l(f=i(e,t,m),{encoding:"utf-8"});break}catch{}if(o){const{script:e}=await s(o,{minify:u,scriptUser:t,scriptName:r,filePath:f,mangleNames:d}),a={file:`${t}/${m}`,users:[t],minLength:n(e),error:void 0};S.push(a),await p(i(c,t,"scripts",`${r}.js`),e),g(a)}else y.get(r).add(t)})))}))),await(w.size?Promise.all((P||await m(i(e),{withFileTypes:!0})).map((async o=>{if(o.name.endsWith(".d.ts"))return;const m=t(o.name);if(!o.isFile()||!a.includes(m))return;const f=r(o.name,m),b=[...w,...y.get(f)].filter((e=>!j.get(e).has(f)));if(!b.length)return;const h=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),$=i(e,o.name),{script:P}=await s(await l($,{encoding:"utf-8"}),{minify:u,scriptUser:!0,scriptName:f,uniqueID:h,filePath:$,mangleNames:d}),N={file:o.name,users:b,minLength:n(P),error:void 0};await Promise.all(b.map((e=>p(i(c,e,`scripts/${f}.js`),P.replace(new RegExp(`\\$${h}\\$SCRIPT_USER\\$`,"g"),e).replace(new RegExp(`\\$${h}\\$FULL_SCRIPT_NAME\\$`,"g"),`${e}.${f}`))))),S.push(N),g(N)}))):Promise.all([...y].map((async([t,r])=>{let o,m,f;for(const r of a)try{m=`${t}${r}`,o=await l(f=i(e,m),{encoding:"utf-8"});break}catch{}if(o){const e=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),{script:a}=await s(o,{minify:u,scriptUser:!0,scriptName:t,uniqueID:e,filePath:f,mangleNames:d}),l={file:m,users:[...r],minLength:n(a),error:void 0};await Promise.all([...r].map((r=>p(i(c,r,`scripts/${t}.js`),a.replace(new RegExp(`\\$${e}\\$SCRIPT_USER\\$`,"g"),r).replace(new RegExp(`\\$${e}\\$FULL_SCRIPT_NAME\\$`,"g"),`${r}.${t}`))))),S.push(l),g(l)}})))),S}export{push as default,push};
|
package/watch.d.ts
CHANGED
@@ -18,5 +18,5 @@ export declare type WatchOptions = PushOptions & {
|
|
18
18
|
* @param scripts to push from (pushes from all if empty)
|
19
19
|
* @param onPush function that's called on each script push
|
20
20
|
*/
|
21
|
-
export declare function watch(sourceDirectory: string, hackmudDirectory: string, { scripts, onPush, minify, mangleNames, typeDeclarationPath, onReady }?: LaxPartial<WatchOptions>): void
|
21
|
+
export declare function watch(sourceDirectory: string, hackmudDirectory: string, { scripts, onPush, minify, mangleNames, typeDeclarationPath: typeDeclarationPath_, onReady }?: LaxPartial<WatchOptions>): Promise<void>;
|
22
22
|
export default watch;
|
package/watch.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
import{watch as r}from"chokidar";import
|
1
|
+
import{watch as r}from"chokidar";import t from"fs";import{extname as e,basename as o,resolve as i}from"path";import{s as a}from"./constants-9bb78688.js";import{generateTypeDeclaration as s}from"./generateTypeDeclaration.js";import{processScript as n}from"./processScript/index.js";import{D as p,w as l}from"./writeFilePersistent-72dc81a3.js";import{a as c}from"./assert-1556d989.js";import{c as m}from"./countHackmudCharacters-1e122984.js";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-transform-exponentiation-operator";import"@babel/traverse";import"@babel/types";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"./processScript/minify.js";import"acorn";import"terser";import"./processScript/shared.js";import"./spliceString-2c6f214f.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"import-meta-resolve";import"./processScript/transform.js";const{readFile:f,readdir:u,writeFile:d}=t.promises;async function watch(t,g,{scripts:h=["*.*"],onPush:w,minify:b=!0,mangleNames:y=!1,typeDeclarationPath:j,onReady:S}={}){if(!h.length)throw new Error("scripts option was an empty array");const D=new p((r=>new Set)),T=new Set,$=new Set;let v=!1;for(const r of h){const[t,e]=r.split(".");t&&"*"!=t?e&&"*"!=e?D.get(e).add(t):T.add(t):e&&"*"!=e?$.add(e):v=!0}const F=r(["*.ts","*.js"],{depth:1,cwd:t,awaitWriteFinish:{stabilityThreshold:100},ignored:"*.d.ts"}).on("change",(async r=>{if(r.endsWith(".d.ts"))return;const s=e(r);if(!a.includes(s))return;const d=o(r,s);if(r==o(r)){if(!(v||T.size||$.has(d)||D.has(d)))return;const s=new p((r=>[]));await Promise.all((await u(t,{withFileTypes:!0})).map((async r=>{if(r.isDirectory())for(const n of await u(i(t,r.name),{withFileTypes:!0})){if(!n.isFile())continue;const t=e(n.name);a.includes(t)&&s.get(o(n.name,t)).push(r.name)}})));const h=new Set;if(v||$.has(d)){for(const r of await u(i(t),{withFileTypes:!0}))r.isDirectory()&&h.add(r.name);for(const r of await u(i(g),{withFileTypes:!0}))r.isDirectory()?h.add(r.name):r.isFile()&&r.name.endsWith(".key")&&h.add(r.name.slice(0,-4));for(const r of D.values())for(const t of r)h.add(t)}for(const r of T)h.add(r);for(const r of D.get(d))h.add(r);const j=[...h].filter((r=>!s.has(r)));if(!j.length)return void(null==w||w({file:r,users:[],minLength:0,error:new Error("no users to push to")}));const S=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),F=i(t,r);let E;try{({script:E}=await n(await f(F,{encoding:"utf-8"}),{minify:b,scriptUser:!0,scriptName:d,uniqueID:S,filePath:F,mangleNames:y}))}catch(t){return c(t instanceof Error),void(null==w||w({file:r,users:[],minLength:0,error:t}))}return await Promise.all(j.map((r=>l(i(g,r,`scripts/${d}.js`),E.replace(new RegExp(`\\$${S}\\$SCRIPT_USER\\$`,"g"),r).replace(new RegExp(`\\$${S}\\$FULL_SCRIPT_NAME\\$`,"g"),`${r}.${d}`))))),void(null==w||w({file:r,users:j,minLength:m(E),error:void 0}))}const h=o(i(r,".."));if(!(v||T.size||$.has(d)||D.get(d).has(h)))return;const j=i(t,r),S=await f(j,{encoding:"utf-8"});let F;try{({script:F}=await n(S,{minify:b,scriptUser:h,scriptName:d,filePath:j,mangleNames:y}))}catch(t){return c(t instanceof Error),void(null==w||w({file:r,users:[],minLength:0,error:t}))}await l(i(g,h,"scripts",`${d}.js`),F),null==w||w({file:r,users:[h],minLength:m(F),error:void 0})}));if(S&&F.on("ready",S),!j)return;let E=j;async function writeTypeDeclaration(){const r=await s(t,g);try{await d(E,r)}catch(t){if(c(t instanceof Error),"EISDIR"!=t.code)throw t;E=i(E,"player.d.ts"),await d(E,r)}}await writeTypeDeclaration(),F.on("add",writeTypeDeclaration),F.on("unlink",writeTypeDeclaration)}export{watch as default,watch};
|
package/generateTypings.d.ts
DELETED
package/generateTypings.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
import e from"fs";import{extname as n,basename as t,resolve as s,relative as r}from"path";const{readdir:i,writeFile:a}=e.promises;async function generateTypings(e,o,f){const c=new Set;if(f)for(const e of await i(f,{withFileTypes:!0}))e.isFile()&&".key"==n(e.name)&&c.add(t(e.name,".key"));const l=[],m=[],p={},$={};await Promise.all((await i(e,{withFileTypes:!0})).map((async r=>{if(r.isFile())".ts"==n(r.name)?l.push(t(r.name,".ts")):".js"==n(r.name)&&m.push(t(r.name,".js"));else if(r.isDirectory()){const a=[],o=[];p[r.name]=a,$[r.name]=o,c.add(r.name);for(const f of await i(s(e,r.name),{withFileTypes:!0}))f.isFile()&&(".ts"==n(f.name)?a.push(t(f.name,".ts")):".js"==n(f.name)&&o.push(t(f.name,".js")))}}))),e=r(".",e);let y="";for(const n of l)y+=`import $${n}$ from "./${e}/${n}"\n`;y+="\n";for(const n in p){const t=p[n];for(const s of t)y+=`import $${n}$${s}$ from "./${e}/${n}/${s}"\n`}y+="\ntype ArrayRemoveFirst<A> = A extends [ infer FirstItem, ...infer Rest ] ? Rest : never\n\ntype Subscript<T extends (...args: any) => any> =\n\t(...args: ArrayRemoveFirst<Parameters<T>>) => ReturnType<T> | ScriptFailure\n\ntype WildFullsec = Record<string, () => ScriptFailure> & {\n";for(const e of l)y+=`\t${e}: Subscript<typeof $${e}$>\n`;for(const e of m)y+=`\t${e}: (...args: any) => any\n`;y+="}\n\ninterface PlayerFullsec {";let u=!0;for(const e of c){const n=p[e],t=$[e];if(n&&n.length||t&&t.length){if(u=!0,y+=`\n\t${e}: WildFullsec & {\n`,n)for(const t of n)y+=`\t\t${t}: Subscript<typeof $${e}$${t}$>\n`;if(t)for(const e of t)y+=`\t\t${e}: (...args: any) => any\n`;y+="\t}"}else u&&(y+="\n",u=!1),y+=`\t${e}: WildFullsec`;y+="\n"}y+="}\n",await a(o,y)}export{generateTypings as default,generateTypings};
|