vaderjs 2.2.5 → 2.3.0

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
@@ -8,70 +8,92 @@
8
8
  </a>
9
9
  </p>
10
10
 
11
- # Vader.js A reactive framework for building fast and scalable web applications
11
+ # Vader.js
12
+ A modern, reactive framework for building ultra-fast web applications — built on simplicity and speed.
12
13
 
13
14
  [![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
+ ---
17
+
18
+ ## šŸš€ Quick Example
19
+
15
20
  ```tsx
16
21
  import { useState, Switch, Match } from "vaderjs"
17
22
 
18
- export default function(){
19
- let [count, setCount] = useState(0)
20
- return(
23
+ export default function() {
24
+ const [count, setCount] = useState(0)
25
+ return (
21
26
  <div>
22
- <Switch>
23
- <Match when={count > 10}>
24
- <h1>Count is greater than 10 </h1>
25
- </Match>
26
- <Match when={count < 10}>
27
- <h1>Count is less than 10 </h1>
28
- </Match>
29
- </Switch>
30
- </div>
27
+ <Switch>
28
+ <Match when={count > 10}>
29
+ <h1>Count is greater than 10</h1>
30
+ </Match>
31
+ <Match when={count <= 10}>
32
+ <h1>Count is less than or equal to 10</h1>
33
+ </Match>
34
+ </Switch>
35
+ </div>
31
36
  )
32
37
  }
33
38
  ```
34
- # Installation
35
39
 
36
- ```js
37
- bun install vaderjs @latest
38
- ```
40
+ ---
39
41
 
42
+ ## šŸ“¦ Installation
40
43
 
44
+ ```bash
45
+ bun install vaderjs@latest
46
+ ```
41
47
 
42
- # Project Setup
43
- Create a pages folder - which allows you to have nextjs page like routing via buns file based router
48
+ ## āš™ļø Project Structure
44
49
 
45
- > Note only use this when using production server - not supported by cloudflare, github or vercel
50
+ Vader.js supports file-based routing out of the box. Just create a `pages` folder like in Next.js:
46
51
 
47
- Tip: Each folder can be deep nested up to 4 levels!
52
+ > āš ļø Note: This routing system is designed for **production servers** only. It will not work with Cloudflare Pages, GitHub Pages, or Vercel.
48
53
 
49
- ```md
50
- /pages/index.jsx = /
51
- /pages/home/[page].jsx = /home/:page
52
- /pages/path/index.jsx = /path/
53
- /pages/test/[[...catchall]]/index.jsx = /path/test/*
54
- /pages/route/[param1]/[param2].jsx = /path/route/:param1/:param2
54
+ You can nest up to 4 levels deep.
55
55
 
56
56
  ```
57
- Keyword folders - all files are passed from these folders to the build folder
58
-
59
- ```md
60
- 1. app - used for jsx route files
61
- 2. public - used for anything / css / json etc
62
- 3. Src - components utilities etc
57
+ /pages/index.jsx -> /
58
+ /pages/home/[page].jsx -> /home/:page
59
+ /pages/path/index.jsx -> /path/
60
+ /pages/test/[[...catchall]]/index.jsx -> /test/*
61
+ /pages/route/[param1]/[param2].jsx -> /route/:param1/:param2
63
62
  ```
64
63
 
64
+ ---
65
+
66
+ ## šŸ—‚ Keyword Folders
67
+
68
+ Certain folders are special and automatically picked up by the bundler:
65
69
 
66
- # Define your config
70
+ | Folder | Purpose |
71
+ | --------- | ----------------------------------- |
72
+ | `app/` | Contains all route `.jsx` files |
73
+ | `src/` | Your components, utilities, etc. |
74
+ | `public/` | Static files like CSS, JSON, images |
75
+
76
+ ---
77
+
78
+ ## šŸ›  Define Config
79
+
80
+ Create a `config.ts` file at the root of your project:
67
81
 
68
82
  ```ts
69
83
  import defineConfig from "vaderjs/config";
70
84
 
71
85
  export default defineConfig({
72
- port: 3000,
73
- host: 'localhost',
74
- hot_reload: true,
75
- })
76
-
86
+ port: 3000,
87
+ host: "localhost",
88
+ hot_reload: true,
89
+ });
77
90
  ```
91
+
92
+
93
+ ## šŸ¤” Why Vader.js?
94
+
95
+ * Minimal reactivity model with zero VDOM
96
+ * File-based routing system built into Bun
97
+ * Tiny runtime, blazing fast updates
98
+ * Familiar API inspired by React, but simpler
99
+ * Perfect for Bun-first, fullstack apps
package/cli.ts ADDED
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import fs from "fs/promises";
4
+ import fsSync from "fs";
5
+ import path from "path";
6
+ import readline from "readline";
7
+
8
+ function ask(question) {
9
+ const rl = readline.createInterface({
10
+ input: process.stdin,
11
+ output: process.stdout,
12
+ });
13
+ return new Promise((resolve) =>
14
+ rl.question(question + " ", (answer) => {
15
+ rl.close();
16
+ resolve(answer.trim());
17
+ })
18
+ );
19
+ }
20
+
21
+ async function run(cmd: string, args: string[] = []) {
22
+ try {
23
+ const proc = Bun.spawn([cmd, ...args], {
24
+ stdout: "inherit",
25
+ stderr: "inherit",
26
+ });
27
+
28
+ const status = await proc.exited;
29
+ if (status !== 0) {
30
+ console.error(`Command failed: ${cmd} ${args.join(" ")}`);
31
+ process.exit(1);
32
+ }
33
+ } catch (error) {
34
+ console.error(`Error executing command: ${error}`);
35
+ process.exit(1);
36
+ }
37
+ }
38
+
39
+ export async function init() {
40
+ console.log("šŸš€ Welcome to Vader.js project initializer!");
41
+
42
+ const cwd = process.cwd();
43
+ let projectDir = await ask(
44
+ `Enter the directory to initialize the project (default: current dir):`
45
+ );
46
+ if (!projectDir) projectDir = ".";
47
+
48
+ projectDir = path.resolve(cwd, projectDir);
49
+ if (!fsSync.existsSync(projectDir)) {
50
+ await fs.mkdir(projectDir, { recursive: true });
51
+ console.log(`Created directory: ${projectDir}`);
52
+ }
53
+
54
+ // Confirm Tailwind usage
55
+ let useTailwind = await ask("Include TailwindCSS v4 support? (y/n):");
56
+ while (!["y", "n", "yes", "no"].includes(useTailwind)) {
57
+ useTailwind = await ask("Please answer 'y' or 'n':");
58
+ }
59
+ const wantsTailwind = useTailwind === "y" || useTailwind === "yes";
60
+
61
+ // Create folders: app, src, public
62
+ const appDir = path.join(projectDir, "app");
63
+ const srcDir = path.join(projectDir, "src");
64
+ const publicDir = path.join(projectDir, "public");
65
+
66
+ for (const dir of [appDir, srcDir, publicDir]) {
67
+ if (!fsSync.existsSync(dir)) {
68
+ await fs.mkdir(dir, { recursive: true });
69
+ console.log(`Created folder: ${dir}`);
70
+ }
71
+ }
72
+
73
+ // Create example app/index.jsx with counter
74
+ const counterCode = wantsTailwind
75
+ ? `import { useState } from "vaderjs";
76
+
77
+ export default function Counter() {
78
+ let [count, setCount] = useState(0);
79
+ return (
80
+ <div class="max-w-md mx-auto p-6 bg-gray-100 rounded shadow text-center">
81
+ <h1 class="text-2xl font-bold mb-4">Counter Example</h1>
82
+ <p class="text-xl mb-4">Count: {count}</p>
83
+ <button
84
+ class="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700"
85
+ onClick={() => setCount(count + 1)}
86
+ >
87
+ Increment
88
+ </button>
89
+ </div>
90
+ );
91
+ }
92
+ `
93
+ : `import { useState } from "vaderjs";
94
+
95
+ export default function Counter() {
96
+ let [count, setCount] = useState(0);
97
+ return (
98
+ <div style={{ maxWidth: "300px", margin: "auto", padding: "1rem", background: "#eee", borderRadius: "8px", textAlign: "center" }}>
99
+ <h1 style={{ fontWeight: "bold", marginBottom: "1rem" }}>Counter Example</h1>
100
+ <p style={{ fontSize: "1.25rem", marginBottom: "1rem" }}>Count: {count}</p>
101
+ <button onClick={() => setCount(count + 1)}>Increment</button>
102
+ </div>
103
+ );
104
+ }
105
+ `;
106
+
107
+ await fs.writeFile(path.join(appDir, "index.jsx"), counterCode);
108
+ console.log(`Created example route: ${path.join("app", "index.jsx")}`);
109
+
110
+ // Create public/styles.css
111
+ if (wantsTailwind) {
112
+ await fs.writeFile(path.join(publicDir, "styles.css"), `@import 'tailwindcss';\n`);
113
+ } else {
114
+ await fs.writeFile(path.join(publicDir, "styles.css"), `/* Add your styles here */\n`);
115
+ }
116
+ console.log(`Created public/styles.css`);
117
+
118
+ // Create minimal package.json if not exist
119
+ const pkgJsonPath = path.join(projectDir, "package.json");
120
+ if (!fsSync.existsSync(pkgJsonPath)) {
121
+ const pkg = {
122
+ name: path.basename(projectDir),
123
+ version: "1.0.0",
124
+ scripts: {
125
+ start: "bun run vaderjs build && bun run vaderjs serve",
126
+ build: "bun run vaderjs build",
127
+ dev: "bun run vaderjs dev",
128
+ },
129
+ dependencies: {
130
+ vaderjs: "latest",
131
+ },
132
+ };
133
+ await fs.writeFile(pkgJsonPath, JSON.stringify(pkg, null, 2));
134
+ console.log(`Created package.json`);
135
+ }
136
+
137
+ // Install dependencies: vaderjs + optionally tailwindcss, postcss plugins
138
+ console.log("Installing dependencies with Bun...");
139
+ const deps = ["vaderjs"];
140
+ if (wantsTailwind) {
141
+ deps.push("tailwindcss", "@tailwindcss/postcss", "postcss-cli");
142
+ }
143
+ await run("bun", ["install", ...deps]);
144
+ console.log("āœ… Dependencies installed.");
145
+
146
+ // If Tailwind requested, create minimal tailwind.config.cjs and postcss.config.cjs
147
+ if (wantsTailwind) {
148
+ const tailwindConfig = `module.exports = {
149
+ content: ["./app/**/*.{js,jsx,ts,tsx}"],
150
+ theme: {
151
+ extend: {},
152
+ },
153
+ plugins: [],
154
+ };`;
155
+ await fs.writeFile(path.join(projectDir, "tailwind.config.cjs"), tailwindConfig);
156
+ console.log("Created tailwind.config.cjs");
157
+
158
+ const postcssConfig = `module.exports = {
159
+ plugins: {
160
+ tailwindcss: {},
161
+ autoprefixer: {},
162
+ },
163
+ };`;
164
+ await fs.writeFile(path.join(projectDir, "postcss.config.cjs"), postcssConfig);
165
+ console.log("Created postcss.config.cjs");
166
+ }
167
+
168
+ // Create jsconfig.json for VSCode/IDE support
169
+ const jsConfig = {
170
+ compilerOptions: {
171
+ jsx: "react",
172
+ jsxFactory: "Vader.createElement",
173
+ jsxFragmentFactory: "Fragment"
174
+ }
175
+ };
176
+ await fs.writeFile(path.join(projectDir, "jsconfig.json"), JSON.stringify(jsConfig, null, 2));
177
+ console.log("Created jsconfig.json");
178
+
179
+ // Final instructions
180
+ console.log(`\nšŸŽ‰ Vader.js project initialized at:\n${projectDir}`);
181
+ console.log(`Run cd ${projectDir} to navigate into the project folder`);
182
+ console.log("Run `bun run dev` or your build script to get started.");
183
+ }
184
+
185
+
186
+