vaderjs 1.4.0-90gbho234 → 1.4.1-h7iuy47
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/@integrations/ssg.js +189 -0
- package/LICENSE +21 -0
- package/README.md +26 -45
- package/binaries/IPC/index.js +277 -0
- package/binaries/main.js +1258 -479
- package/binaries/watcher.js +70 -66
- package/binaries/win32/check.ps1 +7 -0
- package/config/index.js +36 -0
- package/package.json +5 -6
- package/runtime/router.js +1 -1
- package/runtime/vader.js +1 -1
- package/vader.js +54 -89
- package/binaries/generator.js +0 -202
package/binaries/watcher.js
CHANGED
|
@@ -1,70 +1,74 @@
|
|
|
1
1
|
/**
|
|
2
|
+
|
|
2
3
|
* @file watcher.js
|
|
4
|
+
|
|
3
5
|
* @description This file is used as a polyfill for missing functionality of bun.js fs watch on windows
|
|
6
|
+
|
|
4
7
|
*/
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
8
|
+
|
|
9
|
+
import { watch } from "fs";
|
|
10
|
+
|
|
11
|
+
import IPC from "../binaries/IPC/index.js";
|
|
12
|
+
|
|
13
|
+
IPC.NOLISTEN = true;
|
|
14
|
+
|
|
15
|
+
const s = await IPC.newServer(IPC.typeEnums.WATCHER, { port: process.env.PORT || 3434 });
|
|
16
|
+
|
|
17
|
+
console = s.Console;
|
|
18
|
+
|
|
19
|
+
process.cwd = () => {
|
|
20
|
+
return process.env.PWD;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
let folders = process.env.FOLDERS.split(",");
|
|
24
|
+
|
|
25
|
+
let hasSent = false;
|
|
26
|
+
|
|
27
|
+
folders.forEach((folder) => {
|
|
28
|
+
watch(process.cwd() + "/" + folder, { recursive: true }, (event, filename) => {
|
|
29
|
+
switch (event) {
|
|
30
|
+
case "change":
|
|
31
|
+
if (!hasSent) {
|
|
32
|
+
console.log({ type: "change", filename });
|
|
33
|
+
|
|
34
|
+
hasSent = true;
|
|
35
|
+
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
hasSent = false;
|
|
38
|
+
}, 1000);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
break;
|
|
42
|
+
|
|
43
|
+
case "add":
|
|
44
|
+
if (!hasSent) {
|
|
45
|
+
console.log({ type: "add", filename });
|
|
46
|
+
|
|
47
|
+
hasSent = true;
|
|
48
|
+
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
hasSent = false;
|
|
51
|
+
}, 500);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
break;
|
|
55
|
+
|
|
56
|
+
case "close":
|
|
57
|
+
if (!hasSent) {
|
|
58
|
+
console.log({ type: "close", filename });
|
|
59
|
+
|
|
60
|
+
hasSent = true;
|
|
61
|
+
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
hasSent = false;
|
|
64
|
+
}, 500);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
process.on("exit", function (code) {
|
|
73
|
+
console.log("About to exit with code:", code);
|
|
74
|
+
});
|
package/config/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @function defineConfig
|
|
3
|
+
* @description Define the configuration for the application
|
|
4
|
+
* @param {Object} config
|
|
5
|
+
* @param {Object} config.host - Important metadata
|
|
6
|
+
* @param {string} config.host.hostname - The hostname for your webapplication
|
|
7
|
+
* @param {Object} config.host.prod - Define data for production use
|
|
8
|
+
* @param {Number} config.host.prod.port - The production port for your webapp
|
|
9
|
+
* @param {('vercel'|'netlify'|'cloudflare')} config.host.provider - Helps vader to generate routes for your webapp
|
|
10
|
+
* @param {Object} config.dev - The development server configuration
|
|
11
|
+
* @param {Number} config.dev.port - The port to use for the development server
|
|
12
|
+
* @param {('localhost')} config.dev.host - The hostname to use for the development server
|
|
13
|
+
* @param {Array} config.integrations - Additional integrations to enhance vaderjs
|
|
14
|
+
* @param {Function} config.integrations[0] - The integration to use for the application
|
|
15
|
+
* @returns {Object} The defined configuration
|
|
16
|
+
*/
|
|
17
|
+
export const defineConfig = (config = {
|
|
18
|
+
host: {
|
|
19
|
+
provider: '',
|
|
20
|
+
hostname:'',
|
|
21
|
+
prod:{
|
|
22
|
+
port:3000,
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
dev: {
|
|
26
|
+
port: 3000, // Default port for the development server
|
|
27
|
+
host: 'localhost' // Default hostname for the development server
|
|
28
|
+
},
|
|
29
|
+
integrations: []
|
|
30
|
+
}) => {
|
|
31
|
+
return config;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default {
|
|
35
|
+
defineConfig
|
|
36
|
+
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "vaderjs",
|
|
3
3
|
"description": "A Reactive library aimed to helping you build reactive applications inspired by react.js",
|
|
4
4
|
"module": "vader.js",
|
|
5
|
-
"version": "1.4.
|
|
5
|
+
"version": "1.4.1-h7iuy47",
|
|
6
6
|
"bin": {
|
|
7
7
|
"vader": "./vader.js"
|
|
8
8
|
},
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"nextjs",
|
|
13
13
|
"pages router",
|
|
14
14
|
"bun.js",
|
|
15
|
+
"severside generation",
|
|
15
16
|
"spa",
|
|
16
17
|
"vanillajs",
|
|
17
18
|
"vanilla js"
|
|
@@ -28,10 +29,8 @@
|
|
|
28
29
|
"email": "malikwhitterb@gmail.com"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"source-map": "latest"
|
|
35
|
-
|
|
32
|
+
"playwright": "latest",
|
|
33
|
+
"source-map": "latest",
|
|
34
|
+
"ws": "latest"
|
|
36
35
|
}
|
|
37
36
|
}
|
package/runtime/router.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import t from"./vader.js";let e=[];export default class Router{constructor(t,e){this.routes=[],this.middlewares=[],this.errorMiddlewares=[],this.listeners=[],this.basePath=t}get(t,e){this.routes.push({method:"get",path:t,handler:e})}use(t){this.middlewares.push(t)}matchingRoute(){return routes.find((t=>t.url===window.location.pathname||window.location.pathname.split("/")[1]===t.url.split("/")[1]||void 0))}listen(t,e){t||(t=Math.random().toString(36).substring(7)),this.listeners.push(t),window.onpopstate=async t=>{let e=window.location.pathname;if(e.includes("#noNavigation"))return;let r=`/${e.split("/")[1]}`,n=(new DOMParser).parseFromString(await fetch(r,{cache:"reload"}).then((t=>t.text())),"text/html").documentElement,o=(n.querySelector("head"),n.querySelector("body"));document.querySelector("#app").innerHTML=o.querySelector("#app").innerHTML;let s=document.createElement("script");s.id="router",s.innerHTML=o.querySelector('script[id="router"]').innerHTML,s.setAttribute("type","module"),document.body.removeChild(document.getElementById("router")),document.body.appendChild(s)},window.location.pathname.includes("#noNavigation")||(console.log("no navigation"),this.handleRoute(window.location.pathname)),e&&e()}render(e){document.querySelector("#app").innerHTML="",t.render(e,document.querySelector("#app"))}extractParams(t,e){const r=t.split("/").filter((t=>""!==t)),n=e.split("/").filter((t=>""!==t)),o={};return r.forEach(((t,e)=>{if(t.startsWith(":")){const r=t.slice(1);o[r]=n[e]}else if(t.startsWith("*")){n.slice(e).forEach(((t,e)=>{o[e]=t}))}})),o}extractQueryParams(t){const e=t.split("?")[1];if(!e)return{};const r={};return e.split("&").forEach((t=>{const[e,n]=t.split("=");r[e]=n})),r}checkroute(t){return(t=t.endsWith("/")?t.slice(0,-1):t).includes("index.html")&&(t=t.replace("index.html","")),t.includes("?")&&(t=t.split("?")[0]),this.routes.find((e=>{if(console,e.path===t)return!0;if(""===t&&"/"===e.path)return!0;if(e.path.includes("*")||e.path.includes(":")){const r=e.path.split("/").filter((t=>""!==t)),n=t.split("/").filter((t=>""!==t));if(this.basePath&&n.shift(),console.log(r,n),r.length!==n.length&&!e.path.endsWith("*"))return!1;for(let t=0;t<r.length;t++){const e=r[t],o=n[t];if(!e.startsWith(":")&&!e.startsWith("*")&&e!==o)return!1}return!0}const r=this.extractParams(e.path,t);return Object.keys(r).length>0}))}handleRoute(r){let n=200,o={},s=r,a=this.checkroute(r);a||(n=404,a=this.routes.find((t=>"*"===t.path)),a&&(o=this.extractParams(a.path,r)));const i=this.extractQueryParams(s),l=a&&a.path?this.extractParams(a.path,s):o;Object.keys(l).forEach((t=>{l[t]=l[t].split("?")?l[t].split("?")[0]:l[t]}));const c={headers:{},params:l,query:i,path:r,fileUrl:window.location.href.split(window.location.origin)[1],url:window.location.href,method:a?a.method:"get",pause:!1,timestamp:Date.now()};window.$CURRENT_URL=c.path,window.$basePath=" ",window.$FULL_URL=window.location.href.replace("#","");const h={status:n,log:t=>{void 0===t?console.log(`${c.path} ${c.method} ${h.status} ${c.timestamp}`):console.table({"Request Path":c.path,"Request Method":a.method,"Response Status":h.status,"Request Timestamp":c.timestamp})},refresh:()=>{this.handleRoute(window.location.pathname)},redirect:t=>{!t.startsWith("/")&&(t=`/${t}`),window.history.pushState({},"",t),window.dispatchEvent(new Event("popstate"))},render:async e=>{e?.default&&(e=e.default),document.querySelector("#app").innerHTML="",t.render(e,document.querySelector("#app"),{passProps:{router:{req:c,res:h}}})},setQuery:t=>{if($SERVER)return;let e="";Object.keys(t).forEach(((r,n)=>{e+=`${0===n?"?":"&"}${r}=${t[r]}`}));let r=window.location.pathname.split("?")[0];e=e.replace("/","-").replaceAll("/","-"),c.query={...c.query,...t},window.history.pushState({},"",`${r}${e}`)},getQuery:t=>{let e=window.location.search,r=new URLSearchParams(e);return t?r.get(t.key):r},send:t=>{document.querySelector("#app").innerHTML=t},json:t=>{const e=document.querySelector("#app");e.innerHTML="";const r=document.createElement("pre");r.textContent=JSON.stringify(t,null,2),e.appendChild(r)}};e.forEach((t=>{t(c,h)})),a?h.render(a.handler):h.status(404).send("Not Found")}}
|
package/runtime/vader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let
|
|
1
|
+
let e=[],t={},r={};export const Mounted=(t,r,s=!1)=>{let n=setInterval((()=>{switch(!0){case s&&e.includes(r.key):return clearInterval(n);case s&&!e.includes(r.key):e.push(r.key),t();break;case!document.querySelector(`[key="${r.key}"]`):return;default:t(),clearInterval(n)}}),100)};export class Component{constructor(e){this.state=r[this.constructor.name]||{},this.__internalInstance=null,this.key=e?.key||Math.random(),this.checkMount(),this.mounted=!1,this.props=e,this.useKey=e=>{this.props.key=e,this.key=e}}setState(e){this.state=Object.assign({},this.state,e),this.updateInstance(this.__internalInstance)}useState(e,t){this.state[e]||(this.state[e]=t);let r=this.state[e];const state=()=>this.state[e];return[state,t=>{this.state[e]=t,this.updateInstance(this.__internalInstance),r=state()}]}useRef(e,t){return this.state[e]||(this.state[e]=t),{current:this.state[e]}}onMount(){}domDifference(e,t){let r=[];for(let s=0;s<e.length;s++){let n=e[s],a=t[s];if(n&&a&&n.childNodes.length>0&&a.childNodes.length>0){let e=this.domDifference(Array.from(n.childNodes),Array.from(a.childNodes));return r=r.concat(e),r}n.nodeValue!==a.nodeValue&&r.push({type:"replace",old:n,new:a})}return r}checkMount(){if(this.mounted)return;setInterval((()=>{document.querySelector(`[key="${this.key}"]`)&&!this.mounted&&(this.mounted=!0,this.onMount())}))}updateChangedElements(e){e.forEach((e=>{if(e)switch(e.type){case"replace":if(e.old.panrntNode&&"BODY"===e.old.parentNode.nodeName)return;e.old.replaceWith(e.new.cloneNode(!0));break;case"remove":e.old.remove();break;case"attributeSwap":let t=Array.from(e.old.attributes),r=Array.from(e.new.attributes);t.forEach((t=>{e.old.removeAttribute(t.name)})),r.forEach((t=>{e.old.setAttribute(t.name,t.value)}));break;case"add":e.old.appendChild(e.new.cloneNode(!0))}}))}updateInstance(e){let t=document.querySelector(`[key="${this.key}"]`)||document.querySelector("#app").firstChild,r=s.render(e,t,{return:!0}),n=this.domDifference(Array.from(t.childNodes),Array.from(r.childNodes));this.updateChangedElements(n)}parseStyle(e){let t="";return Object.keys(e).forEach((r=>{let s=e[r];r=r.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g,"$1-$2").toLowerCase(),t+=`${r}:${s};`})),t}}export const useState=e=>{this.state[key]||(this.state[key]=e);let t=this.state[key];const getUpdatedState=()=>this.state[key]||e;return t=getUpdatedState(),[getUpdatedState,e=>{t=e,this.state[key]=e,this.updateInstance(this.__internalInstance)}]};export const useReducer=(e,t)=>{const[r,s]=useState(t);return[r,t=>{const n=e(r,t);s(n)}]};export const useRef=e=>{this.state[key]||(this.state[key]=e);let t=this.state[key];return t=(()=>this.state[key]||e)(),[t,e=>{t=e,this.state[key]=e,this.updateInstance(this.__internalInstance)}]};export class Html extends Component{constructor(e){super(e),this.key=e?.key||"DOCUMENT_ROOT",this.props=e,this.checkMount()}render(){return $SERVER?(this.props.lang&&document.documentElement.setAttribute("lang",this.props.lang),s.createElement("div",{children:this.props.children,key:this.key})):s.createElement("div",{children:this.props.children,key:this.key})}onMount(){this.props?.parent&&this.props?.parent&&this.props.parent.onMount()}}export class Head extends Component{constructor(e){super(e),this.head=document.createElement("div"),this.useKey("head"),this.hasRefreshed=!1}render(){if($SERVER||this.props.refresh){Array.isArray(this.props.children)&&this.props.children.forEach((e=>{let r=s.render(e,this.head,{return:!0}),n=this.head.querySelectorAll("*");for(let e=0;e<n.length;e++)n[e].isEqualNode(r)&&console.log("Equal");console.log(this.key,"key"),this.head.appendChild(r),t[this.key]=!0})),Object.keys(this.props).includes("children")&&!Array.isArray(this.props.children)&&this.head.appendChild(s.render(this.props.children,this.head,{return:!0}));let e=document.head;this.head.querySelectorAll("*").forEach((t=>{switch(t.tagName){case"TITLE":e.querySelector("title")&&e.querySelector("title").remove(),e.appendChild(t);break;case"META":return void(e.querySelector(`meta[name="${t.name}"]`)||e.appendChild(t));case"LINK":if($SERVER)return console.log("Server"),void(e.querySelector(`link[href="${t.href}"]`)||e.appendChild(t));case"SCRIPT":if(!t.hasAttribute("eager"))return void(document.querySelector(`script[src="${t.src}"]`)||e.appendChild(t));if(document.querySelector(`script[srcid="${t.src}"]`))return;fetch(t.src).then((e=>e.text())).then((r=>{let s=document.createElement("script");s.innerHTML=r,s.setAttribute("srcid",t.src),s.setAttribute("type",t.type),s.setAttribute("async",t.async||!1),s.setAttribute("defer",t.defer||!1),e.querySelector(`script[srcid="${t.src}"]`)||e.prepend(s)})).catch((e=>{console.warn("Error fetching script",e)}));break;default:console.warn("Unknown tag",t.tagName)}}))}return""}}export class Link extends Component{constructor(e){super(e),this.key=e?.key||Math.random(),this.props=e,this.checkMount()}render(){let e={...this.props,href:this.props?.href,onClick:e=>{switch(e.preventDefault(),!0){case"outside"===this.props.action:console.log("Outside"),e.preventDefault(),window.open(this.props.href,"_blank");break;case"function"==typeof this.props.action:this.props.action(e);break;default:e.preventDefault(),window.history.pushState({},"",this.props.href),window.dispatchEvent(new Event("popstate"))}},key:this.key};return s.createElement("a",e,this.props?.key,null)}}let s=new class vjsx{constructor(){this._vjsx=!0}isClass(e){return/^\s*class\s+/.test(e.toString())}instanizeClass(e,t={}){if("string"==typeof e||"object"==typeof e)return e;switch(this.isClass(e)){case!0:let s=new e(t);return r[e.name]=s.state,s.state=r[e.name],s.$$typeof="vjsx",s.type=e.name,s.key=t?.key||s.name,s.props=t,s.__internalInstance=()=>s.render(s.props),s.render();case!1:let n=new Component;n.key=e.name+Math.random(),e.$$typeof="vjsx",e.useState=n.useState.bind(n),e.setState=n.setState.bind(n),r[e.name]=n.state,n.state=r[e.name],e.state=n.state;let a={},o={};return t?.router&&(a=t.router.req,o=t.router.res),n.__internalInstance=()=>e.bind(n)(t,a,o),e.apply?e.apply(n,[t,a,o]):e}}createElement(e,t,r,...s){let n="function"==typeof e,a=s.find((e=>"vjsx"===e?.$$typeof));if(n)return t.key=r||t?.key||Math.random(),t.parent=a,this.instanizeClass(e,t);let o={type:e,RootParent:a,props:{...t,key:t?.key||Math.random(),children:Array.isArray(t.children)?t.children:[t.children]}};return"TEXT_ELEMENT"===("string"==typeof o?"TEXT_ELEMENT":o.type)?function createTextElement(e){return{type:"TEXT_ELEMENT",props:{nodeValue:e,children:[]}}}(o):o}render(e,t,r){let s=this.instanizeClass(e,r?.passProps);if(r&&r?.passProps&&r?.passProps?.router){let e=r.passProps.router.req;r.passProps.router.res;e.pause}if(!s.type)return;let n="TEXT_ELEMENT"===s.type?document.createTextNode(""):document.createElement(s.type),isListener=e=>e.startsWith("on");if(s.props&&(s.props.key&&(s.key=s.props.key),Object.keys(s.props).filter(isListener).forEach((e=>{let t=e.toLowerCase().substring(2);n.addEventListener(t,s.props[e].bind(s))})),Object.keys(s.props).filter((e=>!isListener(e))).forEach((e=>{switch(!0){case"className"===e||"class"===e||"classname"===e:n.setAttribute("class",s.props[e]),delete s.props[e];break;case"ref"===e:if(Array.isArray(s.props[e].current))return void s.props[e].current.push(n);s.props[e].current=n,n.removeAttribute("ref");break;case"htmlFor"===e:n.setAttribute("for",s.props[e]);break;case"style"===e:n.setAttribute("style",Component.prototype.parseStyle(s.props[e]));break;default:"children"!==e&&n.setAttribute(e,s.props[e])}"TEXT_ELEMENT"!==s.type||(n.nodeValue=s.props[e])}))),s.props&&s.props.children&&Array.isArray(s.props.children)&&s.props?.children&&s.props.children.forEach((e=>{if("number"!=typeof e&&"string"!=typeof e||(e=e.toString()),Array.isArray(e))return void e.forEach((e=>{null!==e&&this.render(e,n,!0)}));if(!e)return;let t="function"==typeof e?this.instanizeClass(e):e;"TEXT_ELEMENT"!==(t?.type?t.type:"TEXT_ELEMENT")?this.render(t,n):n.appendChild(document.createTextNode(t))})),r?.return)return n;s.key&&n.setAttribute("key",s.key),!r?.return&&document.body.contains(t)&&(s?.RootParent?.onMount(),t.innerHTML=""),t.appendChild(n)}},n={createElement:s.createElement,useState:useState,instanizeClass:s.instanizeClass,render:s.render,useRef:useRef,isClass:s.isClass,Head:Head,Html:Html,Mounted:Mounted,Component:Component,Link:Link};export default n;
|
package/vader.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
import { exec } from "child_process";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
globalThis.currentCommand = null;
|
|
5
|
-
|
|
5
|
+
globalThis.isRunning = false;
|
|
6
|
+
let vaderisInstalled = process.cwd() + "/node_modules/vaderjs/binaries/main.js";
|
|
6
7
|
if (!fs.existsSync(process.cwd() + "/_dev")) {
|
|
7
8
|
fs.mkdirSync(process.cwd() + "/_dev");
|
|
9
|
+
!fs.existsSync(process.cwd() + "/_dev/readme.md") && fs.writeFileSync(process.cwd() + "/_dev/readme.md", `This folder is used by vader.js to store important files, deletables include: Bun, Chrome - These should only be uninstalled if you need to reinstall them.`);
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
if (!fs.existsSync(process.cwd() + "/_dev/vader.js")) {
|
|
@@ -13,12 +15,12 @@ if (!fs.existsSync(process.cwd() + "/_dev/vader.js")) {
|
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
function checkIFBundleIsInstalled() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
if (fs.existsSync(process.cwd() + "/_dev/bun")) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
resolve(true);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
22
24
|
exec("bun -v", (err, stdout, stderr) => {
|
|
23
25
|
if (err) {
|
|
24
26
|
reject(err);
|
|
@@ -35,15 +37,10 @@ function checkIFBundleIsInstalled() {
|
|
|
35
37
|
|
|
36
38
|
function run() {
|
|
37
39
|
if (!fs.existsSync(process.cwd() + "/package.json")) {
|
|
38
|
-
fs.writeFileSync(
|
|
39
|
-
process.cwd() + "/package.json",
|
|
40
|
-
JSON.stringify({ name: "my_app", version: "1.0.0" }, null, 2)
|
|
41
|
-
);
|
|
40
|
+
fs.writeFileSync(process.cwd() + "/package.json", JSON.stringify({ name: "my_app", version: "1.0.0" }, null, 2));
|
|
42
41
|
return;
|
|
43
42
|
}
|
|
44
|
-
let packageJson = JSON.parse(
|
|
45
|
-
fs.readFileSync(process.cwd() + "/package.json").toString()
|
|
46
|
-
);
|
|
43
|
+
let packageJson = JSON.parse(fs.readFileSync(process.cwd() + "/package.json").toString());
|
|
47
44
|
if (!packageJson.scripts) {
|
|
48
45
|
packageJson.scripts = {};
|
|
49
46
|
}
|
|
@@ -53,30 +50,26 @@ function run() {
|
|
|
53
50
|
if (!packageJson.dependencies) {
|
|
54
51
|
packageJson.dependencies = {};
|
|
55
52
|
}
|
|
56
|
-
fs.writeFileSync(
|
|
57
|
-
process.cwd() + "/package.json",
|
|
58
|
-
JSON.stringify(packageJson, null, 2)
|
|
59
|
-
);
|
|
60
|
-
|
|
53
|
+
fs.writeFileSync(process.cwd() + "/package.json", JSON.stringify(packageJson, null, 2));
|
|
61
54
|
|
|
62
55
|
if (currentCommand) {
|
|
63
|
-
let child = exec(currentCommand)
|
|
56
|
+
let child = exec(currentCommand);
|
|
64
57
|
child.stdout.pipe(process.stdout);
|
|
65
58
|
child.stderr.pipe(process.stderr);
|
|
66
|
-
child.on(
|
|
59
|
+
child.on("exit", (code) => {
|
|
67
60
|
process.exit(code);
|
|
68
61
|
});
|
|
69
|
-
child.on(
|
|
70
|
-
|
|
62
|
+
child.on("message", (message) => {
|
|
63
|
+
console.log(message.toString());
|
|
71
64
|
});
|
|
72
|
-
child.on(
|
|
65
|
+
child.on("error", (err) => {
|
|
73
66
|
console.error(err);
|
|
74
67
|
});
|
|
75
68
|
|
|
76
|
-
return
|
|
69
|
+
return;
|
|
77
70
|
}
|
|
78
|
-
|
|
79
|
-
console.log(`
|
|
71
|
+
|
|
72
|
+
console.log(`
|
|
80
73
|
Vader.js is a reactive framework for building interactive applications for the web built ontop of bun.js!
|
|
81
74
|
|
|
82
75
|
Usage: npx vaderjs <command>
|
|
@@ -92,74 +85,58 @@ console.log(`
|
|
|
92
85
|
Learn more about vader: https://vader-js.pages.dev/
|
|
93
86
|
|
|
94
87
|
`);
|
|
95
|
-
|
|
96
88
|
}
|
|
97
89
|
|
|
98
90
|
function checkIFChromeIumIsInstalled() {
|
|
99
|
-
let platform = process.platform;
|
|
100
|
-
let findChrome = {
|
|
101
|
-
windows
|
|
91
|
+
let platform = process.platform;
|
|
92
|
+
let findChrome = {
|
|
93
|
+
windows: `powershell -c "${process.cwd() + "\\node_modules\\vaderjs\\binaries\\win32\\check.ps1"}"`,
|
|
102
94
|
others: "/usr/bin/chromium-browser --version",
|
|
103
95
|
};
|
|
104
|
-
let installCommands = {
|
|
96
|
+
let installCommands = {
|
|
105
97
|
windows: `winget install Google.Chrome`,
|
|
106
98
|
others: "sudo apt-get install chromium-browser -y",
|
|
107
99
|
};
|
|
108
100
|
findChrome.windows = findChrome.windows.replace(/\n/g, " ");
|
|
109
|
-
let commandToRun =
|
|
110
|
-
|
|
111
|
-
|
|
101
|
+
let commandToRun = platform === "win32" ? findChrome.windows : findChrome.others;
|
|
102
|
+
|
|
112
103
|
return new Promise((resolve, reject) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
104
|
+
if (fs.existsSync(process.cwd() + "/_dev/chrome")) {
|
|
105
|
+
resolve(true);
|
|
106
|
+
} else {
|
|
107
|
+
exec(commandToRun, (err, stdout, stderr) => {
|
|
117
108
|
let hasError = false;
|
|
118
109
|
if (err) {
|
|
119
|
-
console.log(err);
|
|
120
|
-
|
|
121
|
-
console.log(
|
|
122
|
-
`Attempting to install DEPENDENCY: ${platform === "win32" ? "Google Chrome" : "Chromium"}`
|
|
123
|
-
);
|
|
110
|
+
console.log(err);
|
|
111
|
+
hasError = true;
|
|
112
|
+
console.log(`Attempting to install DEPENDENCY: ${platform === "win32" ? "Google Chrome" : "Chromium"}`);
|
|
124
113
|
}
|
|
125
114
|
if (stdout && !hasError) {
|
|
126
|
-
resolve(
|
|
127
|
-
|
|
128
|
-
);
|
|
129
|
-
fs.writeFileSync(process.cwd() + '/_dev/chrome', `Installed: ${stdout}`);
|
|
130
|
-
run();
|
|
115
|
+
resolve(`${platform === "win32" ? "Google Chrome" : "Chromium"} is installed: ${stdout}`);
|
|
116
|
+
fs.writeFileSync(process.cwd() + "/_dev/chrome", `Installed: ${stdout}`);
|
|
131
117
|
}
|
|
132
118
|
if (stderr) {
|
|
133
119
|
console.log(stderr);
|
|
134
|
-
console.log(
|
|
135
|
-
|
|
136
|
-
);
|
|
137
|
-
let installCommand =
|
|
138
|
-
platform === "win32"
|
|
139
|
-
? installCommands.windows
|
|
140
|
-
: installCommands.others;
|
|
120
|
+
console.log(`Installing DEPENDENCY: ${platform === "win32" ? "Google Chrome" : "Chromium"}`);
|
|
121
|
+
let installCommand = platform === "win32" ? installCommands.windows : installCommands.others;
|
|
141
122
|
return new Promise((resolve, reject) => {
|
|
142
|
-
exec(installCommand, (err, stdout, stderr) => {
|
|
123
|
+
exec(installCommand, (err, stdout, stderr) => {
|
|
143
124
|
if (err) {
|
|
144
125
|
reject(err);
|
|
145
126
|
}
|
|
146
127
|
if (stdout) {
|
|
147
|
-
resolve(
|
|
148
|
-
|
|
149
|
-
);
|
|
150
|
-
fs.writeFileSync(process.cwd() + '/_dev/chrome', `Installed: ${stdout}`);
|
|
128
|
+
resolve(`${platform === "win32" ? "Google Chrome" : "Chromium"} installed successfully: ${stdout}`);
|
|
129
|
+
fs.writeFileSync(process.cwd() + "/_dev/chrome", `Installed: ${stdout}`);
|
|
151
130
|
run();
|
|
152
131
|
}
|
|
153
132
|
if (stderr) {
|
|
154
|
-
reject(
|
|
155
|
-
`${platform === "win32" ? "Google Chrome" : "Chromium"} failed to install: ${stderr}`
|
|
156
|
-
);
|
|
133
|
+
reject(`${platform === "win32" ? "Google Chrome" : "Chromium"} failed to install: ${stderr}`);
|
|
157
134
|
}
|
|
158
135
|
});
|
|
159
136
|
});
|
|
160
137
|
}
|
|
161
138
|
});
|
|
162
|
-
|
|
139
|
+
}
|
|
163
140
|
});
|
|
164
141
|
}
|
|
165
142
|
let Commands = {
|
|
@@ -167,24 +144,15 @@ let Commands = {
|
|
|
167
144
|
build: `bun run build`,
|
|
168
145
|
start: `bun run start`,
|
|
169
146
|
};
|
|
170
|
-
let port = process.argv.includes("-p") || process.argv.includes("--port")
|
|
171
|
-
? process.argv[process.argv.indexOf("-p") + 1] || process.argv[process.argv.indexOf("--port") + 1] || process.env.PORT || 3000
|
|
172
|
-
: process.env.PORT || 3000;
|
|
147
|
+
let port = process.argv.includes("-p") || process.argv.includes("--port") ? process.argv[process.argv.indexOf("-p") + 1] || process.argv[process.argv.indexOf("--port") + 1] || process.env.PORT || 3000 : process.env.PORT || 3000;
|
|
173
148
|
switch (true) {
|
|
174
|
-
case process.argv.includes("dev") &&
|
|
175
|
-
|
|
176
|
-
!process.argv.includes("start"):
|
|
177
|
-
|
|
178
|
-
currentCommand = Commands.dev + (port ? ` -p ${port}` : "");
|
|
149
|
+
case process.argv.includes("dev") && !process.argv.includes("build") && !process.argv.includes("start"):
|
|
150
|
+
currentCommand = Commands.dev + (port ? ` -p ${port}` : "");
|
|
179
151
|
break;
|
|
180
|
-
case process.argv.includes("build") &&
|
|
181
|
-
!process.argv.includes("dev") &&
|
|
182
|
-
!process.argv.includes("start"):
|
|
152
|
+
case process.argv.includes("build") && !process.argv.includes("dev") && !process.argv.includes("start"):
|
|
183
153
|
currentCommand = Commands.build + (port ? ` -p ${port}` : "");
|
|
184
154
|
break;
|
|
185
|
-
case process.argv.includes("start") &&
|
|
186
|
-
!process.argv.includes("dev") &&
|
|
187
|
-
!process.argv.includes("build"):
|
|
155
|
+
case process.argv.includes("start") && !process.argv.includes("dev") && !process.argv.includes("build"):
|
|
188
156
|
currentCommand = Commands.start + (port ? ` -p ${port}` : "");
|
|
189
157
|
break;
|
|
190
158
|
default:
|
|
@@ -193,15 +161,15 @@ switch (true) {
|
|
|
193
161
|
}
|
|
194
162
|
checkIFChromeIumIsInstalled()
|
|
195
163
|
.then((stdout) => {
|
|
196
|
-
|
|
197
164
|
if (stdout) {
|
|
198
165
|
checkIFBundleIsInstalled()
|
|
199
|
-
.then((stdout) => {
|
|
200
|
-
if (stdout) {
|
|
201
|
-
if(!fs.existsSync(process.cwd() +
|
|
202
|
-
|
|
166
|
+
.then((stdout) => {
|
|
167
|
+
if (stdout && !isRunning) {
|
|
168
|
+
if (!fs.existsSync(process.cwd() + "/_dev/bun")) {
|
|
169
|
+
fs.writeFileSync(process.cwd() + "/_dev/bun", `Installed: ${stdout}`);
|
|
203
170
|
}
|
|
204
171
|
run();
|
|
172
|
+
globalThis.isRunning = true;
|
|
205
173
|
}
|
|
206
174
|
})
|
|
207
175
|
.catch(async (err) => {
|
|
@@ -210,17 +178,14 @@ checkIFChromeIumIsInstalled()
|
|
|
210
178
|
windows: 'powershell -c "irm bun.sh/install.ps1|iex',
|
|
211
179
|
others: "curl -fsSL https://bun.sh/install.sh | bash",
|
|
212
180
|
};
|
|
213
|
-
let scriptotRun =
|
|
214
|
-
process.platform === "win32"
|
|
215
|
-
? installScipt.windows
|
|
216
|
-
: installScipt.others;
|
|
181
|
+
let scriptotRun = process.platform === "win32" ? installScipt.windows : installScipt.others;
|
|
217
182
|
exec(scriptotRun, async (err, stdout, stderr) => {
|
|
218
183
|
if (err) {
|
|
219
184
|
console.log("Error installing bun.js");
|
|
220
185
|
process.exit(1);
|
|
221
186
|
}
|
|
222
187
|
if (stdout) {
|
|
223
|
-
if (!platform === "win32") {
|
|
188
|
+
if (!process.platform === "win32") {
|
|
224
189
|
await new Promise((resolve, reject) => {
|
|
225
190
|
console.log(`Adding bun.js to path...`);
|
|
226
191
|
let shell = null;
|