vaderjs 1.4.2-jpiml56 → 1.4.2-kml56

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 CHANGED
@@ -39,8 +39,8 @@ Keyword folders - all files are passed from these folders to the build folder
39
39
 
40
40
  ```md
41
41
  1. pages - used for jsx route files
42
- 2. src - used for your jsx components / javascript -typescript files
43
- 3. public - used for anything / css / json etc
42
+ 2. src - used for your jsx components / javascript files
43
+ 3. public - used for anything
44
44
  ```
45
45
 
46
46
 
@@ -49,28 +49,18 @@ Keyword folders - all files are passed from these folders to the build folder
49
49
  ```ts
50
50
  import { defineConfig } from "vaderjs/config";
51
51
  import cloudflare from "vaderjs/plugins/cloudflare/functions"
52
- import tailwindcss from "vaderjs/plugins/tailwindcss"
53
52
  export default defineConfig({
54
53
  target: "web",
55
54
  host: {
56
55
  hostname: "localhost",
57
- provider:'cloudflare' // used for ssg or ssr
56
+ provider:'cloudflare'
58
57
  },
59
58
  env: {
60
59
  PORT: 3000,
61
60
  SSR: true,
62
61
  apiRoute: "https://api.example.com"
63
62
  },
64
- Router: {
65
- tls: {
66
- cert: "cert.pem",
67
- key: "key.pem"
68
- },
69
- headers: {
70
- "cache-control": "public, max-age=0, must-revalidate"
71
- }
72
- },
73
- plugins: [cloudflare, tailwindcss],
63
+ plugins: [cloudflare],
74
64
  });
75
65
 
76
66
  ```
@@ -67,7 +67,7 @@ export class HTMLTextNode {
67
67
  }
68
68
 
69
69
  insertBefore(node) {
70
- this.nodeValue = `${node.nodeValue}${this.nodeValue}`;
70
+ this.nodeValue = `${node.toString()}${this.nodeValue}`;
71
71
  return this;
72
72
  }
73
73
  }
@@ -111,7 +111,7 @@ export class HTMLElement {
111
111
  if (key !== 'style' && key !== 'ref' && !key.startsWith('on')) {
112
112
  props += `${key}="${this.props[key]}" `
113
113
  }
114
- }
114
+ }
115
115
  let children = this.children
