vaderjs-native 1.0.21 → 1.0.22

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 (2) hide show
  1. package/cli.ts +91 -61
  2. package/package.json +1 -1
package/cli.ts CHANGED
@@ -7,25 +7,15 @@ import readline from "readline";
7
7
  const cwd = process.cwd();
8
8
 
9
9
  /* ------------------------------- utils ------------------------------- */
10
-
11
10
  function ask(question: string): Promise<string> {
12
- const rl = readline.createInterface({
13
- input: process.stdin,
14
- output: process.stdout,
15
- });
11
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
16
12
  return new Promise((resolve) =>
17
- rl.question(question + " ", (answer) => {
18
- rl.close();
19
- resolve(answer.trim());
20
- })
13
+ rl.question(question + " ", (answer) => { rl.close(); resolve(answer.trim()); })
21
14
  );
22
15
  }
23
16
 
24
17
  async function run(cmd: string, args: string[] = []): Promise<void> {
25
- const proc = Bun.spawn([cmd, ...args], {
26
- stdout: "inherit",
27
- stderr: "inherit",
28
- });
18
+ const proc = Bun.spawn([cmd, ...args], { stdout: "inherit", stderr: "inherit" });
29
19
  const status = await proc.exited;
30
20
  if (status !== 0) process.exit(status);
31
21
  }
@@ -40,7 +30,6 @@ function getFlags() {
40
30
  }
41
31
 
42
32
  /* ------------------------- UI Frameworks ------------------------- */
