vaderjs 1.3.3-alpha-3 → 1.3.3-alpha-4
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/README.md +1 -0
- package/package.json +3 -11
- package/runtime/{static/index.html → index.html} +1 -1
- package/vader.js +96 -116
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -2,20 +2,12 @@
|
|
|
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-4",
|
|
6
6
|
"bin": {
|
|
7
7
|
"vader": "./vader.js"
|
|
8
8
|
},
|
|
9
|
-
"scripts": {
|
|
10
|
-
"build": "bunx vader --build",
|
|
11
|
-
"watch": "bun run vader --watch",
|
|
12
|
-
"help": "bunx vader"
|
|
13
|
-
},
|
|
14
9
|
"type": "module",
|
|
15
10
|
"devDependencies": {
|
|
16
|
-
"
|
|
17
|
-
},
|
|
18
|
-
"peerDependencies": {
|
|
19
|
-
"typescript": "^5.0.0"
|
|
11
|
+
"glob": "^10.3.10"
|
|
20
12
|
}
|
|
21
|
-
}
|
|
13
|
+
}
|
package/vader.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import { Glob } from "bun";
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import { glob, globSync, globStream, globStreamSync, Glob } from 'glob'
|
|
4
|
+
|
|
6
5
|
let bundleSize = 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
case !fs.existsSync(process.cwd() + "/src"):
|
|
18
|
-
fs.mkdirSync(process.cwd() + "/src");
|
|
19
|
-
break;
|
|
6
|
+
if(!fs.existsSync(process.cwd() + '/dist')){
|
|
7
|
+
fs.mkdirSync(process.cwd() + '/dist')
|
|
8
|
+
fs.mkdirSync(process.cwd() + '/dist/public')
|
|
9
|
+
fs.mkdirSync(process.cwd() + '/dist/src')
|
|
10
|
+
fs.mkdirSync(process.cwd() + '/dist/pages')
|
|
11
|
+
}else if(!fs.existsSync(process.cwd() + '/dist/public')){
|
|
12
|
+
fs.mkdirSync(process.cwd() + '/dist/public')
|
|
13
|
+
}else if(!fs.existsSync(process.cwd() + '/src') && !fs.existsSync(process.cwd() + '/dist/src')){
|
|
14
|
+
fs.mkdirSync(process.cwd() + '/dist/src')
|
|
15
|
+
fs.mkdirSync(process.cwd() + '/src')
|
|
20
16
|
}
|
|
21
|
-
|
|
17
|
+
|
|
22
18
|
function Compiler(func) {
|
|
23
19
|
let string = func;
|
|
24
20
|
let comments = string
|
|
@@ -222,7 +218,8 @@ function Compiler(func) {
|
|
|
222
218
|
otherdata["jsx"] = isJSXComponent;
|
|
223
219
|
otherdata["ref"] = ref;
|
|
224
220
|
|
|
225
|
-
newvalue = newvalue.
|
|
221
|
+
newvalue = newvalue.split('\n').map(line => line.trim() ? line.trim() + ';' : line).join('\n');
|
|
222
|
+
|
|
226
223
|
let newatribute = `${attributeName}="\${this.bind(\`${newvalue}\` ${isJSXComponent ? "" : ","
|
|
227
224
|
}${JSON.stringify(otherdata)} )}"`;
|
|
228
225
|
|
|
@@ -258,8 +255,9 @@ function Compiler(func) {
|
|
|
258
255
|
params ? (otherdata["params"] = params) : null;
|
|
259
256
|
otherdata["jsx"] = isJSXComponent;
|
|
260
257
|
otherdata["ref"] = ref;
|
|
261
|
-
|
|
262
|
-
|
|
258
|
+
// since js is all in one line split it
|
|
259
|
+
newvalue = newvalue.split('\n').map(line => line.trim() ? line.trim() + ';' : line).join('\n');
|
|
260
|
+
let newattribute = `${attributeName}="\${this.bind(\`${newvalue}\` ${isJSXComponent ? "" : ","}${JSON.stringify(otherdata)} )}"`;
|
|
263
261
|
newattribute = newattribute.replace(/\s+/g, " ")
|
|
264
262
|
string = string.replace(old, newattribute);
|
|
265
263
|
}
|
|
@@ -581,91 +579,86 @@ async function Build() {
|
|
|
581
579
|
globalThis.isBuilding = true
|
|
582
580
|
console.log('Compiling......')
|
|
583
581
|
let reader = async (file) => {
|
|
584
|
-
let text = await
|
|
582
|
+
let text = await fs.readFileSync(file, "utf8");
|
|
585
583
|
return text;
|
|
586
584
|
};
|
|
587
585
|
let writer = async (file, data) => {
|
|
588
|
-
|
|
586
|
+
switch (true) {
|
|
587
|
+
case !fs.existsSync(file):
|
|
588
|
+
fs.mkdirSync(file.split('/').slice(0, -1).join('/'), { recursive: true })
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
await fs.writeFileSync(file, data);
|
|
589
592
|
|
|
590
593
|
return { _written: true };
|
|
591
594
|
};
|
|
592
595
|
|
|
593
596
|
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
|
|
597
|
+
const glb = await glob("**/**/**/**.{jsx,js}", {
|
|
598
|
+
ignore: ["node_modules/**/*", "dist/**/*"],
|
|
599
|
+
cwd: process.cwd() + '/pages/',
|
|
600
|
+
absolute: true,
|
|
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]
|
|
597
607
|
file = file.split(process.cwd() + '/pages/')[1]
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
assetPrefix: "_next/static/",
|
|
604
|
-
fileExtensions: [".jsx", ".js"],
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
let m = router.match(origin.includes('/pages/index.jsx') ? '/' : '/' + file)
|
|
609
|
-
router.reload()
|
|
610
|
-
|
|
611
|
-
if (!m) {
|
|
612
|
-
console.error(`Error: ${file} is not a valid route\nFollow Proper Routing Structure:
|
|
613
|
-
`)
|
|
614
|
-
console.info(`
|
|
615
|
-
/pages/index.jsx
|
|
616
|
-
/pages/folder/index.jsx
|
|
617
|
-
/pages/folder/[param].jsx
|
|
618
|
-
`)
|
|
619
|
-
process.exit(1)
|
|
620
|
-
}
|
|
608
|
+
|
|
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(']', '')
|
|
621
613
|
|
|
614
|
+
aburl.includes('[') ? aburl = '/' + aburl.split('[')[0].replace('/', '') : null
|
|
615
|
+
|
|
622
616
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
626
620
|
|
|
627
621
|
let obj = {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
src: m.src,
|
|
634
|
-
pathname: writtenpath || m.pathname,
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
let data = await reader(process.cwd() + "/pages/" + file)
|
|
622
|
+
url: isBasePath ? '/' : aburl,
|
|
623
|
+
pathname: origin,
|
|
624
|
+
}
|
|
625
|
+
let data = await reader(process.cwd() + origin)
|
|
626
|
+
|
|
638
627
|
data = Compiler(data)
|
|
639
|
-
await writer(process.cwd() + "/dist/pages/" +
|
|
628
|
+
await writer(process.cwd() + "/dist/pages/" + fileName, data);
|
|
640
629
|
let params = obj.params ? Object.keys(obj.params).map((r) => {
|
|
641
630
|
r = r.replace('[', '').replace(']', '')
|
|
642
631
|
return `:${r}`
|
|
643
632
|
}) : ''
|
|
644
633
|
|
|
645
|
-
|
|
634
|
+
|
|
646
635
|
|
|
647
636
|
|
|
648
637
|
|
|
649
638
|
let js = `
|
|
650
|
-
router.get('${obj.
|
|
651
|
-
res.render(await require('
|
|
639
|
+
router.get('${obj.url}', async (req, res) => {
|
|
640
|
+
res.render(await require('.${obj.pathname}'), req, res)
|
|
652
641
|
})
|
|
653
|
-
//@desc ${obj.
|
|
642
|
+
//@desc ${obj.pathname}
|
|
654
643
|
` + '\n'
|
|
655
644
|
|
|
656
645
|
|
|
657
646
|
|
|
658
|
-
let before =
|
|
647
|
+
let before = fs.existsSync(process.cwd() + "/dist/app.js") ? await reader(process.cwd() + "/dist/app.js") : ''
|
|
659
648
|
|
|
660
649
|
let newfile = before + '\n' + js
|
|
661
|
-
if (!before.includes(`//@desc ${obj.
|
|
650
|
+
if (!before.includes(`//@desc ${obj.pathname}`)) {
|
|
662
651
|
await writer(process.cwd() + "/dist/app.js", newfile);
|
|
663
652
|
}
|
|
664
653
|
|
|
665
654
|
}
|
|
666
655
|
|
|
667
|
-
|
|
668
|
-
const scannedSourceFiles = await
|
|
656
|
+
|
|
657
|
+
const scannedSourceFiles = await glob("**/**.{jsx,js}", {
|
|
658
|
+
ignore: ["node_modules/**/*", "dist/**/*"],
|
|
659
|
+
cwd: process.cwd() + '/src/',
|
|
660
|
+
absolute: true,
|
|
661
|
+
});
|
|
669
662
|
scannedSourceFiles.forEach(async (file) => {
|
|
670
663
|
|
|
671
664
|
file = file.split(process.cwd() + '/src/')[1]
|
|
@@ -678,57 +671,43 @@ async function Build() {
|
|
|
678
671
|
await writer(process.cwd() + "/dist/src/" + file, data);
|
|
679
672
|
})
|
|
680
673
|
|
|
681
|
-
const scannedPublicFiles =
|
|
674
|
+
const scannedPublicFiles = await glob("**/**.{css,js,html}", {
|
|
675
|
+
ignore: ["node_modules/**/*", "dist/**/*"],
|
|
676
|
+
cwd: process.cwd() + '/public/',
|
|
677
|
+
absolute: true,
|
|
678
|
+
});
|
|
682
679
|
scannedPublicFiles.forEach(async (file) => {
|
|
683
680
|
file = file.split(process.cwd() + '/public/')[1]
|
|
684
681
|
let data = await reader(process.cwd() + "/public/" + file)
|
|
685
682
|
bundleSize += fs.statSync(process.cwd() + "/public/" + file).size;
|
|
686
683
|
await writer(process.cwd() + "/dist/public/" + file, data);
|
|
687
|
-
})
|
|
688
|
-
const scannedFiles = await
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
684
|
+
})
|
|
685
|
+
const scannedFiles = await glob("**/**.{css,js,html}", {
|
|
686
|
+
ignore: ["node_modules/**/*", "dist/**/*"],
|
|
687
|
+
cwd: process.cwd() + "/runtime/",
|
|
688
|
+
absolute: true,
|
|
689
|
+
})
|
|
692
690
|
|
|
693
691
|
if (!fs.existsSync(process.cwd() + "/dist/index.html")) {
|
|
694
692
|
scannedFiles.forEach(async (file) => {
|
|
693
|
+
file = file.split(process.cwd() + '/runtime/')[1]
|
|
695
694
|
|
|
696
695
|
if (file === "app.js") {
|
|
697
696
|
return
|
|
698
697
|
}
|
|
699
|
-
bundleSize += fs.statSync(process.cwd() +
|
|
700
|
-
let data = await reader(process.cwd() +
|
|
698
|
+
bundleSize += fs.statSync(process.cwd() + "/runtime/" + file).size;
|
|
699
|
+
let data = await reader(process.cwd() + "/runtime/" + file)
|
|
701
700
|
await writer(process.cwd() + "/dist/" + file, data);
|
|
702
701
|
});
|
|
703
|
-
|
|
704
|
-
bundleSize += fs.statSync(
|
|
705
|
-
process.cwd() + '/node_modules/vaderjs/' + "/runtime/" + file
|
|
706
|
-
).size;
|
|
707
|
-
let data = await reader(process.cwd() + '/node_modules/vaderjs/' + "/runtime/" + file);
|
|
708
|
-
await writer(process.cwd() + "/dist/public/vader/" + file, data);
|
|
709
|
-
});
|
|
702
|
+
|
|
710
703
|
}
|
|
711
704
|
|
|
712
|
-
|
|
713
|
-
if (!fs.existsSync(process.cwd() + "/dist/index.html")) {
|
|
714
|
-
scannedFiles.forEach(async (file) => {
|
|
715
|
-
|
|
716
|
-
bundleSize += fs.statSync(process.cwd() + '/node_modules/vaderjs/' + "/runtime/static/" + file).size;
|
|
717
|
-
let data = await reader(process.cwd() + '/node_modules/vaderjs/' + "/runtime/static/" + file);
|
|
718
|
-
await writer(process.cwd() + "/dist/" + file, data);
|
|
719
|
-
});
|
|
720
|
-
scannedVaderFiles.forEach(async (file) => {
|
|
721
|
-
bundleSize += fs.statSync(
|
|
722
|
-
process.cwd() + "/runtime/" + file
|
|
723
|
-
).size;
|
|
724
|
-
let data = await reader(process.cwd() + "/runtime/" + file);
|
|
725
|
-
await writer(process.cwd() + '/node_modules/vaderjs/' + "/dist/public/vader/" + file, data);
|
|
726
|
-
});
|
|
727
|
-
}
|
|
705
|
+
|
|
728
706
|
console.log(`Compilation completed`)
|
|
729
707
|
globalThis.isBuilding = false
|
|
730
708
|
}
|
|
731
709
|
import { watch } from "fs";
|
|
710
|
+
import { url } from "inspector";
|
|
732
711
|
|
|
733
712
|
switch (true) {
|
|
734
713
|
case process.argv.includes('--watch'):
|
|
@@ -737,19 +716,20 @@ switch (true) {
|
|
|
737
716
|
Vader.js v1.3.3
|
|
738
717
|
`)
|
|
739
718
|
Build()
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
719
|
+
|
|
720
|
+
const watcher = watch(
|
|
721
|
+
process.cwd() + '/pages',
|
|
722
|
+
{ recursive: true },
|
|
723
|
+
(event, filename) => {
|
|
724
|
+
if (event == 'change'
|
|
725
|
+
&& !globalThis.isBuilding
|
|
726
|
+
) {
|
|
727
|
+
Build()
|
|
728
|
+
}
|
|
729
|
+
},
|
|
730
|
+
);
|
|
731
|
+
watcher.on('error', (err) => console.log(err))
|
|
732
|
+
|
|
753
733
|
break;
|
|
754
734
|
case process.argv.includes('--build'):
|
|
755
735
|
|