vaderjs 1.3.3-773562-hotfix → 1.3.3-777562-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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/vader.js +222 -288
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-773562-hotfix",
5
+ "version": "1.3.3-777562-hotfix",
6
6
  "bin": {
7
7
  "vader": "./vader.js"
8
8
  },
package/vader.js CHANGED
@@ -143,6 +143,9 @@ function Compiler(func, file) {
143
143
  isJSXComponent = elementTag.match(/^[A-Z]/) ? true : false;
144
144
  }
145
145
  });
146
+ if(isJSXComponent){
147
+ continue
148
+ }
146
149
  // add ; after newlines
147
150
 
148
151
 
@@ -239,34 +242,34 @@ function Compiler(func, file) {
239
242
  continue;
240
243
  }
241
244
  let old = spread;
242
- spread = spread.trim().replace(/\s+/g, " ");
245
+ spread = spread.trim().replace(/\s+/g, " ");
243
246
  // re,pve $={ and }
244
247
  spread = spread.replace(/\s*\$\s*=\s*{\s*{/gs, '')
245
-
248
+
246
249
  // replace trailing }
247
- spread = spread.replace(/}}\s*$/, '').replace(/}\s*}$/, '')
248
- let splitByCommas = spread.split(/,(?![^{}]*})/gs)
250
+ spread = spread.replace(/}}\s*$/, '').replace(/}\s*}$/, '')
251
+ let splitByCommas = spread.split(/,(?![^{}]*})/gs)
249
252
  // remove empty strings
250
253
  splitByCommas = splitByCommas.filter((e) => e.split(':')[0].trim().length > 0)