43
-
44
33
  const UI_FRAMEWORKS = {
45
34
  none: {
46
35
  name: "None (Basic)",
@@ -52,28 +41,28 @@ const UI_FRAMEWORKS = {
52
41
  name: "VaderUI (DaisyUI)",
53
42
  runtimeDeps: ["vaderjs-daisyui", "daisyui", "tailwindcss", "postcss", "autoprefixer"],
54
43
  devDeps: ["@tailwindcss/postcss"],
44
+ configPlugin: "await daisyui()",
55
45
  cssFile: `@import "tailwindcss"; @plugin "daisyui";`,
56
- description: "DaisyUI components for Vader.js",
46
+ description: "A comprehensive DaisyUI component library for Vader.js",
57
47
  },
58
48
  bootstrap: {
59
49
  name: "Bootstrap 5",
60
50
  runtimeDeps: ["vaderjs-bootstrap", "bootstrap"],
61
51
  devDeps: [],
52
+ configPlugin: "bootstrap",
62
53
  cssFile: `/* Import Bootstrap CSS in your HTML or via CDN */`,
63
54
  description: "Bootstrap 5 components rebuilt for Vader.js",
64
55
  },
65
56
  };
66
57
 
67
58
  /* ---------------------------- initProject ---------------------------- */
68
-
69
59
  export async function initProject(dir?: string) {
70
60
  const flags = getFlags();
71
61
  const autoYes = flags.has("--yes");
72
- const projectDir = path.resolve(cwd, dir || ".");
62
+ console.log("šŸš€ Initializing Vader.js project");
73
63
 
74
- if (!fsSync.existsSync(projectDir)) {
75
- await fs.mkdir(projectDir, { recursive: true });
76
- }
64
+ const projectDir = path.resolve(cwd, dir || ".");
65
+ if (!fsSync.existsSync(projectDir)) await fs.mkdir(projectDir, { recursive: true });
77
66
 
78
67
  const files = fsSync.readdirSync(projectDir);
79
68
  if (files.length && !autoYes) {
@@ -81,13 +70,13 @@ export async function initProject(dir?: string) {
81
70
  if (confirm !== "y") process.exit(0);
82
71
  }
83
72
 
84
- // Language selection
85
- console.log("\nSelect language:\n1. JavaScript\n2. TypeScript");
73
+ // Language
74
+ console.log("\nSelect language:\n 1. JavaScript\n 2. TypeScript");
86
75
  const useTypeScript = (await ask("Choose (1-2):")) === "2";
87
76
  const fileExt = useTypeScript ? "tsx" : "jsx";
88
77
  const configExt = useTypeScript ? "ts" : "js";
89
78
 
90
- // Framework selection
79
+ // Framework
91
80
  console.log("\nSelect a UI framework:");
92
81
  Object.values(UI_FRAMEWORKS).forEach((f, i) => {
93
82
  console.log(` ${i + 1}. ${f.name}`);
@@ -95,13 +84,14 @@ export async function initProject(dir?: string) {
95
84
  });
96
85
  const keys = Object.keys(UI_FRAMEWORKS);
97
86
  let frameworkKey = keys[parseInt(await ask(`Choose (1-${keys.length}):`)) - 1];
98
- const framework = UI_FRAMEWORKS[frameworkKey];
87
+ let framework = UI_FRAMEWORKS[frameworkKey];
99
88
 
100
89
  // Platforms
101
90
  console.log("\nSelect platforms to support:");
102
91
  const android = (await ask("Include Android support? (y/n):")).toLowerCase() === "y";
103
92
  const windows = (await ask("Include Windows support? (y/n):")).toLowerCase() === "y";
104
93
 
94
+ // Create folders
105
95
  logSection("šŸ“ Creating folders");
106
96
  for (const d of ["app", "src", "public"]) {
107
97
  const p = path.join(projectDir, d);
@@ -110,10 +100,45 @@ export async function initProject(dir?: string) {
110
100
  if (android) await fs.mkdir(path.join(projectDir, "assets/android"), { recursive: true });
111
101
  if (windows) await fs.mkdir(path.join(projectDir, "assets/windows"), { recursive: true });
112
102
 
103
+ // Starter app
113
104
  logSection("🧱 Writing files");
105
+ let appCode = "";
106
+ if (frameworkKey === "daisyui") {
107
+ appCode = `import * as Vader from "vaderjs-native";
108
+ import { useState } from "vaderjs-native";
109
+ import Button from "vaderjs-daisyui/Components/Actions/Button";
110
+ import { Card } from "vaderjs-daisyui/Components/Data/Display/Card";
111
+ import { Badge } from "vaderjs-daisyui/Components/Data/Display/Badge";
114
112
 
115
- // Starter app
116
- const appCode = `import * as Vader from "vaderjs-native";
113
+ function Main() {
114
+ const [count, setCount] = useState(0);
115
+ return (
116
+ <div className="min-h-screen bg-base-200 p-8">
117
+ <div className="max-w-4xl mx-auto text-center">
118
+ <h1 className="text-4xl font-bold text-primary mb-4">šŸŽ‰ Welcome to Vader.js!</h1>
119
+ <p className="text-lg text-base-content">With ${framework.name} components</p>
120
+ <Badge color="primary" className="mt-2">v1.0.0</Badge>
121
+ </div>
122
+
123
+ <Card className="mt-8 p-6" title="Interactive Demo">
124
+ <div className="flex flex-col md:flex-row justify-between items-center gap-4">
125
+ <div>
126
+ <p className="text-xl font-semibold">Counter: {count}</p>
127
+ </div>
128
+ <div className="flex gap-3">
129
+ <Button color="primary" onClick={() => setCount(count + 1)}>Increment</Button>
130
+ <Button color="secondary" onClick={() => setCount(0)}>Reset</Button>
131
+ <Button color="accent" onClick={() => alert(\`Count is: \${count}\`)}>Show Alert</Button>
132
+ </div>
133
+ </div>
134
+ </Card>
135
+ </div>
136
+ );
137
+ }
138
+
139
+ Vader.render(Vader.createElement(Main), document.getElementById("app"));`;
140
+ } else {
141
+ appCode = `import * as Vader from "vaderjs-native";
117
142
  import { useState } from "vaderjs-native";
118
143
 
119
144
  function Main() {
@@ -128,8 +153,9 @@ function Main() {
128
153
  );
129
154
  }
130
155
 
131
- Vader.render(Vader.createElement(Main), document.getElementById("app"));
132
- `;
156
+ Vader.render(Vader.createElement(Main), document.getElementById("app"));`;
157
+ }
158
+
133
159
  await fs.writeFile(path.join(projectDir, `app/index.${fileExt}`), appCode);
134
160
  await fs.writeFile(path.join(projectDir, "public/styles.css"), framework.cssFile || "");
135
161
  console.log("created app/index & styles");
@@ -149,36 +175,46 @@ Vader.render(Vader.createElement(Main), document.getElementById("app"));
149
175
  console.log("created jsconfig.json");
150
176
 
151
177
  // Config file
152
- const configContent = `import defineConfig from "vaderjs-native/config";
178
+ let configImport = "";
179
+ let configPlugins = "[]";
180
+ if (framework.configPlugin) {
181
+ if (frameworkKey === "daisyui") configImport = 'import daisyui from "vaderjs-daisyui";\n';
182
+ if (frameworkKey === "bootstrap") configImport = 'import bootstrap from "vaderjs-bootstrap";\n';
183
+ configPlugins = `[${framework.configPlugin}]`;
184
+ }
185
+
186
+ const configContent = `${configImport}import defineConfig from "vaderjs-native/config";
153
187
 
154
188
  export default defineConfig({
155
- app: { name: "${path.basename(projectDir)}" },
189
+ app: {
190
+ name: "${path.basename(projectDir)}",
191
+ id: "com.example.${path.basename(projectDir).toLowerCase()}",
192
+ version: { code: 1, name: "1.0.0" },
193
+ },
156
194
  platforms: {
157
- ${android ? `android: { minSdk: 24, targetSdk: 34 },` : ""}
158
- web: { title: "${path.basename(projectDir)}" },
159
- ${windows ? `windows: { width: 1200, height: 800 },` : ""}
195
+ ${android ? `android: { minSdk: 24, targetSdk: 34, permissions: ["INTERNET","ACCESS_NETWORK_STATE"], icon: "./assets/android/icon.png", splash: "./assets/android/splash.png" },` : ""}
196
+ web: { title: "${path.basename(projectDir)}", themeColor: "#111827" },
197
+ ${windows ? `windows: { width: 1200, height: 800, title: "${path.basename(projectDir)}" },` : ""}
160
198
  },
161
- plugins: [],
199
+ plugins: ${configPlugins}
162
200
  });
163
201
  `;
164
- const configExtFinal = useTypeScript ? "ts" : "js";
165
- await fs.writeFile(path.join(projectDir, `vaderjs.config.${configExtFinal}`), configContent);
202
+
203
+ await fs.writeFile(path.join(projectDir, `vaderjs.config.${configExt}`), configContent);
204
+ console.log(`created vaderjs.config.${configExt}`);
166
205
 
167
206
  // Package.json
168
207
  const pkgPath = path.join(projectDir, "package.json");
169
208
  let pkg = fsSync.existsSync(pkgPath)
170
209
  ? JSON.parse(await fs.readFile(pkgPath, "utf8"))
171
- : {
172
- name: path.basename(projectDir),
173
- version: "1.0.0",
174
- type: "module",
175
- scripts: { dev: "bun run vaderjs dev", build: "bun run vaderjs build", serve: "bun run vaderjs serve" },
176
- dependencies: { "vaderjs-native": "latest" },
177
- devDependencies: {},
178
- };
210
+ : { name: path.basename(projectDir), version: "1.0.0", type: "module", scripts: {}, dependencies: { "vaderjs-native": "latest" }, devDependencies: {} };
211
+
212
+ pkg.devDependencies = pkg.devDependencies || {};
213
+ pkg.dependencies = pkg.dependencies || {};
179
214
 
180
215
  let shouldInstall = false;
181
216
 
217
+ // TypeScript
182
218
  if (useTypeScript) {
183
219
  pkg.devDependencies.typescript = "^5.0.0";
184
220
  pkg.devDependencies["@types/bun"] = "latest";
@@ -186,27 +222,25 @@ export default defineConfig({
186
222
  shouldInstall = true;
187
223
  }
188
224
 
189
- // Runtime & dev deps
225
+ // Add framework deps
190
226
  if (framework.runtimeDeps) framework.runtimeDeps.forEach((d) => { pkg.dependencies[d] = "latest"; shouldInstall = true; });
191
227
  if (framework.devDeps) framework.devDeps.forEach((d) => { pkg.devDependencies[d] = "latest"; shouldInstall = true; });
192
228
 
193
229
  await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2));
230
+
194
231
  if (shouldInstall) {
195
232
  logSection("šŸ“¦ Installing dependencies");
196
233
  await run("bun", ["install"]);
197
- } else {
198
- console.log("šŸ“¦ Dependencies already satisfied");
199
234
  }
200
235
 
201
236
  console.log("\nāœ… Project ready!");
202
- };
237
+ }
203
238
 
204
239
  /* ---------------------------- addPlugin ---------------------------- */
205
240
  export async function addPlugin(name: string) {
206
241
  if (!name) return console.error("Please specify a plugin to add.");
207
242
  const flags = getFlags();
208
243
  const force = flags.has("--force");
209
-
210
244
  const pkgName = name.startsWith("vaderjs-") ? name : `vaderjs-${name}`;
211
245
  const importName = pkgName.replace(/^vaderjs-/, "").replace(/-/g, "_");
212
246
 
@@ -216,22 +250,19 @@ export async function addPlugin(name: string) {
216
250
  const configPathTS = path.join(cwd, "vaderjs.config.ts");
217
251
  const configPathJS = path.join(cwd, "vaderjs.config.js");
218
252
  const configPath = fsSync.existsSync(configPathTS) ? configPathTS : configPathJS;
219
- if (!fsSync.existsSync(configPath)) return console.warn("āš ļø Config file not found");
253
+ if (!fsSync.existsSync(configPath)) return console.warn("āš ļø Config not found, skipping plugin registration");
220
254
 
221
255
  let config = await fs.readFile(configPath, "utf8");
222
- if (!config.includes(`from "${pkgName}"`)) {
223
- config = `import ${importName} from "${pkgName}";\n` + config.replace(/plugins:\s*\[/, `plugins: [${importName}, `);
224
- await fs.writeFile(configPath, config);
225
- console.log("āœ” Plugin registered");
226
- } else {
227
- console.log("ā„¹ļø Plugin already registered");
228
- }
256
+ if (config.includes(`from "${pkgName}"`)) return console.log("ā„¹ļø Plugin already registered");
257
+
258
+ config = `import ${importName} from "${pkgName}";\n` + config.replace(/plugins:\s*\[/, `plugins: [${importName}, `);
259
+ await fs.writeFile(configPath, config);
260
+ console.log("āœ” Plugin registered");
229
261
  }
230
262
 
231
263
  /* ---------------------------- removePlugin ---------------------------- */
232
264
  export async function removePlugin(name: string) {
233
265
  if (!name) return console.error("Please specify a plugin to remove.");
234
-
235
266
  const pkgName = name.startsWith("vaderjs-") ? name : `vaderjs-${name}`;
236
267
  const importName = pkgName.replace(/^vaderjs-/, "").replace(/-/g, "_");
237
268
 
@@ -244,9 +275,8 @@ export async function removePlugin(name: string) {
244
275
  if (!fsSync.existsSync(configPath)) return;
245
276
 
246
277
  let config = await fs.readFile(configPath, "utf8");
247
- config = config
248
- .replace(new RegExp(`import ${importName} from ".*?";\\n?`, "g"), "")
249
- .replace(new RegExp(`\\b${importName},?\\s*`, "g"), "");
278
+ config = config.replace(new RegExp(`import ${importName} from ".*?";\\n?`, "g"), "")
279
+ .replace(new RegExp(`\\b${importName},?\\s*`, "g"), "");
250
280
  await fs.writeFile(configPath, config);
251
281
  console.log("āœ” Plugin removed");
252
282
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs-native",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "Build Native Applications using Vaderjs framework.",
5
5
  "bin": {
6
6
  "vaderjs": "./main.ts"