116
116
  .map((child) => {
117
117
  return child.toString();
@@ -155,7 +155,12 @@ export class HTMLElement {
155
155
  .join("");
156
156
  return string;
157
157
 
158
-
158
+ case "innerText":
159
+ return this.children
160
+ .map((child) => {
161
+ return child.toString();
162
+ })
163
+ .join("");
159
164
  default:
160
165
  break;
161
166
  }
@@ -182,8 +187,8 @@ export class HTMLElement {
182
187
  * @returns {HTMLElement}
183
188
  */
184
189
  setContent(content) {
185
- let textNode = new HTMLTextNode(content)
186
- this.children = [textNode];
190
+ let textNode = new HTMLTextNode(content);
191
+ this.children = [textNode];
187
192
  this.outerHTML = this.toString("outerHTML");
188
193
  this.innerHTML = this.toString("innerHTML");
189
194
  return this;
@@ -351,7 +356,7 @@ export class HTMLElement {
351
356
  this.textContent = this.toString("innerText");
352
357
  this.children.forEach((c) => {
353
358
  if (c.children) {
354
- child = c.children.find((child) => {
359
+ child = c.children.find((child) => {
355
360
  child.outerHTML = child.toString("outerHTML");
356
361
  child.innerHTML = child.toString("innerHTML");
357
362
  return child.tagName === selector;
@@ -439,9 +444,6 @@ export class Document {
439
444
  * @returns {HTMLElement}
440
445
  */
441
446
  createElement(nodeData) {
442
- if(!nodeData){
443
- return new HTMLElement("div", {}, [])
444
- }
445
447
  if (typeof nodeData === 'string') {
446
448
  return new HTMLElement(nodeData, {}, [])
447
449
  }
@@ -561,17 +563,7 @@ function handleStyles(styles, nodeEl) {
561
563
  */
562
564
  export function Element(tag, props = {}, ...children) {
563
565
  if(typeof tag === 'function'){
564
- let childObj = children.map((child) => {
565
- if (child.tagName === "TEXT_ELEMENT") {
566
- return new HTMLTextNode(child);
567
- }
568
- if (child instanceof HTMLElement) {
569
- return child;
570
- }
571
- return new HTMLElement(child.tagName, child.props, child.children);
572
- })
573
- childObj = childObj[0]
574
- let el = tag({...props, children: childObj})
566
+ let el = tag(props, children)
575
567
  return el
576
568
  }
577
569
  if(props === null){
@@ -261,7 +261,7 @@ export async function Compile(){
261
261
  }
262
262
  copy = copy.replace(old, newLine)
263
263
  break;
264
- case !line.includes('import') && line.includes('useState') && !line.includes('let useState') && !line.includes('var useState') && !line.includes('console'):
264
+ case !line.includes('import') && line.includes('useState') && !line.includes('let useState'):
265
265
  let varType = line.split('[', 1)[0];
266
266
  let before = line.split('useState(')[1].split(',')[0];
267
267
  let key = line.split('[')[1].split(',')[0];
@@ -331,32 +331,27 @@ export async function Compile(){
331
331
  old = line;
332
332
  copy = copy.replace(old, newStatereducer);
333
333
  break;
334
- case line.includes('vaderjs/client') && line.includes('import') || line.includes('vaderjs') && line.includes('import'):
335
- let b4 = line
336
- copy = copy.replace(b4, '')
337
- break;
338
334
 
339
- case line.includes('import') && !line.includes('vaderjs/client') && !line.includes('vaderjs') && !line.includes('import.meta') && !line.includes('import.meta.url') && !line.includes('import.meta.env'):
340
-
341
- let filePath = line.split('from')[1].trim().replace(/'/g, '').replace(/"/g, '').replace(';', '').replaceAll('../','').replace(/\\/g, '/')
342
- let contents = fs.readFileSync(filePath, 'utf8')
343
- // remove default exports
344
-
345
- if(contents.match(/export\s+default\s+/g)){
346
- contents = contents.replace(/export\s+default\s+/g, '')
347
- }
348
-
349
- copy = copy.replace(line, contents)
350
-
351
- break;
352
-
335
+ case line.includes('vaderjs/client') && line.includes('import') || line.includes('vaderjs') && line.includes('import'):
336
+ let b4 = line
337
+ let isUsingProvider = config?.host?.provider
338
+ let replacement = isUsingProvider === 'cloudflare' ? 'remove' : '/src/client.js'
339
+ if(replacement === 'remove'){
340
+ copy = copy.replace(b4, '')
341
+ break;
342
+ }
343
+ let after = line.replace('vaderjs/client', replacement).replace('vaderjs', replacement)
344
+ copy = copy.replace(b4, after)
345
+ break;
346
+
353
347
  }
354
348
  }
355
-
349
+ if(!contents.includes('import Element')){
350
+
351
+ }
356
352
  return copy
357
353
  }
358
354
 
359
-
360
355
 
361
356
 
362
357
  async function gen(){
@@ -387,11 +382,9 @@ export async function Compile(){
387
382
  'jsxDev':JSON.stringify('this.Element'),
388
383
  'jsx': JSON.stringify('this.Element'),
389
384
  }
390
- })
391
- let contents = await Bun.file(process.cwd() + file).text()
392
- contents = data.transformSync(await main(contents, file))
393
- contents = contents.split('\n').filter((line) => !line.includes('vaderjs/client') && !line.includes('vaderjs')).join('\n')
394
- let variables = grabVariables(contents, file)
385
+ }).transformSync(await Bun.file(process.cwd() + file).text())
386
+ let variables = grabVariables(data, file)
387
+ let contents = await main(data, file)
395
388
 
396
389
  variables.forEach((variable) => {
397
390
  contents.split('\n').forEach((line, index) => {
@@ -415,14 +408,10 @@ export async function Compile(){
415
408
  fs.mkdirSync(process.cwd() + '/build/pages/' + file.split('/').slice(0, -1).join('/'), { recursive: true })
416
409
  file = '/build/pages/' + file.replace('.tsx', '.js').replace('.ts', '.js').replace('.jsx', '.js')
417
410
  break;
418
- case isUsingProvider === 'vercel':
419
- fs.mkdirSync(process.cwd() + '/build/pages/' + file.split('/').slice(0, -1).join('/'), { recursive: true })
420
- file = '/build/pages/' + file.replace('.tsx', '.js').replace('.ts', '.js').replace('.jsx', '.js')
421
- break;
422
411
  default:
423
412
  file = '/build/' + file.replace('./', '').replace('.tsx', '.js').replace('.ts', '.js').replace('.jsx', '.js')
424
413
  }
425
- }
414
+ }
426
415
  fs.writeFileSync(process.cwd() + file, contents)
427
416
 
428
417
 
@@ -436,74 +425,6 @@ export async function Compile(){
436
425
  await Bun.write(process.cwd() + '/build/src/router.js', await Bun.file(process.cwd() + '/node_modules/vaderjs/client/runtime/router.js').text())
437
426
  }
438
427
 
439
- // handle src files
440
- const src = new Glob("/src/**/*.{ts,tsx,js,jsx}", {
441
- absolute: true,
442
- ignore: ["**/node_modules/**"]
443
- });
444
-
445
- const publics = new Glob("/public/**/*", {
446
- absolute: true,
447
- ignore: ["**/node_modules/**"]
448
- })
449
- let srcArray = await Array.fromAsync(src.scan())
450
- srcArray = srcArray.map((file) => {
451
- file = file.replaceAll('\\', '/')
452
- file ='./' + file
453
- return file
454
- })
455
-
456
- for(var file of srcArray){
457
- let data = new Bun.Transpiler({
458
- loader: "tsx",
459
- tsconfig: {
460
- 'compilerOptions':{
461
- 'jsx':'react',
462
- 'jsxFactory': 'this.Element'
463
- }
464
- },
465
- define:{
466
-
467
- 'jsxDev':JSON.stringify('this.Element'),
468
- 'jsx': JSON.stringify('this.Element'),
469
- }
470
- }).transformSync(await Bun.file(process.cwd() + file).text())
471
- let variables = grabVariables(data, file)
472
- let contents = await main(data, file)
473
- variables.forEach((variable) => {
474
- contents.split('\n').forEach((line, index) => {
475
- if(line.includes(variable) && !line.includes('import') && !line.includes('let') && !line.includes('var') && !line.includes('const')
476
- && !line.includes(variable + '()') &&
477
- !line.includes('.' + variable) &&
478
- // not an occurence like variable1, variable2, variable3 or variabless
479
- !line.match(new RegExp(variable + '[0-9]')) && !line.match(new RegExp(variable + '(w+)'))
480
- && !line.includes(variable + ':')
481
- ){
482
- let newLine = line.replaceAll(variable, variable + '()')
483
- contents = contents.replace(line, newLine)
484
- }
485
- });
486
- })
487
- file = file.split('/src')[1]
488
- fs.mkdirSync(process.cwd() + '/build/src/' + file.split('/').slice(0, -1).join('/'), { recursive: true })
489
- fs.writeFileSync(process.cwd() + '/build/src' + file, contents)
490
- }
491
-
492
- let publicArray = await Array.fromAsync(publics.scan())
493
- publicArray = publicArray.map((file) => {
494
- file = file.replaceAll('\\', '/')
495
- file ='./' + file
496
- return file
497
- })
498
-
499
- for(var file of publicArray){
500
- file = file.split('/public')[1]
501
- fs.mkdirSync(process.cwd() + '/build/public/' + file.split('/').slice(0, -1).join('/'), { recursive: true })
502
- let out = `/build/public${file}`
503
- let contents = await Bun.file(process.cwd() + '/public' + file).text()
504
- fs.writeFileSync(process.cwd() + out, contents)
505
-
506
- }
507
428
 
508
429
  resolve()
509
430
  })
package/binaries/vader.js CHANGED
File without changes
@@ -1,5 +1,4 @@
1
1
  import { watch } from 'fs'
2
- import fs from 'fs'
3
2
  globalThis.hasLogged = false
4
3
  export function watchDir(cwd, _){
5
4
  process.chdir(cwd)
@@ -13,11 +12,7 @@ export function watchDir(cwd, _){
13
12
  let paths = ['src', 'pages', 'public', 'routes', 'vader.config.ts']
14
13
  for(var i in paths){
15
14
  let path = paths[i]
16
- if(!fs.existsSync(process.cwd() + '/' + path)){
17
- continue;
18
- }
19
15
  watch(process.cwd() + '/' + path, { recursive: true, absolute:true }, (event, filename) => {
20
- if(!filename.endsWith('.ts') && !filename.endsWith('.tsx') && !filename.endsWith('.js') && !filename.endsWith('.jsx')) return
21
16
  if(filename && !filename.includes('node_modules') && !globalThis.hasLogged){
22
17
  console.log(`\x1b[36mwait \x1b[0m - compiling (client and server)`)
23
18
  globalThis.hasLogged = true