vaderjs 1.4.9 → 1.5.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Pascal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ <p align="center">
2
+ <a href="https://vader-js.pages.dev">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="/icon.jpeg">
5
+ <img src="./logo.png" height="128">
6
+ </picture>
7
+ <h1 align="center">Vader.js</h1>
8
+ </a>
9
+ </p>
10
+
11
+ # Vader.js A reactive framework for building fast and scalable web applications
12
+
13
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Postr-Inc/Vader.js/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/vaderjs.svg?style=flat)](https://www.npmjs.com/package/vaderjs)
14
+
15
+
16
+ # Installation
17
+
18
+ ```js
19
+ npx vaderjs @latest
20
+ ```
21
+
22
+ ```ts
23
+ import { useSate, e } from "vaderjs"
24
+ export default function(){
25
+ let [count, setCount] = useState(0)
26
+ return (
27
+ <div>
28
+ <p>Count is {count} </p>
29
+ <button onClick={()=>setCount(count++)}>
30
+ Increment +1
31
+ </button>
32
+ </div>
33
+ )
34
+ }
35
+ ```
36
+
37
+ # Project Setup
38
+ Create a pages folder - which allows you to have nextjs page like routing via buns file based router
39
+
40
+ Tip: Each folder can be deep nested up to 4 levels!
41
+
42
+ ```md
43
+
44
+ /pages/index.jsx = /
45
+ /pages/home/[page].jsx = /home/:page
46
+ /pages/path/index.jsx = /path/
47
+ /pages/test/[[...catchall]]/index.jsx = /path/test/*
48
+ /pages/route/[param1]/[param2].jsx = /path/route/:param1/:param2
49
+
50
+ ```
51
+ Keyword folders - all files are passed from these folders to the build folder
52
+
53
+ ```md
54
+ 1. pages - used for jsx route files
55
+ 2. src - used for your jsx components / javascript -typescript files
56
+ 3. public - used for anything / css / json etc
57
+ ```
58
+
59
+
60
+ # Define your config
61
+
62
+ ```ts
63
+ import { defineConfig } from "vaderjs/config";
64
+ import cloudflare from "vaderjs/plugins/cloudflare/functions"
65
+ import tailwindcss from "vaderjs/plugins/tailwindcss"
66
+ export default defineConfig({
67
+ target: "web",
68
+ host: {
69
+ hostname: "localhost",
70
+ provider:'cloudflare' // used for ssg or ssr
71
+ },
72
+ env: {
73
+ PORT: 3000,
74
+ SSR: true,
75
+ apiRoute: "https://api.example.com"
76
+ },
77
+ Router: {
78
+ tls: {
79
+ cert: "cert.pem",
80
+ key: "key.pem"
81
+ },
82
+ headers: {
83
+ "cache-control": "public, max-age=0, must-revalidate"
84
+ }
85
+ },
86
+ plugins: [cloudflare, tailwindcss],
87
+ });
88
+
89
+ ```
package/bun.lockb ADDED
Binary file
package/bundler/index.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  import { document } from "vaderjs/document";
11
11
  import fs from "fs";
12
12
  import ansiColors from "ansi-colors";
13
+ import path from "path";
13
14
  let path2 = require("path");
14
15
  globalThis.Fragment = Fragment;
15
16
  globalThis.window = {
@@ -34,12 +35,35 @@ globalThis.document = {
34
35
  };
35
36
  await Bun.build({
36
37
  entrypoints: [process.env.ENTRYPOINT],
37
- minify: true,
38
+ minify: false,
38
39
  root: process.cwd() + "/dist/",
39
40
  outdir: process.cwd() + "/dist/",
40
41
  format: "esm",
41
42
  ...(process.env.DEV ? { sourcemap: "inline" } : {}),
43
+ external:['*.jsx', '*.js']
42
44
  });
45
+
46
+ let builtCode = fs.readFileSync(path.join(process.cwd(), 'dist', process.env.filePath), 'utf-8')
47
+ function handleReplacements(code) {
48
+ let lines = code.split("\n");
49
+ let newLines = [];
50
+ for (let line of lines) {
51
+ let hasImport = line.includes('import')
52
+ if(hasImport && line.includes('from')){
53
+ try {
54
+ let url = line.includes("'") ? line.split("'")[1] : line.split('"')[1]
55
+ let exactFile = path.resolve(url)
56
+ // replace url with exact file path
57
+ line = line.replace(url, exactFile)
58
+ } catch (error) {
59
+ continue;
60
+ }
61
+ }
62
+ }
63
+ return lines.join("\n");
64
+ }
65
+ builtCode = handleReplacements(builtCode)
66
+ fs.writeFileSync(path.join(process.cwd(), 'dist', process.env.filePath), builtCode)
43
67
  let isClass = function (element) {
44
68
  return element.toString().startsWith("class");
45
69
  };
@@ -72,19 +96,23 @@ const generatePage = async (
72
96
  }
73
97
  let headHtml = "";
74
98
  if (head) {
75
- headHtml = document(head());
99
+ headHtml = document(head());
76
100
  }
77
- Bun.write(
101
+
102
+ await Bun.write(
78
103
  process.cwd() + "/dist/" + route + "/index.html",
79
- `<!DOCTYPE html><head>${headHtml}</head>${h}
80
- <script type="module">
81
- import c from '${process.env.filePath}'
82
- import {render} from '/src/vader/index.js'
83
- render(c, document.body.firstChild)
84
- </script>
104
+ `<!DOCTYPE html>
105
+ <head>
106
+ ${headHtml}
107
+ </head>
108
+ ${h}
109
+ <script type="module">
110
+ import c from '${process.env.filePath}'
111
+ import {render} from '/src/vader/index.js'
112
+ render(c, document.body.firstChild)
113
+ </script>
85
114
  `
86
115
  );
87
-
88
116
  console.log(
89
117
  ansiColors.blue(
90
118
  `${process.env.filePath.replace(".js", ".jsx")} - ${parseInt(
@@ -94,4 +122,8 @@ const generatePage = async (
94
122
  );
95
123
  process.exit(0);
96
124
  };
97
- generatePage({ path: process.env.INPUT, route: process.env.OUT });
125
+ try {
126
+ process.env.isImport == undefined && generatePage({ path: process.env.INPUT, route: process.env.OUT });
127
+ } catch (error) {
128
+ console.log(ansiColors.red(error))
129
+ }
package/document/index.ts CHANGED
@@ -13,11 +13,15 @@ export const document = (element: any) => {
13
13
  continue;
14
14
  }
15
15
  if (key === "style") {
16
- let style = "";
17
- for (let styleKey in attributes[key]) {
18
- style += `${styleKey}:${attributes[key][styleKey]};`;
16
+ // convert style object to string
17
+ let styles = attributes[key];
18
+ let styleString = "";
19
+ // convert camelCase to kebab-case
20
+ for (let style in styles) {
21
+ let kebabStyle = style.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
22
+ styleString += `${kebabStyle}:${styles[style]};`;
19
23
  }
20
- el += ` style="${style}"`;
24
+ el += ` style="${styleString}"`;
21
25
  continue;
22
26
  }
23
27
  //@ts-ignore