vaderjs 1.4.1-ui7iuy47 → 1.4.2-jpiml56
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/.editorconfig +11 -0
- package/.vscode/c_cpp_properties.json +21 -0
- package/.vscode/settings.json +12 -0
- package/README.md +44 -197
- package/binaries/Kalix/index.js +673 -0
- package/binaries/compiler/main.js +540 -0
- package/binaries/vader.js +74 -0
- package/binaries/watcher/hmr.js +41 -0
- package/client/index.d.ts +226 -0
- package/client/runtime/index.js +1 -0
- package/client/runtime/router.js +1 -0
- package/config/index.ts +87 -0
- package/index.ts +344 -0
- package/package.json +13 -25
- package/plugins/cloudflare/functions/index.js +102 -0
- package/plugins/cloudflare/toCopy/@server/Kalix/index.js +673 -0
- package/plugins/cloudflare/toCopy/@server/cloudflare_ssr/index.js +85 -0
- package/plugins/cloudflare/toCopy/node_modules/vaderjs/server/index.js +99 -0
- package/plugins/cloudflare/toCopy/src/client.js +1 -0
- package/plugins/cloudflare/toCopy/src/router.js +1 -0
- package/plugins/ssg/index.js +197 -0
- package/plugins/tailwindcss/index.ts +93 -0
- package/plugins/vercel/functions/index.ts +8 -0
- package/router/index.ts +208 -0
- package/server/index.js +143 -0
- package/vader_dev.js +177 -0
- package/@integrations/ssg.js +0 -189
- package/LICENSE +0 -21
- package/binaries/IPC/index.js +0 -277
- package/binaries/main.js +0 -1464
- package/binaries/readme.md +0 -4
- package/binaries/watcher.js +0 -74
- package/binaries/win32/check.ps1 +0 -7
- package/client/index.js +0 -426
- package/config/index.js +0 -36
- package/logo.png +0 -0
- package/runtime/router.js +0 -1
- package/runtime/vader.js +0 -1
- package/vader.js +0 -230
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Document , Element} from "../Kalix/index.js"
|
|
2
|
+
class Component {
|
|
3
|
+
constructor(props){
|
|
4
|
+
this.props = props
|
|
5
|
+
this._key = Math.random().toString(36).substring(7)
|
|
6
|
+
this.state = {}
|
|
7
|
+
this.htmlNode = null
|
|
8
|
+
this.firstChild = null
|
|
9
|
+
this.Element = Element
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
setState(newState){
|
|
14
|
+
this.state = newState
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
useState(name, initialValue){
|
|
19
|
+
if(!this.state[name]){
|
|
20
|
+
this.state[name] = initialValue
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let getState = () => this.state[name]
|
|
24
|
+
let setState = (newValue) => {
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
return [getState, setState]
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
useReducer(name, reducer, initialState){
|
|
32
|
+
let [state, setState] = this.useState(name, initialState)
|
|
33
|
+
let dispatch = (action) => {
|
|
34
|
+
let newState = reducer(state(), action)
|
|
35
|
+
setState(newState)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return [state, dispatch]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
useEffect(effect, deps){
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
render(){
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
export async function generatePage(element, options = {entry:"", props: any}, args = []) {
|
|
51
|
+
globalThis.isServer = true
|
|
52
|
+
let serverSideProps = await options.props(...args)
|
|
53
|
+
let name = element.name
|
|
54
|
+
|
|
55
|
+
let comp = new Component()
|
|
56
|
+
element = element.bind(comp)
|
|
57
|
+
comp.render = (props)=> {
|
|
58
|
+
return element(props)
|
|
59
|
+
}
|
|
60
|
+
let data = new Document().createElement(comp.render(serverSideProps))
|
|
61
|
+
let document = new Document()
|
|
62
|
+
document.documentElement.setContent(data.querySelector('html') ? data.querySelector('html').innerHTML : '')
|
|
63
|
+
document.head.setContent(data.querySelector('head') ? data.querySelector('head').innerHTML : '')
|
|
64
|
+
data.removeChild(data.querySelector('head'))
|
|
65
|
+
let div = new Document().createElement('div')
|
|
66
|
+
div.setAttribute('id', 'app')
|
|
67
|
+
div.setContent(data.innerHTML)
|
|
68
|
+
document.body.appendChild(div)
|
|
69
|
+
let script = new Document().createElement('script')
|
|
70
|
+
script.setAttribute('type', 'module')
|
|
71
|
+
script.setContent(script.innerHTML + '\n' + `
|
|
72
|
+
|
|
73
|
+
import ${name} from "${options?.entry}"
|
|
74
|
+
import {render} from '/src/client.js'
|
|
75
|
+
import Kuai from '/src/router.js'
|
|
76
|
+
let kuai = new Kuai({container: document.getElementById('app')})
|
|
77
|
+
kuai.get('/', (c) => {
|
|
78
|
+
c.html(render(${name}, document.getElementById('app'), {...c, props: ${JSON.stringify(serverSideProps.props)}}))
|
|
79
|
+
})
|
|
80
|
+
kuai.use('/', () => console.log('Middleware'))
|
|
81
|
+
kuai.listen()
|
|
82
|
+
`)
|
|
83
|
+
document.body.appendChild(script)
|
|
84
|
+
return `<!DOCTYPE html>${document.head.toString()}${document.body.innerHTML}`
|
|
85
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Document, Element} from "../../../@server/Kalix/index.js"
|
|
2
|
+
class Component {
|
|
3
|
+
constructor(props){
|
|
4
|
+
this.props = props
|
|
5
|
+
this._key = Math.random().toString(36).substring(7)
|
|
6
|
+
this.state = {}
|
|
7
|
+
this.htmlNode = null
|
|
8
|
+
this.firstChild = null
|
|
9
|
+
this.Element = Element
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
setState(newState){
|
|
14
|
+
this.state = newState
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
useState(name, initialValue){
|
|
19
|
+
if(!this.state[name]){
|
|
20
|
+
this.state[name] = initialValue
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let getState = () => this.state[name]
|
|
24
|
+
let setState = (newValue) => {
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
return [getState, setState]
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
useReducer(name, reducer, initialState){
|
|
32
|
+
let [state, setState] = this.useState(name, initialState)
|
|
33
|
+
let dispatch = (action) => {
|
|
34
|
+
let newState = reducer(state(), action)
|
|
35
|
+
setState(newState)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return [state, dispatch]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
useEffect(effect, deps){
|
|
42
|
+
return effect()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
render(){
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
export async function renderToString(element, args = []) {
|
|
51
|
+
let data = typeof element === 'function' ? await element(...args) : element
|
|
52
|
+
let doc = new Document()
|
|
53
|
+
let el = doc.createElement(data)
|
|
54
|
+
|
|
55
|
+
return el.toString()
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function generatePage(element, options = {entry:"", props: ()=>{}}, args = []) {
|
|
60
|
+
//@ts-ignore
|
|
61
|
+
globalThis.isServer = true
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
let serverSideProps = await options.props({req: args[0], res: args[1]}, args.slice(2))
|
|
64
|
+
let name = element.name
|
|
65
|
+
|
|
66
|
+
let comp = new Component(serverSideProps?.props)
|
|
67
|
+
element = element.bind(comp)
|
|
68
|
+
comp.render = (props)=> {
|
|
69
|
+
return element(props)
|
|
70
|
+
}
|
|
71
|
+
let data = new Document().createElement(comp.render({props: serverSideProps.props, ...args}))
|
|
72
|
+
let document = new Document()
|
|
73
|
+
document.documentElement.setContent(data.querySelector('html') ? data.querySelector('html').innerHTML : '')
|
|
74
|
+
document.head.setContent(data.querySelector('head') ? data.querySelector('head').innerHTML : '')
|
|
75
|
+
data.removeChild(data.querySelector('head'))
|
|
76
|
+
let div = new Document().createElement('div')
|
|
77
|
+
div.setAttribute('id', 'app')
|
|
78
|
+
div.setContent(data.innerHTML)
|
|
79
|
+
document.body.appendChild(div)
|
|
80
|
+
let script = new Document().createElement('script')
|
|
81
|
+
script.setAttribute('type', 'module')
|
|
82
|
+
|
|
83
|
+
script.setContent(script.innerHTML + '\n' + `
|
|
84
|
+
|
|
85
|
+
import ${name} from "${options?.entry}"
|
|
86
|
+
import {render} from '/src/client.js'
|
|
87
|
+
import Kuai from '/src/router.js'
|
|
88
|
+
let kuai = new Kuai({container: document.getElementById('app')})
|
|
89
|
+
kuai.get('/', (c) => {
|
|
90
|
+
c.html(render(${name}, document.getElementById('app'), {...c, props: ${JSON.stringify(serverSideProps.props)}}))
|
|
91
|
+
})
|
|
92
|
+
kuai.use('/', () => console.log('Middleware'))
|
|
93
|
+
kuai.listen()
|
|
94
|
+
`)
|
|
95
|
+
document.body.appendChild(script)
|
|
96
|
+
return `<!DOCTYPE html>${document.head.toString()}${document.body.innerHTML}`
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default renderToString
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
window.vader={version:"1.0.0"},globalThis.isServer=!1,globalThis.preRender=!1,window.hasRan=[],globalThis.memoizedFunctions=[];const memoizedRefs=[];function calculateDiff(e,t){if(void 0===e||void 0===t)return[];let n=[];if(e?.children.length>0){for(var r=0;r<e.children.length;r++)n.push(...calculateDiff(e.children[r],t.children[r]));return n}if(!e?._isRoot)if(3===e.nodeType&&e.nodeValue!==t.nodeValue)n.push({type:"REPLACE",oldNode:e,newNode:t});else if(1===e.nodeType&&e.innerHTML!==t.innerHTML)n.push({type:"REPLACE",oldNode:e,newNode:t});else if(1===e.nodeType&&e.tagName===t.tagName)for(r=0;r<e.attributes.length;r++)e.attributes[r].value!==t.attributes[r].value&&n.push({type:"PROPS",oldNode:e,newNode:t});return n}function generateJSX(e,t,...n){let r={state:{},mainFunction:e,_key:e.name||Math.random().toString(36).substring(7),$$typeof:"JSX_CHILD",firstChild:null,children:n,_name:e.name},o=new Component({$$key:r._key});return e=e.bind(o),o.render=()=>{let r=(n=n.flat(1/0)).map((e=>"function"==typeof e?generateJSX(e,t,e.props.children):e));return e({...t,children:r[0]||r})},r.firstChild=o.render(),r.firstChild.htmlNode._key=r._key,r.firstChild.htmlRoot=r,r.firstChild.htmlNode._isRoot=!0,r.firstChild.props=t||{},r.firstChild._isRoot=!0,r.firstChild._key=r._key,r.firstChild.props.key=r._key,r.firstChild}function handleStyles(e,t){for(let n in e)"object"==typeof e[n]&&handleStyles(e[n],t),t.style[n]=e[n]}let hasBeenCalled=[];function Element(e,t,...n){if(!t&&(t={}),t?.$$key||(t.$$key=e.name||Math.random().toString(36).substring(7)),"function"==typeof e)return generateJSX(e,t,n);let r={tag:e,props:t,children:n,_key:t.$$key,events:[],staticEl:document.createElement(e),parentNode:null};for(var o=0;o<n.length;o++)"string"==typeof n[o]||"number"==typeof n[o]?n[o]={tag:"TEXT_ELEMENT",props:{nodeValue:n[o]},_key:t.$$key,parentNode:{tag:e,props:t,children:n,_key:t.$$key},children:[]}:n[o]&&(n[o].parentNode={tag:e,props:t,children:n});let i="TEXT_ELEMENT"===r.tag?document.createTextNode(""):document.createElement(r.tag);for(var s in r.staticEl=i,t)s.toLowerCase().startsWith("on")?(i.addEventListener(s.substring(2).toLowerCase(),t[s]),r.events.push({type:s.substring(2).toLowerCase(),listener:t[s]})):"$$key"!==s||i._key||1!==i.nodeType?i&&1===i.nodeType&&i.setAttribute(s,t[s]):Object.defineProperty(i,"_key",{value:t[s],writable:!0});if(t.style&&handleStyles(t.style,i),t.id&&(i.id=t.id),t.ref)switch(!0){case Array.isArray(t.ref.current):t.ref.current.find((e=>e===i))||t.ref.current.push(i);break;case t.ref.current===HTMLElement:case null===t.ref.current:t.ref.current=i;break;case"function"==typeof t.ref&&!window.hasRan.includes(t.ref):window.hasRan.push(t.ref),t.ref(i),setTimeout((()=>{window.hasRan.filter((e=>e!==t.ref))}),0);break;default:t.ref.current=i}if(r.htmlNode=i,1===i.nodeType)for(o=0;o<n.length;o++)n[o]&&("TEXT_ELEMENT"===n[o].tag&&i.appendChild(document.createTextNode(n[o].props.nodeValue)),i.appendChild(Element(n[o].tag,n[o].props,...n[o].children).htmlNode));return r}function handleDiff(e){for(var t=0;t<e.length;t++)switch(!0){case"REPLACE"===e[t].type&&!e[t].oldNode._isRoot:e[t].oldNode.parentNode;e[t].oldNode.parentNode.replaceChild(e[t].newNode,e[t].oldNode);case"PROPS"===e[t].type:}}let states={};export const useState=(e,t)=>{};export function useRef(e,t){let n=t;memoizedRefs.find((t=>t.name===e))||memoizedRefs.push({name:e,ref:n});return{current:memoizedRefs.find((t=>t.name===e)).ref,name:e}}export function Mounted(e,t){Array.from(document.querySelectorAll("*")).find((e=>e._key===memoizedFunctions.find((e=>e.mainFunction===t))._key))&&!hasBeenCalled.find((e=>e===t))?(e(),hasBeenCalled.push(t)):setTimeout((()=>{Mounted(e,t)}),0)}let effects=[];export function useEffect(e,t){if(effects.find((t=>t.fn.toString()===e.toString()))){let n=effects.find((t=>t.fn.toString()===e.toString()));n.deps.toString()!==t.toString()&&(n.deps=t,n.fn())}else effects.push({fn:e,deps:t});return()=>{effects=effects.filter((t=>t.fn!==e))}}export function useReducer(e,t,n,r){let[o,i]=void 0;return[o,e=>{let n=t(o,e);i(n)}]}class Component{constructor(e){this.props=e,this._key=e.$$key||Math.random().toString(36).substring(7),this.state={},this.htmlNode=null,this.firstChild=null,this.Element=Element,this.passiveProps={}}setState(e){this.state=e}handleDiff(e){for(var t=0;t<e.length;t++)switch(!0){case"REPLACE"===e[t].type&&!e[t].oldNode._isRoot:e[t].oldNode.parentNode;e[t].oldNode.parentNode.replaceChild(e[t].newNode,e[t].oldNode);case"PROPS"===e[t].type:}}calculateDiff(e,t){if(void 0===e||void 0===t)return[];let n=[];if(e?.children.length>0){for(var r=0;r<e.children.length;r++)n.push(...this.calculateDiff(e.children[r],t.children[r]));return n}if(!e?._isRoot)if(3===e.nodeType&&e.nodeValue!==t.nodeValue)n.push({type:"REPLACE",oldNode:e,newNode:t});else if(1===e.nodeType&&e.innerHTML!==t.innerHTML)n.push({type:"REPLACE",oldNode:e,newNode:t});else if(1===e.nodeType&&e.tagName===t.tagName)for(r=0;r<e.attributes.length;r++)e.attributes[r].value!==t.attributes[r].value&&n.push({type:"PROPS",oldNode:e,newNode:t});return n}useState(e,t){this.state[e]||(this.state[e]=t);return[()=>this.state[e],t=>{let n=this.firstChild.htmlNode;"HTML"===n.tagName&&(n=n.querySelector("body"),n.firstChild._key=this._key),this.state[e]=t,handleDiff(calculateDiff(Array.from(document.querySelectorAll("*")).find((e=>e._key===n._key)),"HTML"===this.render(this.passiveProps).htmlNode.tagName?this.render(this.passiveProps).htmlNode.querySelector("body"):this.render(this.passiveProps).htmlNode))}]}useEffect=useEffect;useReducer(e,t,n){let[r,o]=this.useState(e,n);return[r,e=>{let n=t(r(),e);o(n)}]}render(){return null}}export async function render(e,t,...n){if(!e)throw new Error("No vnode was provided");let r=new Component({$$key:e.name||Math.random().toString(36).substring(7)});e=e.bind(r),n.length>0&&(n={req:n[0],res:n[1]},r.passiveProps=n),r.render=()=>e(r.passiveProps),r.firstChild=r.render(),t.innerHTML="",t.replaceWith(r.firstChild.htmlNode)}export default Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class Kuai{constructor(t={container:"#app"}){this.routes=[],this.middleware=[],this.container=t.container?t.container:document.getElementById("app"),this.renderPlugins=[]}res={text:t=>{this.container.innerHTML=t},html:t=>{switch(typeof t){case"function":if(this.renderPlugins.length>0)return void this.renderPlugins.forEach((e=>{"html"===e.for&&(console.log("Plugin",e),e.plugin(t,this.container))}));this.container.innerHTML=t();break;case"string":this.container.innerHTML=t}},json:t=>{this.container.innerHTML=`<Oject data=${JSON.stringify(t)}></Object>`}};req={navigate:t=>{window.history.pushState({},"",t);let e=this.match(window.location.pathname.replace("/index.html",""));e&&(this.currentRoute=e.path,e.callback(this.res,e.params,this.extractQueryParams(window.location.search)))},back:()=>{window.history.back()},forward:()=>{window.history.forward()},url:window.location};extractQueryParams(t){let e=new URLSearchParams(t),i={};for(let t of e)i[t[0]]=t[1];return i}extractParams(t,e){const i=t.split("/").filter((t=>""!==t)),r=e.split("/").filter((t=>""!==t)),a={};return i.forEach(((t,e)=>{if(t.startsWith(":")){const i=t.slice(1);a[i]=r[e]}else if(t.startsWith("*")){r.slice(e).forEach(((t,e)=>{a[e]=t}))}})),a}use(t,e){this.middleware.push({path:t,middleware:e})}usePlugin(t,e){this.renderPlugins.push({plugin:t,for:e})}match(t){(t=t.endsWith("/")?t.slice(0,-1):t).includes("index.html")&&(t=t.replace("index.html","")),t.includes("?")&&(t=t.split("?")[0]);let e=this.routes.find((e=>{if(e.path===t)return!0;if(""===t&&"/"===e.path)return!0;if(e.path.includes("*")||e.path.includes(":")){const i=e.path.split("/").filter((t=>""!==t)),r=t.split("/").filter((t=>""!==t));if(this.basePath&&r.shift(),i.length!==r.length&&!e.path.endsWith("*"))return!1;for(let t=0;t<i.length;t++){const e=i[t],a=r[t];if(!e.startsWith(":")&&!e.startsWith("*")&&e!==a)return!1}return!0}}));if(e){let i=this.extractParams(e.path,t);return{...e,params:i}}return null}get(t,e){this.routes.push({path:t,callback:e})}listen(){let t=this.match(window.location.pathname.replace("/index.html",""));if(t){this.middleware.forEach((e=>{e.path===t.path&&e.middleware()})),this.currentRoute=t.path;let e={...this.res,res:this.res,req:{...this.req,params:e=>t.params[e]}};t.callback(e)}window.onpopstate=()=>{let t=this.match(window.location.pathname.replace("/index.html",""));t&&(this.currentRoute=t.path,t.callback(this.res,t.params,this.extractQueryParams(window.location.search)))}}}export default Kuai;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import * as Bun from 'bun'
|
|
2
|
+
import { Document, DOMParser} from 'vaderjs/binaries/Kalix/index.js'
|
|
3
|
+
import { renderToString } from '../../server'
|
|
4
|
+
import fs from 'fs'
|
|
5
|
+
let routes = new Bun.FileSystemRouter({
|
|
6
|
+
dir: process.cwd() + '/pages',
|
|
7
|
+
style:"nextjs"
|
|
8
|
+
}).routes
|
|
9
|
+
globalThis.isNotFirstRun = false
|
|
10
|
+
async function generate(){
|
|
11
|
+
let config = await import(process.cwd() + '/vader.config.js').then((config) => { return config.default })
|
|
12
|
+
let provider = config?.host?.provider
|
|
13
|
+
|
|
14
|
+
let providerRoutes = []
|
|
15
|
+
Object.keys(routes).map((route) => {
|
|
16
|
+
if(route.includes('[')){
|
|
17
|
+
|
|
18
|
+
let root = Object.keys(routes).find((r) => {
|
|
19
|
+
return r === '/'
|
|
20
|
+
} )
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
let param = route.split('/[')[1].split(']')[0]
|
|
24
|
+
let p = {}
|
|
25
|
+
let existingParams = routes[root]?.params || []
|
|
26
|
+
existingParams.push({
|
|
27
|
+
isCatchAll: route.includes('[[catchall]]') ? true : false,
|
|
28
|
+
name: param,
|
|
29
|
+
file: routes[route],
|
|
30
|
+
baseFolder: route.split('[')[0]
|
|
31
|
+
})
|
|
32
|
+
p.file = routes[root]
|
|
33
|
+
p.params = existingParams
|
|
34
|
+
routes[root] = p
|
|
35
|
+
delete routes[route]
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
for(var i in routes){
|
|
40
|
+
let path = i
|
|
41
|
+
let file = routes[i]
|
|
42
|
+
if(typeof file === 'object'){
|
|
43
|
+
file = file.file
|
|
44
|
+
}
|
|
45
|
+
let comp = require(file).default
|
|
46
|
+
if(!comp){
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let dom = await renderToString(comp)
|
|
51
|
+
let isHtml = dom.includes('<html')
|
|
52
|
+
let folder = path.split('/pages')[0]
|
|
53
|
+
let newPath = process.cwd() + '/build' + folder + '/index.html'
|
|
54
|
+
let name = comp.name || 'App'
|
|
55
|
+
file = file.replace(/\\/g, '/').replace('\/\/', '/').replace(process.cwd().replace(/\\/g, '/'), '').split('/pages')[1].replace('.tsx', '.js').replace('.jsx', '.js')
|
|
56
|
+
let isParamRoute = routes[i].params ? true : false
|
|
57
|
+
let baseFolder = ''
|
|
58
|
+
if(isParamRoute){
|
|
59
|
+
let route = routes[i].params[0]
|
|
60
|
+
baseFolder = i.split('[')[0]
|
|
61
|
+
let providerPath;
|
|
62
|
+
switch(true){
|
|
63
|
+
case provider === 'vercel':
|
|
64
|
+
if(route.isCatchAll){
|
|
65
|
+
providerPath = `${baseFolder}/*`
|
|
66
|
+
providerRoutes.push({source: providerPath, destination: `${path}/index.html`})
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
providerPath = `${baseFolder}:${route.name}`
|
|
70
|
+
providerRoutes.push({source: providerPath, dest: `/`})
|
|
71
|
+
break;
|
|
72
|
+
case provider === 'nginx':
|
|
73
|
+
providerPath = `RewriteRule ^${baseFolder.replace('/', '')}.*$ ${path}/index.html [L]`
|
|
74
|
+
providerRoutes.push(providerPath)
|
|
75
|
+
break;
|
|
76
|
+
case provider === 'cloudflare':
|
|
77
|
+
if(route.isCatchAll){
|
|
78
|
+
providerPath = `${baseFolder}/*`
|
|
79
|
+
providerRoutes.push({source: providerPath, destination: `${path}/index.html`})
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
providerPath = `${baseFolder}/*`
|
|
83
|
+
providerRoutes.push({source: providerPath, destination: `${path}/index.html`})
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}else{
|
|
87
|
+
let providerPath;
|
|
88
|
+
switch(true){
|
|
89
|
+
case provider === 'vercel':
|
|
90
|
+
providerPath = `${path}`
|
|
91
|
+
providerRoutes.push({source: providerPath, dest: `${path}/index.html`})
|
|
92
|
+
break;
|
|
93
|
+
case provider === 'nginx':
|
|
94
|
+
if(i == '/'){
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
providerPath = `RewriteRule ^${path.replace('/', '')}/$ ${path}/index.html [L]`
|
|
98
|
+
providerRoutes.push(providerPath)
|
|
99
|
+
break;
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
dom = preRender ? dom : '<div id="root"></div>' + `
|
|
105
|
+
<script type="module">
|
|
106
|
+
|
|
107
|
+
import { render } from '/src/client.js'
|
|
108
|
+
let ${name} = await import('/pages/${file.replace(process.cwd(), '')}')
|
|
109
|
+
if(${name}.default){
|
|
110
|
+
${name} = ${name}.default
|
|
111
|
+
}else{
|
|
112
|
+
let keys = Object.keys(${name})
|
|
113
|
+
${name} = ${name}[keys[0]]
|
|
114
|
+
}
|
|
115
|
+
import Kuai from '/src/router.js'
|
|
116
|
+
let kuai = new Kuai()
|
|
117
|
+
${
|
|
118
|
+
routes[i].params ?
|
|
119
|
+
routes[i].params.map((param) => {
|
|
120
|
+
let name = param.name
|
|
121
|
+
let file = param.file.replace(/\\/g, '/').replace('\/\/', '/').replace(process.cwd().replace(/\\/g, '/'), '').split('/pages')[1].replace('.tsx', '.js').replace('.jsx', '.js')
|
|
122
|
+
return `
|
|
123
|
+
// handle if default or named
|
|
124
|
+
let ${name} = await import('/pages/${file}')
|
|
125
|
+
if(${name}.default){
|
|
126
|
+
${name} = ${name}.default
|
|
127
|
+
}else{
|
|
128
|
+
let keys = Object.keys(${name})
|
|
129
|
+
${name} = ${name}[keys[0]]
|
|
130
|
+
}
|
|
131
|
+
kuai.get('${param.baseFolder}:${name}', (c) => {
|
|
132
|
+
render(${name}, ${
|
|
133
|
+
isHtml ? `document.documentElement`: `document.body.firstChild`
|
|
134
|
+
}, c.req, c.res)
|
|
135
|
+
})`
|
|
136
|
+
}).join('\n') : ''
|
|
137
|
+
}
|
|
138
|
+
kuai.get('${path}', (c) => {
|
|
139
|
+
render(${name}, ${
|
|
140
|
+
isHtml ? `document.documentElement`: `document.body.firstChild`
|
|
141
|
+
}, c.req, c.res)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
kuai.listen()
|
|
145
|
+
|
|
146
|
+
`
|
|
147
|
+
dom = dom + `</script>`
|
|
148
|
+
Bun.write(newPath, dom)
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
switch(true){
|
|
152
|
+
case provider === 'vercel':
|
|
153
|
+
let vercelJSON = process.cwd() + '/vercel.json'
|
|
154
|
+
let vercel = {
|
|
155
|
+
"rewrites": providerRoutes
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
fs.writeFileSync(vercelJSON, JSON.stringify(vercel))
|
|
159
|
+
break;
|
|
160
|
+
case provider === 'nginx':
|
|
161
|
+
let full = `
|
|
162
|
+
Header add x-powered-by "vaderjs"
|
|
163
|
+
<IfModule mod_rewrite.c>
|
|
164
|
+
RewriteEngine On
|
|
165
|
+
RewriteBase /
|
|
166
|
+
|
|
167
|
+
# If the request is not for a file or directory
|
|
168
|
+
RewriteCond %{REQUEST_FILENAME} !-f
|
|
169
|
+
RewriteCond %{REQUEST_FILENAME} !-d
|
|
170
|
+
|
|
171
|
+
# Rewrite specific paths to index.html
|
|
172
|
+
${providerRoutes.join('\n')}
|
|
173
|
+
</IfModule>
|
|
174
|
+
`
|
|
175
|
+
fs.writeFileSync(process.cwd() + '/.htaccess', full)
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
console.log(`\x1b[32mSuccess\x1b[0m - Static files generated`)
|
|
179
|
+
|
|
180
|
+
return true
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @name Vaderjs SSG Plugin
|
|
186
|
+
* @description This plugin is used to generate static files from the deep object - using kalix.js
|
|
187
|
+
* @version 0.0.1
|
|
188
|
+
*/
|
|
189
|
+
export default {
|
|
190
|
+
name: 'Vaderjs SSG Plugin',
|
|
191
|
+
version: '0.0.1',
|
|
192
|
+
init: async (component) => {
|
|
193
|
+
|
|
194
|
+
console.log(`\x1b[36mwait \x1b[0m - generating static files`)
|
|
195
|
+
return generate(component)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
//@ts-nocheck
|
|
2
|
+
function checkIFtailwindInstalled() {
|
|
3
|
+
try {
|
|
4
|
+
require.resolve('tailwindcss');
|
|
5
|
+
return true;
|
|
6
|
+
} catch (e) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
name: "tailwind",
|
|
14
|
+
description: "A plugin to install tailwindcss",
|
|
15
|
+
once: true,
|
|
16
|
+
init: async () => {
|
|
17
|
+
let config = require(process.cwd() + "/vader.config.js").default;
|
|
18
|
+
const fs = require("fs");
|
|
19
|
+
const path = require("path");
|
|
20
|
+
const { exec} = require("child_process");
|
|
21
|
+
const tailwindConfig = `
|
|
22
|
+
/** @type {import('tailwindcss').Config} */
|
|
23
|
+
module.exports = {
|
|
24
|
+
content: ['./src/**/*.{jsx,tsx,js,ts}', './pages/**/*.{jsx,tsx,js,ts}', './components/**/*.{jsx,tsx,js,ts}'],
|
|
25
|
+
theme: {
|
|
26
|
+
${
|
|
27
|
+
config?.tailwind?.theme ? JSON.stringify(config.tailwind.theme, null, 2) : ``
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
plugins: [
|
|
31
|
+
${
|
|
32
|
+
config?.tailwind?.plugins ? config?.tailwind?.plugins.map((plugin) => {
|
|
33
|
+
return `require('${plugin}')`
|
|
34
|
+
}).join(",") : ``
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
fs.writeFileSync(
|
|
40
|
+
path.join(process.cwd(), "tailwind.config.js"),
|
|
41
|
+
tailwindConfig
|
|
42
|
+
);
|
|
43
|
+
if (!checkIFtailwindInstalled()) {
|
|
44
|
+
console.log(`\x1b[36mwait \x1b[0m - installing tailwindcss & ${config?.tailwind?.plugins ? config?.tailwind?.plugins.length + " plugins" : ""} (First time only)`);
|
|
45
|
+
let npmPath = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
46
|
+
Bun.spawnSync({
|
|
47
|
+
cmd: [npmPath, "install", "tailwindcss", "postcss", "autoprefixer" , ...config?.tailwind?.plugins || []],
|
|
48
|
+
cwd: process.cwd(),
|
|
49
|
+
stderr: "inherit",
|
|
50
|
+
})
|
|
51
|
+
console.log(`\x1b[32msuccess \x1b[0m - tailwindcss installed`)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
const postcssConfig = `
|
|
55
|
+
module.exports = {
|
|
56
|
+
plugins: {
|
|
57
|
+
tailwindcss: {},
|
|
58
|
+
autoprefixer: {},
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
fs.mkdirSync(path.join(process.cwd(), "src/public/styles"), {
|
|
63
|
+
recursive: true,
|
|
64
|
+
});
|
|
65
|
+
fs.writeFileSync(
|
|
66
|
+
path.join(process.cwd(), "src/public/styles/tailwind.css"),
|
|
67
|
+
`@import 'tailwindcss/base'; @import 'tailwindcss/components'; @import 'tailwindcss/utilities';`
|
|
68
|
+
);
|
|
69
|
+
fs.writeFileSync(
|
|
70
|
+
path.join(process.cwd(), "postcss.config.js"),
|
|
71
|
+
postcssConfig
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if(!fs.existsSync(path.join(process.cwd(), "src/public/styles/tailwind.css"))){
|
|
76
|
+
fs.mkdirSync(path.join(process.cwd(), "src/public/styles"), {
|
|
77
|
+
recursive: true,
|
|
78
|
+
});
|
|
79
|
+
fs.writeFileSync(
|
|
80
|
+
path.join(process.cwd(), "src/public/styles/tailwind.css"),
|
|
81
|
+
`@import 'tailwindcss/base'; @import 'tailwindcss/components'; @import 'tailwindcss/utilities';`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let cmd = process.platform === "win32" ? "npx.cmd" : "npx";
|
|
86
|
+
Bun.spawn({
|
|
87
|
+
cmd: [ cmd, "tailwindcss", process.cwd() + '/tailwind.config.js' , "-i", "src/public/styles/tailwind.css", "-o", config?.tailwind?.output || "public/styles/tailwind.css", "--minify"],
|
|
88
|
+
cwd: process.cwd(),
|
|
89
|
+
stdin: "inherit",
|
|
90
|
+
stderr: "inherit",
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
}
|