vaderjs 1.3.3-6124766be812 → 1.3.3-6722242
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/runtime/vader.js +1 -1
- package/vader.js +163 -170
package/package.json
CHANGED
package/runtime/vader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
window.Vader={version:"1.3.3"},window.componentRegistry={};let errors={"SyntaxError: Unexpected token '<'":"You forgot to enclose tags in a fragment <></>"},mounts=[],hasRan=[];export const strictMount=(e,t)=>{let s=setInterval((()=>{document.querySelector(`[key="${e}"]`)&&!hasRan.includes(e)&&(clearInterval(s),t(),hasRan.push(e))}),120)};export class Component{constructor(){this.$_vaderElement=!0,this.state={},this.key=null,this.components={},this.mounted=!1,this.checkIFMounted(),this.memoizes=[],this.functions=[],this.children=[],this.noKey=!1,this.parentNode={},this.request={headers:{},method:"GET",params:{},path:"",query:{}},this.response={json:e=>{},send:e=>{},redirect:e=>{},render:async e=>{},log:e=>{},setQuery:e=>{}},this.router={use:e=>{}}}createComponent(e,t,s){function r(e){return"function"==typeof e&&/^class\s/.test(Function.prototype.toString.call(e))}let i=r(e)?new e(t):null;if(!e)throw new Error("Component must be defined");let n=[];Object.keys(t).forEach((e=>{if(e.startsWith("$props")&&(n.push(t[e]),delete t[e]),e.startsWith("$_ternary")){let s=t[e];delete t[e],Object.keys(s).forEach((e=>{t[e]=s[e]}))}}));let o=new Component(t);if(r(e))i.props=t||{},i.props.children=s.join("")||[],i.props.children=s.join(""),i.parentNode=this,i.type="class ",i.request=this.request,i.response=this.response,i.key=i.props.key?i.props.key:Math.random(),o=i;else{e.toString();o.key=e.toString().split('key="')[1]?e.toString().split('key="')[1].split('"')[0]:null,t=t?{...t,...n.reduce(((e,t)=>({...e,...t})),{}),children:s.join("")||[]}:{children:s.join("")||[]};let r={key:o.key?o.key:Math.random(),isUnique:!!o.key,render:()=>e.apply(o,[t]),request:this.request,isChild:!0,response:this.response,params:this.request.params,queryParams:this.request.query,reset:o.reset.bind(o),onMount:o.onMount.bind(o),useState:null,router:{use:o.router.use.bind(o)},bindMount:o.bindMount.bind(o),memoize:o.memoize.bind(o),createComponent:o.createComponent.bind(o),isChild:!1,useState:o.useState.bind(o),parseStyle:o.parseStyle.bind(o),bind:o.bind.bind(o),useRef:o.useRef.bind(o),request:this.request,response:this.response,useReducer:o.useReducer.bind(o),hydrate:o.hydrate.bind(o),onUnmount:o.onUnmount.bind(o),type:"function",parentNoe:this,props:{...t,children:s.join("")||[]}};o.render=r.render,o=r,o.props.children=s.join("")||[]}return this.components[o.key]||(this.components[o.key]=o),!this.children.includes(o)&&this.children.push(o),this.components[o.key]}reset(){Object.keys(this.components).forEach((e=>{this.components[e].onUnmount(),delete this.components[e]})),this.state={},this.children=[]}memoize(e){if(!0==!this.memoizes.includes(e.key))this.memoizes.push(e.key),this.components[e.key]=e;let t=this.components[e.key];"class"!==t.type||t.$_vaderElement||console.error(`class ${t.constructor.name} must extend Component`),t.bindMount(),t.parentNode=this,t.props=e.props,t.request=this.request,t.response=this.response,t.onMount=e.onMount.bind(e),t.onUnmount=e.onUnmount.bind(e);let s=t.render();return s&&s.split(">,").length>1&&(s=s.replaceAll(">,",">")),t.nokey||t.noKey?s:`<div key="${t.key}">${s}</div>`}parseStyle(e){let t="";return Object.keys(e).forEach((s=>{let r=e[s];s=s.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g,"$1-$2").toLowerCase(),t+=`${s}:${r};`})),t}bindMount(){mounts.push(this)}domDifference(e,t){let s=[];for(let r=0;r<e.length;r++){let i=e[r],n=t[r];if(i&&n&&i.childNodes.length>0&&n.childNodes.length>0){console.log("equal");let e=this.domDifference(Array.from(i.childNodes),Array.from(n.childNodes));s.push(...e)}i&&n&&0===i.childNodes.length&&0===n.childNodes.length?i.isEqualNode(n)||s.push({type:"replace",old:i,new:n}):i&&n&&Array.from(i.attributes).length!==Array.from(n.attributes).length&&s.push({type:"replace",old:i,new:n})}return s}updateChangedElements(e){e.forEach((e=>{if(e)switch(e.type){case"replace":e.old.replaceWith(e.new);break;case"remove":e.old.remove();break;case"add":e.old.appendChild(e.new.cloneNode(!0))}}))}hydrate(e){if(e){console.log(e.bind);let t=(new DOMParser).parseFromString(this.render(),"text/html").body.querySelectorAll(`[ref="${e.bind?e.bind:e}"]`),s=document.querySelectorAll(`[ref="${e?e.bind:e}"]`);t.forEach((e=>{let t=Array.from(s).find((t=>t.getAttribute("ref")===e.getAttribute("ref")));if(t){let s=this.domDifference(Array.from(t.childNodes),Array.from(e.childNodes))[0];this.updateChangedElements([s])}}))}else{let e=this.key?document.querySelector(`[key="${this.key}"]`):null;if(console.log(e),e){let t=(new DOMParser).parseFromString(this.render(),"text/html").body.querySelector(`[key="${this.key}"]`),s=e,r=this.domDifference([s],[t]);this.updateChangedElements(r)}}}patch(e,t){const s=this.domDifference(e,t);this.updateChangedElements(s)}handleObject(obj){try{obj=JSON.parse(obj)}catch(e){}return eval(obj)}bind(e,t,s,r,...i){return s+=this.key,window["callFunctions"+this.key]=(e,t)=>{let s=this.functions.find((t=>t.ref===e));s&&s.func(t)},this.functions.find((e=>e.ref===s))||this.functions.push({ref:s,func:e}),t?e:`((event)=>{callFunctions${this.key} ? callFunctions${this.key}('${s}', event) : null})(event)`}setState(e,t){this.state=e,this.hydrate(t)}useState(e,t){this.state.hasOwnProperty(e)||(this.state[e]=t);return[(()=>this.state[e])(),(t,s)=>{this.state[e]=t,this.hydrate(s)}]}useRef(e=null,t){this.state[e]||(this.state[e]=t);return{bind:e+this.key,current:(()=>document.querySelector(`[ref="${e+this.key}"]`)||t)()}}useReducer(e=null,t,s=null){this.state[e]||(this.state[e]=t);const r=()=>this.state[e];let i=r();return[r(),(t,n)=>{const o=s(i,t)??t;this.state[e]=o,this.hydrate(n),i=r()}]}render(){}checkIFMounted(){new MutationObserver((e=>{e.forEach((e=>{e.target.querySelector(`[key="${this.key}"]`)&&!this.mounted&&(this.onMount(),this.mounted=!0),Array.from(e.removedNodes).find((e=>e.attributes&&e.attributes.key&&e.attributes.key.value===this.key))&&(this.onUnmount(),this.reset())}))})).observe(document.body,{childList:!0,subtree:!0})}onMount(){}onUnmount(){}}export const useState=(e,t)=>{this.state[e]||(this.state[e]=t);return[states[e],(t,s)=>{states[e]=t,this.hydrate(s)}]};export const useReducer=(e,t)=>[e,e=>{}];export const useRef=e=>({current:e,bind:""});export class Link extends Component{constructor(e){super(e),this.props=e,this.link=document.createElement("a"),this.key=e.href+Math.random(),this.nokey=!0}render(){return this.link.innerHTML=this.props.children,this.link.setAttribute("id",this.props?.href),this.link.style=this.props?.style,this.link.setAttribute("class",this.props?.class||this.props?.className),this.link.setAttribute("onclick",`window.history.pushState({}, '', '${this.props?.href}'); window.dispatchEvent(new Event('popstate'));`),this.link.outerHTML}}export class Image extends Component{constructor(e){super(e),this.props={src:e.src,class:e.class,style:e.style,blur:e.blur,width:e.width,height:e.height,optimize:e.optimize||!0,loader:e.loader||!0,alt:e.alt||"image",ref:e.ref||null},this.key=e.src+Math.random(),this.img=document.createElement("img"),this.placeholder=document.createElement("div")}render(){if(window.isServer)return"";let[e,t]=this.useState("loaded",!1),s=this.useRef("hookref",null),r=this.props.width?this.props.width:window.innerWidth/2,i=this.props.height?this.props.height:window.innerHeight/2;if(!this.props.src)throw new Error("Image src is required");return this.img.setAttribute("src",this.props.src),this.img.setAttribute("class",this.props.class),this.img.setAttribute("style",this.props.style?this.props.style:""),this.img.setAttribute("width",r),this.img.setAttribute("ref",s.bind),this.img.referrerPolicy="no-referrer",this.img.setAttribute("height",i),this.img.setAttribute("loading","lazy"),this.img.setAttribute("alt",this.props.alt),this.props.blur&&this.img.setAttribute("style",`filter: blur(${this.props.blur}px);`),this.props.optimize&&this.img.setAttribute("style",`image-rendering: -webkit-optimize-contrast; object-fit: cover; object-position: center; ${this.props.style?this.props.style:""}`),!this.props.loader||e||window.isServer||(this.placeholder.setAttribute("style",`width: ${r}px; height: ${i}px; background: #eee;`),this.placeholder.setAttribute("class","vader-image-placeholder"),this.placeholder.innerHTML=this.props.loader,window.isServer)?void 0:(this.img.onload=()=>{t(!0,s.bind)},`<span ref="${s.bind}">${e?this.img.outerHTML:this.placeholder.outerHTML}</span>`)}}export class Html extends Component{constructor(e){super(e),this.props={children:e.children,lang:e.lang||"en",attributes:e.attributes||{}},this.key="html",this.html=document.createElement("div")}render(){return window.isServer?(this.html.innerHTML=this.props.children,this.html.setAttribute("lang",this.props.lang?this.props.lang:"en"),this.props.attributes&&Object.keys(this.props.attributes).forEach((e=>{this.html.setAttribute(e,this.props.attributes[e])})),this.html.innerHTML):this.props.children}onMount(){console.log("Document Has Been Mounted")}}export class Head extends Component{constructor(e){super(e),this.props=e,this.key="head",this.head=document.createElement("head")}render(){return""}onMount(){if(!this.state.hasMounted&&window.isServer){console.log(this.props.children),document.head.innerHTML=this.props.children+document.head.innerHTML,document.querySelectorAll("script[eager]").forEach((async e=>{if(!e.getAttribute("src"))throw new Error("Eager scripts must be external");e.remove();let t=e.getAttribute("src"),s=document.createElement("script"),r=null;await fetch(t).then((e=>{if(404===e.status)throw document.documentElement.setAttribute("error",JSON.stringify({error:`File ${t} not found`,status:404})),new Error(`File ${t} not found`);return e.text()})).then((e=>{r=e})).catch((e=>{throw e})),s.innerHTML=r,s.setAttribute("srcid",t),document.querySelector(`[srcid="${t}"]`)||document.head.prepend(s)})),this.state.hasMounted=!0}}}export class Script extends Component{constructor(e){super(e),this.props={children:e.children},this.key="script",this.script=document.createElement("script")}render(){return this.script.innerHTML=this.props.children.split("\n").join(";\n"),this.script.outerHTML}onMount(){document.head.appendChild(this.script),document.body.querySelector(`[key="${this.key}"]`).remove()}}export default{Component:Component,useRef:useRef,useReducer:useReducer,useState:useState,strictMount:strictMount,Link:Link,Image:Image,Head:Head,Script:Script,Html:Html};
|
|
1
|
+
window.Vader={version:"1.3.3"},window.componentRegistry={};let errors={"SyntaxError: Unexpected token '<'":"You forgot to enclose tags in a fragment <></>"},mounts=[],hasRan=[];export const strictMount=(e,t)=>{let s=setInterval((()=>{document.querySelector(`[key="${e}"]`)&&!hasRan.includes(e)&&(clearInterval(s),t(),hasRan.push(e))}),120)};export class Component{constructor(e={}){this.$_vaderElement=!0,this.state={},this.key=null,this.components={},this.mounted=!1,this.checkIFMounted(),this.memoizes=[],this.functions=[],this.props={children:"",$:{},...e},this.children=[],this.noKey=!1,this.parentNode={},this.request={headers:{},method:"GET",params:{},path:"",query:{}},this.response={json:e=>{},send:e=>{},redirect:e=>{},render:async e=>{},log:e=>{},setQuery:e=>{}},this.router={use:e=>{}}}createComponent(e,t,s){function r(e){return"function"==typeof e&&/^class\s/.test(Function.prototype.toString.call(e))}let i=r(e)?new e(t):null;if(!e)throw new Error("Component must be defined");let n=[],o=new Component(t);if(r(e))i.props=t||{},i.props.children=s.join("")||[],i.props.children=s.join(""),i.parentNode=this,i.type="class ",i.request=this.request,i.response=this.response,i.key=i.props.key?i.props.key:Math.random(),o=i;else{e.toString();o.key=e.toString().split('key="')[1]?e.toString().split('key="')[1].split('"')[0]:null,t=t?{...t,...n.reduce(((e,t)=>({...e,...t})),{}),children:s.join("")||[]}:{children:s.join("")||[]};let r={key:o.key?o.key:Math.random(),isUnique:!!o.key,render:()=>e.apply(o,[t]),request:this.request,isChild:!0,response:this.response,params:this.request.params,queryParams:this.request.query,reset:o.reset.bind(o),onMount:o.onMount.bind(o),useState:null,router:{use:o.router.use.bind(o)},bindMount:o.bindMount.bind(o),memoize:o.memoize.bind(o),createComponent:o.createComponent.bind(o),isChild:!1,useState:o.useState.bind(o),parseStyle:o.parseStyle.bind(o),bind:o.bind.bind(o),useRef:o.useRef.bind(o),request:this.request,response:this.response,useReducer:o.useReducer.bind(o),hydrate:o.hydrate.bind(o),onUnmount:o.onUnmount.bind(o),type:"function",parentNoe:this,props:{...t,children:s.join("")||[]}};o.render=r.render,o=r,o.props.children=s.join("")||[]}return this.components[o.key]||(this.components[o.key]=o),!this.children.includes(o)&&this.children.push(o),this.components[o.key]}reset(){Object.keys(this.components).forEach((e=>{this.components[e].onUnmount(),delete this.components[e]})),this.state={},this.children=[]}memoize(e){if(!0==!this.memoizes.includes(e.key))this.memoizes.push(e.key),this.components[e.key]=e;let t=this.components[e.key];"class"!==t.type||t.$_vaderElement||console.error(`class ${t.constructor.name} must extend Component`),t.bindMount(),t.parentNode=this,t.props=e.props,t.request=this.request,t.response=this.response,t.onMount=e.onMount.bind(e),t.onUnmount=e.onUnmount.bind(e);let s=t.render();return s&&s.split(">,").length>1&&(s=s.replaceAll(">,",">")),t.nokey||t.noKey?s:`<div key="${t.key}">${s}</div>`}parseStyle(e){let t="";return Object.keys(e).forEach((s=>{let r=e[s];s=s.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g,"$1-$2").toLowerCase(),t+=`${s}:${r};`})),t}bindMount(){mounts.push(this)}domDifference(e,t){let s=[];for(let r=0;r<e.length;r++){let i=e[r],n=t[r];if(i&&n&&i.childNodes.length>0&&n.childNodes.length>0){let e=this.domDifference(Array.from(i.childNodes),Array.from(n.childNodes));s.push(...e)}i&&n&&0===i.childNodes.length&&0===n.childNodes.length?i.isEqualNode(n)||s.push({type:"replace",old:i,new:n}):i&&n&&Array.from(i.attributes).length!==Array.from(n.attributes).length&&s.push({type:"replace",old:i,new:n})}return s}updateChangedElements(e){e.forEach((e=>{if(e)switch(e.type){case"replace":e.old.replaceWith(e.new);break;case"remove":e.old.remove();break;case"add":e.old.appendChild(e.new.cloneNode(!0))}}))}hydrate(e){if(e){let t=(new DOMParser).parseFromString(this.render(),"text/html").body.querySelectorAll(`[ref="${e.bind?e.bind:e}"]`),s=document.querySelectorAll(`[ref="${e?e.bind:e}"]`);t.forEach((e=>{let t=Array.from(s).find((t=>t.getAttribute("ref")===e.getAttribute("ref")));if(t){let s=this.domDifference(Array.from(t.childNodes),Array.from(e.childNodes))[0];this.updateChangedElements([s])}}))}else{let e=this.key?document.querySelector(`[key="${this.key}"]`):null;if(e){let t=(new DOMParser).parseFromString(this.render(),"text/html").body.querySelector(`[key="${this.key}"]`),s=e,r=this.domDifference([s],[t]);this.updateChangedElements(r)}}}patch(e,t){const s=this.domDifference(e,t);this.updateChangedElements(s)}handleObject(obj){try{obj=JSON.parse(obj)}catch(e){}return eval(obj)}bind(e,t,s,r,...i){return s+=this.key,window["callFunctions"+this.key]=(e,t)=>{let s=this.functions.find((t=>t.ref===e));s&&s.func(t)},this.functions.find((e=>e.ref===s))||this.functions.push({ref:s,func:e}),t?e:`((event)=>{callFunctions${this.key} ? callFunctions${this.key}('${s}', event) : null})(event)`}setState(e,t){this.state=e,this.hydrate(t)}useState(e,t){this.state.hasOwnProperty(e)||(this.state[e]=t);return[(()=>this.state[e])(),(t,s)=>{this.state[e]=t,this.hydrate(s)}]}useRef(e=null,t){this.state[e]||(this.state[e]=t);return{bind:e+this.key,current:(()=>document.querySelector(`[ref="${e+this.key}"]`)||t)()}}useReducer(e=null,t,s=null){this.state[e]||(this.state[e]=t);const r=()=>this.state[e];let i=r();return[r(),(t,n)=>{const o=s(i,t)??t;this.state[e]=o,this.hydrate(n),i=r()}]}render(){}checkIFMounted(){new MutationObserver((e=>{e.forEach((e=>{e.target.querySelector(`[key="${this.key}"]`)&&!this.mounted&&(this.onMount(),this.mounted=!0),Array.from(e.removedNodes).find((e=>e.attributes&&e.attributes.key&&e.attributes.key.value===this.key))&&(this.onUnmount(),this.reset())}))})).observe(document.body,{childList:!0,subtree:!0})}onMount(){}onUnmount(){}}export const useState=(e,t)=>{this.state[e]||(this.state[e]=t);return[states[e],(t,s)=>{states[e]=t,this.hydrate(s)}]};export const useReducer=(e,t)=>[e,e=>{}];export const useRef=e=>({current:e,bind:""});export class Link extends Component{constructor(e){super(e),this.props=e,this.link=document.createElement("a"),this.key=e.href+Math.random(),this.nokey=!0}render(){return this.link.innerHTML=this.props.children,this.link.setAttribute("id",this.props?.href),this.link.style=this.props?.style,this.link.setAttribute("class",this.props?.class||this.props?.className),this.link.setAttribute("onclick",`window.history.pushState({}, '', '${this.props?.href}'); window.dispatchEvent(new Event('popstate'));`),this.link.outerHTML}}export class Image extends Component{constructor(e){super(e),this.props={src:e.src,class:e.class,style:e.style,blur:e.blur,width:e.width,height:e.height,optimize:e.optimize||!0,loader:e.loader||!0,alt:e.alt||"image",ref:e.ref||null},this.key=e.src+Math.random(),this.img=document.createElement("img"),this.placeholder=document.createElement("div")}render(){if(window.isServer)return"";let[e,t]=this.useState("loaded",!1),s=this.useRef("hookref",null),r=this.props.width?this.props.width:window.innerWidth/2,i=this.props.height?this.props.height:window.innerHeight/2;if(!this.props.src)throw new Error("Image src is required");return this.img.setAttribute("src",this.props.src),this.img.setAttribute("class",this.props.class),this.img.setAttribute("style",this.props.style?this.props.style:""),this.img.setAttribute("width",r),this.img.setAttribute("ref",s.bind),this.img.referrerPolicy="no-referrer",this.img.setAttribute("height",i),this.img.setAttribute("loading","lazy"),this.img.setAttribute("alt",this.props.alt),this.props.blur&&this.img.setAttribute("style",`filter: blur(${this.props.blur}px);`),this.props.optimize&&this.img.setAttribute("style",`image-rendering: -webkit-optimize-contrast; object-fit: cover; object-position: center; ${this.props.style?this.props.style:""}`),!this.props.loader||e||window.isServer||(this.placeholder.setAttribute("style",`width: ${r}px; height: ${i}px; background: #eee;`),this.placeholder.setAttribute("class","vader-image-placeholder"),this.placeholder.innerHTML=this.props.loader,window.isServer)?void 0:(this.img.onload=()=>{t(!0,s.bind)},`<span ref="${s.bind}">${e?this.img.outerHTML:this.placeholder.outerHTML}</span>`)}}export class Html extends Component{constructor(e){super(e),this.props={children:e.children,lang:e.lang||"en",attributes:e.attributes||{}},this.key="html",this.html=document.createElement("div")}render(){return window.isServer?(this.html.innerHTML=this.props.children,this.html.setAttribute("lang",this.props.lang?this.props.lang:"en"),this.props.attributes&&Object.keys(this.props.attributes).forEach((e=>{this.html.setAttribute(e,this.props.attributes[e])})),this.html.innerHTML):this.props.children}onMount(){console.log("Document Has Been Mounted")}}export class Head extends Component{constructor(e){super(e),this.props=e,this.key="head",this.head=document.createElement("head")}render(){return""}onMount(){if(!this.state.hasMounted&&window.isServer){document.head.innerHTML=this.props.children+document.head.innerHTML,document.querySelectorAll("script[eager]").forEach((async e=>{if(!e.getAttribute("src"))throw new Error("Eager scripts must be external");e.remove();let t=e.getAttribute("src"),s=document.createElement("script"),r=null;await fetch(t).then((e=>{if(404===e.status)throw document.documentElement.setAttribute("error",JSON.stringify({error:`File ${t} not found`,status:404})),new Error(`File ${t} not found`);return e.text()})).then((e=>{r=e})).catch((e=>{throw e})),s.innerHTML=r,s.setAttribute("srcid",t),document.querySelector(`[srcid="${t}"]`)||document.head.prepend(s)})),this.state.hasMounted=!0}}}export class Script extends Component{constructor(e){super(e),this.props={children:e.children},this.key="script",this.script=document.createElement("script")}render(){return this.script.innerHTML=this.props.children.split("\n").join(";\n"),this.script.outerHTML}onMount(){document.head.appendChild(this.script),document.body.querySelector(`[key="${this.key}"]`).remove()}}export default{Component:Component,useRef:useRef,useReducer:useReducer,useState:useState,strictMount:strictMount,Link:Link,Image:Image,Head:Head,Script:Script,Html:Html};
|
package/vader.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import fs from "fs";
|
|
2
|
+
import fs, { fstatSync } from "fs";
|
|
3
3
|
import { glob, globSync, globStream, globStreamSync, Glob, } from 'glob'
|
|
4
|
-
import puppeteer from 'puppeteer';
|
|
4
|
+
import puppeteer from 'puppeteer';
|
|
5
5
|
import http from 'http'
|
|
6
6
|
import { SourceMapGenerator } from 'source-map'
|
|
7
7
|
|
|
@@ -9,19 +9,19 @@ import { WebSocketServer } from 'ws'
|
|
|
9
9
|
import prettier from 'prettier'
|
|
10
10
|
import { watch } from "fs";
|
|
11
11
|
import path from 'path'
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
globalThis.compiledFiles = []
|
|
14
14
|
|
|
15
15
|
const sourceMapGen = (data, code) => {
|
|
16
|
-
let { origin, fileName } = data
|
|
16
|
+
let { origin, fileName } = data
|
|
17
17
|
const sourceMap = new SourceMapGenerator({ file: '/src/' + fileName.replace('.jsx', '.js') });
|
|
18
18
|
|
|
19
|
-
const lines =
|
|
19
|
+
const lines = fs.readFileSync(origin, "utf8").split("\n");
|
|
20
20
|
let line = 1;
|
|
21
21
|
let column = 0;
|
|
22
|
-
for (const l of lines) {
|
|
22
|
+
for (const l of lines) {
|
|
23
23
|
sourceMap.addMapping({
|
|
24
|
-
source:
|
|
24
|
+
source: origin,
|
|
25
25
|
sourceRoot: '/src',
|
|
26
26
|
original: { line: line, column: 0 },
|
|
27
27
|
generated: { line: line, column: 0 },
|
|
@@ -34,7 +34,7 @@ const sourceMapGen = (data, code) => {
|
|
|
34
34
|
code = code + `\n//# sourceMappingURL=./src/maps/${fileName.replace('.jsx', '.js')}.map \n //#sourceURL=/src/maps/${fileName.replace('.jsx', '.js')}.map`
|
|
35
35
|
return { code, sourceMap };
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
let config = await import('file://' + process.cwd() + '/vader.config.js').then((e) => e.default || e)
|
|
39
39
|
let writer = async (file, data) => {
|
|
40
40
|
globalThis.isWriting = file
|
|
@@ -80,20 +80,21 @@ function Compiler(func, file) {
|
|
|
80
80
|
let childs = [];
|
|
81
81
|
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
// or : value boolean variable etc
|
|
84
|
+
const spreadAttributeRegex = /\s*([a-zA-Z0-9_-]+)\s*(\$\s*=\s*\{\s*\{(?:[^{}]|(?:\{(?:[^{}]|(?:\{[^{}]*\})*)*\})*)*\}\s*\})/gs;
|
|
85
|
+
|
|
85
86
|
|
|
86
87
|
|
|
87
88
|
|
|
88
89
|
function extractAttributes(code) {
|
|
89
90
|
// grab $={...} and ={...}
|
|
90
|
-
const elementRegex =
|
|
91
|
+
const elementRegex = /<([a-zA-Z0-9_-]+)([^>]*)>/gs;
|
|
91
92
|
|
|
92
93
|
// Match attributes in an opening tag, including those with ={}
|
|
93
94
|
// Match attributes in an opening tag, including those with ={...}
|
|
94
95
|
const attributeRegex =
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
/\s*([a-zA-Z0-9_-]+)(\s*=\s*("(?:[^"\\]*(?:\\.[^"\\]*)*)"|'(?:[^'\\]*(?:\\.[^'\\]*)*)'|\{(?:[^{}]|(?:\{(?:[^{}]|(?:\{[^{}]*\})*)*\})*)*\}|(?:\([^)]*\)|\{[^}]*\}|()=>\s*(?:\{[^}]*\})?)|\[[^\]]*\]))?/gs;
|
|
97
|
+
|
|
97
98
|
|
|
98
99
|
|
|
99
100
|
const functionAttributeRegex = /\s*([a-zA-Z0-9_-]+)\s*(=\s*{((?:[^{}]|(?:\{(?:[^{}]|(?:\{[^{}]*\})*)*\})*)*)})/gs;
|
|
@@ -101,7 +102,7 @@ function Compiler(func, file) {
|
|
|
101
102
|
let attributesList = [];
|
|
102
103
|
|
|
103
104
|
let spreadAttributes = [];
|
|
104
|
-
|
|
105
|
+
|
|
105
106
|
/**
|
|
106
107
|
* @search - handle spread for html elements
|
|
107
108
|
* @keywords - spread, spread attributes, spread props, spread html attributes
|
|
@@ -214,10 +215,10 @@ function Compiler(func, file) {
|
|
|
214
215
|
* @keywords - attributes, props, html attributes
|
|
215
216
|
*/
|
|
216
217
|
let match;
|
|
217
|
-
while ((match = elementRegex.exec(
|
|
218
|
+
while ((match = elementRegex.exec(string)) !== null) {
|
|
218
219
|
let [, element, attributes] = match;
|
|
219
220
|
|
|
220
|
-
|
|
221
|
+
|
|
221
222
|
let attributesMatch;
|
|
222
223
|
let elementAttributes = {};
|
|
223
224
|
|
|
@@ -229,81 +230,60 @@ function Compiler(func, file) {
|
|
|
229
230
|
|
|
230
231
|
attributesList.push({ element, attributes: elementAttributes });
|
|
231
232
|
}
|
|
232
|
-
|
|
233
|
-
let spreadMatch;
|
|
234
|
-
while ((spreadMatch = spreadAttributeRegex.exec(string)) !== null) {
|
|
235
|
-
let [, element, spread] = spreadMatch;
|
|
236
|
-
|
|
237
|
-
let isJSXComponent = element.match(/[A-Z]/) ? true : false;
|
|
238
|
-
if (isJSXComponent) {
|
|
239
|
-
continue
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
let old = spread;
|
|
243
|
-
// turn spread into attributes
|
|
244
|
-
spread = spread.replace(/\s*$\s*=\s*/, "");
|
|
245
|
-
spread = spread.replace(/\$\s*=\s*/, "");
|
|
246
|
-
spread = spread.replace('{{', '')
|
|
247
|
-
spread = spread.replace(/,$/, '');
|
|
248
233
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
e
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
234
|
+
let spreadMatch;
|
|
235
|
+
while ((spreadMatch = spreadAttributeRegex.exec(code)) !== null) {
|
|
236
|
+
let [, element, spread] = spreadMatch;
|
|
237
|
+
let isJSXComponent = element.match(/^[A-Z]/) ? true : false;
|
|
238
|
+
if (isJSXComponent) {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
let old = spread;
|
|
242
|
+
spread = spread.trim().replace(/\s+/g, " ");
|
|
243
|
+
// re,pve $={ and }
|
|
244
|
+
spread = spread.replace(/\s*\$\s*=\s*{\s*{/gs, '')
|
|
245
|
+
|
|
246
|
+
// replace trailing }
|
|
247
|
+
spread = spread.replace(/}}\s*$/, '').replace(/}\s*}$/, '')
|
|
248
|
+
let splitByCommas = spread.split(/,(?![^{}]*})/gs)
|
|
249
|
+
// remove empty strings
|
|
250
|
+
splitByCommas = splitByCommas.filter((e) => e.split(':')[0].trim().length > 0)
|
|
251
|
+
splitByCommas = splitByCommas.map((e, index) => {
|
|
252
|
+
let key = e.split(':')[0].trim()
|
|
253
|
+
switch (true) {
|
|
254
|
+
case e.includes('function') && !e.includes('this.bind') || e && e.includes('=>') && !e.includes('this.bind'):
|
|
255
|
+
let value = e.split(':')[1].trim()
|
|
256
|
+
let ref = Math.random().toString(36).substring(2).split('').filter((e) => !Number(e)).join('');
|
|
257
|
+
value = `this.bind(${value}, false, "${ref}", "")`
|
|
258
|
+
e = `${key}="\${${value}}"`
|
|
259
|
+
break;
|
|
260
|
+
case e.includes('style:'):
|
|
261
|
+
let v2 = e.split('style:')[1].trim().replace(/,$/, '')
|
|
262
|
+
v2 = v2.replace(/,$/, '')
|
|
263
|
+
e = `${key}="\${this.parseStyle(${v2})}"`
|
|
264
|
+
break;
|
|
265
|
+
|
|
266
|
+
default:
|
|
267
|
+
let v = e.split(':')
|
|
268
|
+
key = v[0].trim()
|
|
269
|
+
// remove key from v
|
|
270
|
+
v.shift()
|
|
271
|
+
v = v.join(' ')
|
|
272
|
+
e = `${key}="\${${v}}"`
|
|
273
|
+
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
283
276
|
|
|
284
|
-
break;
|
|
285
|
-
case e.includes('[') && e.includes(']'):
|
|
286
|
-
e = e.replace(/:(.*)/gs, '={$1.join(" ")}');
|
|
287
|
-
break;
|
|
288
|
-
default:
|
|
289
|
-
e = e.replace(/:(.*)/gs, '="${$1}"');
|
|
290
|
-
e = e.replace(/,\s*$/gs, '');
|
|
291
|
-
e = e.replace(/}\s*$/gs, '');
|
|
292
|
-
e = e.replaceAll(/{\s*$/gs, '');
|
|
293
277
|
|
|
294
|
-
|
|
295
|
-
}
|
|
278
|
+
return e;
|
|
279
|
+
});
|
|
296
280
|
|
|
297
|
-
return e.trim();
|
|
298
|
-
});
|
|
299
281
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
string = string.replace(old, newSpread);
|
|
306
|
-
}
|
|
282
|
+
let newSpread = splitByCommas.join(' ').trim().replace(/,$/, '');
|
|
283
|
+
|
|
284
|
+
// remove trailing }
|
|
285
|
+
string = string.replace(old, newSpread);
|
|
286
|
+
}
|
|
307
287
|
|
|
308
288
|
return attributesList;
|
|
309
289
|
}
|
|
@@ -346,12 +326,12 @@ function Compiler(func, file) {
|
|
|
346
326
|
}
|
|
347
327
|
let usesBraces = returnStatement.match(/return\s*\(/gs) ? true : false;
|
|
348
328
|
|
|
349
|
-
let attributes = extractAttributes(
|
|
329
|
+
let attributes = extractAttributes(string);
|
|
350
330
|
contents = contents.trim().replace(/\]$/, "")
|
|
351
331
|
contents = contents.replace(/\)$/, "");
|
|
352
332
|
usesBraces ? !contents.includes('<>') ? contents = `<>${contents}</>` : null : null
|
|
353
333
|
updatedContents = contents;
|
|
354
|
-
|
|
334
|
+
|
|
355
335
|
|
|
356
336
|
let newAttributes = [];
|
|
357
337
|
let oldAttributes = [];
|
|
@@ -371,16 +351,16 @@ function Compiler(func, file) {
|
|
|
371
351
|
let value = attributes[key];
|
|
372
352
|
let oldvalue = value;
|
|
373
353
|
if (value && !value.new) {
|
|
374
|
-
|
|
354
|
+
|
|
375
355
|
if (value && value.includes("={")) {
|
|
376
|
-
|
|
356
|
+
|
|
377
357
|
value = value.replace("=", "");
|
|
378
358
|
value == "undefined" ? (value = '"') : (value = value);
|
|
379
359
|
|
|
380
360
|
key == 'style'
|
|
381
361
|
&& value.includes("{{")
|
|
382
362
|
? value = `{this.parseStyle({${value.split('{{')[1].split('}}')[0]}})}` : null
|
|
383
|
-
|
|
363
|
+
|
|
384
364
|
|
|
385
365
|
|
|
386
366
|
value = `="\$${value}",`;
|
|
@@ -504,7 +484,7 @@ function Compiler(func, file) {
|
|
|
504
484
|
|
|
505
485
|
|
|
506
486
|
let props = component.match(dynamicAttributesRegex)
|
|
507
|
-
|
|
487
|
+
|
|
508
488
|
let filteredProps = [];
|
|
509
489
|
let isWithinComponent = false;
|
|
510
490
|
let componentName = name
|
|
@@ -519,25 +499,24 @@ function Compiler(func, file) {
|
|
|
519
499
|
isWithinComponent = true;
|
|
520
500
|
filteredProps.push(prop);
|
|
521
501
|
} else if (isWithinComponent && prop.includes('=')) {
|
|
522
|
-
|
|
502
|
+
|
|
523
503
|
if (prop.startsWith('$=')) {
|
|
524
504
|
let old = prop
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
component = component.replace(old,
|
|
528
|
-
componentAttributes = componentAttributes.replace(old,
|
|
505
|
+
let match = prop.replace(/\$\s*=\s*\{\s*\{\s*([^]*?)\s*\}\s*\}/gs, '$1')
|
|
506
|
+
match = match.replace('$:', '$_ternary:')
|
|
507
|
+
component = component.replace(old, '')
|
|
508
|
+
componentAttributes = componentAttributes.replace(old, match)
|
|
529
509
|
|
|
530
510
|
$_ternaryprops.push(prop)
|
|
531
511
|
|
|
532
512
|
}
|
|
533
513
|
else if (prop.includes('${')) {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
prop = prop.replace('="', ':').replace('}"', '}')
|
|
537
|
-
if (prop.includes('${')) {
|
|
538
|
-
prop = prop.replace('="', ':')
|
|
539
|
-
prop = prop.replace('${', '')
|
|
540
514
|
|
|
515
|
+
|
|
516
|
+
prop = prop.replace('="', ':')
|
|
517
|
+
if (prop.includes('${')) {
|
|
518
|
+
prop = prop.replace('="', ':')
|
|
519
|
+
prop = prop.replace('${', '')
|
|
541
520
|
}
|
|
542
521
|
if (prop.includes('="${{')) {
|
|
543
522
|
prop = prop.replace('${{', '{')
|
|
@@ -547,19 +526,21 @@ function Compiler(func, file) {
|
|
|
547
526
|
}
|
|
548
527
|
|
|
549
528
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
if(value.endsWith('}')){
|
|
557
|
-
value = value.slice(0, -1)
|
|
529
|
+
if (prop.includes('={')) {
|
|
530
|
+
let value = prop.split('={')
|
|
531
|
+
let isObj = value[1].match(/^{.*}$/gs) ? true : false
|
|
532
|
+
if (!isObj) {
|
|
533
|
+
// remove trailing }
|
|
534
|
+
value[1] = value[1].replace(/}\s*$/, '')
|
|
558
535
|
}
|
|
559
|
-
|
|
536
|
+
|
|
537
|
+
if (value[0] == 'style' && isObj) {
|
|
538
|
+
value[1] = `this.parseStyle(${value[1]})`
|
|
539
|
+
}
|
|
540
|
+
prop = `${value[0]}:${value[1]}`
|
|
560
541
|
}
|
|
561
542
|
|
|
562
|
-
if (prop.includes('function')) {
|
|
543
|
+
if (prop.includes('function') || prop.includes('=>')) {
|
|
563
544
|
// parse 'function' to function
|
|
564
545
|
prop = prop.replace("'", '')
|
|
565
546
|
|
|
@@ -570,13 +551,13 @@ function Compiler(func, file) {
|
|
|
570
551
|
|
|
571
552
|
prop = prop.replace('=function', ':function')
|
|
572
553
|
}
|
|
573
|
-
|
|
554
|
+
|
|
574
555
|
filteredProps.push(prop);
|
|
575
556
|
|
|
576
557
|
|
|
577
558
|
|
|
578
|
-
}else if (isWithinComponent && prop.includes('}')) {
|
|
579
|
-
|
|
559
|
+
} else if (isWithinComponent && prop.includes('}')) {
|
|
560
|
+
|
|
580
561
|
}
|
|
581
562
|
|
|
582
563
|
|
|
@@ -683,10 +664,10 @@ function Compiler(func, file) {
|
|
|
683
664
|
let text = fs.readFileSync(file, "utf8");
|
|
684
665
|
if (!file.endsWith('.js') && file.endsWith('.jsx')) {
|
|
685
666
|
text = Compiler(text, file);
|
|
686
|
-
|
|
667
|
+
|
|
687
668
|
}
|
|
688
669
|
let dest = file.split('node_modules')[1]
|
|
689
|
-
dest = dest.split(baseFolder)[1]
|
|
670
|
+
dest = dest.split(baseFolder)[1]
|
|
690
671
|
writer(process.cwd() + '/dist/src/' + baseFolder + dest, text)
|
|
691
672
|
let importname = match.split('import')[1].split('from')[0].trim()
|
|
692
673
|
let oldImportstring = match.split('from')[1].trim().replace(/'/g, '').replace(/"/g, '').trim()
|
|
@@ -895,7 +876,7 @@ const glb = await glob("**/**/**/**.{jsx,js}", {
|
|
|
895
876
|
async function Build() {
|
|
896
877
|
globalThis.isBuilding = true
|
|
897
878
|
console.log(globalThis.isProduction ? 'Creating Optimized Production Build\n' : '')
|
|
898
|
-
let str = `Page \t\t\t\t Size\n`
|
|
879
|
+
let str = `Page \t\t\t\t Size\n`
|
|
899
880
|
globalThis.isProduction ? console.log('\x1b[32m%s\x1b[0m', str) : null
|
|
900
881
|
let reader = async (file) => {
|
|
901
882
|
let text = await fs.readFileSync(file, "utf8");
|
|
@@ -903,11 +884,11 @@ async function Build() {
|
|
|
903
884
|
};
|
|
904
885
|
|
|
905
886
|
|
|
906
|
-
|
|
887
|
+
|
|
907
888
|
function ssg(routes = []) {
|
|
908
|
-
globalThis.isBuilding = true
|
|
889
|
+
globalThis.isBuilding = true
|
|
909
890
|
routes.forEach(async (route) => {
|
|
910
|
-
if (route.url.includes(':')) {
|
|
891
|
+
if (route.url.includes(':')) {
|
|
911
892
|
return
|
|
912
893
|
}
|
|
913
894
|
let equalparamroute = routes.map((e) => {
|
|
@@ -928,6 +909,8 @@ async function Build() {
|
|
|
928
909
|
<head>
|
|
929
910
|
<script>
|
|
930
911
|
window.routes = JSON.parse('${JSON.stringify(routes)}')
|
|
912
|
+
|
|
913
|
+
|
|
931
914
|
</script>
|
|
932
915
|
<script id="isServer">
|
|
933
916
|
window.isServer = true
|
|
@@ -950,8 +933,16 @@ async function Build() {
|
|
|
950
933
|
res.render(module, req, res, module.$metadata)
|
|
951
934
|
}
|
|
952
935
|
catch(error){
|
|
953
|
-
|
|
954
|
-
|
|
936
|
+
let errorMessage = {
|
|
937
|
+
message: error.message,
|
|
938
|
+
name: error.name,
|
|
939
|
+
stack: error.stack,
|
|
940
|
+
path: window.location.pathname
|
|
941
|
+
};
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
document.documentElement.setAttribute('error', JSON.stringify(errorMessage));
|
|
945
|
+
throw new Error(error)
|
|
955
946
|
}
|
|
956
947
|
})
|
|
957
948
|
${equalparamroute.length > 0 ? equalparamroute.map((e) => {
|
|
@@ -964,7 +955,7 @@ async function Build() {
|
|
|
964
955
|
})\n`
|
|
965
956
|
}) : ''}
|
|
966
957
|
router.listen(3000)
|
|
967
|
-
|
|
958
|
+
|
|
968
959
|
</script>
|
|
969
960
|
</head>
|
|
970
961
|
<body>
|
|
@@ -1015,28 +1006,24 @@ async function Build() {
|
|
|
1015
1006
|
const browser = await puppeteer.launch({
|
|
1016
1007
|
headless: "new", args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
1017
1008
|
warning: false,
|
|
1018
|
-
})
|
|
1009
|
+
})
|
|
1019
1010
|
try {
|
|
1020
1011
|
|
|
1021
1012
|
route.url = route.url.replaceAll(/\/:[a-zA-Z0-9_-]+/gs, '')
|
|
1022
1013
|
let page = await browser.newPage();
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
console.error('BROWSER ERROR:', err);
|
|
1014
|
+
// Handle browser errors
|
|
1015
|
+
page.on('error', (err) => {
|
|
1016
|
+
console.error('BROWSER ERROR:', JSON.parse(err));
|
|
1026
1017
|
});
|
|
1027
|
-
|
|
1028
|
-
window.onerror = function (msg, url, lineNo, columnNo, error) {
|
|
1029
|
-
console.log(msg, url, lineNo, columnNo, error)
|
|
1030
|
-
}
|
|
1031
|
-
})
|
|
1018
|
+
|
|
1032
1019
|
try {
|
|
1033
1020
|
page.on('pageerror', async err => {
|
|
1034
|
-
let errorObj =
|
|
1035
|
-
console.log('\x1b[31m%s\x1b[0m', '
|
|
1036
|
-
|
|
1021
|
+
let errorObj = JSON.parse(await page.evaluate(() => document.documentElement.getAttribute('error')) || '{}')
|
|
1022
|
+
console.log('\x1b[31m%s\x1b[0m', 'Compiler Error:', errorObj)
|
|
1023
|
+
|
|
1037
1024
|
});
|
|
1038
1025
|
} catch (error) {
|
|
1039
|
-
|
|
1026
|
+
browser.close()
|
|
1040
1027
|
}
|
|
1041
1028
|
// Handle page crashes
|
|
1042
1029
|
page.on('crash', () => {
|
|
@@ -1045,14 +1032,14 @@ async function Build() {
|
|
|
1045
1032
|
page.on('requestfailed', request => {
|
|
1046
1033
|
console.error('REQUEST FAILED:', request.url(), request.failure().errorText);
|
|
1047
1034
|
});
|
|
1048
|
-
|
|
1049
|
-
|
|
1035
|
+
await page.goto(`http://localhost:${port}/`, { waitUntil: 'networkidle2' });
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1050
1041
|
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
1042
|
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
1043
|
await page.evaluate(() => {
|
|
1057
1044
|
document.getElementById('meta').remove()
|
|
1058
1045
|
document.querySelector('#isServer').innerHTML = 'window.isServer = false'
|
|
@@ -1060,29 +1047,29 @@ async function Build() {
|
|
|
1060
1047
|
document.querySelector('#root').innerHTML = ''
|
|
1061
1048
|
console.log(`Disabled prerendering for ${window.location.pathname}`)
|
|
1062
1049
|
}
|
|
1063
|
-
})
|
|
1050
|
+
})
|
|
1064
1051
|
let html = await page.content();
|
|
1065
1052
|
|
|
1066
|
-
html = await prettier.format(html, { parser: "html" })
|
|
1067
|
-
|
|
1068
|
-
|
|
1053
|
+
html = await prettier.format(html, { parser: "html" })
|
|
1054
|
+
|
|
1055
|
+
|
|
1069
1056
|
await writer(process.cwd() + '/dist/' + (route.url === '/' ? 'index.html' : `${route.url}/` + 'index.html'), html)
|
|
1070
|
-
|
|
1057
|
+
|
|
1071
1058
|
|
|
1072
1059
|
} catch (error) {
|
|
1073
|
-
console.log(error)
|
|
1074
|
-
}
|
|
1060
|
+
console.log(error)
|
|
1061
|
+
}
|
|
1075
1062
|
|
|
1076
1063
|
finally {
|
|
1077
|
-
|
|
1078
|
-
server.close()
|
|
1064
|
+
browser.close()
|
|
1065
|
+
server.close()
|
|
1079
1066
|
}
|
|
1080
1067
|
})
|
|
1081
1068
|
|
|
1082
1069
|
let timeout = setTimeout(() => {
|
|
1083
1070
|
globalThis.isBuilding = false
|
|
1084
1071
|
clearTimeout(timeout)
|
|
1085
|
-
}, 1000)
|
|
1072
|
+
}, 1000)
|
|
1086
1073
|
}
|
|
1087
1074
|
|
|
1088
1075
|
globalThis.routes = []
|
|
@@ -1114,14 +1101,15 @@ async function Build() {
|
|
|
1114
1101
|
|
|
1115
1102
|
|
|
1116
1103
|
let data = await fs.readFileSync(origin, "utf8");
|
|
1117
|
-
|
|
1118
|
-
|
|
1104
|
+
|
|
1105
|
+
// gen sourcemap if not production
|
|
1119
1106
|
let size = fs.statSync(origin).size;
|
|
1120
|
-
if(!globalThis.isProduction){
|
|
1121
|
-
let { sourceMap } = sourceMapGen({origin:origin, fileName:fileName}, await Compiler(data, origin))
|
|
1107
|
+
if (!globalThis.isProduction) {
|
|
1108
|
+
let { sourceMap } = sourceMapGen({ origin: origin, fileName: fileName }, await Compiler(data, origin))
|
|
1109
|
+
data = data + `\n//# sourceMappingURL=/src/maps/${fileName.replace('.jsx', '.js.map')}\n //#sourceURL=${origin}`
|
|
1122
1110
|
await writer(process.cwd() + "/dist/src/maps/" + fileName.replace('.jsx', '.js.map'), JSON.stringify(sourceMap, null, 2))
|
|
1123
1111
|
}
|
|
1124
|
-
await writer(process.cwd() + "/dist/" + fileName.replace('.jsx', '.js'), await Compiler(data, origin))
|
|
1112
|
+
await writer(process.cwd() + "/dist/" + fileName.replace('.jsx', '.js'), await Compiler(data, origin))
|
|
1125
1113
|
|
|
1126
1114
|
// configure routing for each page
|
|
1127
1115
|
|
|
@@ -1185,17 +1173,18 @@ async function Build() {
|
|
|
1185
1173
|
|
|
1186
1174
|
globalThis.routes.push({ fileName: fileName, url: obj.url, html: '/' + (isBasePath ? 'index.html' : `${obj.url}/` + 'index.html') })
|
|
1187
1175
|
|
|
1188
|
-
|
|
1189
|
-
let stats = {
|
|
1176
|
+
|
|
1177
|
+
let stats = {
|
|
1178
|
+
route: obj.url.padEnd(30),
|
|
1190
1179
|
size: Math.round(size / 1000) + 'kb',
|
|
1191
1180
|
letParentFolder: obj.url.split('/').slice(0, -1).join('/'),
|
|
1192
1181
|
isChildRoute: obj.url.split('/').slice(0, -1).join('/').includes(':') ? true : false,
|
|
1193
1182
|
parentRoute: obj.url.split('/').slice(0, -1).join('/').split(':')[0],
|
|
1194
|
-
|
|
1195
|
-
}
|
|
1183
|
+
|
|
1184
|
+
}
|
|
1196
1185
|
stats.isChildRoute ? stats.route = `? ${obj.url}` : null
|
|
1197
1186
|
let string = `${isBasePath ? '+' : '+'} ${stats.route.padEnd(30)} ${stats.size}`
|
|
1198
|
-
|
|
1187
|
+
|
|
1199
1188
|
globalThis.isProduction ? console.log(string) : null
|
|
1200
1189
|
}
|
|
1201
1190
|
|
|
@@ -1231,9 +1220,13 @@ async function Build() {
|
|
|
1231
1220
|
|
|
1232
1221
|
let data = await reader(process.cwd() + "/src/" + name)
|
|
1233
1222
|
if (name.includes('.jsx')) {
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1223
|
+
let origin = process.cwd() + "/src/" + name
|
|
1224
|
+
if (!globalThis.isProduction) {
|
|
1225
|
+
let { sourceMap } = sourceMapGen({ origin: origin, fileName: name }, await Compiler(data, origin))
|
|
1226
|
+
data = data + `\n//# sourceMappingURL=/src/maps/${name.replace('.jsx', '.js.map')}\n //#sourceURL=${origin}`
|
|
1227
|
+
await writer(process.cwd() + "/dist/src/maps/" + name.replace('.jsx', '.js.map'), JSON.stringify(sourceMap, null, 2))
|
|
1228
|
+
}
|
|
1229
|
+
await writer(process.cwd() + "/dist/src/" + name.split('.jsx').join('.js'), await Compiler(data, origin))
|
|
1237
1230
|
return
|
|
1238
1231
|
}
|
|
1239
1232
|
bundleSize += fs.statSync(process.cwd() + "/src/" + name).size;
|
|
@@ -1378,7 +1371,7 @@ const s = () => {
|
|
|
1378
1371
|
console.log(`Server is running on port ${PORT}`);
|
|
1379
1372
|
globalThis.ws = ws
|
|
1380
1373
|
});
|
|
1381
|
-
|
|
1374
|
+
|
|
1382
1375
|
|
|
1383
1376
|
}
|
|
1384
1377
|
|
|
@@ -1404,7 +1397,7 @@ Vader.js v1.3.3
|
|
|
1404
1397
|
if (event == 'change'
|
|
1405
1398
|
&& !globalThis.isBuilding
|
|
1406
1399
|
) {
|
|
1407
|
-
if(globalThis.ws && !globalThis.isWriting){
|
|
1400
|
+
if (globalThis.ws && !globalThis.isWriting) {
|
|
1408
1401
|
globalThis.ws.clients.forEach((client) => {
|
|
1409
1402
|
console.log('Reloading...')
|
|
1410
1403
|
client.send('reload')
|
|
@@ -1432,7 +1425,7 @@ Vader.js v1.3.3
|
|
|
1432
1425
|
Vader.js v1.3.3
|
|
1433
1426
|
Building to ./dist
|
|
1434
1427
|
`)
|
|
1435
|
-
if(fs.existsSync(process.cwd() + '/dist/src/maps')){
|
|
1428
|
+
if (fs.existsSync(process.cwd() + '/dist/src/maps')) {
|
|
1436
1429
|
fs.rmSync(process.cwd() + '/dist/src/maps', { recursive: true })
|
|
1437
1430
|
}
|
|
1438
1431
|
Build()
|