@eas-framework/server
Version:
Node.js framework, with a lot of built in features
26 lines (25 loc) • 14.6 kB
JavaScript
var c=(n,t)=>()=>(n&&(t=n(n=0)),t);var ut,g,P=c(()=>{ut=!0,g=new Proxy(console,{get(n,t,e){return t=="important"?n.error:ut&&t!="do-nothing"?n[t]:()=>{}}})});import{Dirent as Ot,promises as u}from"fs";import G from"path";function h(n,t){return new Promise(async e=>{try{e(t(null,await n))}catch(r){e(t(r))}})}function R(n,...t){return h(u[n](...t),e=>(e&&g.error(e),!e))}function pt(n){return h(u.stat(n),(t,e)=>!!e)}function H(n,t,e,r={}){return h(u.stat(n),(i,o)=>(i&&!e&&g.error(i),t&&o?o[t]:o||r))}async function gt(n,t=!0){return(await H(n,void 0,!0)).isFile?.()&&t}function ht(n){return R("mkdir",n)}function ft(n){return R("rmdir",n)}function dt(n){return R("unlink",n)}async function mt(n){return h(u.unlink(n),t=>!t)}function bt(n,t={}){return h(u.readdir(n,t),(e,r)=>(e&&g.error(e),r||[]))}async function St(n){return h(u.mkdir(n),t=>!t)}function J(n,t){return h(u.writeFile(n,t),e=>(e&&g.error(e),!e))}async function xt(n,t){try{return await J(n,JSON.stringify(t))}catch(e){g.error(e)}return!1}function z(n,t="utf8",e=!1){return h(u.readFile(n,{encoding:t}),(r,i)=>(r&&!e&&g.error(r),i||""))}async function yt(n,t){try{return JSON.parse(await z(n,t))}catch(e){g.error(e)}return{}}async function Tt(n,t=""){return n=G.dirname(n),h(u.mkdir(G.join(t,n),{recursive:!0}),e=>!e)}var p,F=c(()=>{P();p={...u,exists:pt,existsFile:gt,stat:H,mkdir:ht,mkdirIfNotExists:St,writeFile:J,writeJsonFile:xt,readFile:z,readJsonFile:yt,rmdir:ft,unlink:dt,unlinkIfExists:mt,readdir:bt,makePathReal:Tt}});function E(n,t){let e=t.indexOf(n);return e==-1?[t]:[t.substring(0,e),t.substring(e+n.length)]}var N=c(()=>{});import{cwd as At}from"process";import b from"path";import{fileURLToPath as kt}from"url";function wt(n){return b.dirname(kt(n))}function $(){return b.join(A,j,"/")}function m(n){return b.join($(),n,"/")}function B(n){return b.join(Ct,n+"Compile","/")}var Ct,j,S,y,W,_,K,A,x,O,T,d,l,k=c(()=>{F();N();Ct=b.join(wt(import.meta.url),"/SystemData"),j="WebSite",S="WWW",y="Logs",W="node_modules",_="Models",K="Components",A=At()+"/";x=$(),O=B(S),T={Static:[m(S),O,S],Logs:[m(y),B(y),y],Models:[m(_),O,_],Components:[m(K),O,K],node_modules:[m(W),B(W),W],get[S](){return T.Static}},d={page:"page",model:"model",component:"integ"},l={pageTypes:d,pageTypesArray:[],pageCodeFile:{page:[d.page+".js",d.page+".ts"],model:[d.model+".js",d.model+".ts"],component:[d.component+".js",d.component+".ts"]},pageCodeFileArray:[],partExtensions:["serv","api"],ReqFileTypes:{js:"serv.js",ts:"serv.ts","api-ts":"api.js","api-js":"api.ts"},ReqFileTypesArray:[],get WebSiteFolder(){return j},get fullWebSitePath(){return x},set WebSiteFolder(n){j=n,x=$(),T.Static[0]=m(S),T.Logs[0]=m(y)},get tsConfig(){return x+"tsconfig.json"},async tsConfigFile(){if(await p.existsFile(this.tsConfig))return await p.readFile(this.tsConfig)},relative(n){return b.relative(x,n)}};l.pageTypesArray=Object.values(l.pageTypes);l.pageCodeFileArray=Object.values(l.pageCodeFile).flat();l.ReqFileTypesArray=Object.values(l.ReqFileTypes)});import{SourceMapConsumer as Zt,SourceMapGenerator as Vt}from"source-map";function Q(n,t){let e=`sourceMappingURL=data:application/json;charset=utf-8;base64,${Buffer.from(n.toString()).toString("base64")}`;return t?e=`/*# ${e}*/`:e="//# "+e,`\r
`+e}var X=c(()=>{});import{SourceMapGenerator as Dt,SourceMapConsumer as ne}from"source-map";import w from"path";var C,Y=c(()=>{k();N();X();C=class{constructor(t,e=!0,r=!1,i=!1){this.filePath=t;this.httpSource=e;this.relative=r;this.isCss=i;this.lineCount=0;this.map=new Dt({file:t.split(/\/|\\/).pop()}),e||(this.fileDirName=w.dirname(this.filePath))}getSource(t){return t=t.split("<line>").pop().trim(),this.httpSource?(l.pageTypesArray.includes(w.extname(t).substring(1))?t+=".source":t=E("/",t).pop()+"?source=true",w.normalize((this.relative?"":"/")+t.replace(/\\/gi,"/"))):w.relative(this.fileDirName,l.fullWebSitePath+t)}getRowSourceMap(){return this.map.toJSON()}mapAsURLComment(){return Q(this.map,this.isCss)}}});function Z(n,t,e,r){let i=new D(t,e,r);return i.addMappingFromTrack(n),i.getRowSourceMap()}function V(n,t){let e=new D(t);return e.addMappingFromTrack(n),n.eq+e.mapAsURLComment()}var D,tt=c(()=>{Y();D=class extends C{constructor(t,e=!1,r=!1){super(t,e,r),this.lineCount=1}addMappingFromTrack(t){let e=t.getDataArray(),r=e.length,i=!0;for(let o=0;o<r;o++){let{text:a,line:s,info:f}=e[o];if(a==`
`){this.lineCount++,i=!1;continue}!i&&s&&f&&a.trim()&&(i=!0,this.map.addMapping({original:{line:s,column:0},generated:{line:this.lineCount,column:0},source:this.getSource(f)}))}}}});var L,et=c(()=>{k();tt();L=class n{constructor(t,e){this.DataArray=[];this.InfoText=null;this.OnLine=1;this.OnChar=1;typeof t=="string"?this.InfoText=t:t&&this.setDefault(t),e&&this.AddFileText(e,this.InfoText)}static get emptyInfo(){return{info:"",line:0,char:0}}setDefault(t=this.DefaultInfoText){this.InfoText=t.info,this.OnLine=t.line,this.OnChar=t.char}getDataArray(){return this.DataArray}get DefaultInfoText(){return this.DataArray.find(t=>t.info)??n.emptyInfo}get DefaultInfoTextLast(){for(let t=this.DataArray.length-1;t>=0;t--)if(this.DataArray[t].info)return this.DataArray[t];return n.emptyInfo}get StartInfo(){return this.DataArray[0]??this.DefaultInfoText}get OneString(){let t="";for(let e of this.DataArray)t+=e.text;return t}get eq(){return this.OneString}get originalLineInfo(){let t=this.DefaultInfoText;return`${t.info}:${t.line}:${t.char}`}get lineInfo(){let t=this.originalLineInfo.split("<line>");return t.push(l.fullWebSitePath+t.pop()),t.join("<line>")}get length(){return this.DataArray.length}Clone(){let t=new n(this.StartInfo);for(let e of this.DataArray)t.AddTextAfter(e.text,e.info,e.line,e.char);return t}AddClone(t){this.DataArray=this.DataArray.concat(t.DataArray),this.setDefault({info:t.InfoText,line:t.OnLine,char:t.OnChar})}static concat(...t){let e=new n;for(let r of t)r instanceof n?e.AddClone(r):e.AddTextAfter(String(r));return e}ClonePlus(...t){return n.concat(this.Clone(),...t)}Plus(...t){for(let e of t)e instanceof n?this.AddClone(e):this.AddTextAfterNoTrack(String(e));return this}Plus$(t,...e){for(let r in e){let i=t[r],o=e[r];this.AddTextAfterNoTrack(i),o instanceof n?this.AddClone(o):o!=null&&this.AddTextAfterNoTrack(String(o))}return this.AddTextAfterNoTrack(t[t.length-1]),this}AddTextAction(t,e,r=this.DefaultInfoText.info,i=0,o=1){let a=[];for(let s of[...t])a.push({text:s,info:r,line:i,char:o}),o++,s==`
`&&(i++,o=1);this.DataArray[e](...a)}AddTextAfter(t,e,r,i){return this.AddTextAction(t,"push",e,r,i),this}AddTextAfterNoTrack(t,e=""){for(let r of t)this.DataArray.push({text:r,info:e,line:0,char:0});return this}AddTextBefore(t,e,r,i){return this.AddTextAction(t,"unshift",e,r,i),this}AddTextBeforeNoTrack(t,e=""){let r=[];for(let i of t)r.push({text:i,info:e,line:0,char:0});return this.DataArray.unshift(...r),this}AddFileText(t,e=this.DefaultInfoText.info){let r=1,i=1;for(let o of[...t])this.DataArray.push({text:o,info:e,line:r,char:i}),i++,o==`
`&&(r++,i=1)}CutString(t=0,e=this.length){let r=new n(this.StartInfo);return r.DataArray=r.DataArray.concat(this.DataArray.slice(t,e)),r}substring(t,e){return isNaN(e)?e=void 0:e=Math.abs(e),isNaN(t)?t=void 0:t=Math.abs(t),this.CutString(t,e)}substr(t,e){return t<0&&(t=this.length-t),this.substring(t,e!=null?e+t:e)}slice(t,e){return t<0&&(t=this.length-t),e<0&&(t=this.length-t),this.substring(t,e)}charAt(t){return t||(t=0),this.CutString(t,t+1)}at(t){return this.charAt(t)}charCodeAt(t){return this.charAt(t).OneString.charCodeAt(0)}codePointAt(t){return this.charAt(t).OneString.codePointAt(0)}*[Symbol.iterator](){for(let t of this.DataArray){let e=new n;e.DataArray.push(t),yield e}}getLine(t,e=!0){return this.split(`
`)[t-+e]}charLength(t){if(t<=0)return t;let e=0;for(let r of this.DataArray)if(e++,t-=r.text.length,t<=0)return e;return e}indexOf(t){return this.charLength(this.OneString.indexOf(t))}lastIndexOf(t){return this.charLength(this.OneString.lastIndexOf(t))}unicodeMe(t){let e="";for(let r of t)e+="\\u"+("000"+r.charCodeAt(0).toString(16)).slice(-4);return e}get unicode(){let t=new n;for(let e of this.DataArray)t.AddTextAfter(this.unicodeMe(e.text),e.info,e.line,e.char);return t}search(t){return this.charLength(this.OneString.search(t))}startsWith(t,e){return this.OneString.startsWith(t,e)}endsWith(t,e){return this.OneString.endsWith(t,e)}includes(t,e){return this.OneString.includes(t,e)}trimStart(){let t=this.Clone();t.setDefault();for(let e=0;e<t.DataArray.length;e++){let r=t.DataArray[e];if(r.text.trim()=="")t.DataArray.shift(),e--;else{r.text=r.text.trimStart();break}}return t}trimLeft(){return this.trimStart()}trimEnd(){let t=this.Clone();t.setDefault();for(let e=t.DataArray.length-1;e>=0;e--){let r=t.DataArray[e];if(r.text.trim()=="")t.DataArray.pop();else{r.text=r.text.trimEnd();break}}return t}trimRight(){return this.trimEnd()}trim(){return this.trimStart().trimEnd()}SpaceOne(t){let e=this.at(0),r=this.at(this.length-1),i=this.Clone().trim();return e.eq&&i.AddTextBefore(t||e.eq,e.DefaultInfoText.info,e.DefaultInfoText.line,e.DefaultInfoText.char),r.eq&&i.AddTextAfter(t||r.eq,r.DefaultInfoText.info,r.DefaultInfoText.line,r.DefaultInfoText.char),i}ActionString(t){let e=this.Clone();for(let r of e.DataArray)r.text=t(r.text);return e}toLocaleLowerCase(t){return this.ActionString(e=>e.toLocaleLowerCase(t))}toLocaleUpperCase(t){return this.ActionString(e=>e.toLocaleUpperCase(t))}toUpperCase(){return this.ActionString(t=>t.toUpperCase())}toLowerCase(){return this.ActionString(t=>t.toLowerCase())}normalize(){return this.ActionString(t=>t.normalize())}StringIndexer(t,e){t instanceof RegExp&&(t=new RegExp(t,t.flags.replace("g","")));let r=[],i=this.OneString,o=i.match(t),a=0,s=0,f=this.Clone();for(;(e==null||s<e)&&o?.[0]?.length;){let v=[...o[0]].length,I=f.charLength(o.index);r.push({index:I+a,length:v}),i=i.slice(o.index+o[0].length),f=f.CutString(I+v),a+=I+v,o=i.match(t),s++}return r}RegexInString(t){return t instanceof RegExp?t:new n("n",t).unicode.eq}split(t,e){let r=this.StringIndexer(this.RegexInString(t),e),i=[],o=0;for(let a of r)i.push(this.CutString(o,a.index)),o=a.index+a.length;return i.push(this.CutString(o)),i}repeat(t){let e=this.Clone();for(let r=0;r<t;r++)e.AddClone(this.Clone());return e}static join(t){let e=new n;for(let r of t)e.AddClone(r);return e}replaceWithTimes(t,e,r){let i=this.StringIndexer(t,r),o=new n,a=0;for(let s of i)o=o.ClonePlus(this.CutString(a,s.index),e),a=s.index+s.length;return o.AddClone(this.CutString(a)),o}replace(t,e){return this.replaceWithTimes(this.RegexInString(t),e,t instanceof RegExp?void 0:1)}replacer(t,e){let r=this.Clone(),i;function o(){i=r.match(t)}o();let a=new n(r.StartInfo);for(;i;)a.Plus(r.substring(0,i.index)),a.Plus(e(i)),r=r.substring(i.index+i[0].length),o();return a.Plus(r),a}async replacerAsync(t,e){let r=this.Clone(),i;function o(){i=r.match(t)}o();let a=new n(r.StartInfo);for(;i;)a.Plus(r.substring(0,i.index)),a.Plus(await e(i)),r=r.substring(i.index+i[0].length),o();return a.Plus(r),a}replaceAll(t,e){return this.replaceWithTimes(this.RegexInString(t),e)}matchAll(t){let e=this.StringIndexer(t),r=[];for(let i of e)r.push(this.substr(i.index,i.length));return r}match(t){if(t instanceof RegExp&&t.global)return this.matchAll(t);let e=this.OneString.match(t);if(e==null)return null;let r=[];r[0]=this.substr(e.index,e.shift().length),r.index=e.index,r.input=this.Clone();let i=r[0].Clone();for(let o in e){if(isNaN(Number(o)))break;let a=e[o];if(a==null){r.push(a);continue}let s=i.indexOf(a);r.push(i.substr(s,a.length)),i=i.substring(s)}return r}toString(){return this.OneString}extractInfo(t="<line>"){return this.DefaultInfoText.info.split(t).pop().trim()}originalPositionFor(t,e){let r=this.getLine(t);return r.startsWith("//")&&(r=this.getLine(t-1),e=0),{...r.at(e-1).DefaultInfoText,searchLine:r}}debugLine({message:t,text:e,location:r,line:i,col:o}){let a=this.originalPositionFor(i??r?.line??1,o??r?.column??0);return`${e||t}, on file -><color>${l.fullWebSitePath+a.searchLine.extractInfo()}:${a.line}:${a.char}${r?.lineText?`
Line: "`+r.lineText.trim()+'"':""}`}StringWithTack(t){return V(this,t)}StringTack(t,e,r){return Z(this,t,e,r)}}});import me from"chalk";var U,be,rt=c(()=>{U=class{constructor(){this.events=[];this.eventLog=[];this.logAll=!1}event(t,e){this.events.push({name:t,func:e})}dispatch(t,e={}){e.date=new Date,this.eventLog.push(e),this.events.forEach(r=>r.name==t&&r.func(e)),this.simpleLog(t,e)}simpleLog(t,e){this.logAll&&console.log(t,e)}},be=new U});function q(n){for(;n.includes(" ");)n=n.replace(/ {2}/gi," ");return n=n.replace(/\r\n|\n/gi,""),n=n.replace(/, /gi,","),n=n.replace(/: /gi,":"),n=n.replace(/ \{/gi,"{"),n=n.replace(/\{ /gi,"{"),n=n.replace(/; /gi,";"),n=n.replace(/\/\*.*?\*\//gms,""),n.trim()}var nt=c(()=>{});import ke from"markdown-it";import Ce from"highlight.js";import Ie from"markdown-it-anchor";import Re from"@sindresorhus/slugify";import Ee from"markdown-it-attrs";import We from"markdown-it-abbr";async function ot(){for(let n of Lt){let t=(await p.readFile(it+n+".css")).replace(/(\n\.markdown-body {)|(^.markdown-body {)/gm,e=>e+"padding:20px;")+`
.code-copy>div>a{
margin-top: 25px;
margin-right: 10px;
position: relative;
bottom: -7px;
}
.code-copy>div {
text-align:right;
opacity:0;
height:0;
}
.code-copy:hover>div {
opacity:1;
}
.code-copy>div a:focus {
color:#6bb86a
}
`;await p.writeFile(it+n+".min.css",q(t))}}function Mt(n,t){let[e,r,i]=n.split(/(}|\*\/).hljs{/),o=n[e.length]=="}"?"}":"*/";return[e+o,".hljs{"+(i??r),".hljs{"+t.split(/(}|\*\/).hljs{/).pop()]}async function vt(n){let t=n.split("|");if(t.length==1)return n;let e=t[2]||t.slice(0,2).join("~").replace("/","-");if(await p.existsFile(M+e+".css"))return e;let r=await p.readFile(M+t[0]+".css"),i=await p.readFile(M+t[1]+".css"),[o,a,s]=Mt(i,r),f=`${o}@media(prefers-color-scheme:dark){${a}}@media(prefers-color-scheme:light){${s}}`;return await p.writeFile(M+e+".css",f),e}function at(){return vt("atom-one-light|atom-one-dark|atom-one")}var Lt,it,M,st=c(()=>{et();rt();F();k();nt();P();Lt=["","-dark","-light"],it=A+"node_modules/github-markdown-css/github-markdown";M=A+"node_modules/highlight.js/styles/"});var It={};var lt=c(async()=>{st();await ot();await at()});import{chdir as Pt,cwd as Rt}from"process";var Ft=Rt().split("/");function ct(n){if(Ft.at(-n)=="node_modules")return Pt("../".repeat(n)),!0}ct(2)||ct(3);lt();