js-to-sh
Version:
Turn javascript code into shellscript
16 lines (15 loc) • 22.7 kB
JavaScript
;var we=Object.create;var v=Object.defineProperty,xe=Object.defineProperties,Te=Object.getOwnPropertyDescriptor,Ee=Object.getOwnPropertyDescriptors,Se=Object.getOwnPropertyNames,J=Object.getOwnPropertySymbols,je=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable;var V=(s,e,t)=>e in s?v(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,D=(s,e)=>{for(var t in e||(e={}))G.call(e,t)&&V(s,t,e[t]);if(J)for(var t of J(e))Me.call(e,t)&&V(s,t,e[t]);return s},R=(s,e)=>xe(s,Ee(e));var ve=(s,e)=>{for(var t in e)v(s,t,{get:e[t],enumerable:!0})},K=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Se(e))!G.call(s,o)&&o!==t&&v(s,o,{get:()=>e[o],enumerable:!(r=Te(e,o))||r.enumerable});return s};var Ce=(s,e,t)=>(t=s!=null?we(je(s)):{},K(e||!s||!s.__esModule?v(t,"default",{value:s,enumerable:!0}):t,s)),Ae=s=>K(v({},"__esModule",{value:!0}),s);var d=(s,e,t)=>new Promise((r,o)=>{var i=f=>{try{l(t.next(f))}catch(y){o(y)}},a=f=>{try{l(t.throw(f))}catch(y){o(y)}},l=f=>f.done?r(f.value):Promise.resolve(f.value).then(i,a);l((t=t.apply(s,e)).next())});var Fe={};ve(Fe,{Method:()=>p,Transpiler:()=>n,breakLines:()=>m,fetchNew:()=>he,getTabs:()=>u,isCommand:()=>be,isDir:()=>ie,isEmpty:()=>ne,isExecutable:()=>ae,isFile:()=>ce,isNumber:()=>le,isReadable:()=>ue,isWritable:()=>me});module.exports=Ae(Fe);var Ne=()=>typeof document=="undefined"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,c=Ne();var U=require("@loggings/beta"),C=class C{constructor(e){this.interaction=e;C.all.set(this.interaction.type,this)}static get(e){return this.all.get(e)}subprocess(e,t,r){if(e===void 0)throw new Error("Not identified methodType");let o=C.all.get(e);if(o===void 0)return console.debug(`[${e}] Not identified`),"";let i=o.interaction.parser(t,{parser:o.interaction.parser,type:o.interaction.type,subprocess:o.subprocess,data:r});return console.debug((0,U.Rgb)(255,220,0)+`[${e}] `+(0,U.Rgb)(0,224,255)+i),i}};C.all=new Map;var p=C;new p({type:"ArrayExpression",parser(s,e){return s.elements.map(r=>r===null?"":e.subprocess(r.type,r))}});var x=require("@loggings/beta");function m(s){let e="",t=s.filter(r=>typeof r=="string"?r.length!==0:!0);for(let r=0;r<t.length;r++)typeof t[r]=="string"&&t[r].length===0||(e+=t[r],r!==t.length-1&&(e+=`
`));return e}var z=Ce(require("abstract-syntax-tree"),1),_=require("fs"),X=require("path");var h=class h{constructor(e){var t,r;h.options=R(D({},e),{path:(0,X.join)((t=e.cwd)!=null?t:"",e.path)}),this.ast=h.loader(),global.loggings.config({format:"{message}",level:(r=h.options)!=null&&r.debug?"debug":"info"}),console.debug((0,x.Rgb)(249,248,113)+"Debug Mode!"),console.debug((0,x.Rgb)(132,94,194)+"Transpiling:",(0,x.Rgb)(255,199,95)+h.options.path)}static loader(e){return e===void 0&&(e=(0,_.readFileSync)(h.options.path,{encoding:"utf-8"})),new z.default(e)}parser(e){let t=[];e=e!=null?e:this.ast,t.push(`#!/bin/bash
`);for(let r of e.body){let o=p.all.get(r.type);if(o===void 0){console.debug((0,x.Rgb)(255,220,0)+`[${r.type}] `+(0,x.Colors)("red","Not defined"));continue}let i=o.interaction.parser(r,{type:o.interaction.type,parser:o.interaction.parser,subprocess:o.subprocess});for(let[,a]of Object.entries(h.globalDeclarations))t.push(a);h.globalDeclarations={},t.push(i)}return m(t)}static parseOperator(e){return e==="==="||e==="=="?"==":["!==","!="].includes(e)?"!=":e===">"?"-gt":e===">="?"-ge":e==="<"?"-lt":e==="<="?"-le":e}static parseReturnString(e,t){switch(e){case"Identifier":return`"$${t}"`;case"Literal":return Number.isNaN(Number(t))?`"${t}"`:`${t}`;case"CallExpression":return`$(${t})`;case"ArrayExpression":return`(${t.join(" ")})`;case"ArrowFunctionExpression":return`${t}`;case"ObjectExpression":return`${t}`}return`"${t}"`}};h.tabs=0,h.globalDeclarations={};var n=h;function u(s){return" ".repeat(s)}new p({type:"ArrowFunctionExpression",parser(s,e){let t=[],r=e.subprocess(s.body.type,s.body),o=s.params.map(i=>e.subprocess(i.type,i));for(let[i,a]of Object.entries(o))t.push(u(n.tabs)+`local ${a}=$${Number(i)+1}`);return t.push(r),m(t)}});new p({type:"AwaitExpression",parser(s,e){return e.subprocess(s.argument.type,s.argument)}});new p({type:"BinaryExpression",parser(s,e){let t=e.subprocess(s.left.type,s.left),r=e.subprocess(s.right.type,s.right),o=n.parseOperator(s.operator),i=`${n.parseReturnString(s.left.type,t)} ${o} ${n.parseReturnString(s.right.type,r)}`;return o==="+"?`$(( ${i} ))`:`[[ ${i} ]]`}});var j=require("fs");var B=require("glob"),T=require("path"),W=require("url"),ke=(0,T.basename)((0,W.fileURLToPath)(c)),H=(0,T.dirname)((0,W.fileURLToPath)(c)),Q=()=>ke==="index.js"?(0,B.globSync)((0,T.join)(H,"..","transformers/**/*.sh"),{cwd:(0,T.join)("..",H)}):(0,B.globSync)("src/transformers/shellscript/**/*.sh",{cwd:process.cwd()});var Y=require("path");new p({type:"CallExpression",parser(s,e){if(s.callee.type==="MemberExpression"){let t=s.callee,r=s.arguments;return e.subprocess(t.type,t,r.map(o=>n.parseReturnString(o.type,e.subprocess(o.type,o))).join(" "))}else{let t=s.callee.name,r={};switch(Q().map(a=>Object.assign(r,{[(0,Y.basename)(a)]:a})),t){case"fetch":{let a=(0,j.readFileSync)(r["fetch.sh"],{encoding:"utf-8"}),l=(0,j.readFileSync)(r["isCommand.sh"],{encoding:"utf-8"});n.globalDeclarations=Object.assign({isCommand:l,fetch:a},n.globalDeclarations);break}}let o=s.arguments.map(a=>n.parseReturnString(a.type,e.subprocess(a.type,a))),i=r[`${t}.sh`];if((0,j.existsSync)(i)){let a=(0,j.readFileSync)(i,{encoding:"utf-8"});n.globalDeclarations=Object.assign(n.globalDeclarations,{[t]:a})}return`${t} ${o.length>0?o.join(" "):""}`}}});var Z=require("@loggings/beta");new p({type:"ClassDeclaration",parser(s,e){return new E(s,e).parseClassDeclaration()}});var O=class O{constructor(e,t){this.options=t;this.constant="";this.uuid=crypto.randomUUID().replaceAll("-","");this.AST=e,this.className=this.getClassName(this.AST),this.variables=this.getVariables(this.AST),O.all.set(this.className,this)}getClassName(e){if(e.id===null)throw new Error("[getClassName] classs.id is null");return this.options.subprocess(e.id.type,e.id)}getVariables(e){let t=[];for(let r of e.body.body)if(r.type==="MethodDefinition"){let o=r,{variables:i}=this.parseClassMethodDefinition(o);t.push(...i)}return t}parseClassDeclaration(){var a;let e=[];n.tabs++;let t=/START_CONSTRUCTOR([\s\S]*?)END_CONSTRUCTOR/g;e.push(`
${u(n.tabs-1)}function ${this.className}_new () {`),e.push(`${u(n.tabs)}local self=$1`);let r=(a=t.exec(this.parseClassBody(this.AST.body)))==null?void 0:a[1].trim();e.push(r?u(n.tabs)+r:""),n.tabs--,e.push(`${u(n.tabs)}}`);let i=this.parseClassBody(this.AST.body).replace(t,"").replaceAll("(CLASS)",this.className+"_").toString().replaceAll("local self=$1",`local self=$1
${this.variables.map(l=>`${u(n.tabs+1)}local ${l}=$(eval echo \\$$$self"_${l}")
`).join("")}`);return e.push(i),m(e)}parseClassFunctionExpression(e){return e.params.map(r=>this.options.subprocess(r.type,r))}parseClassBody(e){let t=[];for(let r of e.body)switch(r.type){case"FunctionExpression":break;case"MethodDefinition":{let{code:o}=this.parseClassMethodDefinition(r);t.push(o);break}default:console.debug((0,Z.Colors)("red",`[parseClassBody] ${r.type}`))}return m(t)}parseClassMethodDefinition(e){let t=[],r=[];if(e.key===null)throw new Error("[parseClassMethodDefinition] element.key is null");let o=this.options.subprocess(e.key.type,e.key),i=2;switch(e.kind){case"method":{let a=this.options.subprocess(e.value.type,e.value);t.push(`${u(n.tabs)}function (CLASS)${o} {`),n.tabs++,t.push(`${u(n.tabs)}local self=$1`),t.push(`${u(n.tabs)}${a}`),n.tabs--,t.push(`${u(n.tabs)}}`);break}case"get":break;case"set":break;case"constructor":{let a=this.parseClassFunctionExpression(e.value);t.push("START_CONSTRUCTOR");for(let l of a)r.push(l),t.push(`${u(n.tabs)}eval "$self"_${l}='$${i++}'`);t.push("END_CONSTRUCTOR")}}return{code:m(t),variables:r}}parseAssignmentExpression(e){let t=this.options.subprocess(e.right.type,e.right);return`${u(n.tabs)}${t}`}};O.all=new Map;var E=O;new p({type:"FunctionExpression",parser(s,e){var t;return s.body===void 0||s.body===null?(console.debug("[FunctionExpression] is null"),""):e.subprocess((t=s.body)==null?void 0:t.type,s.body)}});new p({type:"Identifier",parser(s){return s.name}});new p({type:"Literal",parser(s){return s.value}});var ee=require("@loggings/beta");var b=class b{constructor(e){var t,r;this.options=Object.assign(e,{variable:(r=(t=e.variable)==null?void 0:t.replaceAll('"',""))!=null?r:void 0})}parse(){return this.map()}map(){switch(this.options.methodName){case"clear":return"clear";case"debug":case"log":case"info":case"warn":case"error":return`${u(n.tabs)}echo "${u(b.tabs)}${this.options.variable}"`;case"count":return this.handleCount();case"countReset":return this.resetCount();case"group":return b.tabs=b.tabs+1,"";case"groupCollapsed":return b.tabs=b.tabs+1,"";case"groupEnd":return b.tabs=b.tabs-1,"";case"time":return this.time();case"timeEnd":return this.timeEnd();default:return'echo "Unknown console method:"'}}handleCount(){let e=[],t=this.options.variable||"default";return e.push(`((count_${t}++))`),e.push(`echo "${u(b.tabs)}${t}: $count_${t}"`),m(e)}resetCount(){let e=[],t=this.options.variable||"default";return e.push(`((count_${t}=0))`),e.push(`echo "${u(b.tabs)}${t}: $count_${t}"`),m(e)}time(){return`((start_time_${this.options.variable||"default"}=$(date +%s%N)))`}timeEnd(){let e=[],t=this.options.variable||"default";return e.push(`((end_time_${t}=$(date +%s%N)))`),e.push(`echo "${u(b.tabs)}${t}: $((($end_time_${t}-start_time_${t})/1000000)) ms"`),m(e)}};b.tabs=0;var P=b;new p({type:"MemberExpression",parser(s,e){let t=e.data;if(s.object.type==="MetaProperty")return e.subprocess(s.object.type,s.object,s.property);let r=[],o=s.object.name,i=s.property.name;if(o===void 0)return n.parseReturnString(s.property.type,i);let a=E.all.entries(),l;for(let[,f]of a)f.constant===o&&(l=f.className);if(l!==void 0)return r.push(`${l}_${i} $${o}`),m(r);switch(o){case"console":{r.push(new P({methodName:i,variable:t}).parse());break}default:console.debug((0,ee.Colors)("red",`[parseMemberExpression] Not identified: ${o}.${i}`)),r.push(`${o}.${i}`)}return m(r)}});var te=require("@loggings/beta");new p({type:"MetaProperty",parser(s,e){let t=e.subprocess(s.meta.type,s.meta),r=e.subprocess(s.property.type,s.property),o=e.data;if(o===void 0)throw new Error("[MetaProperty] property is undefined");let i=e.subprocess(o.type,o);switch(`${t}.${r}.${i}`){case"import.meta.dirname":return'$(dirname "$(realpath "$0")")';default:console.debug((0,te.Colors)("red",`[parseMetaProperty] Not identified: ${t}.${r}.${i}`))}return""}});new p({type:"NewExpression",parser(s,e){let t=e.subprocess(s.callee.type,s.callee),r=s.arguments.map(o=>n.parseReturnString(o.type,e.subprocess(o.type,o)));return`${t}_new (ARG) ${r.join(" ")}`}});new p({type:"ObjectExpression",parser(s,e){let t=s.properties.map(i=>e.subprocess(i.type,i)).map(([i,a,l])=>[i,n.parseReturnString(l,a)]),r=[],o=[];for(let i=1;i<7;i++){r[i-1]=void 0;for(let[a,l]of t)switch(i){case 2:{a==="method"&&(r[0]=l);break}case 3:{a==="headers"&&(r[1]=l);break}case 4:{a==="body"&&(r[2]=l);break}case 5:{a==="redirect"&&(r[3]=l);break}case 6:{a==="referrer"&&(r[4]=l);break}case 7:{a==="credentials"&&(r[5]=l);break}}}for(let i of r)o.push(i||'""');return o.join(" ")}});new p({type:"PrivateIdentifier",parser(s){return s.name}});new p({type:"TemplateLiteral",parser(s,e){let t=[];for(let[r,o]of Object.entries(s.quasis))if(t.push(o.value.raw),Number(r)<s.expressions.length){let i=s.expressions[Number(r)],a=n.parseReturnString(i.type,e.subprocess(i.type,i));t.push(a)}return t.join("")}});new p({type:"Property",parser(s,e){let t=e.subprocess(s.key.type,s.key),r=e.subprocess(s.value.type,s.value);return[t,r,s.value.type]}});new p({type:"BlockStatement",parser(s,e){let t=[];for(let r of s.body){let o=e.subprocess(r.type,r);if(Array.isArray(o)){t.push(...o);continue}t.push(o)}return m(t)}});new p({type:"BreakStatement",parser(s,e){return(s==null?void 0:s.label)===null?(console.debug("[BreakStatement]: Label is null"),""):e.subprocess("Identifier",s.label)}});new p({type:"ElseStatement",parser(s,e){let t=[];if(s.type!=="IfStatement"){t.push(u(n.tabs-1)+"else");let r=e.subprocess(s.type,s);return Array.isArray(r)?r.map(o=>t.push(o)):t.push(r),m(t)}return t.push(`elif [[ ${e.subprocess(s.test.type,s.test)} ]]; then`),t.push(`${u(n.tabs)}${e.subprocess(s.consequent.type,s.consequent)}`),s.alternate&&t.push(e.subprocess(s.alternate.type,s.alternate)),m(t)}});new p({type:"ExpressionStatement",parser(s,e){let t=[],r=s.expression;return t.push(e.subprocess(r.type,r)),m(t)}});new p({type:"ForOfStatement",parser(s,e){let t=[],r=e.subprocess(s.left.type,s.left),o=e.subprocess(s.right.type,s.right),i=e.subprocess(s.body.type,s.body);return t.push(`
${u(n.tabs)}for ${r} in "\${${o}[@]}"; do`),n.tabs=n.tabs+1,t.push(u(n.tabs)+i),n.tabs=n.tabs-1,t.push(`${u(n.tabs)}done`),m(t)}});new p({type:"FunctionDeclaration",parser(s,e){var i;if(s.id===null||s.body===null||s.body===void 0)return console.debug("[FunctionDeclaration] node.id is null"),"";let t=[],r=s.params.map(a=>e.subprocess(a.type,a)),o=e.subprocess((i=s.id)==null?void 0:i.type,s.id);t.push(`function ${u(n.tabs)}${o}() {`),n.tabs++;for(let[a,l]of Object.entries(r))t.push(`${u(n.tabs)}local ${l}=$${Number(a)+1}`);return t.push(e.subprocess(s.body.type,s.body)),n.tabs--,t.push(u(n.tabs)+`}
`),m(t)}});new p({type:"IfStatement",parser(s,e){n.tabs++;let t=e.subprocess(s.test.type,s.test),r=e.subprocess(s.consequent.type,s.consequent),o=p.get("ElseStatement"),i=s.alternate?o.interaction.parser(s.alternate,{parser:o.interaction.parser,type:o.interaction.type,subprocess:o.subprocess}):"",a=[];return a.push(`${n.tabs>=1?`
`:""}if ${t}; then`),a.push(r),i.length>0&&a.push(i),a.push(`fi${n.tabs>=1?`
`:""}`),n.tabs--,m(a)}});var S=require("path");var F=require("fs"),se=require("@loggings/beta");new p({type:"ImportDeclaration",parser(s,e){let t=e.subprocess(s.type,s),r=(0,S.dirname)((0,S.resolve)(n.options.path));if(!(0,F.existsSync)((0,S.join)(r,t)))throw new Error((0,se.Colors)("red",`[${t}] It is not possible to use external or internal packages.`));let o=(0,S.join)(r,t.replace("javascript","shellscript").replace(".js",".sh"));return(0,F.readFileSync)(o,{encoding:"utf-8"})}});new p({type:"ReturnStatement",parser(s,e){var r;if(s.argument===null)return console.debug("[ReturnStatement] node.argument is null"),"";let t=e.subprocess(s.argument.type,s.argument);return`echo ${n.parseReturnString((r=s.argument.type)!=null?r:"Literal",t)}`}});new p({type:"SwitchStatement",parser(s,e){let t=[],r=e.subprocess(s.discriminant.type,s.discriminant);t.push(`${u(n.tabs)}case $${r} in`),n.tabs++;for(let o of s.cases){if(n.tabs++,o.test){let i=e.subprocess(o.test.type,o.test);t.push(`${u(n.tabs)}"${i}")`)}else t.push(u(n.tabs)+"*))");n.tabs++,t.push(u(n.tabs)+m(o.consequent.map(i=>e.subprocess(i.type,i)))),t.push(u(n.tabs)+";;"),n.tabs--,n.tabs--}return t.push(u(n.tabs)+"esac"),n.tabs--,m(t)}});var re=require("@loggings/beta");new p({type:"VariableDeclaration",parser(s,e){var r;let t=[];for(let o of s.declarations){let i=e.subprocess(o.id.type,o.id);if(o.init===null){t.push(i);continue}o.init.type==="ArrowFunctionExpression"&&n.tabs++;let a=e.subprocess(o.init.type,o.init);o.init.type==="ArrowFunctionExpression"&&n.tabs--;let l=n.parseReturnString(o.init.type==="AwaitExpression"?o.init.argument.type:(r=o.init.type)!=null?r:"Literal",a);if(l.includes("(ARG)")&&o.init.type==="NewExpression"){let f=e.subprocess(o.init.callee.type,o.init.callee),y=E.all.get(f);y===void 0?console.debug((0,re.Colors)("red",`[${f}] Not implemented`)):y.constant=i,t.push(`
${i}="${f}_${crypto.randomUUID().replaceAll("-","")}"`),t.push(a.replaceAll("(ARG)",`$${i}`)+`
`);continue}o.init.type==="ArrowFunctionExpression"?(t.push(`function ${i} () {`),t.push(l),t.push("}")):t.push(`${i}=${l}`)}return m(t)}});var oe=require("fs/promises");var ie=s=>d(void 0,null,function*(){try{return(yield(0,oe.stat)(s)).isDirectory()}catch(e){return!1}});global.isDir=ie;var ne=s=>{switch(typeof s){case"undefined":return!0;default:return!1}};global.isEmpty=ne;var L=require("fs/promises");var ae=s=>d(void 0,null,function*(){try{return yield(0,L.access)(s,L.constants.X_OK),!0}catch(e){return!1}});global.isExecutable=ae;var pe=require("fs/promises");var ce=s=>d(void 0,null,function*(){try{return(yield(0,pe.stat)(s)).isFile()}catch(e){return!1}});global.isFile=ce;var le=s=>!Number.isNaN(Number(s));global.isNumber=le;var I=require("fs/promises");var ue=s=>d(void 0,null,function*(){try{return yield(0,I.access)(s,I.constants.R_OK),!0}catch(e){return!1}});global.isReadable=ue;var q=require("fs/promises");var me=s=>d(void 0,null,function*(){try{return yield(0,q.access)(s,q.constants.W_OK),!0}catch(e){return!1}});global.isWritable=me;var de=require("child_process"),fe=require("util");var be=s=>d(void 0,null,function*(){try{let e=(0,fe.promisify)(de.exec),{stdout:t}=yield e(`command -v ${s}`);return t.length!==0}catch(e){return!1}});global.isCommand=be;var De=fetch,he=(s,e)=>d(void 0,null,function*(){return yield De(s,e)});global.fetch=he;var g=require("@loggings/beta");var k=require("fs/promises"),ye=require("glob"),w=require("path"),$e=require("url");var ge={name:"js-to-sh",description:"Turn javascript code into shellscript",version:"1.2.1",main:"dist/cjs/index.cjs",module:"dist/mjs/index.js",types:"dist/types/index.d.ts",typings:"dist/types/index.d.ts",type:"module",bin:{tjss:"dist/cjs/index.cjs","transpiler-js-shell":"dist/cjs/index.cjs","js-to-sh":"dist/cjs/index.cjs"},typesVersions:{"*":{".":["./dist/types/index.d.ts"],globals:["./dist/types/index.d.ts"]}},exports:{".":{types:"./dist/types/index.d.ts",import:"./dist/mjs/index.js",require:"./dist/cjs/index.cjs"},"./globals":{types:"./dist/types/index.d.ts",import:"./dist/types/index.d.ts",require:"./dist/types/index.d.js"},"./loader":{types:"./dist/types/index.d.ts",import:"./dist/mjs/index.js",require:"./dist/cjs/index.cjs"}},engines:{node:">=20"},scripts:{cli:"bun src/cli.ts",test:"tsx test/app.ts && chmod 777 output/*",build:"rimraf dist && bun build/build.ts",lint:"eslint -c eslint.config.js"},keywords:["transpiler","javascript","transpiler-js","transpilers","builder","shellscript","js-to-sh","ast","abstract-syntax-tree"],repository:{type:"git",url:"git+https://github.com/Ashu11-A/Transpiler-JS-Shell.git"},author:"Ashu11A",license:"MIT",bugs:{url:"https://github.com/Ashu11-A/Transpiler-JS-Shell/issues"},homepage:"https://github.com/Ashu11-A/Transpiler-JS-Shell",dependencies:{"@loggings/beta":"^2.4.0","abstract-syntax-tree":"^2.22.0",glob:"^11.0.0"},devDependencies:{"@eslint/js":"^9.16.0","@types/node":"^22.10.2",chokidar:"^4.0.1","dts-bundle-generator":"^9.5.1",eslint:"^9.16.0",globals:"^15.13.0",meriyah:"^6.0.3",rimraf:"^6.0.1","tsc-alias":"^1.8.10",tsup:"^8.3.5",tsx:"^4.19.2",typescript:"^5.7.2","typescript-eslint":"^8.18.0"}};var M=require("@loggings/beta");var $=class ${constructor(e){$.args=e}validate(e){for(let t of e.filter(r=>r.includes("-")))if(!$.args.flatMap(({command:o,alias:i})=>[o,...i.map(a=>a||o)]).includes(t))throw new Error(`Not found arg ${t}, try --help`)}formatAliasToCommand(e){var r;let t=[];for(let o=0;o<e.length;o++)for(let i of $.args)if(i.alias.includes(e[o])||e[o]===i.command){if(i!=null&&i.hasString){if((r=e[o+1])!=null&&r.startsWith("-")){t.push(i);continue}++o,t.push(R(D({},i),{string:e[o]}));continue}t.push(i);continue}return t}quickSort(e){return e.sort((t,r)=>t.rank-r.rank)}static help(){let e=[];e.push(`Usage: ${(0,M.Colors)("yellow","tjss")} ${(0,M.Colors)("magenta","[options]")}
`),e.push(` Options:
`);let t=Math.max(...$.args.map(o=>o.alias.join(", ").length)),r=Math.max(...$.args.map(o=>`--${o.command}`.length));for(let o of $.args){let i=o.alias.join(", "),a=`--${o.command}`,l=" ".repeat(t-i.length),f=" ".repeat(r-a.length);e.push(` ${(0,M.Colors)("blue",i)}${l} ${(0,M.Colors)("white",a)}${f} ${(0,M.Colors)("green",o.description)}`)}return e.join(`
`)}run(e){return d(this,null,function*(){this.validate(e);let t=this.quickSort(this.formatAliasToCommand(e));if(t.length===0){console.log($.help());return}for(let r of t)yield r.function(r.string)})}};$.args=[];var A=$;g.Loggings.rem(g.LoggingsRegister.identify);g.Loggings.useConsole(new g.Loggings);var Pe=process.argv.slice(2).map(s=>s.replace("--","")),N=new Map;process.argv[1]!==(0,$e.fileURLToPath)(c)&&!Object.keys(ge.bin).includes((0,w.basename)(process.argv[1]))||new A([{alias:["-h"],command:"help",description:"Show all available arguments",rank:0,function(){return d(this,null,function*(){console.log(A.help()),process.exit()})}},{alias:["-D"],command:"debug",description:"Activates debug mode.",rank:0,function(){return d(this,null,function*(){process.env.transpilerDebug="true"})}},{alias:["-d"],command:"dir",description:"Directory for fetching and transpiling .js files",hasString:!0,rank:1,function(i){return d(this,null,function*(){if(i===void 0)throw new Error("Dir not expecificate");if(!(yield isDir(i)))throw new Error("Directory specified invalid");let a=yield(0,ye.glob)(`${i}/**/*.{js,ts}`,{cwd:process.cwd()});for(let l of a){let f=new n({path:l,debug:!1}).parser();N.set(l.split("/").slice(1).join("/"),f)}})}},{alias:["-f"],command:"file",description:"File to be transpiled.",rank:1,hasString:!0,function(i){return d(this,null,function*(){var l;if(i===void 0)throw new Error("File not expecificate");let a=new n({path:i,debug:JSON.parse((l=process.env.transpilerDebug)!=null?l:"false")}).parser();N.set(i,a)})}},{alias:["-o"],command:"output",description:"Output directory or file to save the transpiled files.",rank:9,hasString:!0,function(i){return d(this,null,function*(){if(i===void 0)throw new Error("--output requires an input");let a=N.entries();if(N.size>1&&i.includes(".sh"))throw new Error(`Output was declared to be ${i}, but you passed a directory, it is not possible to process several files and save them in a single file`);for(let[l,f]of a){let y=(0,w.join)(process.cwd(),i);if(i.includes(".sh")){yield(0,k.writeFile)(y,f,{encoding:"utf-8"}),console.log(`${(0,g.Colors)("yellow","Transpiled:")} ${(0,g.Colors)("blue",l)} \u27A4 ${(0,g.Rgb)(12,232,41)+i}`);continue}if(N.size>1){yield(0,k.mkdir)((0,w.dirname)((0,w.join)(y,l)),{recursive:!0}),(0,k.writeFile)((0,w.join)(y,l).replace(".ts",".sh").replace(".js",".sh"),f,{encoding:"utf-8"});continue}throw new Error(`Output ${i} is invalid!`)}})}}]).run(Pe);0&&(module.exports={Method,Transpiler,breakLines,fetchNew,getTabs,isCommand,isDir,isEmpty,isExecutable,isFile,isNumber,isReadable,isWritable});