vaderjs 2.3.1 → 2.3.3

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.
Files changed (3) hide show
  1. package/cli.ts +164 -122
  2. package/main.js +1 -1
  3. package/package.json +1 -1
package/cli.ts CHANGED
@@ -2,77 +2,77 @@
2
2
 
3
3
  import fs from "fs/promises";
4
4
  import fsSync from "fs";
5
- import path from "path";
5
+ import path from "path";
6
6
  import readline from "readline";
7
7
 
8
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
- );
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
19
  }
20
20
 
21
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);
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);
32
36
  }
33
- } catch (error) {
34
- console.error(`Error executing command: ${error}`);
35
- process.exit(1);
36
- }
37
37
  }
38
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
- }
39
+ export async function init() {
40
+ console.log("šŸš€ Welcome to Vader.js project initializer!");
53
41
 
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";
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 = ".";
60
47
 
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");
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
+ }
65
53
 
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}`);
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
+ }
70
71
  }
71
- }
72
72
 
73
- // Create example app/index.jsx with counter
74
- const counterCode = wantsTailwind
75
- ? `import { useState } from "vaderjs";
73
+ // Create example app/index.jsx with counter
74
+ const counterCode = wantsTailwind
75
+ ? `import { useState } from "vaderjs";
76
76
 
77
77
  export default function Counter() {
78
78
  let [count, setCount] = useState(0);
@@ -90,7 +90,7 @@ export default function Counter() {
90
90
  );
91
91
  }
92
92
  `
93
- : `import { useState } from "vaderjs";
93
+ : `import { useState } from "vaderjs";
94
94
 
