vaderjs 1.3.3-alpha-7 → 1.3.3-alpha-9

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/vader.js CHANGED
@@ -599,58 +599,47 @@ async function Build() {
599
599
  cwd: process.cwd() + '/pages/',
600
600
  absolute: true,
601
601
  recursive: true
602
- });
603
- for await (let file of glb) {
604
-
605
- let origin = file.split(process.cwd())[1] || file
606
- let fileName = file.split(process.cwd() + '/pages/')[1]
607
- file = file.split(process.cwd() + '/pages/')[1]
602
+ });
608
603
 
609
- file === 'index.jsx' ? file = '/' : null
610
- let isBasePath = file === '/' ? true : false
611
- // ex: /pages/index.jsx - / or /pages/[id].jsx - /:id or /pages/folder/index.jsx - /folder
612
- let aburl = origin.split('pages')[1].split('.jsx')[0].replace('.jsx', '').replace('/index', '').replace('/_', '/:').replace('/[', '/:').replace(']', '')
613
-
614
- aburl.includes('[') ? aburl = '/' + aburl.split('[')[0].replace('/', '') : null
615
-
616
-
617
-
618
-
619
-
620
-
604
+ // Process files in the 'pages' directory
605
+ for await (let file of glb) {
606
+ // Normalize file paths
607
+ let origin = file.replace(/\\/g, '/');
608
+ let fileName = origin.split('/pages/')[1].split('.jsx')[0].replace('.jsx', '') + '.jsx';
609
+ let isBasePath = fileName === 'index.jsx';
610
+
611
+ // Extract URL-related information from the file path
612
+ let aburl = origin.split('pages')[1].split('.jsx')[0].replace('.jsx', '').replace('/index', '').replace('/_', '/:').replace('/[', '/:').replace(']', '');
613
+ aburl.includes('[') ? aburl = '/' + aburl.split('[')[0].replace('/', '') : null;
614
+
615
+ // Create an object with URL and pathname properties
621
616
  let obj = {
622
- url: isBasePath ? '/' : aburl,
623
- pathname: origin,
624
- }
625
- let data = await reader(process.cwd() + origin)
626
-
627
- data = Compiler(data)
617
+ url: isBasePath ? '/' : aburl,
618
+ pathname: `/pages/${origin.split('pages/')[1].split('.jsx')[0].replace('.jsx', '')}.jsx`,
619
+ };
620
+
621
+ // Read and compile file content
622
+ let data = await fs.readFileSync(origin, "utf8");
623
+ data = Compiler(data);
624
+
625
+ // Write compiled content to the 'dist/pages' directory
626
+ console.log(`Compiling ${fileName} to ${obj.url}`)
628
627
  await writer(process.cwd() + "/dist/pages/" + fileName, data);
629
- let params = obj.params ? Object.keys(obj.params).map((r) => {
630
- r = r.replace('[', '').replace(']', '')
631
- return `:${r}`
632
- }) : ''
633
-
634
-
635
-
636
-
637
-
628
+
629
+ // Generate routing logic
638
630
  let js = `
639
- router.get('${obj.url}', async (req, res) => {
640
- res.render(await require('.${obj.pathname}'), req, res)
641
- })
642
- //@desc ${obj.pathname}
643
- ` + '\n'
644
-
645
-
646
-
647
- let before = fs.existsSync(process.cwd() + "/dist/app.js") ? await reader(process.cwd() + "/dist/app.js") : ''
648
-
649
- let newfile = before + '\n' + js
631
+ router.get('${obj.url}', async (req, res) => {
632
+ res.render(await require('.${obj.pathname}'), req, res)
633
+ })
634
+ //@desc ${obj.pathname}
635
+ ` + '\n';
636
+
637
+ // Update 'app.js' file with routing logic
638
+ let before = fs.existsSync(process.cwd() + "/dist/app.js") ? await reader(process.cwd() + "/dist/app.js") : '';
639
+ let newfile = before + '\n' + js;
650
640
  if (!before.includes(`//@desc ${obj.pathname}`)) {
651
641
  await writer(process.cwd() + "/dist/app.js", newfile);
652
642
  }
653
-
654
643
  }
655
644
 
656
645
 
@@ -659,16 +648,30 @@ async function Build() {
659
648
  cwd: process.cwd() + '/src/',
660
649
  absolute: true,
661
650
  });
662
- scannedSourceFiles.forEach(async (file) => {
651
+ const scannedVaderFiles = await glob("**/**.{html,js}", {
652
+ cwd: process.cwd() + '/node_modules/vaderjs/runtime',
653
+ absolute: true,
654
+ });
655
+ scannedVaderFiles.forEach(async (file) => {
656
+ file = file.replace(/\\/g, '/');
663
657
 
664
- file = file.split(process.cwd() + '/src/')[1]
665
- let data = await reader(process.cwd() + "/src/" + file)
666
- bundleSize += fs.statSync(process.cwd() + "/src/" + file).size;
667
- if(file.endsWith('.jsx')){
668
- data = Compiler(data)
658
+ let name = file.split( '/node_modules/vaderjs/runtime/')[1]
659
+ let data = await reader(file)
660
+ bundleSize += fs.statSync(file).size;
661
+ await writer(process.cwd() + "/dist/" + name, data);
662
+ })
663
+ scannedSourceFiles.forEach(async (file) => {
664
+ file = file.replace(/\\/g, '/');
665
+ let name = file.split('/src/')[1]
666
+ console.log(`Compiling ${name} to /src/${name}`)
667
+ //parse jsx
668
+
669
+ let data = await reader(process.cwd() + "/src/" + name)
670
+ if (name.includes('.jsx')) {
671
+ data = Compiler(data);
669
672
  }
670
-
671
- await writer(process.cwd() + "/dist/src/" + file, data);
673
+ bundleSize += fs.statSync(process.cwd() + "/src/" + name).size;
674
+ await writer(process.cwd() + "/dist/src/" + name, data);
672
675
  })
673
676
 
674
677
  const scannedPublicFiles = await glob("**/**.{css,js,html}", {
@@ -677,7 +680,8 @@ async function Build() {
677
680
  absolute: true,
678
681
  });
679
682
  scannedPublicFiles.forEach(async (file) => {
680
- file = file.split(process.cwd() + '/public/')[1]
683
+ file = file.replace(/\\/g, '/');
684
+ file = file.split('/public/')[1]
681
685
  let data = await reader(process.cwd() + "/public/" + file)
682
686
  bundleSize += fs.statSync(process.cwd() + "/public/" + file).size;
683
687
  await writer(process.cwd() + "/dist/public/" + file, data);
@@ -706,8 +710,7 @@ async function Build() {
706
710
  console.log(`Compilation completed`)
707
711
  globalThis.isBuilding = false
708
712
  }
709
- import { watch } from "fs";
710
- import { url } from "inspector";
713
+ import { watch } from "fs";
711
714
 
712
715
  switch (true) {
713
716
  case process.argv.includes('--watch'):
@@ -741,15 +744,14 @@ Building to ./dist
741
744
  break;
742
745
  default:
743
746
  console.log(`
744
- Vader.js is a reactive framework for building interactive applications inspired by React.js and Next.js
747
+ Vader.js is a reactive framework for building interactive applications for the web built ontop of bun.js!
745
748
 
746
749
  Usage: vader <command>
747
750
 
748
751
  Commands:
749
752
  --watch Watch the pages folder for changes and recompile
750
753
 
751
- --build Build the project - use this to initialize the project
752
-
754
+ --build Build the project
753
755
  Learn more about vader: https://vader-js.pages.dev/
754
756
 
755
757
  `)