vaderjs 1.4.1-ui7iuy47 → 1.4.2-bml56

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/binaries/main.js DELETED
@@ -1,1464 +0,0 @@
1
- import { Glob } from "bun";
2
-
3
- import fs from "fs";
4
-
5
- import * as Bun from "bun";
6
-
7
- import WebSocket from "ws";
8
-
9
- console.log(process.cwd() + '/vader.config.js')
10
-
11
- let config = await import(process.cwd() + '/vader.config.js').then((m) => m ? m.default : {}).catch((e) => {
12
-
13
- console.error(e)
14
-
15
- return {}
16
-
17
- })
18
-
19
- import IPCServer from "vaderjs/binaries/IPC/index.js"
20
-
21
- import { exec } from "child_process";
22
-
23
- const IPC = IPCServer
24
-
25
-
26
-
27
- globalThis.isVader = true
28
-
29
- /**
30
-
31
- * @description - Call functions when the integration is triggered
32
-
33
- * @param {function} fn
34
-
35
- * @param {args} args
36
-
37
- */
38
-
39
- globalThis.call = async (fn, args) => {
40
-
41
- return await fn(args) || void 0
42
-
43
- }
44
-
45
- /**@description - Used to store hmr websocket clients */
46
-
47
- globalThis.clients = []
48
-
49
- /**@description - Used to keep track of routes */
50
-
51
- globalThis.routes = []
52
-
53
- /**
54
-
55
- * @description - Used to keep track of the mode
56
-
57
- */
58
-
59
- globalThis.mode = ''
60
-
61
- /**@usedby @transForm */
62
-
63
- globalThis.isBuilding = false
64
-
65
- globalThis.hasGenerated = []
66
-
67
- let currentState = ''
68
-
69
- /**
70
-
71
- * @description - Used to keep track of the bundle size
72
-
73
- */
74
-
75
- let bundleSize = 0
76
-
77
-
78
-
79
-
80
-
81
- /**
82
-
83
- * @description - variables used to generate arrays of paths recursively
84
-
85
- */
86
-
87
- const glob = new Glob("/pages/**/**/*.{,tsx,js,jsx}", { absolute: true });
88
-
89
- const vaderGlob = new Glob("/node_modules/vaderjs/runtime/**/**/*.{,tsx,js}", { absolute: true });
90
-
91
- const srcGlob = new Glob("/src/**/**/*.{jsx,ts,tsx,js}", { absolute: true });
92
-
93
- const publicGlob = new Glob("/public/**/**/*.{css,js,html,jpg,png,gif,svg,ico,video,webm,mp4,jpeg}", { absolute: true });
94
-
95
- const distPages = new Glob("/dist/pages/**/**/*.{tsx,js,jsx}", { absolute: true })
96
-
97
- const distSrc = new Glob("/dist/src/**/**/*.{tsx,js,jsx}", { absolute: true })
98
-
99
- const distPublic = new Glob("/dist/public/**/**/*.{css,js,html,jpg,png,gif,svg,ico,video,webm,mp4,jpeg}", { absolute: true });
100
-
101
-
102
-
103
- const router = new Bun.FileSystemRouter({
104
-
105
- style: "nextjs",
106
-
107
- dir: process.cwd() + '/pages',
108
-
109
- origin: process.env.ORIGIN || "http://localhost:3000",
110
-
111
- assetPrefix: "_next/static/"
112
-
113
- });
114
-
115
- /**
116
-
117
- * @function handleReplaceMents
118
-
119
- * @description - replaces data to be compatible with Vader.js
120
-
121
- * @param {*} data
122
-
123
- * @returns
124
-
125
- */
126
-
127
- function handleReplaceMents(data) {
128
-
129
- data.split('\n').forEach((line, index) => {
130
-
131
- switch (true) {
132
-
133
-
134
-
135
- case line.includes('useReducer') && !line.includes('import'):
136
-
137
- line = line.replaceAll(/\s+/g, " ");
138
-
139
-
140
-
141
- let varTypereducer = line.split("=")[0].trim().split("[")[0].trim();
142
-
143
- let keyreducer = line.split("=")[0].trim().split("[")[1].trim().split(",")[0].trim();
144
-
145
- let setKeyreducer = line.split("=")[0].trim().split(",")[1].trim().replace("]", "");
146
-
147
- let reducer = line.split("=")[1].split("useReducer(")[1];
148
-
149
-
150
-
151
- let newStatereducer = `${varTypereducer} [${keyreducer}, ${setKeyreducer}] = this.useReducer('${keyreducer}', ${line.includes('=>') ? reducer + '=>{' : reducer}`;
152
-
153
-
154
-
155
- data = data.replace(line, newStatereducer);
156
-
157
- break
158
-
159
-
160
-
161
- case line.includes('useState') && !line.includes('import'):
162
-
163
- let varType = line.split("[")[0]
164
-
165
- if (!line.split("=")[0].split(",")[1]) {
166
-
167
- throw new Error('You forgot to value selector (useState) ' + ' at ' + `${file}:${string.split(line)[0].split('\n').length}`)
168
-
169
- }
170
-
171
- let key = line.split("=")[0].split(",")[0].trim().split('[')[1];
172
-
173
-
174
-
175
- if (!line.split("=")[0].split(",")[1]) {
176
-
177
- throw new Error('You forgot to add a setter (useState) ' + ' at ' + `${file}:${string.split(line)[0].split('\n').length}`)
178
-
179
- }
180
-
181
- let setKey = line.split("=")[0].split(",")[1].trim().replace("]", "");
182
-
183
- key = key.replace("[", "").replace(",", "");
184
-
185
- let valuestate = line.split("=")[1].split("useState(")[1];
186
-
187
-
188
-
189
- let regex = /useState\((.*)\)/gs;
190
-
191
- valuestate = valuestate.match(regex) ? valuestate.match(regex)[0].split("useState(")[1].split(")")[0].trim() : valuestate
192
-
193
- let newState = `${varType} [${key}, ${setKey}] = this.useState('${key}', ${valuestate}`;
194
-
195
- data = data.replace(line, newState);
196
-
197
- break;
198
-
199
-
200
-
201
- case line.includes("useRef") && !line.includes("import"):
202
-
203
- line = line.trim();
204
-
205
- let typeref = line.split(" ")[0]
206
-
207
-
208
-
209
- let keyref = line.split(typeref)[1].split("=")[0].trim().replace("[", "").replace(",", "");
210
-
211
-
212
-
213
-
214
-
215
- let valueref = line.split("=")[1].split("useRef(")[1];
216
-
217
-
218
-
219
- let newStateref = `${typeref} ${keyref} = this.useRef('${keyref}', ${valueref}`;
220
-
221
- data = data.replace(line, newStateref);
222
-
223
- case line.includes('.jsx') && line.includes('import') || line.includes('.tsx') && line.includes('import'):
224
-
225
- let old = line
226
-
227
- line = line.replace('.jsx', '.js')
228
-
229
- line = line.replace('.tsx', '.js')
230
-
231
- data = data.replace(old, line)
232
-
233
-
234
-
235
- break;
236
-
237
- }
238
-
239
- })
240
-
241
-
242
-
243
- data = data.replaceAll('jsxDEV', 'Vader.createElement')
244
-
245
- data = data.replaceAll('jsx', 'Vader.createElement')
246
-
247
- data = data.replaceAll('vaderjs/client', '/vader.js')
248
-
249
- data = data.replaceAll('.tsx', '.js')
250
-
251
- let reactImportMatch = data.match(/import React/g);
252
-
253
- if (reactImportMatch) {
254
-
255
- let fullmatch = data.match(/import React from "react"/g);
256
-
257
- if (fullmatch) {
258
-
259
- data = data.replaceAll('import React from "react"', '');
260
-
261
- }
262
-
263
- }
264
-
265
- data = data.replaceAll('.ts', '.js')
266
-
267
-
268
-
269
- // check if Vader is imported
270
-
271
- let vaderImport = data.match(/import Vader/g);
272
-
273
- if (!vaderImport) {
274
-
275
- data = `import Vader from "/vader.js";\n` + data;
276
-
277
- }
278
-
279
- return data;
280
-
281
- }
282
-
283
-
284
-
285
-
286
-
287
- /**
288
-
289
- * @function ContentType
290
-
291
- * @description - returns the content type based on the file extension
292
-
293
- * @param {*} url
294
-
295
- * @returns
296
-
297
- */
298
-
299
- const ContentType = (url) => {
300
-
301
- switch (url.split('.').pop()) {
302
-
303
- case 'css':
304
-
305
- return 'text/css';
306
-
307
- case 'js':
308
-
309
- return 'text/javascript';
310
-
311
- case 'json':
312
-
313
- return 'application/json';
314
-
315
- case 'html':
316
-
317
- return 'text/html';
318
-
319
- case 'jpg':
320
-
321
- return 'image/jpg';
322
-
323
- case 'png':
324
-
325
- return 'image/png';
326
-
327
- case 'gif':
328
-
329
- return 'image/gif';
330
-
331
- case 'svg':
332
-
333
- return 'image/svg+xml';
334
-
335
- case 'ico':
336
-
337
- return 'image/x-icon';
338
-
339
- default:
340
-
341
- return 'text/html';
342
-
343
-
344
-
345
- }
346
-
347
- }
348
-
349
-
350
-
351
-
352
-
353
- /**
354
-
355
- * @function Server
356
-
357
- * @description - Creates a hmr development server
358
-
359
- * @param {Number} port
360
-
361
- */
362
-
363
- function Server(port) {
364
-
365
- Bun.serve({
366
-
367
- port: port,
368
-
369
- async fetch(req, res) {
370
-
371
- const url = new URL(req.url);
372
-
373
- const success = res.upgrade(req);
374
-
375
- if (success) {
376
-
377
- return new Response('Connected', {
378
-
379
- headers: {
380
-
381
- "Content-Type": "text/html"
382
-
383
- }
384
-
385
- })
386
-
387
- }
388
-
389
- if (req.url.includes('.')) {
390
-
391
- if (!fs.existsSync(process.cwd() + '/dist' + url.pathname)) {
392
-
393
- return new Response('Not Found', {
394
-
395
- status: 404,
396
-
397
- headers: {
398
-
399
- "Content-Type": "text/html"
400
-
401
- }
402
-
403
- })
404
-
405
- }
406
-
407
- console.log('Serving: ' + url.pathname)
408
-
409
- return new Response(fs.readFileSync(process.cwd() + '/dist/' + url.pathname, 'utf-8'), {
410
-
411
- headers: {
412
-
413
- "Content-Type": ContentType(req.url)
414
-
415
- }
416
-
417
- })
418
-
419
- }
420
-
421
- let matchedRoute = router.match(url.pathname);
422
-
423
- if (matchedRoute) {
424
-
425
- let { filePath, kind, name, params, pathname, query, } = matchedRoute
426
-
427
- let folder = url.pathname.split('/')[1]
428
-
429
- let jsFile = filePath.split('pages/').pop().split('.').shift() + '.js'
430
-
431
- let pageContent = fs.readFileSync(process.cwd() + '/dist/' + folder + '/index.html', 'utf8')
432
-
433
- globalThis.mode === 'dev' ? pageContent += `
434
-
435
- <script type="module">
436
-
437
- let ws = new WebSocket('ws://localhost:${port}');
438
-
439
- ws.onmessage = async (e) => {
440
-
441
- if(e.data === 'reload'){
442
-
443
- window.location.reload()
444
-
445
- console.log('Reloading...')
446
-
447
- }
448
-
449
- }
450
-
451
- </script>
452
-
453
- ` : void 0
454
-
455
- return new Response(pageContent, {
456
-
457
- headers: {
458
-
459
- "Content-Type": "text/html",
460
-
461
- "X-Powered-By": "Vader.js v1.3.3"
462
-
463
- }
464
-
465
- })
466
-
467
- }
468
-
469
-
470
-
471
- return new Response('Not Found', {
472
-
473
- status: 404,
474
-
475
- headers: {
476
-
477
- "Content-Type": "text/html"
478
-
479
- }
480
-
481
- })
482
-
483
- },
484
-
485
- websocket: {
486
-
487
- open(ws) {
488
-
489
- clients.push(ws)
490
-
491
- },
492
-
493
- }
494
-
495
- })
496
-
497
- }
498
-
499
- /**
500
-
501
- * @function write
502
-
503
- * @description - Writes data to a file
504
-
505
- * @returns {void} 0
506
-
507
- * @param {string} file
508
-
509
- * @param {any} data
510
-
511
- * @returns
512
-
513
- */
514
-
515
- const write = (file, data) => {
516
-
517
- try {
518
-
519
- if (!fs.existsSync('./dist')) {
520
-
521
- fs.mkdirSync('./dist')
522
-
523
- }
524
-
525
- Bun.write(file, data);
526
-
527
- } catch (error) {
528
-
529
- console.error(error)
530
-
531
- }
532
-
533
-
534
-
535
- }
536
-
537
- /**
538
-
539
- * @function read
540
-
541
- * @param {path} file
542
-
543
- * @returns {Promise<string>}
544
-
545
- */
546
-
547
- const read = async (file) => {
548
-
549
- return await Bun.file(file).text();
550
-
551
- }
552
-
553
- /**
554
-
555
- * @object integrationStates
556
-
557
- * @description - Used to store integration states
558
-
559
- */
560
-
561
-
562
-
563
- globalThis.integrationStates = []
564
-
565
- /**
566
-
567
- * @description a boolean value that checks if vader is being used - useful for running toplevel code at integration start
568
-
569
- */
570
-
571
- globalThis.context = {
572
-
573
- vader: true
574
-
575
- }
576
-
577
- /**
578
-
579
- * @function handleIntegrations
580
-
581
- * @description - Handles module integrations that add more functionality to Vader.js
582
-
583
- * @returns {void} 0
584
-
585
- */
586
-
587
- function handleIntegrations() {
588
-
589
- if (config?.integrations) {
590
-
591
- config.integrations.forEach((integration) => {
592
-
593
- let int = integration
594
-
595
- globalThis.integrationStates.push(int)
596
-
597
- })
598
-
599
- }
600
-
601
-
602
-
603
- return void 0;
604
-
605
- }
606
-
607
- handleIntegrations()
608
-
609
- /**
610
-
611
- * @function generateProviderRoutes
612
-
613
- * @description - Generates routes for hosting provders ie: vercel, cloudflare
614
-
615
- * @returns {void} 0
616
-
617
- */
618
-
619
- async function generateProviderRoutes() {
620
-
621
- if (!config?.host?.provider) {
622
-
623
- console.warn('No provider found in vader.config.js ignoring route generation...')
624
-
625
- return void 0;
626
-
627
- }
628
-
629
- let providerType = [{
630
-
631
- provider: 'vercel',
632
-
633
- file: 'vercel.json',
634
-
635
- out: process.cwd() + '/vercel.json',
636
-
637
- obj: {
638
-
639
- rewrites: []
640
-
641
- }
642
-
643
- }, {
644
-
645
- provider: 'cloudflare',
646
-
647
- file: '_redirects',
648
-
649
- out: 'dist/_redirects'
650
-
651
- }]
652
-
653
-
654
-
655
- let provider = providerType.find((p) => p.provider === config.host.provider)
656
-
657
- if (provider) {
658
-
659
- let prev = null
660
-
661
-
662
-
663
- switch (provider.provider) {
664
-
665
- case 'vercel':
666
-
667
- if (!fs.existsSync(provider.out)) {
668
-
669
- fs.writeFileSync(provider.out, JSON.stringify({ rewrites: [] }))
670
-
671
- }
672
-
673
- prev = await read(provider.out);
674
-
675
- if (!prev) {
676
-
677
- prev = []
678
-
679
- } else {
680
-
681
- prev = JSON.parse(prev).rewrites
682
-
683
- }
684
-
685
- routes.forEach((r) => {
686
-
687
- let previous = prev.find((p) => p.source.includes(r.path))
688
-
689
- if (previous) {
690
-
691
- return void 0;
692
-
693
- }
694
-
695
-
696
-
697
- prev.push({
698
-
699
- source: '/' + r.path,
700
-
701
- destination: '/' + r.path + '/index.html'
702
-
703
- })
704
-
705
-
706
-
707
- if (r.params.length > 0) {
708
-
709
- r.params.forEach((param) => {
710
-
711
- if (!param.paramData) {
712
-
713
- return void 0;
714
-
715
- }
716
-
717
- let parampath = Object.keys(param.paramData).map((p) => `:${p}`).join('/')
718
-
719
- prev.push({
720
-
721
- source: '/' + r.path + '/' + parampath,
722
-
723
- destination: '/' + r.path + '/index.html'
724
-
725
- })
726
-
727
- })
728
-
729
- }
730
-
731
-
732
-
733
- fs.writeFileSync(provider.out, JSON.stringify({ rewrites: prev }, null, 2))
734
-
735
-
736
-
737
-
738
-
739
- })
740
-
741
- provider.obj.rewrites = prev
742
-
743
- write(provider.out, JSON.stringify(provider.obj, null, 2))
744
-
745
- break;
746
-
747
- case 'cloudflare':
748
-
749
- console.warn('Cloudflare is not supported yet refer to their documentation for more information:https://developers.cloudflare.com/pages/configuration/redirects/')
750
-
751
- break;
752
-
753
- }
754
-
755
-
756
-
757
-
758
-
759
-
760
-
761
-
762
-
763
- }
764
-
765
- return void 0;
766
-
767
- }
768
-
769
-
770
-
771
- /**
772
-
773
- * @function transform
774
-
775
- * @description - Transforms the jsx files to js files based on file paths
776
-
777
- */
778
-
779
-
780
-
781
- async function transForm() {
782
-
783
- return new Promise(async (resolve, reject) => {
784
-
785
- globalThis.isBuilding = true
786
-
787
- router.reload()
788
-
789
- for await (var file of glob.scan('.')) {
790
-
791
- file = file.replace(/\\/g, '/');
792
-
793
- let isBasePath = file.split('pages/')?.[1]?.split('/').length === 1;
794
-
795
-
796
-
797
- let folder = file.split('pages/')?.[1]?.split('/').slice(0, -1).join('/') || null;
798
-
799
- if (isBasePath) {
800
-
801
- folder = '/'
802
-
803
- }
804
-
805
- let route = isBasePath ? router.match('/') : router.match('/' + folder)
806
-
807
-
808
-
809
- if (route) {
810
-
811
- let { filePath, kind, name, params, pathname, query, } = route
812
-
813
- let data = await read(filePath);
814
-
815
- try {
816
-
817
- data = new Bun.Transpiler({ loader: "tsx", target: "browser", }).transformSync(data);
818
-
819
- } catch (e) {
820
-
821
- console.error(e)
822
-
823
- }
824
-
825
- let out = `./dist/${isBasePath ? 'index.js' : folder + '/index.js'}`;
826
-
827
- isBasePath ? folder = '/' : null;
828
-
829
- data = handleReplaceMents(data);
830
-
831
- let isAparam = null
832
-
833
- if (folder === "") {
834
-
835
- return
836
-
837
- }
838
-
839
- switch (true) {
840
-
841
- case kind === 'dynamic':
842
-
843
- isAparam = true
844
-
845
- break;
846
-
847
- case kind === 'catch-all':
848
-
849
- isAparam = true
850
-
851
- break;
852
-
853
- case kind === 'optional-catch-all':
854
-
855
- isAparam = true
856
-
857
- break;
858
-
859
- }
860
-
861
- routes.push({ path: folder, file: out, isParam: isAparam, params: params, query, pathname })
862
-
863
- write(out, data);
864
-
865
- bundleSize += data.length
866
-
867
-
868
-
869
-
870
-
871
- }
872
-
873
-
874
-
875
- }
876
-
877
-
878
-
879
- for await (var file of srcGlob.scan('.')) {
880
-
881
- if (!fs.existsSync(process.cwd() + '/dist/src/')) {
882
-
883
- fs.mkdirSync(process.cwd() + '/dist/src/')
884
-
885
- }
886
-
887
- file = file.replace(/\\/g, '/');
888
-
889
- switch (file.split('.').pop()) {
890
-
891
- case 'ts':
892
-
893
- let transpiler = new Bun.Transpiler({ loader: "ts", target: "browser", });
894
-
895
- let data = await read(file);
896
-
897
- try {
898
-
899
- data = transpiler.transformSync(data);
900
-
901
- } catch (error) {
902
-
903
- console.error(error)
904
-
905
- }
906
-
907
- file = file.replace('.ts', '.js')
908
-
909
- let path = process.cwd() + '/dist/src/' + file.split('src/').pop()
910
-
911
- write(path, data);
912
-
913
- bundleSize += data.length
914
-
915
-
916
-
917
- break;
918
-
919
-
920
-
921
- case 'tsx':
922
-
923
- let transpilerx = new Bun.Transpiler({ loader: "tsx", target: "browser", });
924
-
925
- let datax = await read(file);
926
-
927
- try {
928
-
929
- datax = transpilerx.transformSync(datax);
930
-
931
- } catch (error) {
932
-
933
- console.error(error)
934
-
935
- }
936
-
937
- datax = handleReplaceMents(datax);
938
-
939
- file = file.replace('.tsx', '.js')
940
-
941
- let pathx = process.cwd() + '/dist/src/' + file.split('src/').pop()
942
-
943
- write(pathx, datax);
944
-
945
-
946
-
947
-
948
-
949
- break;
950
-
951
- case 'jsx':
952
-
953
- let transpilerjx = new Bun.Transpiler({ loader: "jsx", target: "browser" });
954
-
955
- let datajx = await read(file);
956
-
957
-
958
-
959
- let source = transpilerjx.scan(datajx)
960
-
961
- try {
962
-
963
- datajx = transpilerjx.transformSync(datajx)
964
-
965
- } catch (error) {
966
-
967
- console.error(error)
968
-
969
- }
970
-
971
- datajx = handleReplaceMents(datajx);
972
-
973
- file = file.replace('.jsx', '.js')
974
-
975
- let pathjx = process.cwd() + '/dist/src/' + file.split('src/').pop()
976
-
977
- write(pathjx, datajx);
978
-
979
- bundleSize += datajx.length
980
-
981
- break;
982
-
983
- }
984
-
985
- }
986
-
987
-
988
-
989
-
990
-
991
- for await (var file of publicGlob.scan('.')) {
992
-
993
- let data = await read(file);
994
-
995
- file = file.replace(/\\/g, '/');
996
-
997
- write(process.cwd() + '/dist/public/' + file.split('public/').pop(), data);
998
-
999
- bundleSize += fs.existsSync(process.cwd() + '/dist/public/' + file.split('public/').pop()) ? fs.statSync(process.cwd() + '/dist/public/' + file.split('public/').pop()).size : 0
1000
-
1001
- }
1002
-
1003
- for await (var file of vaderGlob.scan('.')) {
1004
-
1005
- let data = await read(file);
1006
-
1007
- file = file.replace(/\\/g, '/');
1008
-
1009
- write(process.cwd() + '/dist/' + file.split('node_modules/vaderjs/runtime/').pop(), data);
1010
-
1011
- bundleSize += fs.statSync(process.cwd() + '/dist/' + file.split('node_modules/vaderjs/runtime/').pop()).size
1012
-
1013
- }
1014
-
1015
-
1016
-
1017
- // clean dist folder
1018
-
1019
- for await (var file of distPages.scan('.')) {
1020
-
1021
- file = file.replace(/\\/g, '/');
1022
-
1023
- let path = process.cwd() + '/pages/' + file.split('dist/pages/').pop()
1024
-
1025
- path = path.replace('.js', config?.files?.mimeType || '.jsx')
1026
-
1027
-
1028
-
1029
- if (!fs.existsSync(path)) {
1030
-
1031
- fs.unlinkSync(file)
1032
-
1033
- }
1034
-
1035
-
1036
-
1037
- }
1038
-
1039
-
1040
-
1041
-
1042
-
1043
-
1044
-
1045
-
1046
-
1047
-
1048
-
1049
-
1050
-
1051
- /**
1052
-
1053
- * @function organizeRoutes
1054
-
1055
- * @description - Organizes routes that have param paths
1056
-
1057
- */
1058
-
1059
-
1060
-
1061
- const organizeRoutes = () => {
1062
-
1063
- // if path starts with the same path and is dynamic then they are the same route and push params to the same route
1064
-
1065
- let newRoutes = []
1066
-
1067
- routes.forEach((route) => {
1068
-
1069
- let exists = routes.find((r) => {
1070
-
1071
- if (r.path.includes('[')) {
1072
-
1073
- r.path = r.path.split('[').shift()
1074
-
1075
- }
1076
-
1077
-
1078
-
1079
- r.path = r.path.split('/').filter((p) => p !== '').join('/')
1080
-
1081
- if (r.isParam) {
1082
-
1083
- return r.path === route.path && r.isParam
1084
-
1085
- }
1086
-
1087
-
1088
-
1089
- })
1090
-
1091
- if (exists) {
1092
-
1093
- let b4Params = route.params
1094
-
1095
- route.params = []
1096
-
1097
- route.params.push(b4Params)
1098
-
1099
- route.params.push({
1100
-
1101
- jsFile: '/' + exists.path + '/index.js',
1102
-
1103
- folder: '/' + exists.path,
1104
-
1105
- paramData: exists.params
1106
-
1107
- }
1108
-
1109
- )
1110
-
1111
- route.query = exists.query
1112
-
1113
- newRoutes.push(route)
1114
-
1115
- }
1116
-
1117
- else if (!exists && !route.isParam) {
1118
-
1119
- newRoutes.push(route)
1120
-
1121
-
1122
-
1123
- }
1124
-
1125
- //remove param route that matched
1126
-
1127
- routes = routes.filter((r) => exists ? r.path !== exists.path : true)
1128
-
1129
-
1130
-
1131
- })
1132
-
1133
- globalThis.routes = newRoutes
1134
-
1135
- }
1136
-
1137
- organizeRoutes()
1138
-
1139
-
1140
-
1141
-
1142
-
1143
- generateProviderRoutes()
1144
-
1145
- globalThis.isBuilding = false
1146
-
1147
- if (!fs.existsSync(process.cwd() + '/_dev/meta')) {
1148
-
1149
- fs.mkdirSync(process.cwd() + '/_dev/meta')
1150
-
1151
- }
1152
-
1153
- fs.writeFileSync(process.cwd() + '/_dev/meta/routes.json', JSON.stringify(routes, null, 2))
1154
-
1155
- console.log(`Finished building ${Math.round(bundleSize / 1000)}kb`)
1156
-
1157
-
1158
-
1159
- bundleSize = 0
1160
-
1161
- resolve()
1162
-
1163
- });
1164
-
1165
-
1166
-
1167
- }
1168
-
1169
- let port = 3000
1170
-
1171
- switch (true) {
1172
-
1173
- case process.argv.includes('dev') && !process.argv.includes('build') && !process.argv.includes('start'):
1174
-
1175
-
1176
-
1177
- port = process.argv.includes('-p') ? process.argv[process.argv.indexOf('-p') + 1] : config?.dev?.port || 3000
1178
-
1179
- globalThis.oneAndDone = false
1180
-
1181
- console.log(`
1182
-
1183
- Vader.js v${fs.readFileSync(process.cwd() + '/node_modules/vaderjs/package.json', 'utf8').split('"version": "')[1].split('"')[0]}
1184
-
1185
- - Watching for changes in ./pages
1186
-
1187
- - Watching for changes in ./src
1188
-
1189
- - Watching for changes in ./public
1190
-
1191
- - Serving on port ${port}
1192
-
1193
- `)
1194
-
1195
- globalThis.mode = 'dev'
1196
-
1197
- Server(port)
1198
-
1199
- transForm()
1200
-
1201
-
1202
-
1203
- Bun.spawn({
1204
-
1205
- cwd: process.cwd() + '/node_modules/vaderjs/binaries/',
1206
-
1207
- env: {
1208
-
1209
- PWD: process.cwd(),
1210
-
1211
- IPC: IPC,
1212
-
1213
- FOLDERS: 'pages,src,public',
1214
-
1215
- onExit: (code) => {
1216
-
1217
- globalThis.isBuilding = false
1218
-
1219
- globalThis.oneAndDone = true
1220
-
1221
- }
1222
-
1223
- },
1224
-
1225
- cmd: ['node', 'watcher.js'],
1226
-
1227
- })
1228
-
1229
- async function runOnChange() {
1230
-
1231
- for (var ints in integrationStates) {
1232
-
1233
- if (integrationStates && integrationStates[ints].on.includes('dev:change')) {
1234
-
1235
- console.log('Starting integration...')
1236
-
1237
- let int = integrationStates[ints]
1238
-
1239
- let { name, version, useRuntime, entryPoint, onAction, doOn } = int
1240
-
1241
-
1242
- if (globalThis[`isRunning${name}`]) {
1243
-
1244
- setTimeout(() => {
1245
- globalThis[`isRunning${name}`] = false
1246
- }, 1000)
1247
- return void 0
1248
-
1249
- }
1250
-
1251
- globalThis[`isRunning${name}`] = true
1252
- console.log(`Using integration: ${name} v${version}`)
1253
-
1254
- Bun.spawn({
1255
-
1256
- cwd: process.cwd(),
1257
-
1258
- isVader: true,
1259
-
1260
- env: {
1261
-
1262
- PWD: process.cwd(),
1263
-
1264
- isVader: true,
1265
-
1266
- FOLDERS: 'pages,src,public',
1267
-
1268
- onExit: (code) => {
1269
-
1270
- globalThis.isBuilding = false
1271
-
1272
- globalThis[`isRunning${name}`] = false
1273
-
1274
- }
1275
-
1276
- },
1277
-
1278
- cmd: [useRuntime || 'node', entryPoint],
1279
-
1280
- })
1281
-
1282
-
1283
-
1284
- console.log(`Using integration: ${name} v${version}`)
1285
-
1286
-
1287
-
1288
- }
1289
-
1290
- }
1291
-
1292
- }
1293
-
1294
-
1295
-
1296
-
1297
-
1298
- IPC.client({
1299
-
1300
- use: IPCServer.typeEnums.WATCHER,
1301
-
1302
- port: 3434
1303
-
1304
- }).Console.read((message) => {
1305
-
1306
- message = message.msg
1307
-
1308
- switch (true) {
1309
-
1310
- case message.data?.type === 'change':
1311
-
1312
- console.log('File changed:', message.data.filename)
1313
-
1314
- transForm()
1315
-
1316
- clients.forEach((client) => {
1317
-
1318
- client.send('reload')
1319
-
1320
- })
1321
-
1322
- runOnChange()
1323
-
1324
-
1325
-
1326
- break;
1327
-
1328
- case message.data?.type === 'add':
1329
-
1330
- console.log('File added:', message.data.filename)
1331
-
1332
- transForm()
1333
-
1334
- break;
1335
-
1336
- }
1337
-
1338
- })
1339
-
1340
-
1341
-
1342
-
1343
-
1344
-
1345
-
1346
- break;
1347
-
1348
- case process.argv.includes('build') && !process.argv.includes('dev') && !process.argv.includes('start'):
1349
-
1350
- globalThis.devMode = false
1351
-
1352
-
1353
-
1354
-
1355
-
1356
-
1357
-
1358
- globalThis.mode = 'prod'
1359
-
1360
- globalThis.isProduction = true
1361
-
1362
- globalThis.routeStates = []
1363
-
1364
- console.log(`
1365
-
1366
- Vader.js v1.3.3
1367
-
1368
- Building to ./dist
1369
-
1370
- `)
1371
-
1372
-
1373
-
1374
- await transForm()
1375
-
1376
- for (var ints in integrationStates) {
1377
-
1378
- console.log(integrationStates[ints], 'integrationStates[ints]')
1379
-
1380
- if (integrationStates && integrationStates[ints].on.includes('build')) {
1381
-
1382
- console.log('Starting integration...')
1383
-
1384
- let int = integrationStates[ints]
1385
-
1386
- let { name, version, useRuntime, entryPoint, onAction, doOn } = int
1387
-
1388
- console.log(`Using integration: ${name} v${version} from ${entryPoint}`)
1389
-
1390
-
1391
-
1392
- Bun.spawn({
1393
-
1394
- cwd: process.cwd(),
1395
-
1396
- isVader: true,
1397
-
1398
- env: {
1399
-
1400
- PWD: process.cwd(),
1401
-
1402
- isVader: true,
1403
-
1404
- FOLDERS: 'pages,src,public',
1405
-
1406
- onExit: (code) => {
1407
-
1408
- globalThis.isBuilding = false
1409
-
1410
- }
1411
-
1412
- },
1413
-
1414
- cmd: ["node", entryPoint]
1415
-
1416
- })
1417
-
1418
-
1419
-
1420
-
1421
-
1422
-
1423
-
1424
- }
1425
-
1426
- }
1427
-
1428
-
1429
-
1430
- break;
1431
-
1432
- case process.argv.includes('start') && !process.argv.includes('dev') && !process.argv.includes('build'):
1433
-
1434
- port = process.argv.includes('-p') ? process.argv[process.argv.indexOf('-p') + 1] : config?.host?.prod?.port || 3000
1435
-
1436
- console.log(`
1437
-
1438
- Vader.js v1.3.3
1439
-
1440
- Serving ./dist on port ${port}
1441
-
1442
- url: ${config?.host?.prod?.hostname || 'http://localhost'}:${port}
1443
-
1444
- `)
1445
-
1446
- globalThis.devMode = false
1447
-
1448
- globalThis.isProduction = true
1449
-
1450
-
1451
-
1452
- Server(port)
1453
-
1454
- break;
1455
-
1456
- default:
1457
-
1458
-
1459
-
1460
- break;
1461
-
1462
-
1463
-
1464
- }