vaderjs 1.3.3-alpha-100 → 1.3.3-alpha-102
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 +3 -2
- package/runtime/router.js +1 -1
- package/vader.js +197 -76
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.3.3-alpha-
|
|
5
|
+
"version": "1.3.3-alpha-102",
|
|
6
6
|
"bin": {
|
|
7
7
|
"vader": "./vader.js"
|
|
8
8
|
},
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"glob": "latest",
|
|
31
|
-
"terser":"latest"
|
|
31
|
+
"terser":"latest",
|
|
32
|
+
"puppeteer":"latest"
|
|
32
33
|
}
|
|
33
34
|
}
|
package/runtime/router.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Component}from"./vader.js";let middlewares=[];class VaderRouter{constructor(e,t){this.routes=[],this.middlewares=[],this.errorMiddlewares=[],this.listeners=[],this.basePath=e}get(e,t){this.routes.push({path:e,handler:t,method:"get"})}use(e){this.middlewares.push(e)}listen(e,t){e||(e=Math.random().toString(36).substring(7)),this.listeners.push(e),1===this.listeners.length?this.handleRoute(window.location.hash):this.listeners.pop(),t&&t(),window.onhashchange=()=>{this.handleRoute(window.location.hash)}}extractParams(e,t){const s=e.split("/"),n=t.split("/"),
|
|
1
|
+
import{Component}from"./vader.js";let middlewares=[];class VaderRouter{constructor(e,t){this.routes=[],this.middlewares=[],this.errorMiddlewares=[],this.listeners=[],this.basePath=e}get(e,t){this.routes.push({path:e,handler:t,method:"get"})}use(e){this.middlewares.push(e)}listen(e,t){e||(e=Math.random().toString(36).substring(7)),this.listeners.push(e),1===this.listeners.length?this.handleRoute(window.location.hash.length>0?window.location.hash:window.location.pathname):this.listeners.pop(),t&&t(),window.onhashchange=()=>{this.handleRoute(window.location.hash)}}extractParams(e,t){const s=e.split("/"),n=t.split("/"),o={};return s.forEach(((e,t)=>{if(e.startsWith(":")){const s=e.slice(1);o[s]=n[t]}else if(e.startsWith("*")){n.slice(t).forEach(((e,t)=>{o[t]=e}))}})),o}extractQueryParams(e){const t=e.split("?")[1];if(!t)return{};const s={};return t.split("&").forEach((e=>{const[t,n]=e.split("=");s[t]=n})),s}handleRoute(e){e=e.includes("#")?e.slice(1):e,console.log(e);let t=200,s=e,n=this.routes.find((t=>{if(t.path===e)return!0;if(""===e&&"/"===t.path)return!0;if(e.includes("?")&&(e=e.split("?")[0]),t.path.includes("*")||t.path.includes(":")){const s=t.path.split("/"),n=e.split("/");if(s.length!==n.length&&!t.path.endsWith("*"))return!1;for(let e=0;e<s.length;e++){const t=s[e],o=n[e];if(!t.startsWith(":")&&!t.startsWith("*")&&t!==o)return!1}return!0}const n=this.extractParams(t.path,s);return Object.keys(n).length>0}));n||(n=this.routes.find((e=>{if(e.path.includes("/404"))return this.error=!0,!0;!this.error&&e.path.includes("/404")&&(window.location.hash=this.basePath)})),t=n?200:404);const o=this.extractQueryParams(s),r=n&&n.path?this.extractParams(n.path,s):{};Object.keys(r).forEach((e=>{r[e]=r[e].split("?")?r[e].split("?")[0]:r[e]}));const i={headers:{},params:r,query:o,path:e,fileUrl:window.location.href.split(window.location.origin)[1],url:window.location.href,method:n?n.method:"get",pause:!1,timestamp:Date.now()};window.$CURRENT_URL=i.path,window.$FULL_URL=window.location.href.replace("#","");const a={status:t,log:e=>{void 0===e?console.log(`${i.path} ${i.method} ${a.status} ${i.timestamp}`):console.table({"Request Path":i.path,"Request Method":n.method,"Response Status":a.status,"Request Timestamp":i.timestamp})},refresh:()=>{this.handleRoute(window.location.hash)},redirect:e=>{!e.startsWith("/")&&(e=`/${e}`),window.location.hash=`#${e}`},render:async(e,t,s,n)=>{function i(e){return"function"==typeof e&&/^class\s/.test(Function.prototype.toString.call(e))}try{let n=new Component;if(i(e.default)){let t=new e.default;n.state=t.state,n=t}else{if(e.default.toString().includes("this.key"))throw new Error('Using this.key is not supported in functional components use the attribute key="a value" instead');n.key=e.default.toString().split('key="')[1]?e.default.toString().split('key="')[1].split('"')[0]:null;let i={key:n.key,render:()=>e.default.apply(n,[t,s]),request:t,response:s,params:r,queryParams:o,reset:n.reset.bind(n),onMount:n.onMount.bind(n),useState:null,router:{use:n.router.use.bind(n)},bindMount:n.bindMount.bind(n),memoize:n.memoize.bind(n),createComponent:n.createComponent.bind(n),isChild:!1,useState:n.useState.bind(n),parseStyle:n.parseStyle.bind(n),bind:n.bind.bind(n),useRef:n.useRef.bind(n),useReducer:n.useReducer.bind(n),onMount:n.onMount.bind(n),onUnmount:n.onUnmount.bind(n),hydrate:n.hydrate.bind(n)};n.render=i.render,n=i,console.log(t)}if(!document.querySelector("#root"))throw new Error("Root element not found, please add an element with id root");n.reset(),n.components={},n.request=t,n.response=s,n.router.use&&!n.isChild?await new Promise((async o=>{if(i(e.default))if(i(e.default))switch(await n.router.use(t,s),t.pause){case!0:console.log("pausing",t.pause);let e=setInterval((()=>{t.pause?console.log("still pausing",t.pause):(clearInterval(e),o())}),1e3);break;case!1:o()}else o();else switch(await e.default.apply(n,[t,s]),await n.router.use(t,s),t.pause){case!0:let e=setInterval((()=>{t.pause?console.log("still pausing request",t.url):(clearInterval(e),o())}),1e3);break;case!1:o()}})):n.router.use&&n.isChild&&console.warn("Router.use() is not supported in child components");const a=await n.render();document.querySelector("#root").innerHTML!==a&&(console.log("rendering"),document.querySelector("#root").innerHTML=a),n.bindMount(),n.onMount()}catch(e){console.error(e)}},setQuery:e=>{let t="";Object.keys(e).forEach(((s,n)=>{t+=`${0===n?"?":"&"}${s}=${e[s]}`}));let s=window.location.hash.split("?")[0];t=t.replace("/","-").replaceAll("/","-"),window.location.hash=`${s}${t}`},send:e=>{document.querySelector("#root").innerHTML=e},json:e=>{const t=document.querySelector("#root");t.innerHTML="";const s=document.createElement("pre");s.textContent=JSON.stringify(e,null,2),t.appendChild(s)}};middlewares.forEach((e=>{e(i,a)})),n&&n.handler(i,a)}}window.VaderRouter=VaderRouter;export default VaderRouter;
|
package/vader.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import { glob, globSync, globStream, globStreamSync, Glob, } from 'glob'
|
|
4
|
+
import puppeteer from 'puppeteer';
|
|
5
|
+
import http from 'http'
|
|
4
6
|
let bundleSize = 0;
|
|
5
7
|
let errorCodes = {
|
|
6
8
|
"SyntaxError: Unexpected token '<'": "You forgot to enclose tags in a fragment <></>",
|
|
@@ -8,24 +10,14 @@ let errorCodes = {
|
|
|
8
10
|
/**
|
|
9
11
|
* define directories
|
|
10
12
|
*/
|
|
11
|
-
|
|
12
|
-
...fs.existsSync(process.cwd() + '/pages') ? { pages: true } : { pages: false },
|
|
13
|
-
...fs.existsSync(process.cwd() + '/src') ? { components: true } : { components: false },
|
|
14
|
-
...fs.existsSync(process.cwd() + '/public') ? { public: true } : { public: false },
|
|
15
|
-
...fs.existsSync(process.cwd() + '/dist') ? { dist: true } : { dist: false },
|
|
16
|
-
...fs.existsSync(process.cwd() + '/dist/pages') ? { distpages: true } : { distpages: false },
|
|
17
|
-
...fs.existsSync(process.cwd() + '/dist/src') ? { distcomponents: true } : { distcomponents: false },
|
|
18
|
-
...fs.existsSync(process.cwd() + '/dist/public') ? { distpublic: true } : { distpublic: false },
|
|
19
|
-
}
|
|
13
|
+
|
|
20
14
|
|
|
15
|
+
if(!fs.existsSync(process.cwd() + '/dist')){
|
|
16
|
+
fs.mkdirSync(process.cwd() + '/dist')
|
|
17
|
+
}
|
|
21
18
|
|
|
22
|
-
Object.keys(dirs).map((key, index) => {
|
|
23
|
-
if (!dirs[key]) {
|
|
24
|
-
fs.mkdirSync(process.cwd() + '/' + key)
|
|
25
|
-
}
|
|
26
|
-
}).filter(Boolean)[0]
|
|
27
19
|
|
|
28
|
-
if (process.env.isCloudflare) {
|
|
20
|
+
if (process.env.isCloudflare || !process.cwd() + '/dist/index.html') {
|
|
29
21
|
let htmlFile = fs.readFileSync(process.cwd() + "/node_modules/vaderjs/runtime/index.html", 'utf8')
|
|
30
22
|
fs.writeFileSync(process.cwd() + "/dist/index.html", htmlFile)
|
|
31
23
|
}
|
|
@@ -663,18 +655,7 @@ function Compiler(func, file) {
|
|
|
663
655
|
|
|
664
656
|
}
|
|
665
657
|
|
|
666
|
-
|
|
667
|
-
if (!html.includes(`<link rel="preload" href="${path.replace(/'/g, '').trim()}" as="${path.replace(/'/g, '').trim().includes('.css') ? 'style' : 'script'}">`)
|
|
668
|
-
&& !path.includes('.module.css')
|
|
669
|
-
) {
|
|
670
|
-
let preload = `
|
|
671
|
-
${path.trim().includes('.css') ? `<link rel="stylesheet" href="${path.trim().replace(/'/g, '').trim()}">` : ''
|
|
672
|
-
}
|
|
673
|
-
${!path.trim().includes('.css') ? `<link rel="modulepreload" href="${path.trim().replace(/'/g, '').trim()}">` : ''}<link rel="preload" href="${path.trim().replace(/'/g, '').trim()}" as="${path.trim().includes('.css') ? 'style' : 'script'}">`
|
|
674
|
-
html = html.replace('</head>', `${preload}\n</head>`)
|
|
675
|
-
|
|
676
|
-
fs.writeFileSync(process.cwd() + '/dist/index.html', html)
|
|
677
|
-
}
|
|
658
|
+
|
|
678
659
|
if (newImport) {
|
|
679
660
|
string = string.replace(beforeimport, newImport)
|
|
680
661
|
}
|
|
@@ -716,24 +697,8 @@ async function Build() {
|
|
|
716
697
|
globalThis.isWriting = null
|
|
717
698
|
return { _written: true };
|
|
718
699
|
};
|
|
719
|
-
const scannedVaderFiles = await glob("**/**.{html,js}", {
|
|
720
|
-
cwd: process.cwd() + '/node_modules/vaderjs/runtime',
|
|
721
|
-
absolute: true,
|
|
722
|
-
});
|
|
723
|
-
|
|
724
|
-
scannedVaderFiles.forEach(async (file) => {
|
|
725
|
-
file = file.replace(/\\/g, '/');
|
|
726
700
|
|
|
727
701
|
|
|
728
|
-
let name = file.split('/node_modules/vaderjs/runtime/')[1]
|
|
729
|
-
if (file.includes('index.html') && fs.existsSync(process.cwd() + "/dist/" + name)) {
|
|
730
|
-
return
|
|
731
|
-
}
|
|
732
|
-
let data = await reader(file)
|
|
733
|
-
bundleSize += fs.statSync(file).size;
|
|
734
|
-
await writer(process.cwd() + "/dist/" + name, data);
|
|
735
|
-
})
|
|
736
|
-
|
|
737
702
|
const glb = await glob("**/**/**/**.{jsx,js}", {
|
|
738
703
|
ignore: ["node_modules/**/*", "dist/**/*"],
|
|
739
704
|
cwd: process.cwd() + '/pages/',
|
|
@@ -744,12 +709,165 @@ async function Build() {
|
|
|
744
709
|
// Process files in the 'pages' directory
|
|
745
710
|
let appjs = '';
|
|
746
711
|
let hasWritten = []
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
712
|
+
function ssg(routes = []) {
|
|
713
|
+
console.log(`Generating html files for ${routes.length} routes`)
|
|
714
|
+
routes.forEach(async (route) => {
|
|
715
|
+
if(route.url.includes(':')){
|
|
716
|
+
console.log('Route ' + route.url + ' is a dynamic route and will not be generated')
|
|
717
|
+
return
|
|
718
|
+
}
|
|
719
|
+
console.log('Generating html file for route ' + route.url)
|
|
720
|
+
let equalparamroute = routes.map((e) => {
|
|
721
|
+
|
|
722
|
+
if (e.url.includes(':')) {
|
|
723
|
+
let url = e.url.split('/:')[0]
|
|
724
|
+
if(url&&route.url === url){
|
|
725
|
+
return e
|
|
726
|
+
}else{
|
|
727
|
+
return null
|
|
728
|
+
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return null
|
|
732
|
+
}).filter(Boolean)
|
|
733
|
+
let document = `
|
|
734
|
+
<!DOCTYPE html>
|
|
735
|
+
<html lang="en">
|
|
736
|
+
<head>
|
|
737
|
+
<meta charset="UTF-8">
|
|
738
|
+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
739
|
+
<script type="module" id="meta">
|
|
740
|
+
window.module = await import('/${route.fileName.replace('.jsx', '.js')}')
|
|
741
|
+
let metadata = await module.$metadata
|
|
742
|
+
if(metadata && metadata.title){
|
|
743
|
+
document.head.innerHTML += '<title>' + metadata.title + '</title>'
|
|
744
|
+
}
|
|
745
|
+
if(metadata && metadata.description){
|
|
746
|
+
document.head.innerHTML += '<meta name="description" content="' + metadata.description + '">'
|
|
747
|
+
}
|
|
748
|
+
if(metadata && metadata.keywords){
|
|
749
|
+
document.head.innerHTML += '<meta name="keywords" content="' + metadata.keywords + '">'
|
|
750
|
+
}
|
|
751
|
+
if(metadata && metadata.author){
|
|
752
|
+
document.head.innerHTML += '<meta name="author" content="' + metadata.author + '">'
|
|
753
|
+
}
|
|
754
|
+
if(metadata && metadata.image){
|
|
755
|
+
let image = metadata.image.file
|
|
756
|
+
let type = metadata.image.type
|
|
757
|
+
|
|
758
|
+
document.head.innerHTML += '<meta property="og:image" content="' + image + '">'
|
|
759
|
+
document.head.innerHTML += '<meta property="og:image:type" content="' + type + '">'
|
|
760
|
+
}
|
|
761
|
+
if(metadata && metadata.url){
|
|
762
|
+
document.head.innerHTML += '<meta property="og:url" content="' + metadata.url + '">'
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
if(metadata && metadata.robot){
|
|
766
|
+
document.head.innerHTML += '<meta name="robots" content="' + metadata.robot + '">'
|
|
767
|
+
}
|
|
768
|
+
if(metadata && metadata.manifest){
|
|
769
|
+
document.head.innerHTML += '<link rel="manifest" href="' + metadata.manifest + '">'
|
|
770
|
+
}
|
|
771
|
+
if(metadata && metadata.tags){
|
|
772
|
+
metadata.tags.forEach(tag => {
|
|
773
|
+
document.head.innerHTML += tag
|
|
774
|
+
})
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
if(metadata && metadata.styles){
|
|
778
|
+
metadata.styles.forEach(style => {
|
|
779
|
+
style = style.replaceAll('./', '/')
|
|
780
|
+
style = style.replaceAll('../', '/')
|
|
781
|
+
style = style.replace("'", '')
|
|
782
|
+
document.head.innerHTML += '<link rel="stylesheet" href="' + style + '">'
|
|
783
|
+
})
|
|
784
|
+
}
|
|
785
|
+
if(metadata && metadata.icon){
|
|
786
|
+
document.head.innerHTML += '<link rel="icon" href="' + metadata.icon + '">'
|
|
787
|
+
}
|
|
788
|
+
</script>
|
|
789
|
+
</head>
|
|
790
|
+
<body>
|
|
791
|
+
<div id="root"></div>
|
|
792
|
+
</body>
|
|
793
|
+
|
|
794
|
+
<script type="module">
|
|
795
|
+
import VaderRouter from '/router.js'
|
|
796
|
+
const router = new VaderRouter('${route.url}', 3000)
|
|
797
|
+
router.get('${route.url}', async (req, res) => {
|
|
798
|
+
let module = await import('/${route.fileName.replace('.jsx', '.js')}')
|
|
799
|
+
res.render(module, req, res, module.$metadata)
|
|
800
|
+
})
|
|
801
|
+
${equalparamroute.length > 0 ? equalparamroute.map((e) => {
|
|
802
|
+
let folderName = '/' + e.url.split('/')[1]
|
|
803
|
+
|
|
804
|
+
e.url = e.url.replace(folderName, '')
|
|
805
|
+
|
|
806
|
+
return `router.get('${e.url}', async (req, res) => {
|
|
807
|
+
let module = await import('/${e.fileName.replace('.jsx', '.js')}')
|
|
808
|
+
res.render(module, req, res, module.$metadata)
|
|
809
|
+
})\n`
|
|
810
|
+
}): ''}
|
|
811
|
+
router.listen(3000)
|
|
812
|
+
</script>
|
|
813
|
+
</html>
|
|
814
|
+
`;
|
|
815
|
+
|
|
816
|
+
let port = Math.floor(Math.random() * 10000) + 1;
|
|
817
|
+
|
|
818
|
+
const server = http.createServer((req, res) => {
|
|
819
|
+
if (req.url === '/') {
|
|
820
|
+
// Respond with the generated HTML
|
|
821
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
822
|
+
res.end(document);
|
|
823
|
+
} else {
|
|
824
|
+
// Serve static files (adjust the file paths based on your project structure)
|
|
825
|
+
const filePath = process.cwd() + '/dist/' + req.url
|
|
826
|
+
|
|
827
|
+
fs.readFile(filePath, (err, data) => {
|
|
828
|
+
if (err) {
|
|
829
|
+
res.writeHead(404, { 'Content-Type': filePath.includes('js') ? 'text/javascript' : 'text/html' });
|
|
830
|
+
res.end('File not found');
|
|
831
|
+
} else {
|
|
832
|
+
res.writeHead(200, { 'Content-Type': filePath.includes('js') ? 'text/javascript' : 'text/html' });
|
|
833
|
+
res.end(data);
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
server.listen(port)
|
|
840
|
+
|
|
841
|
+
globalThis.listen = true;
|
|
842
|
+
|
|
843
|
+
puppeteer.launch({ headless: "new", args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
844
|
+
warning: false,
|
|
845
|
+
}).then(async (browser) => {
|
|
846
|
+
|
|
847
|
+
// remove /: from route
|
|
848
|
+
route.url = route.url.replaceAll(/\/:[a-zA-Z0-9_-]+/gs, '')
|
|
849
|
+
const page = await browser.newPage();
|
|
850
|
+
await page.goto(`http://localhost:${port}` + '#' + route.url, { waitUntil: 'networkidle2' });
|
|
851
|
+
await page.waitForSelector('#root');
|
|
852
|
+
await page.evaluate(() => {
|
|
853
|
+
document.getElementById('meta').remove()
|
|
854
|
+
})
|
|
855
|
+
const html = await page.content();
|
|
856
|
+
await page.close();
|
|
857
|
+
let isBasePath = route.url === '/' ? true : false
|
|
858
|
+
await writer(process.cwd() + '/dist/' + (isBasePath ? 'index.html' : `${route.url}/` + 'index.html'), html)
|
|
859
|
+
await browser.close();
|
|
860
|
+
// close http
|
|
861
|
+
server.close()
|
|
862
|
+
console.log(`Generated html file for route ${route.url}`)
|
|
863
|
+
})
|
|
864
|
+
|
|
865
|
+
})
|
|
866
|
+
|
|
867
|
+
console.log('Done')
|
|
750
868
|
}
|
|
751
|
-
|
|
752
|
-
|
|
869
|
+
|
|
870
|
+
globalThis.routes = []
|
|
753
871
|
|
|
754
872
|
for await (let file of glb) {
|
|
755
873
|
// Normalize file paths
|
|
@@ -774,22 +892,14 @@ async function Build() {
|
|
|
774
892
|
fullpath: origin,
|
|
775
893
|
};
|
|
776
894
|
|
|
777
|
-
if(process.cwd() + '/dist/index.html'){
|
|
778
|
-
let html = fs.readFileSync(process.cwd() + '/dist/index.html', 'utf8')
|
|
779
|
-
if (!html.includes(`<link rel="preload" href="${obj.url}" as="script">`)) {
|
|
780
|
-
html = html.replace('</head>', `<link rel="preload" href="./pages/${fileName.replace('.jsx', '.js')}" as="script">\n</head>`)
|
|
781
|
-
fs.writeFileSync(process.cwd() + '/dist/index.html', html)
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
|
|
785
895
|
|
|
786
896
|
|
|
787
897
|
let data = await fs.readFileSync(origin, "utf8");
|
|
788
898
|
data = Compiler(data, origin);
|
|
899
|
+
|
|
789
900
|
|
|
790
901
|
|
|
791
|
-
|
|
792
|
-
await writer(process.cwd() + "/dist/pages/" + fileName.replace('.jsx', '.js'), data).then(async () => {
|
|
902
|
+
await writer(process.cwd() + "/dist/" + fileName.replace('.jsx', '.js'), data).then(async () => {
|
|
793
903
|
|
|
794
904
|
let { minify } = await import('terser')
|
|
795
905
|
|
|
@@ -804,7 +914,9 @@ async function Build() {
|
|
|
804
914
|
|
|
805
915
|
})
|
|
806
916
|
|
|
807
|
-
|
|
917
|
+
minified.code += `\n\n window.params = ${JSON.stringify(obj.url.split('/').filter((e) => e.includes(':')).map((e) => e.split(':')[1]))}`
|
|
918
|
+
|
|
919
|
+
await writer(process.cwd() + "/dist/" + fileName.replace('.jsx', '.js'), minified.code)
|
|
808
920
|
} catch (error) {
|
|
809
921
|
console.log(error)
|
|
810
922
|
}
|
|
@@ -814,22 +926,15 @@ async function Build() {
|
|
|
814
926
|
obj.compiledPath = process.cwd() + "/dist/pages/" + fileName.replace('.jsx', '.js')
|
|
815
927
|
|
|
816
928
|
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
res.render(await import('./pages/${fileName.replace('.jsx', '.js')}'), req, res)
|
|
821
|
-
})
|
|
822
|
-
//@desc ${obj.pathname}
|
|
823
|
-
` + '\n';
|
|
824
|
-
appjs += js
|
|
825
|
-
|
|
826
|
-
writejs()
|
|
827
|
-
|
|
929
|
+
|
|
930
|
+
globalThis.routes.push({fileName:fileName, url:obj.url})
|
|
931
|
+
|
|
828
932
|
|
|
829
933
|
|
|
830
934
|
|
|
831
935
|
}
|
|
832
936
|
|
|
937
|
+
ssg(globalThis.routes)
|
|
833
938
|
|
|
834
939
|
|
|
835
940
|
const scannedSourceFiles = await glob("**/**.{jsx,js,json}", {
|
|
@@ -837,7 +942,23 @@ async function Build() {
|
|
|
837
942
|
cwd: process.cwd() + '/src/',
|
|
838
943
|
absolute: true,
|
|
839
944
|
});
|
|
840
|
-
|
|
945
|
+
const scannedVaderFiles = await glob("**/**.{html,js}", {
|
|
946
|
+
cwd: process.cwd() + '/node_modules/vaderjs/runtime',
|
|
947
|
+
absolute: true,
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
scannedVaderFiles.forEach(async (file) => {
|
|
951
|
+
file = file.replace(/\\/g, '/');
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
let name = file.split('/node_modules/vaderjs/runtime/')[1]
|
|
955
|
+
if (file.includes('index.html') && fs.existsSync(process.cwd() + "/dist/" + name)) {
|
|
956
|
+
return
|
|
957
|
+
}
|
|
958
|
+
let data = await reader(file)
|
|
959
|
+
bundleSize += fs.statSync(file).size;
|
|
960
|
+
await writer(process.cwd() + "/dist/" + name, data);
|
|
961
|
+
})
|
|
841
962
|
scannedSourceFiles.forEach(async (file) => {
|
|
842
963
|
file = file.replace(/\\/g, '/');
|
|
843
964
|
let name = file.split('/src/')[1]
|
|
@@ -868,7 +989,7 @@ async function Build() {
|
|
|
868
989
|
await writer(process.cwd() + "/dist/src/" + name, data);
|
|
869
990
|
})
|
|
870
991
|
|
|
871
|
-
const scannedPublicFiles = await glob("**/**.{css,js,html,mjs,cjs
|
|
992
|
+
const scannedPublicFiles = await glob("**/**.{css,js,html,mjs,cjs}", {
|
|
872
993
|
ignore: ["node_modules/**/*", "dist/**/*"],
|
|
873
994
|
cwd: process.cwd() + '/public/',
|
|
874
995
|
absolute: true,
|
|
@@ -894,15 +1015,15 @@ async function Build() {
|
|
|
894
1015
|
|
|
895
1016
|
let objCase = {
|
|
896
1017
|
...file == "app.js" ? { exit: true } : null,
|
|
897
|
-
...file.includes("index.html") && fs.existsSync(process.cwd() + "/
|
|
1018
|
+
...file.includes("index.html") && fs.existsSync(process.cwd() + "/dist/" + file) ? { exit: true } : null,
|
|
898
1019
|
|
|
899
1020
|
}
|
|
900
1021
|
if (objCase.exit) {
|
|
901
1022
|
console.log('exiting')
|
|
902
|
-
return
|
|
1023
|
+
return true
|
|
903
1024
|
}
|
|
904
|
-
bundleSize += fs.statSync(process.cwd() + "/runtime/" + file).size;
|
|
905
|
-
let data = await reader(process.cwd() + "/runtime/" + file)
|
|
1025
|
+
bundleSize += fs.statSync(process.cwd() + "/node_modules/vaderjs/runtime/" + file).size;
|
|
1026
|
+
let data = await reader(process.cwd() + "/node_modules/vaderjs/runtime/" + file)
|
|
906
1027
|
await writer(process.cwd() + "/dist/" + file, data);
|
|
907
1028
|
});
|
|
908
1029
|
|