vaderjs 1.3.3-7725642-hotfix → 1.3.3-773562-hotfix
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/vader.js +211 -189
package/package.json
CHANGED
package/vader.js
CHANGED
|
@@ -143,9 +143,6 @@ function Compiler(func, file) {
|
|
|
143
143
|
isJSXComponent = elementTag.match(/^[A-Z]/) ? true : false;
|
|
144
144
|
}
|
|
145
145
|
});
|
|
146
|
-
if(isJSXComponent){
|
|
147
|
-
continue
|
|
148
|
-
}
|
|
149
146
|
// add ; after newlines
|
|
150
147
|
|
|
151
148
|
|
|
@@ -242,34 +239,34 @@ function Compiler(func, file) {
|
|
|
242
239
|
continue;
|
|
243
240
|
}
|
|
244
241
|
let old = spread;
|
|
245
|
-
spread = spread.trim().replace(/\s+/g, " ");
|
|
242
|
+
spread = spread.trim().replace(/\s+/g, " ");
|
|
246
243
|
// re,pve $={ and }
|
|
247
244
|
spread = spread.replace(/\s*\$\s*=\s*{\s*{/gs, '')
|
|
248
|
-
|
|
245
|
+
|
|
249
246
|
// replace trailing }
|
|
250
|
-
spread = spread.replace(/}}\s*$/, '').replace(/}\s*}$/, '')
|
|
251
|
-
let splitByCommas =
|
|
247
|
+
spread = spread.replace(/}}\s*$/, '').replace(/}\s*}$/, '')
|
|
248
|
+
let splitByCommas = spread.split(/,(?![^{}]*})/gs)
|
|
252
249
|
// remove empty strings
|
|
253
250
|
splitByCommas = splitByCommas.filter((e) => e.split(':')[0].trim().length > 0)
|
|
254
|
-
splitByCommas = splitByCommas.map((e, index) => {
|
|
251
|
+
splitByCommas = splitByCommas.map((e, index) => {
|
|
255
252
|
let key = e.split(':')[0].trim()
|
|
256
253
|
switch (true) {
|
|
257
254
|
case e.includes('function') && !e.includes('this.bind') || e && e.includes('=>') && !e.includes('this.bind'):
|
|
258
255
|
let value = e.split(':')[1].trim()
|
|
259
|
-
let ref = Math.random().toString(36).substring(2).split('').filter((e) => !Number(e)).join('');
|
|
256
|
+
let ref = Math.random().toString(36).substring(2).split('').filter((e) => !Number(e)).join('');
|
|
260
257
|
value = `this.bind(${value}, false, "${ref}", "")`
|
|
261
258
|
e = `${key}="\${${value}}"`
|
|
262
259
|
break;
|
|
263
|
-
case
|
|
264
|
-
let v2 = e.split('style:')[1].trim().replace(/,$/, '')
|
|
265
|
-
v2 = v2.replace(/,$/, '')
|
|
260
|
+
case e.includes('style:'):
|
|
261
|
+
let v2 = e.split('style:')[1].trim().replace(/,$/, '')
|
|
262
|
+
v2 = v2.replace(/,$/, '')
|
|
266
263
|
e = `${key}="\${this.parseStyle(${v2})}"`
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
default:
|
|
270
|
-
let v = e.split(':')
|
|
264
|
+
break;
|
|
265
|
+
|
|
266
|
+
default:
|
|
267
|
+
let v = e.split(':')
|
|
271
268
|
key = v[0].trim()
|
|
272
|
-
|
|
269
|
+
// remove key from v
|
|
273
270
|
v.shift()
|
|
274
271
|
v = v.join(' ')
|
|
275
272
|
e = `${key}="\${${v}}"`
|
|
@@ -280,7 +277,7 @@ function Compiler(func, file) {
|
|
|
280
277
|
|
|
281
278
|
return e;
|
|
282
279
|
});
|
|
283
|
-
|
|
280
|
+
|
|
284
281
|
|
|
285
282
|
let newSpread = splitByCommas.join(' ').trim().replace(/,$/, '');
|
|
286
283
|
|
|
@@ -351,7 +348,7 @@ function Compiler(func, file) {
|
|
|
351
348
|
newAttributes.push(attribute);
|
|
352
349
|
for (let key in attributes) {
|
|
353
350
|
|
|
354
|
-
let value = attributes[key];
|
|
351
|
+
let value = attributes[key];
|
|
355
352
|
let oldvalue = value;
|
|
356
353
|
if (value && !value.new) {
|
|
357
354
|
|
|
@@ -482,8 +479,9 @@ function Compiler(func, file) {
|
|
|
482
479
|
|
|
483
480
|
let name = component.split("<")[1].split(">")[0].split(" ")[0].replace("/", "");
|
|
484
481
|
let componentAttributes = component.split("<")[1].split(">")[0].split(" ").join(" ").replace(name, "").trim();
|
|
485
|
-
|
|
486
|
-
|
|
482
|
+
const dynamicAttributesRegex = /(\w+)(?:="([^"]*?)"|='([^']*?)'|(?:=\{([^}]*?)\})?|(?:=\{(.*?)*\})?|(?:={([^}]*?)})?|(?:{([^}]*?)})?|(?:}))?|\$=\s*\{\s*\{\s*([^]*?)\s*\}\s*\}/gs;
|
|
483
|
+
|
|
484
|
+
|
|
487
485
|
|
|
488
486
|
let props = component.match(dynamicAttributesRegex)
|
|
489
487
|
|
|
@@ -494,7 +492,6 @@ function Compiler(func, file) {
|
|
|
494
492
|
|
|
495
493
|
let $_ternaryprops = []
|
|
496
494
|
|
|
497
|
-
if(props){
|
|
498
495
|
for (let prop of props) {
|
|
499
496
|
|
|
500
497
|
if (prop === componentName) {
|
|
@@ -502,8 +499,18 @@ function Compiler(func, file) {
|
|
|
502
499
|
isWithinComponent = true;
|
|
503
500
|
filteredProps.push(prop);
|
|
504
501
|
} else if (isWithinComponent && prop.includes('=')) {
|
|
505
|
-
|
|
506
|
-
|
|
502
|
+
|
|
503
|
+
if (prop.startsWith('$=')) {
|
|
504
|
+
let old = prop
|
|
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)
|
|
509
|
+
|
|
510
|
+
$_ternaryprops.push(prop)
|
|
511
|
+
|
|
512
|
+
}
|
|
513
|
+
else if (prop.includes('${')) {
|
|
507
514
|
|
|
508
515
|
|
|
509
516
|
prop = prop.replace('="', ':')
|
|
@@ -522,16 +529,14 @@ function Compiler(func, file) {
|
|
|
522
529
|
if (prop.includes('={')) {
|
|
523
530
|
let value = prop.split('={')
|
|
524
531
|
let isObj = value[1].match(/^{.*}$/gs) ? true : false
|
|
525
|
-
if (!isObj) {
|
|
532
|
+
if (!isObj) {
|
|
533
|
+
// remove trailing }
|
|
526
534
|
value[1] = value[1].replace(/}\s*$/, '')
|
|
527
|
-
}else if(!value[0].length > 0 && isObj){
|
|
528
|
-
prop = ''
|
|
529
535
|
}
|
|
530
|
-
|
|
531
|
-
value[1] = value[1].replace(/}\s*$/, '')
|
|
536
|
+
|
|
532
537
|
if (value[0] == 'style' && isObj) {
|
|
533
538
|
value[1] = `this.parseStyle(${value[1]})`
|
|
534
|
-
}
|
|
539
|
+
}
|
|
535
540
|
prop = `${value[0]}:${value[1]}`
|
|
536
541
|
}
|
|
537
542
|
|
|
@@ -560,7 +565,6 @@ function Compiler(func, file) {
|
|
|
560
565
|
isWithinComponent = false;
|
|
561
566
|
}
|
|
562
567
|
}
|
|
563
|
-
}
|
|
564
568
|
component = component.replaceAll(/\s+/g, " ");
|
|
565
569
|
|
|
566
570
|
component = component.replace(componentAttributes, '')
|
|
@@ -631,52 +635,54 @@ function Compiler(func, file) {
|
|
|
631
635
|
|
|
632
636
|
string = string.replaceAll('vaderjs/client', '/vader.js')
|
|
633
637
|
|
|
634
|
-
const importRegex = /import\s*([^\s,]+|\{[^}]+\})\s*from\s*(['"])(.*?)\2/
|
|
638
|
+
const importRegex = /import\s*([^\s,]+|\{[^}]+\})\s*from\s*(['"])(.*?)\2/gs;
|
|
635
639
|
const imports = string.match(importRegex);
|
|
636
640
|
let replaceMents = [];
|
|
637
641
|
|
|
638
642
|
|
|
639
|
-
|
|
640
|
-
let
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
643
|
+
if (imports) {
|
|
644
|
+
for (let match of imports) {
|
|
645
|
+
let path = match.split('from')[1].trim().replace(/'/g, '').replace(/"/g, '').trim()
|
|
646
|
+
switch (true) {
|
|
647
|
+
case path && !path.includes('./') && !path.includes('/vader.js') && !path.includes('/vaderjs/client') && !path.startsWith('src') && !path.startsWith('public') && !path.includes('http') && !path.includes('https'):
|
|
648
|
+
let componentFolder = fs.existsSync(process.cwd() + '/node_modules/' + path) ? process.cwd() + '/node_modules/' + path : process.cwd() + '/node_modules/' + path.split('/')[0]
|
|
649
|
+
componentFolder = componentFolder.split(process.cwd())[1]
|
|
650
|
+
if (!fs.existsSync(process.cwd() + componentFolder)) {
|
|
651
|
+
throw new Error('Could not find ' + path + ' at ' + match + ' in file ' + file)
|
|
652
|
+
}
|
|
648
653
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
654
|
+
if (!fs.existsSync(process.cwd() + '/dist/src/' + componentFolder.split('/').slice(2).join('/'))) {
|
|
655
|
+
fs.mkdirSync(process.cwd() + '/dist/src/' + componentFolder.split('/').slice(2).join('/'), { recursive: true })
|
|
656
|
+
}
|
|
652
657
|
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
658
|
+
let baseFolder = componentFolder.split('node_modules')[1].split('/')[1]
|
|
659
|
+
let glp = globSync('**/**/**/**.{jsx,js}', {
|
|
660
|
+
cwd: process.cwd() + '/node_modules/' + baseFolder + '/',
|
|
661
|
+
absolute: true,
|
|
662
|
+
recursive: true
|
|
663
|
+
})
|
|
664
|
+
for (let file of glp) {
|
|
665
|
+
let text = fs.readFileSync(file, "utf8");
|
|
666
|
+
if (!file.endsWith('.js') && file.endsWith('.jsx')) {
|
|
667
|
+
text = Compiler(text, file);
|
|
663
668
|
|
|
669
|
+
}
|
|
670
|
+
let dest = file.split('node_modules')[1]
|
|
671
|
+
dest = dest.split(baseFolder)[1]
|
|
672
|
+
writer(process.cwd() + '/dist/src/' + baseFolder + dest, text)
|
|
673
|
+
let importname = match.split('import')[1].split('from')[0].trim()
|
|
674
|
+
let oldImportstring = match.split('from')[1].trim().replace(/'/g, '').replace(/"/g, '').trim()
|
|
675
|
+
let newImport = `/src/${baseFolder + dest}`
|
|
676
|
+
newImport = newImport.replaceAll('.jsx', '.js').replaceAll('\\', '/')
|
|
677
|
+
replaceMents.push({ match: oldImportstring, replace: newImport })
|
|
678
|
+
console.log(`📦 imported Node Package ${baseFolder} `)
|
|
664
679
|
}
|
|
665
|
-
let dest = file.split('node_modules')[1]
|
|
666
|
-
dest = dest.split(baseFolder)[1]
|
|
667
|
-
writer(process.cwd() + '/dist/src/' + baseFolder + dest, text)
|
|
668
|
-
let importname = match.split('import')[1].split('from')[0].trim()
|
|
669
|
-
let oldImportstring = match.split('from')[1].trim().replace(/'/g, '').replace(/"/g, '').trim()
|
|
670
|
-
let newImport = `/src/${baseFolder + dest}`
|
|
671
|
-
newImport = newImport.replaceAll('.jsx', '.js').replaceAll('\\', '/')
|
|
672
|
-
replaceMents.push({ match: oldImportstring, replace: newImport })
|
|
673
|
-
console.log(`📦 imported Node Package ${baseFolder} `)
|
|
674
|
-
}
|
|
675
680
|
|
|
676
681
|
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
682
|
+
break;
|
|
683
|
+
default:
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
680
686
|
}
|
|
681
687
|
}
|
|
682
688
|
|
|
@@ -869,6 +875,7 @@ const glb = await glob("**/**/**/**.{jsx,js}", {
|
|
|
869
875
|
absolute: true,
|
|
870
876
|
recursive: true
|
|
871
877
|
});
|
|
878
|
+
let hasRendered = []
|
|
872
879
|
async function Build() {
|
|
873
880
|
globalThis.isBuilding = true
|
|
874
881
|
console.log(globalThis.isProduction ? 'Creating Optimized Production Build\n' : '')
|
|
@@ -883,119 +890,49 @@ async function Build() {
|
|
|
883
890
|
|
|
884
891
|
function ssg(routes = []) {
|
|
885
892
|
globalThis.isBuilding = true
|
|
893
|
+
let server = http.createServer((req, res) => {
|
|
894
|
+
let route = routes.find((e) => e.url === req.url)
|
|
895
|
+
if (route) {
|
|
896
|
+
let document = globalThis.routeDocuments.find((e) => e.url === req.url)
|
|
897
|
+
console.log(`\x1b[32m%s\x1b[0m`, `Prerendering ${req.url}...`)
|
|
898
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
899
|
+
res.end(document.document);
|
|
900
|
+
} else {
|
|
901
|
+
const filePath = process.cwd() + '/dist/' + req.url
|
|
902
|
+
|
|
903
|
+
fs.readFile(filePath, (err, data) => {
|
|
904
|
+
if (err) {
|
|
905
|
+
res.writeHead(404, { 'Content-Type': filePath.includes('js') ? 'text/javascript' : 'text/html' });
|
|
906
|
+
res.end('File not found');
|
|
907
|
+
} else {
|
|
908
|
+
res.writeHead(200, { 'Content-Type': filePath.includes('js') ? 'text/javascript' : 'text/html' });
|
|
909
|
+
res.end(data);
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
let port = 12000
|
|
916
|
+
server.on('error', (err) => {
|
|
917
|
+
if (err.code === 'EADDRINUSE') {
|
|
918
|
+
setTimeout(() => {
|
|
919
|
+
server.close();
|
|
920
|
+
server.listen(++port);
|
|
921
|
+
}, 1000);
|
|
922
|
+
}
|
|
923
|
+
})
|
|
924
|
+
|
|
925
|
+
server.listen(port);
|
|
886
926
|
routes.forEach(async (route) => {
|
|
887
927
|
if (route.url.includes(':')) {
|
|
888
928
|
return
|
|
889
929
|
}
|
|
890
|
-
let equalparamroute = routes.map((e) => {
|
|
891
|
-
if (e.url.includes(':')) {
|
|
892
|
-
let url = e.url.split('/:')[0]
|
|
893
|
-
if (url && route.url === url) {
|
|
894
|
-
return e
|
|
895
|
-
} else {
|
|
896
|
-
return null
|
|
897
|
-
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
return null
|
|
901
|
-
}).filter(Boolean)
|
|
902
|
-
let document = `
|
|
903
|
-
<!DOCTYPE html>
|
|
904
|
-
<html lang="en">
|
|
905
|
-
<head>
|
|
906
|
-
<script>
|
|
907
|
-
window.routes = JSON.parse('${JSON.stringify(routes)}')
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
</script>
|
|
911
|
-
<script id="isServer">
|
|
912
|
-
window.isServer = true
|
|
913
|
-
</script>
|
|
914
|
-
<meta charset="UTF-8">
|
|
915
|
-
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
916
|
-
<script type="module" id="meta">
|
|
917
|
-
window.history.pushState({}, '', '${route.url}')
|
|
918
|
-
|
|
919
|
-
</script>
|
|
920
|
-
<script type="module" id="router">
|
|
921
|
-
import VaderRouter from '/router.js'
|
|
922
|
-
const router = new VaderRouter('${route.url}', 3000)
|
|
923
|
-
router.get('${route.url}', async (req, res) => {
|
|
924
|
-
try{
|
|
925
|
-
let module = await import('/${route.fileName.replace('.jsx', '.js')}')
|
|
926
|
-
if(Object.keys(module).includes('$prerender') && !module.$prerender){
|
|
927
|
-
document.head.setAttribute('prerender', 'false')
|
|
928
|
-
}
|
|
929
|
-
res.render(module, req, res, module.$metadata)
|
|
930
|
-
}
|
|
931
|
-
catch(error){
|
|
932
|
-
let errorMessage = {
|
|
933
|
-
message: error.message,
|
|
934
|
-
name: error.name,
|
|
935
|
-
stack: error.stack,
|
|
936
|
-
path: window.location.pathname
|
|
937
|
-
};
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
document.documentElement.setAttribute('error', JSON.stringify(errorMessage));
|
|
941
|
-
throw new Error(error)
|
|
942
|
-
}
|
|
943
|
-
})
|
|
944
|
-
${equalparamroute.length > 0 ? equalparamroute.map((e) => {
|
|
945
930
|
|
|
946
931
|
|
|
947
932
|
|
|
948
|
-
return `router.get('${e.url}', async (req, res) => {
|
|
949
|
-
let module = await import('/${e.fileName.replace('.jsx', '.js')}')
|
|
950
|
-
res.render(module, req, res, module.$metadata)
|
|
951
|
-
})\n`
|
|
952
|
-
}) : ''}
|
|
953
|
-
router.listen(3000)
|
|
954
|
-
|
|
955
|
-
</script>
|
|
956
|
-
</head>
|
|
957
|
-
<body>
|
|
958
|
-
<div id="root"></div>
|
|
959
|
-
</body>
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
</html>
|
|
963
|
-
`;
|
|
964
933
|
|
|
965
|
-
// generate random but common ports
|
|
966
|
-
let port = Math.floor(Math.random() * (65535 - 49152 + 1) + 49152)
|
|
967
934
|
|
|
968
|
-
const server = http.createServer((req, res) => {
|
|
969
935
|
|
|
970
|
-
if (req.url === '/') {
|
|
971
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
972
|
-
res.end(document);
|
|
973
|
-
} else {
|
|
974
|
-
// Serve static files (adjust the file paths based on your project structure)
|
|
975
|
-
const filePath = process.cwd() + '/dist/' + req.url
|
|
976
|
-
|
|
977
|
-
fs.readFile(filePath, (err, data) => {
|
|
978
|
-
if (err) {
|
|
979
|
-
res.writeHead(404, { 'Content-Type': filePath.includes('js') ? 'text/javascript' : 'text/html' });
|
|
980
|
-
res.end('File not found');
|
|
981
|
-
} else {
|
|
982
|
-
res.writeHead(200, { 'Content-Type': filePath.includes('js') ? 'text/javascript' : 'text/html' });
|
|
983
|
-
res.end(data);
|
|
984
|
-
}
|
|
985
|
-
});
|
|
986
|
-
}
|
|
987
|
-
});
|
|
988
|
-
|
|
989
|
-
server.listen(port)
|
|
990
|
-
server.on('error', (err) => {
|
|
991
|
-
if (err.code === 'EADDRINUSE') {
|
|
992
|
-
console.log(`Port ${port} is in use, trying another port...`);
|
|
993
|
-
setTimeout(() => {
|
|
994
|
-
server.close();
|
|
995
|
-
server.listen(++port);
|
|
996
|
-
}, 1000);
|
|
997
|
-
}
|
|
998
|
-
})
|
|
999
936
|
|
|
1000
937
|
globalThis.listen = true;
|
|
1001
938
|
|
|
@@ -1011,14 +948,16 @@ async function Build() {
|
|
|
1011
948
|
page.on('error', (err) => {
|
|
1012
949
|
console.error('BROWSER ERROR:', JSON.parse(err));
|
|
1013
950
|
});
|
|
1014
|
-
|
|
951
|
+
|
|
1015
952
|
try {
|
|
1016
|
-
page.on('pageerror', async err => {
|
|
1017
|
-
let errorObj =
|
|
1018
|
-
console.log('\x1b[31m%s\x1b[0m', 'Compiler Error:',
|
|
953
|
+
page.on('pageerror', async err => {
|
|
954
|
+
let errorObj = JSON.parse(await page.evaluate(() => document.documentElement.getAttribute('error')) || '{}')
|
|
955
|
+
console.log('\x1b[31m%s\x1b[0m', 'Compiler Error:', errorObj)
|
|
1019
956
|
|
|
957
|
+
console.log('\x1b[31m%s\x1b[0m', 'Error:', err)
|
|
1020
958
|
});
|
|
1021
959
|
} catch (error) {
|
|
960
|
+
console.log(error)
|
|
1022
961
|
browser.close()
|
|
1023
962
|
}
|
|
1024
963
|
// Handle page crashes
|
|
@@ -1028,16 +967,10 @@ async function Build() {
|
|
|
1028
967
|
page.on('requestfailed', request => {
|
|
1029
968
|
console.error('REQUEST FAILED:', request.url(), request.failure().errorText);
|
|
1030
969
|
});
|
|
1031
|
-
await page.goto(`http://localhost:${port}
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
970
|
+
await page.goto(`http://localhost:${port}${route.url}`, { waitUntil: 'networkidle2' });
|
|
1038
971
|
|
|
1039
972
|
await page.evaluate(() => {
|
|
1040
|
-
document.
|
|
973
|
+
document.querySelector('#meta').remove()
|
|
1041
974
|
document.querySelector('#isServer').innerHTML = 'window.isServer = false'
|
|
1042
975
|
if (document.head.getAttribute('prerender') === 'false') {
|
|
1043
976
|
document.querySelector('#root').innerHTML = ''
|
|
@@ -1053,19 +986,26 @@ async function Build() {
|
|
|
1053
986
|
|
|
1054
987
|
|
|
1055
988
|
} catch (error) {
|
|
1056
|
-
|
|
989
|
+
|
|
1057
990
|
}
|
|
1058
991
|
|
|
1059
992
|
finally {
|
|
1060
993
|
browser.close()
|
|
1061
994
|
server.close()
|
|
995
|
+
hasRendered.push(route.url)
|
|
996
|
+
console.log(`\x1b[32m%s\x1b[0m`, `Prerendered ${route.url}...`)
|
|
1062
997
|
}
|
|
1063
998
|
})
|
|
1064
999
|
|
|
1065
|
-
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
if (hasRendered.length === routes.length) {
|
|
1003
|
+
server.close()
|
|
1004
|
+
hasRendered = []
|
|
1066
1005
|
globalThis.isBuilding = false
|
|
1067
1006
|
clearTimeout(timeout)
|
|
1068
|
-
}
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1069
1009
|
}
|
|
1070
1010
|
|
|
1071
1011
|
globalThis.routes = []
|
|
@@ -1167,6 +1107,7 @@ async function Build() {
|
|
|
1167
1107
|
}
|
|
1168
1108
|
|
|
1169
1109
|
|
|
1110
|
+
|
|
1170
1111
|
globalThis.routes.push({ fileName: fileName, url: obj.url, html: '/' + (isBasePath ? 'index.html' : `${obj.url}/` + 'index.html') })
|
|
1171
1112
|
|
|
1172
1113
|
|
|
@@ -1184,6 +1125,87 @@ async function Build() {
|
|
|
1184
1125
|
globalThis.isProduction ? console.log(string) : null
|
|
1185
1126
|
}
|
|
1186
1127
|
|
|
1128
|
+
|
|
1129
|
+
globalThis.routeDocuments = []
|
|
1130
|
+
globalThis.routes.map((route) => {
|
|
1131
|
+
let equalparamroute = globalThis.routes.map((e) => {
|
|
1132
|
+
if (e.url.includes(':')) {
|
|
1133
|
+
let url = e.url.split('/:')[0]
|
|
1134
|
+
if (url && route.url === url) {
|
|
1135
|
+
return e
|
|
1136
|
+
} else {
|
|
1137
|
+
return null
|
|
1138
|
+
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
return null
|
|
1142
|
+
}).filter(Boolean)
|
|
1143
|
+
let document = `
|
|
1144
|
+
<!DOCTYPE html>
|
|
1145
|
+
<html lang="en">
|
|
1146
|
+
<head>
|
|
1147
|
+
<script>
|
|
1148
|
+
window.routes = JSON.parse('${JSON.stringify(globalThis.routes)}')
|
|
1149
|
+
</script>
|
|
1150
|
+
<script type="module" id="meta">
|
|
1151
|
+
window.history.pushState({}, '', '${route.url}')
|
|
1152
|
+
|
|
1153
|
+
</script>
|
|
1154
|
+
<script id="isServer">
|
|
1155
|
+
window.isServer = true
|
|
1156
|
+
</script>
|
|
1157
|
+
<meta charset="UTF-8">
|
|
1158
|
+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
1159
|
+
|
|
1160
|
+
<script type="module" id="router">
|
|
1161
|
+
import VaderRouter from '/router.js'
|
|
1162
|
+
const router = new VaderRouter('${route.url}')
|
|
1163
|
+
router.get('${route.url}', async (req, res) => {
|
|
1164
|
+
try{
|
|
1165
|
+
let module = await import('/${route.fileName.replace('.jsx', '.js')}')
|
|
1166
|
+
if(Object.keys(module).includes('$prerender') && !module.$prerender){
|
|
1167
|
+
document.head.setAttribute('prerender', 'false')
|
|
1168
|
+
}
|
|
1169
|
+
res.render(module, req, res, module.$metadata)
|
|
1170
|
+
}
|
|
1171
|
+
catch(error){
|
|
1172
|
+
let errorMessage = {
|
|
1173
|
+
message: error.message,
|
|
1174
|
+
name: error.name,
|
|
1175
|
+
stack: error.stack,
|
|
1176
|
+
path: window.location.pathname
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
document.documentElement.setAttribute('error', JSON.stringify(errorMessage));
|
|
1181
|
+
throw new Error(error)
|
|
1182
|
+
}
|
|
1183
|
+
})
|
|
1184
|
+
${equalparamroute.length > 0 ? equalparamroute.map((e) => {
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
return `router.get('${e.url}', async (req, res) => {
|
|
1189
|
+
let module = await import('/${e.fileName.replace('.jsx', '.js')}')
|
|
1190
|
+
res.render(module, req, res, module.$metadata)
|
|
1191
|
+
})\n`
|
|
1192
|
+
}) : ''}
|
|
1193
|
+
router.listen(3000)
|
|
1194
|
+
|
|
1195
|
+
</script>
|
|
1196
|
+
</head>
|
|
1197
|
+
<body>
|
|
1198
|
+
<div id="root"></div>
|
|
1199
|
+
</body>
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
</html>
|
|
1203
|
+
`;
|
|
1204
|
+
globalThis.routeDocuments.push({ url: route.url, document: document })
|
|
1205
|
+
})
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
|
|
1187
1209
|
ssg(globalThis.routes)
|
|
1188
1210
|
|
|
1189
1211
|
|
|
@@ -1216,7 +1238,7 @@ async function Build() {
|
|
|
1216
1238
|
|
|
1217
1239
|
let data = await reader(process.cwd() + "/src/" + name)
|
|
1218
1240
|
if (name.includes('.jsx')) {
|
|
1219
|
-
let origin = process.cwd() + "/src/" + name
|
|
1241
|
+
let origin = process.cwd() + "/src/" + name
|
|
1220
1242
|
if (!globalThis.isProduction) {
|
|
1221
1243
|
let { sourceMap } = sourceMapGen({ origin: origin, fileName: name }, await Compiler(data, origin))
|
|
1222
1244
|
data = data + `\n//# sourceMappingURL=/src/maps/${name.replace('.jsx', '.js.map')}\n //#sourceURL=${origin}`
|
|
@@ -1229,7 +1251,7 @@ async function Build() {
|
|
|
1229
1251
|
await writer(process.cwd() + "/dist/src/" + name, data);
|
|
1230
1252
|
})
|
|
1231
1253
|
|
|
1232
|
-
const scannedPublicFiles = await glob("
|
|
1254
|
+
const scannedPublicFiles = await glob("**/**.{css,js,html,mjs,cjs}", {
|
|
1233
1255
|
ignore: ["node_modules/**/*", "dist/**/*"],
|
|
1234
1256
|
cwd: process.cwd() + '/public/',
|
|
1235
1257
|
absolute: true,
|
|
@@ -1237,7 +1259,7 @@ async function Build() {
|
|
|
1237
1259
|
scannedPublicFiles.forEach(async (file) => {
|
|
1238
1260
|
file = file.replace(/\\/g, '/');
|
|
1239
1261
|
file = file.split('/public/')[1]
|
|
1240
|
-
let data =
|
|
1262
|
+
let data = await reader(process.cwd() + "/public/" + file)
|
|
1241
1263
|
bundleSize += fs.statSync(process.cwd() + "/public/" + file).size;
|
|
1242
1264
|
await writer(process.cwd() + "/dist/public/" + file, data);
|
|
1243
1265
|
})
|
|
@@ -1270,7 +1292,7 @@ async function Build() {
|
|
|
1270
1292
|
}
|
|
1271
1293
|
|
|
1272
1294
|
globalThis.isBuilding = false
|
|
1273
|
-
console.log(`\nTotal bundle size: ${Math.round(bundleSize / 1000)}kb`)
|
|
1295
|
+
globalThis.isProduction ? console.log(`\nTotal bundle size: ${Math.round(bundleSize / 1000)}kb`) : null
|
|
1274
1296
|
|
|
1275
1297
|
bundleSize = 0;
|
|
1276
1298
|
|