vaderjs 2.2.1 → 2.2.3-s

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/bundler/index.js CHANGED
@@ -195,12 +195,8 @@ var process = {
195
195
  .join(',\n')}
196
196
  }
197
197
  }
198
- `;
199
- let rename = process.env.filePath.split('.js')[0] + Math.random().toString().split('.')[1] + '.js'
198
+ `;
200
199
  fs.writeFileSync(path.join(process.cwd(), 'dist', process.env.filePath), builtCode)
201
- var before = process.env.filePath
202
- process.env.filePath = rename
203
- fs.renameSync(path.join(process.cwd(), 'dist', before), path.join(process.cwd(), 'dist', process.env.filePath))
204
200
  let isClass = function (element) {
205
201
  return element && element.toString().startsWith("class");
206
202
  };
package/main.js CHANGED
@@ -4,18 +4,18 @@ import ansiColors from 'ansi-colors'
4
4
  import { Glob } from 'bun'
5
5
  const args = Bun.argv.slice(2)
6
6
  globalThis.isBuilding = false;
7
- import fs from 'fs'
7
+ import fs from 'fs'
8
8
  import { platform } from 'os'
9
9
  import path from 'path'
10
10
 
11
11
  let bunPath = 'bun'; // Default for Linux/Mac
12
12
  if (platform() === 'win32') {
13
- bunPath ='bun'; // Bun path for Windows
13
+ bunPath = 'bun'; // Bun path for Windows
14
14
  } else {
15
15
  bunPath = path.resolve(process.env.HOME || process.env.USERPROFILE, '.bun', 'bin', 'bun');
16
16
  }
17
-
18
-
17
+
18
+
19
19
 
20
20
 
