vaderjs 1.8.0 → 1.8.1

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/index.ts CHANGED
@@ -79,15 +79,15 @@ export const A = (props: {
79
79
  /**
80
80
  * @description Set the elements classlist
81
81
  */
82
- class: string;
82
+ className?: string;
83
83
  /**
84
84
  * @description Once clicked send user to a different link
85
85
  */
86
- href: string;
87
- style: string;
88
- openInNewTab: boolean
89
- onClick: () => void;
90
- onChange: () => void;
86
+ href?: string;
87
+ style?: string;
88
+ openInNewTab?: boolean
89
+ onClick?: () => void;
90
+ onChange?: () => void;
91
91
  }, children: any) => {
92
92
  function handleClick(e) {
93
93
  e.preventDefault();
@@ -95,9 +95,7 @@ export const A = (props: {
95
95
  window.open(props.href, "_blank");
96
96
  return void 0;
97
97
  }
98
- window.history.pushState({}, "", props.href);
99
- window.dispatchEvent(new PopStateEvent("popstate"));
100
- window.location.reload();
98
+ window.location.href = props.href;
101
99
  return void 0;
102
100
  }
103
101
  return e("a", { ...props, onClick: handleClick }, props.children);
@@ -112,6 +110,14 @@ export const Fragment = (props: any, children: any) => {
112
110
  }
113
111
  }
114
112
 
113
+ if(typeof window !== "undefined") {
114
+ window.history.back = () => {
115
+ window.history.go(-1);
116
+ }
117
+ window.history.forward = () => {
118
+ window.history.go(1);
119
+ }
120
+ }
115
121
  globalThis.Fragment = Fragment;
116
122
 
117
123
  /**
@@ -153,6 +159,12 @@ export const e = (element, props, ...children) => {
153
159
  if (el.type !== "head") {
154
160
  el.props = { idKey: crypto.randomUUID(), ...el.props };
155
161
  }
162
+
163
+ // if element == false return empty string
164
+ if (el.type === false) {
165
+ return "";
166
+ }
167
+
156
168
  return el;
157
169
  }
158
170
  };
@@ -166,9 +178,14 @@ export const e = (element, props, ...children) => {
166
178
  */
167
179
 
168
180
 
169
- export function Switch({ children }) {
181
+ interface SwitchProps {
182
+ children: any[] | any;
183
+ }
184
+
185
+ // make children optional
186
+ export function Switch({ children = [] }: SwitchProps) {
170
187
  for (let child of children) {
171
- if (child.props.when) {
188
+ if (child && child.props && child.props.when) {
172
189
  return child;
173
190
  }
174
191
  }
@@ -625,7 +642,7 @@ export class Component {
625
642
  } else if (typeof child === "object") {
626
643
  // Nested object children
627
644
  el.appendChild(this.parseToElement(child));
628
- } else if (child !== null && child !== undefined) {
645
+ } else if (child !== null && child !== undefined && child !== false) {
629
646
  // Text nodes
630
647
  el.appendChild(document.createTextNode(child));
631
648
  }
package/main.js CHANGED
@@ -75,15 +75,16 @@ if (!fs.existsSync(process.cwd() + '/jsconfig.json')) {
75
75
  await Bun.write(process.cwd() + '/jsconfig.json', JSON.stringify(json, null, 4))
76
76
  }
77
77
 
78
- var bindes = []
78
+ globalThis.bindes = []
79
79
  var fnmap = []
80
80
  const vader = {
81
+ isDev: mode === 'development',
81
82
  onFileChange: (file, cb) => {
82
83
  fs.watch(file, cb)
83
84
  },
84
85
  runCommand: (cmd) => {
85
86
  return new Promise((resolve, reject) => {
86
- Bun.spawn(cmd, {
87
+ let c = Bun.spawn(cmd, {
87
88
  stdout: 'inherit',
88
89
  cwd: process.cwd(),
89
90
  onExit({ exitCode: code }) {
@@ -95,6 +96,11 @@ const vader = {
95
96
  }
96
97
  })
97
98
 
99
+ setTimeout(() => {
100
+ c.kill()
101
+ reject()
102
+ }, 5000)
103
+
98
104
 
99
105
  })
100
106
  },
@@ -105,6 +111,7 @@ const vader = {
105
111
  },
106
112
  injectHTML: (html) => {
107
113
  bindes.push(html)
114
+ globalThis.bindes = bindes
108
115
  },
109
116
  }
110
117
  const handleReplacements = (code) => {
@@ -294,6 +301,7 @@ async function generateApp() {
294
301
  await plugin.onBuildFinish(vader)
295
302
  }
296
303
  }
304
+
297
305
  })
298
306
 
299
307
 
@@ -444,90 +452,106 @@ if (mode === 'development') {
444
452
  else if (mode == 'production') {
445
453
  await handleFiles()
446
454
  await generateApp()
455
+
456
+ console.log(`Build complete in ${Date.now() - start}ms at ${new Date().toLocaleTimeString()}`);
447
457
  }
448
458
  else {
449
459
  if (isBuilding) console.log(`Build complete in ${Date.now() - start}ms at ${new Date().toLocaleTimeString()}`);
450
-
451
- }
452
-
453
-
454
- if (mode == 'development' || mode == 'serve') {
455
- let server = Bun.serve({
456
- port: port || 8080,
457
- websocket: {
458
- open(ws) {
459
- globalThis.clients.push(ws)
460
- ws.send('Connected')
461
- },
462
- message(ws, message) {
463
- globalThis.clients.forEach(c => {
464
- c.send(message)
465
- })
460
+ if (mode == 'development' || mode == 'serve') {
461
+ let server = Bun.serve({
462
+ port: port || 8080,
463
+ websocket: {
464
+ open(ws) {
465
+ globalThis.clients.push(ws)
466
+ ws.send('Connected')
467
+ },
468
+ message(ws, message) {
469
+ globalThis.clients.forEach(c => {
470
+ c.send(message)
471
+ })
472
+ },
473
+
466
474
  },
467
-
468
- },
469
- async fetch(req, res) {
470
- if (res.upgrade(req)) {
471
- return new Response('Upgraded', { status: 101 })
472
- }
473
-
474
- let url = new URL(req.url)
475
- if (url.pathname.includes('.')) {
476
- let p = url.pathname.replaceAll("%5B", "[").replaceAll("%5D", "]")
477
- let file = await Bun.file(path.join(process.cwd() + '/dist' + p))
478
- if (!await file.exists()) return new Response('Not found', { status: 404 })
479
- let imageTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/webp', 'image/tiff', 'image/bmp', 'image/ico', 'image/cur', 'image/jxr', 'image/jpg']
480
-
481
- return new Response(imageTypes.includes(file.type) ? await file.arrayBuffer() : await file.text(), {
482
- headers: {
483
- 'Content-Type': file.type,
484
- 'Cache-Control': imageTypes.includes(file.type) ? 'max-age=31536000' : 'no-cache',
485
- 'Access-Control-Allow-Origin': '*'
486
- }
487
- })
488
- }
489
- let router = new Bun.FileSystemRouter({
490
- dir: process.cwd() + '/app',
491
- style: 'nextjs'
492
- })
493
- router.reload()
494
- let route = router.match(url.pathname)
495
- if (!route) {
496
- return new Response('Not found', { status: 404 })
497
- }
498
- let p = route.pathname;
499
- let base = path.dirname(route.filePath)
500
- base = base.replace(/\\/g, '/')
501
- base = base.replace(path.join(process.cwd() + '/app').replace(/\\/g, '/'), '')
502
- base = base.replace(/\\/g, '/').replace('/app', '/dist')
503
- base = process.cwd() + "/dist/" + base
504
- let data = await Bun.file(path.join(base, 'index.html')).text()
505
- if (mode == "development") {
506
- return new Response(data + `
507
- <script>
508
- let ws = new WebSocket('ws://localhost:${server.port}')
509
- ws.onmessage = (e) => {
510
- if(e.data === 'reload'){
511
- console.log('Reloading to display changes from server')
512
- window.location.reload()
475
+ async fetch(req, res) {
476
+ if (res.upgrade(req)) {
477
+ return new Response('Upgraded', { status: 101 })
513
478
  }
514
- }
515
- </script>
516
- `, {
517
- headers: {
518
- 'Content-Type': 'text/html'
519
- }
479
+
480
+ let url = new URL(req.url)
481
+ if (url.pathname.includes('.')) {
482
+ let p = url.pathname.replaceAll("%5B", "[").replaceAll("%5D", "]")
483
+ let file = await Bun.file(path.join(process.cwd() + '/dist' + p))
484
+ if (!await file.exists()) return new Response('Not found', { status: 404 })
485
+ let imageTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/webp', 'image/tiff', 'image/bmp', 'image/ico', 'image/cur', 'image/jxr', 'image/jpg']
486
+
487
+ return new Response(imageTypes.includes(file.type) ? await file.arrayBuffer() : await file.text(), {
488
+ headers: {
489
+ 'Content-Type': file.type,
490
+ 'Cache-Control': imageTypes.includes(file.type) ? 'max-age=31536000' : 'no-cache',
491
+ 'Access-Control-Allow-Origin': '*'
492
+ }
493
+ })
494
+ }
495
+ let router = new Bun.FileSystemRouter({
496
+ dir: process.cwd() + '/app',
497
+ style: 'nextjs'
520
498
  })
521
- } else {
522
- return new Response(data, {
523
- headers: {
524
- 'Content-Type': 'text/html'
499
+ router.reload()
500
+ let route = router.match(url.pathname)
501
+ if (!route) {
502
+ return new Response('Not found', { status: 404 })
503
+ }
504
+ let p = route.pathname;
505
+ let base = path.dirname(route.filePath)
506
+ base = base.replace(/\\/g, '/')
507
+ base = base.replace(path.join(process.cwd() + '/app').replace(/\\/g, '/'), '')
508
+ base = base.replace(/\\/g, '/').replace('/app', '/dist')
509
+ base = process.cwd() + "/dist/" + base
510
+ if(!fs.existsSync(path.join(base, 'index.html'))){
511
+ return new Response(`
512
+ <html>
513
+ <head>
514
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
515
+ <meta http-equiv="refresh" content="5">
516
+ </head>
517
+ <body>
518
+ <h1>404 Not Found</h1>
519
+ <p>Route not found</p>
520
+ </body>
521
+ `, { status: 404 }, {
522
+ headers: {
523
+ 'Content-Type': 'text/html'
524
+ }
525
+ })
526
+ }
527
+ let data = await Bun.file(path.join(base, 'index.html')).text()
528
+ if (mode == "development") {
529
+ return new Response(data + `
530
+ <script>
531
+ let ws = new WebSocket('ws://localhost:${server.port}')
532
+ ws.onmessage = (e) => {
533
+ if(e.data === 'reload'){
534
+ console.log('Reloading to display changes from server')
535
+ window.location.reload()
525
536
  }
526
- })
537
+ }
538
+ </script>
539
+ `, {
540
+ headers: {
541
+ 'Content-Type': 'text/html'
542
+ }
543
+ })
544
+ } else {
545
+ return new Response(data, {
546
+ headers: {
547
+ 'Content-Type': 'text/html'
548
+ }
549
+ })
550
+ }
551
+
527
552
  }
528
-
529
- }
530
- })
531
-
532
- console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
553
+ })
554
+
555
+ console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
556
+ }
533
557
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "A simple and powerful JavaScript library for building modern web applications.",
5
5
  "bin": {
6
6
  "vaderjs": "./main.js"
@@ -47,15 +47,18 @@ export default {
47
47
  }else{
48
48
  initTailwind()
49
49
 
50
- vader.onFileChange('tailwind.config.js', async () => {
50
+ if(vader.isDev){
51
+ vader.onFileChange('tailwind.config.js', async () => {
51
52
  console.log('Rebuilding TailwindCSS...')
52
53
  await vader.runCommand(['bun', 'run', 'postcss', './public/styles.css', '-o', 'dist/public/tailwind.css'])
53
54
  console.log('TailwindCSS rebuilt successfully!')
54
55
  })
56
+ }
55
57
  await vader.runCommand(['bun', 'run', 'postcss', './public/styles.css', '-o', 'dist/public/tailwind.css'])
56
58
  vader.injectHTML(`<style>${fs.readFileSync(path.resolve(process.cwd(), 'dist/public/tailwind.css'))}</style>`)
57
59
  }
58
60
 
61
+ return
59
62
  },
60
63
  onBuildFinish: async (vader) => {
61
64
  console.log('TailwindCSS plugin finished building')