hackmud-script-manager 0.14.0-f09e93a → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/hsm.js +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/processScript/index.d.ts +0 -1
- package/processScript/index.js +1 -1
- package/processScript/postprocess.js +1 -1
- package/push.js +1 -1
- package/watch.d.ts +2 -1
- package/watch.js +1 -1
package/bin/hsm.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
import o from"chalk";import{watch as e}from"chokidar";import s from"fs";import{homedir as t}from"os";import{resolve as
|
2
|
+
import o from"chalk";import{watch as e}from"chokidar";import s from"fs";import{homedir as t}from"os";import{resolve as n,basename as i,extname as a,dirname as r,relative as l}from"path";import{s as c}from"../processScript/transform.js";import{D as p,w as g}from"../writeFilePersistent-72dc81a3.js";import{generateTypings as m}from"../generateTypings.js";import{syncMacros as f}from"../syncMacros.js";import{pull as h}from"../pull.js";import{watch as u}from"../watch.js";import{push as b}from"../push.js";import{processScript as d}from"../processScript/index.js";import{c as k}from"../processScript/minify.js";import"@babel/traverse";import"@babel/types";import"../processScript/shared.js";import"../assert-1556d989.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"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"../processScript/postprocess.js";import"../processScript/preprocess.js";import"../spliceString-2c6f214f.js";import"acorn";import"terser";const{readFile:w,rmdir:y,writeFile:j,mkdir:$}=s.promises,v=n(t(),".config"),P=n(v,"hsm.json"),S=new Map,C=[];let x;const N=o.rgb(255,244,4),F=o.rgb(243,249,152),O=o.rgb(179,255,155),L=o.rgb(255,150,224),U=o.rgb(30,255,0),D=o.rgb(202,202,202),E=new p((o=>{let e=0;for(const s of o)e+=(e>>1)+e+"xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(s)+1;return[N,F,O,L,U,D][e%6](o)}));for(const o of process.argv.slice(2))if("-"==o[0]){const[e,s]=o.split("=");let t=s;if(t)if("true"==t)t=!0;else if("false"==t)t=!1;else{const o=Number(t);isFinite(o)&&(t=o)}else t=!0;if("-"==o[1])S.set(e.slice(2),t);else for(const o of e.slice(1))S.set(o,t)}else C.push(o);function help(){switch(C[0]){case"config":switch(C[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>"]]');break;case"dev":case"watch":console.log(`hsm ${C[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(`${i(process.argv[1])} ${C[0]} <target> [output]`);break;default:console.log("hsm <push, watch, pull, config, golf>")}}function version(){console.log("0.14.0")}async function getConfig(){return x||(x=await w(P,{encoding:"utf-8"}).then((o=>{let e;try{e=JSON.parse(o)}catch{return console.log("config file was corrupted, resetting"),{}}return e&&"object"==typeof e?e:(console.log("config file was corrupted, resetting"),{})}),(()=>(console.log(`creating config file at ${P}`),{}))))}function exploreObject(o,e,s=!1){for(const n of e){var t;o=s?"object"==typeof o[n]?o[n]:o[n]={}:null===(t=o)||void 0===t?void 0:t[n]}return o}function updateConfig(){if(x){const o=JSON.stringify(x,void 0,"\t");j(P,o).catch((async e=>{switch(e.code){case"EISDIR":await y(P);break;case"ENOENT":await $(v);break;default:throw e}j(P,o)}))}}function onPushLogger({file:e,users:s,srcLength:t,minLength:r,error:l}){l?console.log(`error "${o.bold(l.message)}" in ${o.bold(e)}`):console.log(`pushed ${o.bold(e)} to ${s.map((e=>o.bold(E.get(e)))).join(", ")} | ${o.bold(String(r))} chars from ${o.bold(String(t))} | saved ${o.bold(String(t-r))} (${o.bold(`${Math.round(100*(1-r/t))}%`)}) | ${o.bold(`${n(x.hackmudPath,s[0],"scripts",i(e,a(e)))}.js`)}`)}(async()=>{if(S.get("version")||S.get("v"))version();else if(S.get("help")||S.get("h"))help();else{switch(C[0]){case"push":{const o=await getConfig();if(!o.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const e=C[1]||".",s=o.hackmudPath,t=C.slice(2);t.length||t.push("*.*");(await b(e,s,{scripts:t,onPush:onPushLogger,minify:!S.get("skip-minify")})).length||console.warn("couldn't find any scripts to push"),updateConfig()}break;case"dev":case"watch":{var s;if(!C[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 e=C.slice(2);e.length||e.push("*.*"),S.has("skip-minify")&&S.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names"),u(C[1],o.hackmudPath,{scripts:e,onPush:onPushLogger,typeDeclarationPath:null===(s=S.get("type-declaration-path"))||void 0===s?void 0:s.toString(),minify:!S.get("skip-minify"),mangleNames:Boolean(S.get("mangle-names")),onReady:()=>console.log("watching")})}break;case"pull":{const o=await getConfig();if(!o.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const e=C[1];if(!e){help();break}const s=C[2]||".",t=o.hackmudPath;try{await h(s,t,e)}catch{console.log("something went wrong, did you forget to #down the script?")}}break;case"sync-macros":{const{hackmudPath:o}=await getConfig();if(!o){console.log("you need to set hackmudPath in config before you can use this command");break}const{macrosSynced:e,usersSynced:s}=await f(o);console.log(`synced ${e} macros to ${s} users`)}break;case"gen-types":{const o=n(C[1]||".");m(o,C[2]?n(C[2]):n(o,"../player.d.ts"),(await getConfig()).hackmudPath)}break;case"config":switch(C[1]){case"get":C[2]?console.log(exploreObject(await getConfig(),C[2].split("."))):console.log(await getConfig());break;case"delete":if(C[2]){var t;const o=C[2].split("."),e=o.pop();if(!o.length){help();break}const s=await getConfig();null===(t=exploreObject(s,o))||void 0===t||delete t[e],console.log(s)}else console.log("Usage:\nhsm config delete <key>");break;case"set":if(C[2]&&C[3]){const o=C[2].split(".");if(!o.length){help();break}const e=o.pop(),s=await getConfig();if(o.length||"hackmudPath"!=e){let t=s;for(const e of o)"object"==typeof t[e]||(t[e]={}),t=t[e];t[e]=C[3]}else s.hackmudPath=n(C[3]);console.log(s)}else console.log("Usage:\nhsm config set <key> <value>");break;default:C[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=C[1];if(!s){console.log(`Target required\nUsage: ${i(process.argv[1])} ${C[0]} <target> [output]`);break}const t=a(s);if(!c.includes(t)){console.log(`Unsupported file extension "${o.bold(t)}"\nSupported extensions are "${c.map((e=>o.bold(e))).join('", "')}"`);break}S.get("watch")?e(s,{awaitWriteFinish:{stabilityThreshold:100}}).on("ready",(()=>console.log(`watching ${s}`))).on("change",(()=>golfFile(s,t))):await golfFile(s,t)}break;default:C[0]&&console.log("unknown command"),help()}updateConfig()}async function golfFile(e,s){await w(e,{encoding:"utf-8"}).then((async t=>{const a=i(e,s),c=a.endsWith(".src"),p=c?a.slice(0,-4):a;let m="UNKNOWN";"scripts"==i(n(e,".."))&&"hackmud"==i(n(e,"../../.."))&&(m=i(n(e,"../..")));const f=!S.get("skip-minify"),h=Boolean(S.get("mangle-names"));!f&&h&&console.warn("warning: `--mangle-names` has no effect while `--skip-minify` is active");const u=performance.now(),{script:b,srcLength:w,warnings:y}=await d(t,{minify:f,scriptUser:m,scriptName:p,filePath:e,mangleNames:h}),j=performance.now()-u;for(const{message:e,line:s}of y)console.log(`warning "${o.bold(e)}" on line ${o.bold(String(s))}`);let $;$=C[2]?C[2]:n(r(e),c?`${p}.js`:".js"==s?`${a}.min.js`:`${a}.js`);const v=k(b);await g($,b).catch((async o=>{if(!C[2]||"EISDIR"!=o.code)throw o;$=n($,`${i(e,s)}.js`),await g($,b)})).then((()=>console.log(`wrote ${o.bold(v)} chars to ${o.bold(l(".",$))} | saved ${o.bold(w-v)} chars | took ${Math.round(100*j)/100}ms`)),(o=>console.log(o.message)))}),(o=>console.log(o.message)))}})();
|
package/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export{s as supportedExtensions}from"./processScript/transform.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"@babel/traverse";import"@babel/types";import"./processScript/shared.js";import"./assert-1556d989.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"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"
|
1
|
+
export{s as supportedExtensions}from"./processScript/transform.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"@babel/traverse";import"@babel/types";import"./processScript/shared.js";import"./assert-1556d989.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"@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"./spliceString-2c6f214f.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"./writeFilePersistent-72dc81a3.js";import"chokidar";
|
package/package.json
CHANGED
package/processScript/index.d.ts
CHANGED
package/processScript/index.js
CHANGED
@@ -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
|
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 c from"@babel/plugin-proposal-nullish-coalescing-operator";import m 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 h from"@babel/plugin-proposal-private-property-in-object";import y 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 v from"@babel/traverse";import x 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 _,transform as D}from"./transform.js";export{transform as compile}from"./transform.js";import{c as P,minify as M}from"./minify.js";export{minify}from"./minify.js";import{postprocess as O}from"./postprocess.js";export{postprocess}from"./postprocess.js";import{preprocess as U}from"./preprocess.js";export{preprocess}from"./preprocess.js";import{includesIllegalString as q,replaceIllegalStrings as V}from"./shared.js";import{a as W}from"../assert-1556d989.js";import"acorn";import"terser";import"../spliceString-2c6f214f.js";const{default:T}=S,{format:F}=N,{default:H}=e,{default:K}=v;async function processScript(e,{minify:v=!0,uniqueID:S=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),scriptUser:N="UNKNOWN",scriptName:z="UNKNOWN",filePath:A,mangleNames:B=!1}={}){W(/^\w{11}$/.exec(S));const G=e;let J,Q;const R=/^function\s*\(.+\/\/(?<autocomplete>.+)/.exec(e);if(R)e=`export default ${e}`,({autocomplete:J}=R.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 "))J=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":Q=4;break;case"highsec":case"high":case"hs":case"3s":case"h":case"3":Q=3;break;case"midsec":case"mid":case"ms":case"2s":case"m":case"2":Q=2;break;case"lowsec":case"low":case"ls":case"1s":case"l":case"1":Q=1;break;case"nullsec":case"null":case"ns":case"0s":case"n":case"0":Q=0;break;default:throw new Error(`unrecognised seclevel "${e}"`)}}}W(/^\w{11}$/.exec(S));const X=A?C(A):`${S}.ts`,Y=await I({input:X,plugins:[{name:"hackmud-script-manager",transform:e=>U(e,{uniqueID:S}).code},T({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],[y.default,{syntaxType:"hash",importPolyfill:!0}],[o.default],[t.default],[h.default],[n.default],[m.default],[c.default],[d.default],[u.default],[i.default],[f.default],[k.default]],configFile:!1,extensions:_}),E(),$({extensions:_}),L()],treeshake:{moduleSideEffects:!1}}),Z=["NULLSEC","LOWSEC","MIDSEC","HIGHSEC","FULLSEC"];e=(await Y.generate({})).output[0].code;const{file:ee,seclevel:re}=D(r(e,{sourceType:"module"}),G,{uniqueID:S,scriptUser:N,scriptName:z});if(null!=Q&&re<Q)throw new Error(`detected seclevel ${Z[re]} is lower than stated seclevel ${Z[Q]}`);e=H(ee).code;const oe=P(e.replace(/^function\s*\w+\(/,"function("));if(v?e=await M(ee,J,{uniqueID:S,mangleNames:B}):(K(ee,{MemberExpression({node:e}){e.computed||(W("Identifier"==e.property.type),"prototype"==e.property.name?(e.computed=!0,e.property=x.stringLiteral("prototype")):"__proto__"==e.property.name?(e.computed=!0,e.property=x.stringLiteral("__proto__")):q(e.property.name)&&(e.computed=!0,e.property=x.stringLiteral(V(S,e.property.name))))},VariableDeclarator(e){!function renameVariables(r){switch(r.type){case"Identifier":q(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)W("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&&q(e.key.name)&&(e.key=x.stringLiteral(V(S,e.key.name)),e.shorthand=!1)},StringLiteral({node:e}){e.value=V(S,e.value)},TemplateLiteral({node:e}){for(const r of e.quasis)r.value.cooked?(r.value.cooked=V(S,r.value.cooked),r.value.raw=r.value.cooked.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"$\\{")):r.value.raw=V(S,r.value.raw)}}),e=F(H(ee,{comments:!1}).code,{parser:"babel",arrowParens:"avoid",semi:!1,trailingComma:"none"})),e=O(e,re,S),q(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{srcLength:oe,script:e,warnings:[]}}export{processScript as default,processScript};
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
function postprocess($,e,p){return $.replace(/^function\s*\w+\(/,"function(").replace(new RegExp(`\\$${p}\\$\\\\\\\\0\\$SC_DOLLAR\\$`,"g"),"SC\\$").replace(new RegExp(`\\$${p}\\$\\\\\\\\0\\$DB_DOLLAR\\$`,"g"),"DB\\$").replace(new RegExp(`\\$${p}\\$\\\\\\\\0\\$D\\$`,"g"),"__D_\\S").replace(new RegExp(`\\$${p}\\$\\\\\\\\0\\$FMCL\\$`,"g"),"__FMCL\\_").replace(new RegExp(`\\$${p}\\$\\\\\\\\0\\$G\\$`,"g"),"__G\\_").replace(new RegExp(`\\$${p}\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)`,"g"),`#${"nlmhf"[e]}s.$1.$2`).replace(new RegExp(`\\$${p}\\$DEBUG`,"g"),"#D").replace(new RegExp(`\\$${p}\\$FMCL`,"g"),"#FMCL").replace(new RegExp(`\\$${p}\\$GLOBAL`,"g"),"#G").replace(new RegExp(`\\$${p}\\$DB\\$(\\w+)`,"g"),"#db.$1")}export{postprocess as default,postprocess};
|
package/push.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
import e from"fs";import{resolve as r,extname as i,basename as t}from"path";import{s as a}from"./processScript/transform.js";import{processScript as o}from"./processScript/index.js";import{D as s,w as p}from"./writeFilePersistent-72dc81a3.js";import{c as n}from"./processScript/minify.js";import"@babel/traverse";import"@babel/types";import"./processScript/shared.js";import"./assert-1556d989.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"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"
|
1
|
+
import e from"fs";import{resolve as r,extname as i,basename as t}from"path";import{s as a}from"./processScript/transform.js";import{processScript as o}from"./processScript/index.js";import{D as s,w as p}from"./writeFilePersistent-72dc81a3.js";import{c as n}from"./processScript/minify.js";import"@babel/traverse";import"@babel/types";import"./processScript/shared.js";import"./assert-1556d989.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"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"./spliceString-2c6f214f.js";import"acorn";import"terser";const{readFile:l,readdir:m}=e.promises;async function push(e,c,{scripts:g=["*.*"],onPush:u=(()=>{}),minify:f=!0,mangleNames:b=!1}={}){const d=new s((e=>new Set)),h=new Set,w=new Set;let $=!1;for(const e of g){const[r,i]=e.split(".");r&&"*"!=r?i&&"*"!=i?d.get(r).add(i):h.add(r):i&&"*"!=i?w.add(i):$=!0}const y=new s((e=>new Set)),S=[],j=new s((e=>new Set));let P;if(w.size||$){const t=await m(r(c),{withFileTypes:!0}),a=new Set([...(P=await m(r(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"==i(e.name))).map((e=>e.name.slice(0,-4))),...d.keys(),...h]);if($)for(const e of a)h.add(e);else for(const e of a){const r=d.get(e);for(const e of w)r.add(e)}}return await Promise.all([...h].map((async s=>{await m(r(e,s),{withFileTypes:!0}).then((async m=>{await Promise.all(m.map((async m=>{const g=i(m.name);if(m.isFile()&&a.includes(g)){const i=t(m.name,g),a=r(e,s,m.name),{srcLength:d,script:h}=await o(await l(a,{encoding:"utf-8"}),{minify:f,scriptUser:s,scriptName:i,filePath:a,mangleNames:b}),w={file:`${s}/${m.name}`,users:[s],minLength:n(h),error:void 0,srcLength:d};j.get(s).add(i),S.push(w),await p(r(c,s,`scripts/${i}.js`),h),u(w)}})))}),(e=>{if("ENOENT"!=e.code)throw e}))}))),await Promise.all([...d].map((async([i,t])=>{h.has(i)||await Promise.all([...t].map((async t=>{let s,m,g;for(const o of a)try{m=`${t}${o}`,s=await l(g=r(e,i,m),{encoding:"utf-8"});break}catch{}if(s){const{srcLength:e,script:a}=await o(s,{minify:f,scriptUser:i,scriptName:t,filePath:g,mangleNames:b}),l={file:`${i}/${m}`,users:[i],minLength:n(a),error:void 0,srcLength:e};S.push(l),await p(r(c,i,"scripts",`${t}.js`),a),u(l)}else y.get(t).add(i)})))}))),await(h.size?Promise.all((P||await m(r(e),{withFileTypes:!0})).map((async s=>{const m=i(s.name);if(!s.isFile()||!a.includes(m))return;const g=t(s.name,m),d=[...h,...y.get(g)].filter((e=>!j.get(e).has(g)));if(!d.length)return;const w=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),$=r(e,s.name),{srcLength:P,script:L}=await o(await l($,{encoding:"utf-8"}),{minify:f,scriptUser:!0,scriptName:g,uniqueID:w,filePath:$,mangleNames:b}),N={file:s.name,users:d,minLength:n(L),error:void 0,srcLength:P};await Promise.all(d.map((e=>p(r(c,e,`scripts/${g}.js`),L.replace(new RegExp(`$${w}$SCRIPT_USER`,"g"),e).replace(new RegExp(`$${w}$FULL_SCRIPT_NAME`,"g"),`${e}.${g}`))))),S.push(N),u(N)}))):Promise.all([...y].map((async([i,t])=>{let s,m,g;for(const t of a)try{m=`${i}${t}`,s=await l(g=r(e,m),{encoding:"utf-8"});break}catch{}if(s){const e=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),{srcLength:a,script:l}=await o(s,{minify:f,scriptUser:!0,scriptName:i,uniqueID:e,filePath:g,mangleNames:b}),d={file:m,users:[...t],minLength:n(l),error:void 0,srcLength:a};await Promise.all([...t].map((t=>p(r(c,t,`scripts/${i}.js`),l.replace(new RegExp(`$${e}$SCRIPT_USER`,"g"),t).replace(new RegExp(`$${e}$FULL_SCRIPT_NAME`,"g"),`${t}.${i}`))))),S.push(d),u(d)}})))),S}export{push as default,push};
|
package/watch.d.ts
CHANGED
@@ -7,6 +7,7 @@ export declare type WatchOptions = PushOptions & {
|
|
7
7
|
* writing the type declarations enables interscript type checking and autocompletetes for the args
|
8
8
|
*/
|
9
9
|
typeDeclarationPath: string;
|
10
|
+
onReady: () => void;
|
10
11
|
};
|
11
12
|
/**
|
12
13
|
* Watches target file or folder for updates and builds and pushes updated file.
|
@@ -17,5 +18,5 @@ export declare type WatchOptions = PushOptions & {
|
|
17
18
|
* @param scripts to push from (pushes from all if empty)
|
18
19
|
* @param onPush function that's called on each script push
|
19
20
|
*/
|
20
|
-
export declare function watch(sourceDirectory: string, hackmudDirectory: string, { scripts, onPush, minify, mangleNames, typeDeclarationPath }?: LaxPartial<WatchOptions>): void;
|
21
|
+
export declare function watch(sourceDirectory: string, hackmudDirectory: string, { scripts, onPush, minify, mangleNames, typeDeclarationPath, onReady }?: LaxPartial<WatchOptions>): void;
|
21
22
|
export default watch;
|
package/watch.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
import{watch as r}from"chokidar";import o from"fs";import{extname as t,basename as i,resolve as e}from"path";import{s}from"./processScript/transform.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"./processScript/minify.js";import"@babel/traverse";import"@babel/types";import"./processScript/shared.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"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"
|
1
|
+
import{watch as r}from"chokidar";import o from"fs";import{extname as t,basename as i,resolve as e}from"path";import{s}from"./processScript/transform.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"./processScript/minify.js";import"@babel/traverse";import"@babel/types";import"./processScript/shared.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"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"./spliceString-2c6f214f.js";import"acorn";import"terser";const{readFile:u,readdir:g}=o.promises;function watch(o,f,{scripts:b=["*.*"],onPush:d,minify:h=!0,mangleNames:w=!1,typeDeclarationPath:y,onReady:j}={}){if(!b.length)throw new Error("scripts option was an empty array");const S=new n((r=>new Set)),L=new Set,v=new Set;let F=!1;for(const r of b){const[o,t]=r.split(".");o&&"*"!=o?t&&"*"!=t?S.get(t).add(o):L.add(o):t&&"*"!=t?v.add(t):F=!0}const $=r("",{depth:1,cwd:o,awaitWriteFinish:{stabilityThreshold:100}}).on("change",(async r=>{const p=t(r);if(!s.includes(p))return;const b=i(r,p);if(r==i(r)){if(!(F||L.size||v.has(b)||S.has(b)))return;const p=new n((r=>[]));await Promise.all((await g(o,{withFileTypes:!0})).map((async r=>{if(r.isDirectory())for(const a of await g(e(o,r.name),{withFileTypes:!0})){if(!a.isFile())continue;const o=t(a.name);s.includes(o)&&p.get(i(a.name,o)).push(r.name)}})));const y=new Set;if(F||v.has(b)){for(const r of await g(e(o),{withFileTypes:!0}))r.isDirectory()&&y.add(r.name);for(const r of await g(e(f),{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 L)y.add(r);for(const r of S.get(b))y.add(r);const j=[...y].filter((r=>!p.has(r)));if(!j.length)return void(null==d||d({file:r,users:[],srcLength:0,minLength:0,error:new Error("no users to push to")}));const $=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),P=e(o,r);let E,T;try{({srcLength:E,script:T}=await a(await u(P,{encoding:"utf-8"}),{minify:h,scriptUser:!0,scriptName:b,uniqueID:$,filePath:P,mangleNames:w}))}catch(o){return c(o instanceof Error),void(null==d||d({file:r,users:[],srcLength:0,minLength:0,error:o}))}return await Promise.all(j.map((r=>l(e(f,r,`scripts/${b}.js`),T.replace(new RegExp(`$${$}$SCRIPT_USER`,"g"),r).replace(new RegExp(`$${$}$FULL_SCRIPT_NAME`,"g"),`${r}.${b}`))))),void(null==d||d({file:r,users:j,minLength:m(T),error:void 0,srcLength:E}))}const y=i(e(r,".."));if(!(F||L.size||v.has(b)||S.get(b).has(y)))return;const j=e(o,r),$=await u(j,{encoding:"utf-8"});let P,E;try{({srcLength:P,script:E}=await a($,{minify:h,scriptUser:y,scriptName:b,filePath:j,mangleNames:w}))}catch(o){return c(o instanceof Error),void(null==d||d({file:r,users:[],srcLength:0,minLength:0,error:o}))}await l(e(f,y,"scripts",`${b}.js`),E),null==d||d({file:r,users:[y],srcLength:P,minLength:m(E),error:void 0})}));j&&$.on("ready",j),y&&(p(o,e(o,y),f),$.on("add",(()=>p(o,e(o,y),f))),$.on("unlink",(()=>p(o,e(o,y),f))))}export{watch as default,watch};
|