21
21
  if (!fs.existsSync(process.cwd() + '/app') && !args.includes('init')) {
@@ -94,7 +94,7 @@ const vader = {
94
94
  },
95
95
  runCommand: (cmd) => {
96
96
  return new Promise((resolve, reject) => {
97
- let c = Bun.spawn(cmd, {
97
+ let c = Bun.spawn(cmd, {
98
98
  stdout: 'inherit',
99
99
  cwd: process.cwd(),
100
100
  onExit({ exitCode: code }) {
@@ -106,10 +106,7 @@ const vader = {
106
106
  }
107
107
  })
108
108
 
109
- setTimeout(() => {
110
- c.kill()
111
- reject()
112
- }, 5000)
109
+
113
110
 
114
111
 
115
112
  })
@@ -129,8 +126,8 @@ const handleReplacements = (code) => {
129
126
  let newLines = []
130
127
  for (let line of lines) {
131
128
  let hasImport = line.includes('import')
132
-
133
- if(hasImport && line.includes('public')){
129
+
130
+ if (hasImport && line.includes('public')) {
134
131
  // remove ../ from path
135
132
 
136
133
  line = line.replaceAll('../', '').replaceAll('./', '')
@@ -187,7 +184,7 @@ const handleReplacements = (code) => {
187
184
  if (!hasImport && line.includes('useRef')) {
188
185
  line = line.replace(' ', '')
189
186
  let b4 = line
190
- let key = line.split('=')[0].split(' ').filter(Boolean)[1]
187
+ let key = line.split('=')[0].split(' ').filter(Boolean)[1]
191
188
  b4 = line.replace('useRef(', `this.useRef('${key}',`)
192
189
  line = b4
193
190
  }
@@ -198,27 +195,31 @@ const handleReplacements = (code) => {
198
195
  return c
199
196
  }
200
197
 
201
- if (!fs.existsSync(process.cwd() + '/dev/bundler.js')) {
198
+ if (!fs.existsSync(process.cwd() + '/dev/bundler.js')) {
202
199
  fs.mkdirSync(process.cwd() + '/dev', { recursive: true })
203
200
  fs.copyFileSync(require.resolve('vaderjs/bundler/index.js'), process.cwd() + '/dev/bundler.js')
204
201
  }
205
202
  let start = Date.now()
206
203
  async function generateApp() {
207
204
  globalThis.isBuilding = true;
208
- console.log(ansiColors.green('Building...'))
205
+ console.log(ansiColors.green('Building...'))
209
206
  if (mode === 'development') {
210
-
207
+
211
208
  } else {
212
209
  fs.mkdirSync(process.cwd() + '/dist', { recursive: true })
213
210
  }
214
- let plugins = config.plugins || []
215
- for (let plugin of plugins) {
216
- if (plugin.onBuildStart) {
217
- await plugin.onBuildStart(vader)
211
+ try {
212
+ let plugins = config.plugins || []
213
+ for (let plugin of plugins) {
214
+ if (plugin.onBuildStart) {
215
+ await plugin.onBuildStart(vader)
216
+ }
218
217
  }
218
+ } catch (error) {
219
+ console.log(error)
219
220
  }
220
221
 
221
-
222
+
222
223
  return new Promise(async (resolve, reject) => {
223
224
  let routes = new Bun.FileSystemRouter({
224
225
  dir: path.join(process.cwd(), '/app'),
@@ -233,19 +234,29 @@ async function generateApp() {
233
234
  code = handleReplacements(code)
234
235
  let size = code.length / 1024
235
236
  r = r.replace(process.cwd().replace(/\\/g, '/') + '/app', '')
236
- r = r.replace('.jsx', '.js').replace('.tsx', '.js')
237
+ r = r.replace('.jsx', '.js').replace('.tsx', '.js')
237
238
  fs.mkdirSync(path.join(process.cwd() + '/dist', path.dirname(r)), { recursive: true })
238
239
  let params = routes.match(route).params || {}
239
- let base = routes.match(route)
240
- let paramIndexes = []
240
+ let base = routes.match(route)
241
+ let paramIndexes = []
241
242
  for (let param in params) {
242
- let routes = base.pathname.split('/')
243
+ let routes = base.pathname.split('/')
243
244
  let index = routes.indexOf('[' + param + ']')
244
245
  paramIndexes.push(index)
245
- }
246
-
246
+ }
247
+
247
248
  // dont return
248
-
249
+ code = await new Bun.Transpiler({
250
+ loader: 'tsx',
251
+ tsconfig: {
252
+ "compilerOptions": {
253
+ "jsx": "react",
254
+ "jsxFactory": "e",
255
+ "jsxFragmentFactory": "Fragment"
256
+ }
257
+ }
258
+ }).transformSync(code)
259
+
249
260
  fs.writeFileSync(
250
261
  process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r),
251
262
  `
@@ -253,32 +264,38 @@ async function generateApp() {
253
264
  let params = {
254
265
  // get index tehn do route[index]
255
266
  ${Object.keys(params).map((param, i) => {
256
- if (paramIndexes[i] !== -1) {
257
- var r_copy = r;
258
- r_copy = r_copy.split('/').filter(Boolean)
259
- var index = paramIndexes[i] - 1
260
- return `${param}: route[${index}]`
261
- }
262
- }).join(',\n')}
267
+ if (paramIndexes[i] !== -1) {
268
+ var r_copy = r;
269
+ r_copy = r_copy.split('/').filter(Boolean)
270
+ var index = paramIndexes[i] - 1
271
+ return `${param}: route[${index}]`
272
+ }
273
+ }).join(',\n')}
263
274
  }
264
275
 
265
276
  \n${code}
266
277
  `
267
278
  );
268
279
  fs.mkdirSync(process.cwd() + '/dev', { recursive: true })
269
-
280
+
270
281
 
271
282
  if (!fs.existsSync(process.cwd() + '/dev/readme.md')) {
272
283
  fs.writeFileSync(process.cwd() + '/dev/readme.md', `# Please do not edit the bundler.js file in the dev directory. This file is automatically generated by the bundler. \n\n`)
273
284
  }
274
- if(!fs.existsSync(path.join(process.cwd(), '/dist/src/vader'))){
275
- fs.mkdirSync(process.cwd() + '/dist/src/vader', { recursive: true })
276
- fs.writeFileSync(process.cwd() + '/dist/src/vader/index.js', await new Bun.Transpiler({
285
+ async function runT() {
286
+ return await new Bun.Transpiler({
277
287
  loader: 'ts',
278
- }).transformSync(await Bun.file(require.resolve('vaderjs')).text()))
279
- }
280
- await Bun.spawn({
281
- cmd: [bunPath, 'run', './dev/bundler.js'] ,
288
+ }).transformSync(await Bun.file(require.resolve('vaderjs')).text())
289
+ }
290
+ if (!fs.existsSync(path.join(process.cwd(), '/dist/src/vader'))
291
+ || fs.readFileSync(path.join(process.cwd(), '/dist/src/vader/index.js')) != await runT()
292
+ ) {
293
+ fs.mkdirSync(process.cwd() + '/dist/src/vader', { recursive: true })
294
+ fs.writeFileSync(path.join(process.cwd(), '/dist/src/vader/index.js'), (await runT()))
295
+
296
+ }
297
+ await Bun.spawn({
298
+ cmd: [bunPath, 'run', './dev/bundler.js'],
282
299
  cwd: process.cwd(),
283
300
  stdout: 'inherit',
284
301
  env: {
@@ -336,13 +353,17 @@ async function generateApp() {
336
353
 
337
354
  }
338
355
  // run all plugins that have onBuildFinish
339
- let plugins = config.plugins || []
340
- for (let plugin of plugins) {
341
- if (plugin.onBuildFinish) {
342
- await plugin.onBuildFinish(vader)
356
+ try {
357
+ let plugins = config.plugins || []
358
+ for (let plugin of plugins) {
359
+ if (plugin.onBuildFinish) {
360
+ await plugin.onBuildFinish(vader)
361
+ }
343
362
  }
363
+ } catch (error) {
364
+ console.error(ansiColors.red(error))
344
365
  }
345
-
366
+
346
367
  })
347
368
 
348
369
 
@@ -350,7 +371,7 @@ async function generateApp() {
350
371
 
351
372
  function handleFiles() {
352
373
  return new Promise(async (resolve, reject) => {
353
- try {
374
+ try {
354
375
  let glob = new Glob('public/**/*')
355
376
  for await (var i of glob.scan()) {
356
377
  let file = i
@@ -369,6 +390,9 @@ function handleFiles() {
369
390
  let code = await Bun.file(file).text()
370
391
 
371
392
  code = handleReplacements(code)
393
+ code = await new Bun.Transpiler({
394
+ loader: 'ts',
395
+ }).transformSync(code)
372
396
 
373
397
  file = file.replace('.jsx', '.js').replace('.tsx', '.js')
374
398
  fs.writeFileSync(path.join(process.cwd() + '/dist', file.replace('.jsx', '.js').replace('.tsx', '.js')), code)
@@ -440,71 +464,73 @@ if (mode === 'development') {
440
464
  try {
441
465
  await generateApp()
442
466
  await handleFiles()
443
- let watcher;
444
- let isBuilding = false;
445
- let debounceTimeout;
446
-
447
- const startWatcher = () => {
448
- if (watcher) watcher.close(); // Close any existing watcher
449
-
450
- watcher = fs.watch(path.join(process.cwd(), '/'), { recursive: true }, (eventType, file) => {
451
- if (!file) return; // Ensure file name is valid
452
- if (file.includes('node_modules')) return;
453
-
454
- if (
455
- file.endsWith('.tsx') || file.endsWith('.jsx') || file.endsWith('.css') || file.endsWith('.ts')
456
- ) {
457
- // Reset config if needed
458
- if (file.endsWith('vader.config.ts')) {
459
- delete require.cache[require.resolve(process.cwd() + '/vader.config.ts')];
460
- globalThis.config = require(process.cwd() + '/vader.config.ts').default;
461
- }
462
-
463
- if (file.includes('dist')) return;
464
-
465
- clearTimeout(debounceTimeout);
466
- debounceTimeout = setTimeout(async () => {
467
- if (!isBuilding) {
468
- isBuilding = true;
469
- try {
470
- await generateApp();
471
- await handleFiles();
472
- setTimeout(() => {
473
- clients.forEach(c => c.send('reload'));
474
- }, 1000);
475
- } catch (error) {
476
- console.error(error);
477
- } finally {
478
- isBuilding = false;
467
+ let watcher;
468
+ let isBuilding = false;
469
+ let debounceTimeout;
470
+
471
+ const startWatcher = () => {
472
+ if (watcher) watcher.close(); // Close any existing watcher
473
+
474
+ watcher = fs.watch(path.join(process.cwd(), '/'), { recursive: true }, (eventType, file) => {
475
+ if (!file) return; // Ensure file name is valid
476
+ if (file.includes('node_modules')) return;
477
+ if (file.includes('dist')) return;
478
+ if (!fs.existsSync(path.join(process.cwd(), file))) {
479
+ fs.rmSync(path.join(process.cwd(), "dist", file))
480
+ }
481
+
482
+ if (
483
+ file.endsWith('.tsx') || file.endsWith('.jsx') || file.endsWith('.css') || file.endsWith('.ts')
484
+ ) {
485
+ // Reset config if needed
486
+ if (file.endsWith('vader.config.ts')) {
487
+ delete require.cache[require.resolve(process.cwd() + '/vader.config.ts')];
488
+ globalThis.config = require(process.cwd() + '/vader.config.ts').default;
479
489
  }
490
+
491
+ clearTimeout(debounceTimeout);
492
+ debounceTimeout = setTimeout(async () => {
493
+ if (!isBuilding) {
494
+ isBuilding = true;
495
+ try {
496
+ await generateApp();
497
+ await handleFiles();
498
+ setTimeout(() => {
499
+ clients.forEach(c => c.send('reload'));
500
+ }, 1000);
501
+ } catch (error) {
502
+ console.error(error);
503
+ } finally {
504
+ isBuilding = false;
505
+ }
506
+ }
507
+ }, 500);
480
508
  }
481
- }, 500);
482
- }
483
509
 
484
- // Restart watcher if a new directory is created
485
- if (eventType === 'rename') {
486
- setTimeout(startWatcher, 1000); // Slight delay to allow the OS to recognize new files
487
- }
488
- });
489
- };
510
+ // Restart watcher if a new directory is created
511
+ if (eventType === 'rename') {
512
+ setTimeout(startWatcher, 500); // Slight delay to allow the OS to recognize new files
513
+ }
514
+ });
515
+ };
490
516
 
491
- // Start the watcher and restart it periodically
492
- setInterval(startWatcher, 10000);
493
- startWatcher(); // Run initially
517
+ // Start the watcher and restart it periodically
518
+ setInterval(startWatcher, 500);
519
+ startWatcher(); // Run initially
494
520
  } catch (error) {
495
- console.error(error)
521
+ console.error(error)
496
522
  }
497
523
 
498
524
  }
499
525
  else if (mode == 'production') {
500
526
  await handleFiles()
501
527
  await generateApp()
502
-
528
+
503
529
  console.log(`Build complete in ${Date.now() - start}ms at ${new Date().toLocaleTimeString()}`);
504
530
  }
505
531
  else {
506
532
  if (isBuilding) console.log(`Build complete in ${Date.now() - start}ms at ${new Date().toLocaleTimeString()}`);
507
-
533
+
508
534
  }
509
535
 
510
536
  if (mode == 'development' || mode == 'serve') {
@@ -557,7 +583,7 @@ if (mode == 'development' || mode == 'serve') {
557
583
  base = base.replace(path.join(process.cwd() + '/app').replace(/\\/g, '/'), '')
558
584
  base = base.replace(/\\/g, '/').replace('/app', '/dist')
559
585
  base = process.cwd() + "/dist/" + base
560
- if(!fs.existsSync(path.join(base, 'index.html'))){
586
+ if (!fs.existsSync(path.join(base, 'index.html'))) {
561
587
  return new Response(`
562
588
  <html>
563
589
  <head>
@@ -613,7 +639,4 @@ if (mode == 'development' || mode == 'serve') {
613
639
  })
614
640
 
615
641
  console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
616
- }
617
-
618
-
619
-
642
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs",
3
- "version": "2.2.1",
3
+ "version": "2.2.3s",
4
4
  "description": "A simple and powerful JavaScript library for building modern web applications.",
5
5
  "bin": {
6
6
  "vaderjs": "./main.js"
@@ -5,14 +5,14 @@ function checkIfTailwindInstalled() {
5
5
  try {
6
6
  //@ts-ignore
7
7
  require.resolve('tailwindcss')
8
+ require.resolve('postcss')
8
9
  return true
9
10
  } catch (e) {
10
11
  return false
11
12
  }
12
13
  }
13
14
 
14
- function initTailwind() {
15
- const tailwindConfig = path.resolve(process.cwd(), 'tailwind.config.js')
15
+ function initTailwind() {
16
16
  const postcssConfig = path.resolve(process.cwd(), 'postcss.config.mjs')
17
17
  const tailwindCssFile = path.join(process.cwd(), '/public/styles.css')
18
18
  if(!fs.existsSync(tailwindCssFile)){
@@ -48,4 +48,4 @@ export default {
48
48
  console.log('TailwindCSS plugin finished building')
49
49
  },
50
50
 
51
- }
51
+ }