95
95
  export default function Counter() {
96
96
  let [count, setCount] = useState(0);
@@ -104,83 +104,125 @@ export default function Counter() {
104
104
  }
105
105
  `;
106
106
 
107
- await fs.writeFile(path.join(appDir, "index.jsx"), counterCode);
108
- console.log(`Created example route: ${path.join("app", "index.jsx")}`);
107
+ await fs.writeFile(path.join(appDir, "index.jsx"), counterCode);
108
+ console.log(`Created example route: ${path.join("app", "index.jsx")}`);
109
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
- }
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
136
119
 
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
120
 
146
- // If Tailwind requested, create minimal tailwind.config.cjs and postcss.config.cjs
147
- if (wantsTailwind) {
148
- const tailwindConfig = `module.exports = {
121
+ // Install dependencies: vaderjs + optionally tailwindcss, postcss plugins, autoprefixer
122
+ console.log("Installing dependencies with Bun...");
123
+ const deps = ["vaderjs", "autoprefixer"];
124
+ if (wantsTailwind) {
125
+ deps.push("tailwindcss@4", "@tailwindcss/postcss", "postcss-cli");
126
+ }
127
+ await run("bun", ["install", ...deps]);
128
+ console.log("āœ… Dependencies installed.");
129
+
130
+ // If Tailwind requested, create minimal tailwind.config.cjs and postcss.config.cjs
131
+ if (wantsTailwind) {
132
+ const tailwindConfig = `module.exports = {
149
133
  content: ["./app/**/*.{js,jsx,ts,tsx}"],
150
134
  theme: {
151
135
  extend: {},
152
136
  },
153
137
  plugins: [],
154
138
  };`;
155
- await fs.writeFile(path.join(projectDir, "tailwind.config.cjs"), tailwindConfig);
156
- console.log("Created tailwind.config.cjs");
139
+ await fs.writeFile(path.join(projectDir, "tailwind.config.cjs"), tailwindConfig);
140
+ console.log("Created tailwind.config.cjs");
157
141
 
158
- const postcssConfig = `module.exports = {
142
+ const postcssConfig = `export default {
159
143
  plugins: {
160
- tailwindcss: {},
144
+ "@tailwindcss/postcss": {},
161
145
  autoprefixer: {},
162
- },
163
- };`;
164
- await fs.writeFile(path.join(projectDir, "postcss.config.cjs"), postcssConfig);
165
- console.log("Created postcss.config.cjs");
166
146
  }
167
-
168
- // Create jsconfig.json for VSCode/IDE support
169
- const jsConfig = {
170
- compilerOptions: {
171
- jsx: "react",
172
- jsxFactory: "Vader.createElement",
173
- jsxFragmentFactory: "Fragment"
147
+ };`;
148
+ await fs.writeFile(path.join(projectDir, "postcss.config.cjs"), postcssConfig);
149
+ console.log("Created postcss.config.cjs");
174
150
  }
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
151
 
152
+ // Create vaderjs.config.ts regardless, add Tailwind plugin if needed
153
+ const vaderConfig = `import defineConfig from "vaderjs/config";
154
+ ${wantsTailwind ? 'import tailwind from "vaderjs/plugins/tailwind";' : ''}
155
+
156
+ export default defineConfig({
157
+ port: 3000,
158
+ plugins: [${wantsTailwind ? "tailwind" : ""}],
159
+ });`;
160
+
161
+ await fs.writeFile(path.join(projectDir, "vaderjs.config.ts"), vaderConfig);
162
+ console.log("Created vaderjs.config.ts");
163
+
164
+ // Create jsconfig.json for VSCode/IDE support
165
+ const jsConfig = {
166
+ compilerOptions: {
167
+ jsx: "react",
168
+ jsxFactory: "Vader.createElement",
169
+ jsxFragmentFactory: "Fragment",
170
+ },
171
+ };
172
+ await fs.writeFile(path.join(projectDir, "jsconfig.json"), JSON.stringify(jsConfig, null, 2));
173
+ console.log("Created jsconfig.json");
174
+
175
+ // Final instructions
176
+ const pkgJsonPath = path.join(projectDir, "package.json");
177
+
178
+ if (!fsSync.existsSync(pkgJsonPath)) {
179
+ // If package.json doesn't exist, create it with basic content
180
+ const pkg = {
181
+ name: path.basename(projectDir),
182
+ version: "1.0.0",
183
+ scripts: {
184
+ start: "bun run vaderjs build && bun run vaderjs serve",
185
+ build: "bun run vaderjs build",
186
+ dev: "bun run vaderjs dev",
187
+ },
188
+ dependencies: {
189
+ vaderjs: "latest",
190
+ },
191
+ };
192
+
193
+ // If Tailwind is requested, add it to the dependencies
194
+ if (wantsTailwind) {
195
+ pkg.dependencies.tailwindcss = "latest";
196
+ pkg.dependencies["@tailwindcss/postcss"] = "latest";
197
+ pkg.dependencies.postcss = "latest";
198
+ pkg.dependencies.autoprefixer = "latest";
199
+ }
200
+
201
+ await fs.writeFile(pkgJsonPath, JSON.stringify(pkg, null, 2));
202
+ console.log(`Created package.json`);
203
+ } else {
204
+ // If package.json exists, update it by adding Tailwind if it's not there
205
+ const pkgJson = JSON.parse(await fs.readFile(pkgJsonPath, "utf8"));
206
+
207
+ // Only update the dependencies and scripts if Tailwind is enabled
208
+ if (wantsTailwind && !pkgJson.dependencies.tailwindcss) {
209
+ pkgJson.dependencies.tailwindcss = "latest";
210
+ pkgJson.dependencies["@tailwindcss/postcss"] = "latest";
211
+ pkgJson.dependencies.postcss = "latest";
212
+ pkgJson.dependencies.autoprefixer = "latest";
213
+ }
214
+
215
+ // Ensure the scripts are in place (if they're not there already)
216
+ if (!pkgJson.scripts) pkgJson.scripts = {};
217
+ pkgJson.scripts.start = pkgJson.scripts.start || "bun run vaderjs build && bun run vaderjs serve";
218
+ pkgJson.scripts.build = pkgJson.scripts.build || "bun run vaderjs build";
219
+ pkgJson.scripts.dev = pkgJson.scripts.dev || "bun run vaderjs dev";
220
+
221
+ await fs.writeFile(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
222
+ console.log(`Updated package.json`);
223
+ }
185
224
 
186
-
225
+ console.log(`\nšŸŽ‰ Vader.js project initialized at:\n${projectDir}`);
226
+ console.log(`Run cd ${projectDir} to navigate into the project folder`);
227
+ console.log("Run `bun run dev` or your build script to get started.");
228
+ }
package/main.js CHANGED
@@ -82,7 +82,7 @@ const vaderAPI = {
82
82
 
83
83
  async function loadConfig() {
84
84
  try {
85
- const configModule = await import(path.join(PROJECT_ROOT, "vader.config.js"));
85
+ const configModule = await import(path.join(PROJECT_ROOT, "vaderjs.config.js"));
86
86
  return configModule.default || configModule;
87
87
  } catch {
88
88
  logger.warn("No 'vader.config.js' found, using defaults.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
4
4
  "description": "A simple and powerful JavaScript library for building modern web applications.",
5
5
  "bin": {
6
6
  "vaderjs": "./main.js"