251
- splitByCommas = splitByCommas.map((e, index) => {
254
+ splitByCommas = splitByCommas.map((e, index) => {
252
255
  let key = e.split(':')[0].trim()
253
256
  switch (true) {
254
257
  case e.includes('function') && !e.includes('this.bind') || e && e.includes('=>') && !e.includes('this.bind'):
255
258
  let value = e.split(':')[1].trim()
256
- let ref = Math.random().toString(36).substring(2).split('').filter((e) => !Number(e)).join('');
259
+ let ref = Math.random().toString(36).substring(2).split('').filter((e) => !Number(e)).join('');
257
260
  value = `this.bind(${value}, false, "${ref}", "")`
258
261
  e = `${key}="\${${value}}"`
259
262
  break;
260
- case e.includes('style:'):
261
- let v2 = e.split('style:')[1].trim().replace(/,$/, '')
262
- v2 = v2.replace(/,$/, '')
263
+ case e.includes('style:'):
264
+ let v2 = e.split('style:')[1].trim().replace(/,$/, '')
265
+ v2 = v2.replace(/,$/, '')
263
266
  e = `${key}="\${this.parseStyle(${v2})}"`
264
- break;
265
-
266
- default:
267
- let v = e.split(':')
267
+ break;
268
+
269
+ default:
270
+ let v = e.split(':')
268
271
  key = v[0].trim()
269
- // remove key from v
272
+ // remove key from v
270
273
  v.shift()
271
274
  v = v.join(' ')
272
275
  e = `${key}="\${${v}}"`
@@ -277,7 +280,7 @@ function Compiler(func, file) {
277
280
 
278
281
  return e;
279
282
  });
280
-
283
+
281
284
 
282
285
  let newSpread = splitByCommas.join(' ').trim().replace(/,$/, '');
283
286
 
@@ -348,7 +351,7 @@ function Compiler(func, file) {
348
351
  newAttributes.push(attribute);
349
352
  for (let key in attributes) {
350
353
 
351
- let value = attributes[key];
354
+ let value = attributes[key];
352
355
  let oldvalue = value;
353
356
  if (value && !value.new) {
354
357
 
@@ -479,12 +482,17 @@ function Compiler(func, file) {
479
482
 
480
483
  let name = component.split("<")[1].split(">")[0].split(" ")[0].replace("/", "");
481
484
  let componentAttributes = component.split("<")[1].split(">")[0].split(" ").join(" ").replace(name, "").trim();
482
- const dynamicAttributesRegex = /(\w+)(?:="([^"]*?)"|='([^']*?)'|(?:=\{([^}]*?)\})?|(?:=\{(.*?)*\})?|(?:={([^}]*?)})?|(?:{([^}]*?)})?|(?:}))?|\$=\s*\{\s*\{\s*([^]*?)\s*\}\s*\}/gs;
483
-
484
-
485
-
486
- let props = component.match(dynamicAttributesRegex)
485
+ // catchall = "" ={} =[]
486
+
487
+
488
+ let props = component.split("<")[1].split(">")[0]
489
+
490
+
491
+ const dynamicAttributesRegex = /([a-zA-Z0-9_-]+)\s*=\s*("(?:[^"\\]*(?:\\.[^"\\]*)*)"|'(?:[^'\\]*(?:\\.[^'\\]*)*)'|\{(?:[^{}]|(?:\{(?:[^{}]|(?:\{.*.*\})*)*\})*)*\}|(?:\([^)]*\)|()\s*=>\s*(?:\{.*\})?|\{[^}]*\})|\[[^\]]*\])/gs;
487
492
 
493
+ const attributeObject = {};
494
+
495
+
488
496
  let filteredProps = [];
489
497
  let isWithinComponent = false;
490
498
  let componentName = name
@@ -492,79 +500,32 @@ function Compiler(func, file) {
492
500
 
493
501
  let $_ternaryprops = []
494
502
 
495
- for (let prop of props) {
496
-
497
- if (prop === componentName) {
498
-
499
- isWithinComponent = true;
500
- filteredProps.push(prop);
501
- } else if (isWithinComponent && prop.includes('=')) {
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('${')) {
514
-
515
-
516
- prop = prop.replace('="', ':')
517
- if (prop.includes('${')) {
518
- prop = prop.replace('="', ':')
519
- prop = prop.replace('${', '')
520
- }
521
- if (prop.includes('="${{')) {
522
- prop = prop.replace('${{', '{')
523
- prop = prop.replace('}}', '}')
524
- prop = prop.replace('="', ':')
525
- prop = prop.replace('}"', '}')
526
- }
527
-
528
- }
529
- if (prop.includes('={')) {
530
- let value = prop.split('={')
531
- let isObj = value[1].match(/^{.*}$/gs) ? true : false
532
- if (!isObj) {
533
- // remove trailing }
534
- value[1] = value[1].replace(/}\s*$/, '')
535
- }
536
-
537
- if (value[0] == 'style' && isObj) {
538
- value[1] = `this.parseStyle(${value[1]})`
539
- }
540
- prop = `${value[0]}:${value[1]}`
541
- }
542
-
543
- if (prop.includes('function') || prop.includes('=>')) {
544
- // parse 'function' to function
545
- prop = prop.replace("'", '')
546
-
547
- if (prop.endsWith("}'")) {
548
- prop = prop.replace("}'", '}')
549
-
550
- }
551
-
552
- prop = prop.replace('=function', ':function')
553
- }
554
-
555
- filteredProps.push(prop);
556
-
557
-
558
-
559
- } else if (isWithinComponent && prop.includes('}')) {
560
-
503
+ let match;
504
+ let propstring = ''
505
+ // props right now is just a string with all of them on one line and a space between each
506
+ while ((match = dynamicAttributesRegex.exec(props)) !== null) {
507
+ let str = match[0].trim().replace(/\s+/g, " ");
508
+ if(!str.includes('=')){
509
+ continue
561
510
  }
562
-
563
-
564
- else {
565
- isWithinComponent = false;
511
+ str = str.split('=')
512
+ let key = str[0].trim()
513
+ let value = str[1].trim()
514
+ if(value.startsWith('"') && !value.endsWith('"') || value.startsWith("'") && !value.endsWith("'")
515
+ || value.startsWith('`') && !value.endsWith('`')){
516
+ // wrap in respective quotes
517
+ value = value + value[0]
566
518
  }
567
- }
519
+ let isObject = value.startsWith('{{') && value.endsWith('}}')
520
+ if(isObject){
521
+ value = value.split('{{')[1].split('}}')[0].trim()
522
+ value = `{${value}}`
523
+ } else{
524
+ // remove starting { and ending } using regex
525
+ value = value.replace(/^{/, '').replace(/}$/, '')
526
+ }
527
+ propstring += `${key}:${value},`
528
+ }
568
529
  component = component.replaceAll(/\s+/g, " ");
569
530
 
570
531
  component = component.replace(componentAttributes, '')
@@ -574,8 +535,8 @@ function Compiler(func, file) {
574
535
 
575
536
  let children = new RegExp(`<${name}[^>]*>([^]*)<\/${name}>`, 'gs').exec(component)?.[1] || null;
576
537
 
577
- props = filteredProps.join(',').replace(/\s+/g, " ").trim().replace(/,$/, '')
578
-
538
+
539
+
579
540
  let savedname = name;
580
541
 
581
542
 
@@ -605,26 +566,17 @@ function Compiler(func, file) {
605
566
  }
606
567
  });
607
568
 
569
+
570
+
571
+ propstring = propstring.replace(/,$/, '')
608
572
 
609
-
610
-
611
- props = props.replaceAll(`,${savedname}`, '').replaceAll(savedname, '')
612
- if (props.startsWith(',')) {
613
- props = props.replace(',', '')
614
- }
615
- props = props.replaceAll("='", ":'")
616
- .replaceAll('=`', ':`')
617
- .replaceAll('="', ':"')
618
- .replaceAll('={', ':')
619
-
620
-
573
+
621
574
  /**
622
575
  * @memoize - memoize a component to be remembered on each render and replace the old jsx
623
- */
624
-
576
+ */
625
577
 
626
578
  let replace = "";
627
- replace = `\${this.memoize(this.createComponent(${savedname}, {${props}}, [\`${myChildrens.join('')}\`]))}`;
579
+ replace = `\${this.memoize(this.createComponent(${savedname}, {${propstring}}, [\`${myChildrens.join('')}\`]))}`;
628
580
 
629
581
 
630
582
  body = body.replace(before, replace);
@@ -635,54 +587,52 @@ function Compiler(func, file) {
635
587
 
636
588
  string = string.replaceAll('vaderjs/client', '/vader.js')
637
589
 
638
- const importRegex = /import\s*([^\s,]+|\{[^}]+\})\s*from\s*(['"])(.*?)\2/gs;
590
+ const importRegex = /import\s*([^\s,]+|\{[^}]+\})\s*from\s*(['"])(.*?)\2/g;
639
591
  const imports = string.match(importRegex);
640
592
  let replaceMents = [];
641
593
 
642
594
 
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
- }
595
+ for (let match of imports) {
596
+ let path = match.split('from')[1].trim().replace(/'/g, '').replace(/"/g, '').trim()
597
+ switch (true) {
598
+ case path && !path.includes('./') && !path.includes('/vader.js') && !path.includes('/vaderjs/client') && !path.startsWith('src') && !path.startsWith('public') && !path.includes('http') && !path.includes('https'):
599
+ let componentFolder = fs.existsSync(process.cwd() + '/node_modules/' + path) ? process.cwd() + '/node_modules/' + path : process.cwd() + '/node_modules/' + path.split('/')[0]
600
+ componentFolder = componentFolder.split(process.cwd())[1]
601
+ if (!fs.existsSync(process.cwd() + componentFolder)) {
602
+ throw new Error('Could not find ' + path + ' at ' + match + ' in file ' + file)
603
+ }
653
604
 
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
- }
605
+ if (!fs.existsSync(process.cwd() + '/dist/src/' + componentFolder.split('/').slice(2).join('/'))) {
606
+ fs.mkdirSync(process.cwd() + '/dist/src/' + componentFolder.split('/').slice(2).join('/'), { recursive: true })
607
+ }
657
608
 
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);
609
+ let baseFolder = componentFolder.split('node_modules')[1].split('/')[1]
610
+ let glp = globSync('**/**/**/**.{jsx,js}', {
611
+ cwd: process.cwd() + '/node_modules/' + baseFolder + '/',
612
+ absolute: true,
613
+ recursive: true
614
+ })
615
+ for (let file of glp) {
616
+ let text = fs.readFileSync(file, "utf8");
617
+ if (!file.endsWith('.js') && file.endsWith('.jsx')) {
618
+ text = Compiler(text, file);
668
619
 
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} `)
679
620
  }
621
+ let dest = file.split('node_modules')[1]
622
+ dest = dest.split(baseFolder)[1]
623
+ writer(process.cwd() + '/dist/src/' + baseFolder + dest, text)
624
+ let importname = match.split('import')[1].split('from')[0].trim()
625
+ let oldImportstring = match.split('from')[1].trim().replace(/'/g, '').replace(/"/g, '').trim()
626
+ let newImport = `/src/${baseFolder + dest}`
627
+ newImport = newImport.replaceAll('.jsx', '.js').replaceAll('\\', '/')
628
+ replaceMents.push({ match: oldImportstring, replace: newImport })
629
+ console.log(`📦 imported Node Package ${baseFolder} `)
630
+ }
680
631
 
681
632
 
682
- break;
683
- default:
684
- break;
685
- }
633
+ break;
634
+ default:
635
+ break;
686
636
  }
687
637
  }
688
638
 
@@ -875,7 +825,6 @@ const glb = await glob("**/**/**/**.{jsx,js}", {
875
825
  absolute: true,
876
826
  recursive: true
877
827
  });
878
- let hasRendered = []
879
828
  async function Build() {
880
829
  globalThis.isBuilding = true
881
830
  console.log(globalThis.isProduction ? 'Creating Optimized Production Build\n' : '')
@@ -890,49 +839,119 @@ async function Build() {
890
839
 
891
840
  function ssg(routes = []) {
892
841
  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);
926
842
  routes.forEach(async (route) => {
927
843
  if (route.url.includes(':')) {
928
844
  return
929
845
  }
846
+ let equalparamroute = routes.map((e) => {
847
+ if (e.url.includes(':')) {
848
+ let url = e.url.split('/:')[0]
849
+ if (url && route.url === url) {
850
+ return e
851
+ } else {
852
+ return null
853
+
854
+ }
855
+ }
856
+ return null
857
+ }).filter(Boolean)
858
+ let document = `
859
+ <!DOCTYPE html>
860
+ <html lang="en">
861
+ <head>
862
+ <script>
863
+ window.routes = JSON.parse('${JSON.stringify(routes)}')
864
+
865
+
866
+ </script>
867
+ <script id="isServer">
868
+ window.isServer = true
869
+ </script>
870
+ <meta charset="UTF-8">
871
+ <meta name="viewport" content="width=device-width,initial-scale=1.0">
872
+ <script type="module" id="meta">
873
+ window.history.pushState({}, '', '${route.url}')
874
+
875
+ </script>
876
+ <script type="module" id="router">
877
+ import VaderRouter from '/router.js'
878
+ const router = new VaderRouter('${route.url}', 3000)
879
+ router.get('${route.url}', async (req, res) => {
880
+ try{
881
+ let module = await import('/${route.fileName.replace('.jsx', '.js')}')
882
+ if(Object.keys(module).includes('$prerender') && !module.$prerender){
883
+ document.head.setAttribute('prerender', 'false')
884
+ }
885
+ res.render(module, req, res, module.$metadata)
886
+ }
887
+ catch(error){
888
+ let errorMessage = {
889
+ message: error.message,
890
+ name: error.name,
891
+ stack: error.stack,
892
+ path: window.location.pathname
893
+ };
894
+
895
+
896
+ document.documentElement.setAttribute('error', JSON.stringify(errorMessage));
897
+ throw new Error(error)
898
+ }
899
+ })
900
+ ${equalparamroute.length > 0 ? equalparamroute.map((e) => {
930
901
 
931
902
 
932
903
 
904
+ return `router.get('${e.url}', async (req, res) => {
905
+ let module = await import('/${e.fileName.replace('.jsx', '.js')}')
906
+ res.render(module, req, res, module.$metadata)
907
+ })\n`
908
+ }) : ''}
909
+ router.listen(3000)
910
+
911
+ </script>
912
+ </head>
913
+ <body>
914
+ <div id="root"></div>
915
+ </body>
916
+
917
+
918
+ </html>
919
+ `;
933
920
 
921
+ // generate random but common ports
922
+ let port = Math.floor(Math.random() * (65535 - 49152 + 1) + 49152)
934
923
 
924
+ const server = http.createServer((req, res) => {
935
925
 
926
+ if (req.url === '/') {
927
+ res.writeHead(200, { 'Content-Type': 'text/html' });
928
+ res.end(document);
929
+ } else {
930
+ // Serve static files (adjust the file paths based on your project structure)
931
+ const filePath = process.cwd() + '/dist/' + req.url
932
+
933
+ fs.readFile(filePath, (err, data) => {
934
+ if (err) {
935
+ res.writeHead(404, { 'Content-Type': filePath.includes('js') ? 'text/javascript' : 'text/html' });
936
+ res.end('File not found');
937
+ } else {
938
+ res.writeHead(200, { 'Content-Type': filePath.includes('js') ? 'text/javascript' : 'text/html' });
939
+ res.end(data);
940
+ }
941
+ });
942
+ }
943
+ });
944
+
945
+ server.listen(port)
946
+ server.on('error', (err) => {
947
+ if (err.code === 'EADDRINUSE') {
948
+ console.log(`Port ${port} is in use, trying another port...`);
949
+ setTimeout(() => {
950
+ server.close();
951
+ server.listen(++port);
952
+ }, 1000);
953
+ }
954
+ })
936
955
 
937
956
  globalThis.listen = true;
938
957
 
@@ -948,16 +967,14 @@ async function Build() {
948
967
  page.on('error', (err) => {
949
968
  console.error('BROWSER ERROR:', JSON.parse(err));
950
969
  });
951
-
970
+
952
971
  try {
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)
972
+ page.on('pageerror', async err => {
973
+ let errorObj = JSON.parse(await page.evaluate(() => document.documentElement.getAttribute('error')) || '{}')
974
+ console.log('\x1b[31m%s\x1b[0m', 'Compiler Error:', errorObj)
956
975
 
957
- console.log('\x1b[31m%s\x1b[0m', 'Error:', err)
958
976
  });
959
977
  } catch (error) {
960
- console.log(error)
961
978
  browser.close()
962
979
  }
963
980
  // Handle page crashes
@@ -967,10 +984,16 @@ async function Build() {
967
984
  page.on('requestfailed', request => {
968
985
  console.error('REQUEST FAILED:', request.url(), request.failure().errorText);
969
986
  });
970
- await page.goto(`http://localhost:${port}${route.url}`, { waitUntil: 'networkidle2' });
987
+ await page.goto(`http://localhost:${port}/`, { waitUntil: 'networkidle2' });
988
+
989
+
990
+
991
+
992
+
993
+
971
994
 
972
995
  await page.evaluate(() => {
973
- document.querySelector('#meta').remove()
996
+ document.getElementById('meta').remove()
974
997
  document.querySelector('#isServer').innerHTML = 'window.isServer = false'
975
998
  if (document.head.getAttribute('prerender') === 'false') {
976
999
  document.querySelector('#root').innerHTML = ''
@@ -986,26 +1009,19 @@ async function Build() {
986
1009
 
987
1010
 
988
1011
  } catch (error) {
989
-
1012
+ console.log(error)
990
1013
  }
991
1014
 
992
1015
  finally {
993
1016
  browser.close()
994
1017
  server.close()
995
- hasRendered.push(route.url)
996
- console.log(`\x1b[32m%s\x1b[0m`, `Prerendered ${route.url}...`)
997
1018
  }
998
1019
  })
999
1020
 
1000
-
1001
-
1002
- if (hasRendered.length === routes.length) {
1003
- server.close()
1004
- hasRendered = []
1021
+ let timeout = setTimeout(() => {
1005
1022
  globalThis.isBuilding = false
1006
1023
  clearTimeout(timeout)
1007
- }
1008
-
1024
+ }, 1000)
1009
1025
  }
1010
1026
 
1011
1027
  globalThis.routes = []
@@ -1107,7 +1123,6 @@ async function Build() {
1107
1123
  }
1108
1124
 
1109
1125
 
1110
-
1111
1126
  globalThis.routes.push({ fileName: fileName, url: obj.url, html: '/' + (isBasePath ? 'index.html' : `${obj.url}/` + 'index.html') })
1112
1127
 
1113
1128
 
@@ -1125,87 +1140,6 @@ async function Build() {
1125
1140
  globalThis.isProduction ? console.log(string) : null
1126
1141
  }
1127
1142
 
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
-
1209
1143
  ssg(globalThis.routes)
1210
1144
 
1211
1145
 
@@ -1238,7 +1172,7 @@ async function Build() {
1238
1172
 
1239
1173
  let data = await reader(process.cwd() + "/src/" + name)
1240
1174
  if (name.includes('.jsx')) {
1241
- let origin = process.cwd() + "/src/" + name
1175
+ let origin = process.cwd() + "/src/" + name
1242
1176
  if (!globalThis.isProduction) {
1243
1177
  let { sourceMap } = sourceMapGen({ origin: origin, fileName: name }, await Compiler(data, origin))
1244
1178
  data = data + `\n//# sourceMappingURL=/src/maps/${name.replace('.jsx', '.js.map')}\n //#sourceURL=${origin}`
@@ -1251,7 +1185,7 @@ async function Build() {
1251
1185
  await writer(process.cwd() + "/dist/src/" + name, data);
1252
1186
  })
1253
1187
 
1254
- const scannedPublicFiles = await glob("**/**.{css,js,html,mjs,cjs}", {
1188
+ const scannedPublicFiles = await glob("**/**/**.{css,js,html,mjs,cjs,png,jpg,jpeg,gif,svg,mp4,webm,ogg}", {
1255
1189
  ignore: ["node_modules/**/*", "dist/**/*"],
1256
1190
  cwd: process.cwd() + '/public/',
1257
1191
  absolute: true,
@@ -1259,7 +1193,7 @@ async function Build() {
1259
1193
  scannedPublicFiles.forEach(async (file) => {
1260
1194
  file = file.replace(/\\/g, '/');
1261
1195
  file = file.split('/public/')[1]
1262
- let data = await reader(process.cwd() + "/public/" + file)
1196
+ let data = fs.readFileSync(process.cwd() + "/public/" + file);
1263
1197
  bundleSize += fs.statSync(process.cwd() + "/public/" + file).size;
1264
1198
  await writer(process.cwd() + "/dist/public/" + file, data);
1265
1199
  })
@@ -1292,7 +1226,7 @@ async function Build() {
1292
1226
  }
1293
1227
 
1294
1228
  globalThis.isBuilding = false
1295
- globalThis.isProduction ? console.log(`\nTotal bundle size: ${Math.round(bundleSize / 1000)}kb`) : null
1229
+ console.log(`\nTotal bundle size: ${Math.round(bundleSize / 1000)}kb`)
1296
1230
 
1297
1231
  bundleSize = 0;
1298
1232
 
@@ -1400,7 +1334,7 @@ switch (true) {
1400
1334
  globalThis.devMode = true
1401
1335
  globalThis.isProduction = false
1402
1336
  console.log(`
1403
- Vader.js v1.3.3
1337
+ Vader.js v${fs.readFileSync(process.cwd() + '/node_modules/vaderjs/package.json', 'utf8').split('"version": "')[1].split('"')[0]}
1404
1338
  - Watching for changes in ./pages
1405
1339
  - Watching for changes in ./src
1406
1340
  - Watching for changes in ./public
@@ -1440,7 +1374,7 @@ Vader.js v1.3.3
1440
1374
  globalThis.isProduction = true
1441
1375
  globalThis.routeStates = []
1442
1376
  console.log(`
1443
- Vader.js v1.3.3
1377
+ Vader.js v${fs.readFileSync(process.cwd() + '/node_modules/vaderjs/package.json', 'utf8').split('"version": "')[1].split('"')[0]}
1444
1378
  Building to ./dist
1445
1379
  `)
1446
1380
  if (fs.existsSync(process.cwd() + '/dist/src/maps')) {
@@ -1454,7 +1388,7 @@ Building to ./dist
1454
1388
  process.env.PORT = port
1455
1389
  globalThis.devMode = false
1456
1390
  console.log(`
1457
- Vader.js v1.3.3
1391
+ Vader.js v${fs.readFileSync(process.cwd() + '/node_modules/vaderjs/package.json', 'utf8').split('"version": "')[1].split('"')[0]}
1458
1392
  Serving ./dist on port ${port}
1459
1393
  url: http://localhost:${port}
1460
1394
  `)