vaderjs-native 1.0.37 → 1.0.38
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 +21 -21
- package/bun.lock +48 -0
- package/cli/android/build.ts +378 -378
- package/cli/android/dev.ts +129 -129
- package/cli.ts +353 -279
- package/jsconfig.json +6 -6
- package/main.ts +1002 -1026
- package/package.json +18 -18
- package/plugins/index.ts +63 -63
- /package/{README.MD → README.md} +0 -0
package/cli.ts
CHANGED
|
@@ -1,279 +1,353 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
import fs from "fs/promises";
|
|
3
|
-
import fsSync from "fs";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import readline from "readline";
|
|
6
|
-
|
|
7
|
-
const cwd = process.cwd();
|
|
8
|
-
|
|
9
|
-
/*
|
|
10
|
-
|
|
11
|
-
function ask(question: string): Promise<string> {
|
|
12
|
-
const rl = readline.createInterface({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
</
|
|
164
|
-
</div>
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import fs from "fs/promises";
|
|
3
|
+
import fsSync from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import readline from "readline";
|
|
6
|
+
|
|
7
|
+
const cwd = process.cwd();
|
|
8
|
+
|
|
9
|
+
/* ------------------------------------------------ utils ------------------------------------------------ */
|
|
10
|
+
|
|
11
|
+
function ask(question: string): Promise<string> {
|
|
12
|
+
const rl = readline.createInterface({
|
|
13
|
+
input: process.stdin,
|
|
14
|
+
output: process.stdout,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return new Promise(resolve =>
|
|
18
|
+
rl.question(question + " ", ans => {
|
|
19
|
+
rl.close();
|
|
20
|
+
resolve(ans.trim());
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function run(cmd: string, args: string[] = []) {
|
|
26
|
+
const proc = Bun.spawn([cmd, ...args], {
|
|
27
|
+
stdout: "inherit",
|
|
28
|
+
stderr: "inherit",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const code = await proc.exited;
|
|
32
|
+
if (code !== 0) process.exit(code);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function logSection(title: string) {
|
|
36
|
+
console.log(`\n${title}`);
|
|
37
|
+
console.log("─".repeat(title.length));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* ------------------------------------------------ frameworks ------------------------------------------------ */
|
|
41
|
+
|
|
42
|
+
const UI_FRAMEWORKS: Record<string, any> = {
|
|
43
|
+
none: {
|
|
44
|
+
name: "None (Basic)",
|
|
45
|
+
runtimeDeps: [],
|
|
46
|
+
devDeps: [],
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
daisyui: {
|
|
50
|
+
name: "VaderUI (DaisyUI)",
|
|
51
|
+
runtimeDeps: ["vaderjs-daisyui", "daisyui"],
|
|
52
|
+
devDeps: ["tailwindcss", "postcss", "autoprefixer"],
|
|
53
|
+
pluginImport: `import daisyui from "vaderjs-daisyui";`,
|
|
54
|
+
pluginRef: "daisyui",
|
|
55
|
+
requiresRootCss: true,
|
|
56
|
+
requiresTailwindConfig: true,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/* ------------------------------------------------ project generator ------------------------------------------------ */
|
|
61
|
+
|
|
62
|
+
export async function initProject(dir?: string) {
|
|
63
|
+
console.log("🚀 Initializing Vader.js project");
|
|
64
|
+
|
|
65
|
+
const projectDir = path.resolve(cwd, dir || ".");
|
|
66
|
+
|
|
67
|
+
if (!fsSync.existsSync(projectDir)) {
|
|
68
|
+
await fs.mkdir(projectDir, { recursive: true });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (fsSync.readdirSync(projectDir).length) {
|
|
72
|
+
const confirm = await ask("Directory is not empty. Continue? (y/n):");
|
|
73
|
+
if (confirm !== "y") process.exit(0);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* ---------------- language ---------------- */
|
|
77
|
+
|
|
78
|
+
console.log("\nSelect language:");
|
|
79
|
+
console.log(" 1. JavaScript");
|
|
80
|
+
console.log(" 2. TypeScript");
|
|
81
|
+
|
|
82
|
+
const useTypeScript = (await ask("Choose (1-2):")) === "2";
|
|
83
|
+
|
|
84
|
+
const fileExt = useTypeScript ? "tsx" : "jsx";
|
|
85
|
+
const configExt = useTypeScript ? "ts" : "js";
|
|
86
|
+
|
|
87
|
+
/* ---------------- port ---------------- */
|
|
88
|
+
|
|
89
|
+
const port = (await ask("Enter dev server port (default 5173):")) || "5173";
|
|
90
|
+
|
|
91
|
+
/* ---------------- framework ---------------- */
|
|
92
|
+
|
|
93
|
+
console.log("\nSelect UI framework:");
|
|
94
|
+
|
|
95
|
+
const keys = Object.keys(UI_FRAMEWORKS);
|
|
96
|
+
keys.forEach((k, i) => {
|
|
97
|
+
console.log(` ${i + 1}. ${UI_FRAMEWORKS[k].name}`);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const fwKey = keys[Number(await ask(`Choose (1-${keys.length}):`)) - 1];
|
|
101
|
+
const framework = UI_FRAMEWORKS[fwKey];
|
|
102
|
+
|
|
103
|
+
/* ------------------------------------------------ folders ------------------------------------------------ */
|
|
104
|
+
|
|
105
|
+
logSection("📁 Creating project structure");
|
|
106
|
+
|
|
107
|
+
for (const d of ["app", "src", "public"]) {
|
|
108
|
+
await fs.mkdir(path.join(projectDir, d), { recursive: true });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* ------------------------------------------------ framework configs ------------------------------------------------ */
|
|
112
|
+
|
|
113
|
+
if (framework.requiresRootCss) {
|
|
114
|
+
await fs.writeFile(
|
|
115
|
+
path.join(projectDir, "root.css"),
|
|
116
|
+
`@import "tailwindcss";
|
|
117
|
+
@plugin "daisyui";
|
|
118
|
+
`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (framework.requiresTailwindConfig) {
|
|
123
|
+
await fs.writeFile(
|
|
124
|
+
path.join(projectDir, "tailwind.config.js"),
|
|
125
|
+
`export default {
|
|
126
|
+
content: [
|
|
127
|
+
"./app/**/*.{js,jsx,ts,tsx}",
|
|
128
|
+
"./src/**/*.{js,jsx,ts,tsx}"
|
|
129
|
+
],
|
|
130
|
+
|
|
131
|
+
theme: { extend: {} },
|
|
132
|
+
|
|
133
|
+
plugins: [require("daisyui")]
|
|
134
|
+
};
|
|
135
|
+
`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* ------------------------------------------------ app/index template ------------------------------------------------ */
|
|
140
|
+
|
|
141
|
+
const appIndexTemplate = framework.pluginRef
|
|
142
|
+
? `
|
|
143
|
+
import * as Vader from "vaderjs-native";
|
|
144
|
+
import { useState } from "vaderjs-native";
|
|
145
|
+
import Button from "vaderjs-daisyui/Components/Actions/Button";
|
|
146
|
+
|
|
147
|
+
function Main() {
|
|
148
|
+
const [count, setCount] = useState(0);
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<div className="min-h-screen flex flex-col items-center justify-center bg-base-200">
|
|
152
|
+
<h1 className="text-5xl font-bold">
|
|
153
|
+
Vader<span className="text-primary">.js</span>
|
|
154
|
+
</h1>
|
|
155
|
+
|
|
156
|
+
<div className="mt-10 flex gap-4">
|
|
157
|
+
<Button color="primary" onClick={() => setCount(count + 1)}>
|
|
158
|
+
Count: {count}
|
|
159
|
+
</Button>
|
|
160
|
+
|
|
161
|
+
<Button color="secondary" onClick={() => setCount(0)}>
|
|
162
|
+
Reset
|
|
163
|
+
</Button>
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export default Main;
|
|
170
|
+
`
|
|
171
|
+
: `
|
|
172
|
+
import * as Vader from "vaderjs-native";
|
|
173
|
+
import { useState } from "vaderjs-native";
|
|
174
|
+
|
|
175
|
+
function Main() {
|
|
176
|
+
const [count, setCount] = useState(0);
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<div style={{
|
|
180
|
+
minHeight: "100vh",
|
|
181
|
+
display: "flex",
|
|
182
|
+
flexDirection: "column",
|
|
183
|
+
alignItems: "center",
|
|
184
|
+
justifyContent: "center",
|
|
185
|
+
fontFamily: "sans-serif"
|
|
186
|
+
}}>
|
|
187
|
+
<h1>Vader.js</h1>
|
|
188
|
+
|
|
189
|
+
<p>Zero plugin runtime.</p>
|
|
190
|
+
|
|
191
|
+
<button onClick={() => count + 1}>
|
|
192
|
+
Count: {count}
|
|
193
|
+
</button>
|
|
194
|
+
</div>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export default Main;
|
|
199
|
+
`;
|
|
200
|
+
|
|
201
|
+
await fs.writeFile(
|
|
202
|
+
path.join(projectDir, `app/index.${fileExt}`),
|
|
203
|
+
appIndexTemplate
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
/* ------------------------------------------------ Router scaffold ------------------------------------------------ */
|
|
207
|
+
|
|
208
|
+
const routerCode = `
|
|
209
|
+
import * as Vader from "vaderjs-native";
|
|
210
|
+
import { createRouter } from "vaderjs-native/router";
|
|
211
|
+
import Main from "../app/index";
|
|
212
|
+
|
|
213
|
+
export const router = createRouter({
|
|
214
|
+
routes: [
|
|
215
|
+
{
|
|
216
|
+
path: "/",
|
|
217
|
+
component: Main,
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
|
|
221
|
+
fallback: function NotFound() {
|
|
222
|
+
return <div style={{
|
|
223
|
+
padding: "40px",
|
|
224
|
+
textAlign: "center",
|
|
225
|
+
fontFamily: "sans-serif"
|
|
226
|
+
}}>
|
|
227
|
+
404 - Page Not Found
|
|
228
|
+
</div>;
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
`;
|
|
232
|
+
|
|
233
|
+
await fs.writeFile(
|
|
234
|
+
path.join(projectDir, "src/router.tsx"),
|
|
235
|
+
routerCode
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
/* ------------------------------------------------ App.tsx wrapper ------------------------------------------------ */
|
|
239
|
+
|
|
240
|
+
const appWrapper = `
|
|
241
|
+
import * as Vader from "vaderjs-native";
|
|
242
|
+
import { useRoute } from "vaderjs-native/router";
|
|
243
|
+
import { router } from "./src/router";
|
|
244
|
+
|
|
245
|
+
function App() {
|
|
246
|
+
const route = useRoute();
|
|
247
|
+
|
|
248
|
+
if (!route) {
|
|
249
|
+
const Fallback = router.getFallback();
|
|
250
|
+
return <Fallback />;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const Component = route.route.component;
|
|
254
|
+
return <Component />;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export default App;
|
|
258
|
+
`;
|
|
259
|
+
|
|
260
|
+
await fs.writeFile(path.join(projectDir, "App.tsx"), appWrapper);
|
|
261
|
+
|
|
262
|
+
/* ------------------------------------------------ jsconfig ------------------------------------------------ */
|
|
263
|
+
|
|
264
|
+
await fs.writeFile(
|
|
265
|
+
path.join(projectDir, "jsconfig.json"),
|
|
266
|
+
JSON.stringify(
|
|
267
|
+
{
|
|
268
|
+
compilerOptions: {
|
|
269
|
+
jsx: "react",
|
|
270
|
+
jsxFactory: "Vader.createElement",
|
|
271
|
+
jsxFragmentFactory: "Fragment",
|
|
272
|
+
},
|
|
273
|
+
include: ["app", "src"],
|
|
274
|
+
},
|
|
275
|
+
null,
|
|
276
|
+
2
|
|
277
|
+
)
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
/* ------------------------------------------------ config ------------------------------------------------ */
|
|
281
|
+
|
|
282
|
+
const name = path.basename(projectDir);
|
|
283
|
+
|
|
284
|
+
const pluginImport = framework.pluginImport
|
|
285
|
+
? framework.pluginImport + "\n"
|
|
286
|
+
: "";
|
|
287
|
+
|
|
288
|
+
const pluginsArray = framework.pluginRef
|
|
289
|
+
? `[${framework.pluginRef}]`
|
|
290
|
+
: `[]`;
|
|
291
|
+
|
|
292
|
+
const config = `
|
|
293
|
+
${pluginImport}
|
|
294
|
+
import defineConfig from "vaderjs-native/config";
|
|
295
|
+
|
|
296
|
+
export default defineConfig({
|
|
297
|
+
server: {
|
|
298
|
+
port: ${port}
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
app: {
|
|
302
|
+
name: "${name}",
|
|
303
|
+
id: "com.example.${name}",
|
|
304
|
+
version: { code: 1, name: "1.0.0" },
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
platforms: {
|
|
308
|
+
web: {
|
|
309
|
+
title: "${name}",
|
|
310
|
+
themeColor: "#111827"
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
|
|
314
|
+
plugins: ${pluginsArray}
|
|
315
|
+
});
|
|
316
|
+
`;
|
|
317
|
+
|
|
318
|
+
await fs.writeFile(
|
|
319
|
+
path.join(projectDir, `vaderjs.config.${configExt}`),
|
|
320
|
+
config
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
/* ------------------------------------------------ package.json ------------------------------------------------ */
|
|
324
|
+
|
|
325
|
+
const pkg = {
|
|
326
|
+
name,
|
|
327
|
+
version: "1.0.0",
|
|
328
|
+
type: "module",
|
|
329
|
+
dependencies: {
|
|
330
|
+
"vaderjs-native": "latest",
|
|
331
|
+
},
|
|
332
|
+
devDependencies: {},
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
framework.runtimeDeps?.forEach((d: string) => {
|
|
336
|
+
pkg.dependencies[d] = "latest";
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
framework.devDeps?.forEach((d: string) => {
|
|
340
|
+
pkg.devDependencies[d] = "latest";
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
await fs.writeFile(
|
|
344
|
+
path.join(projectDir, "package.json"),
|
|
345
|
+
JSON.stringify(pkg, null, 2)
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
logSection("📦 Installing dependencies");
|
|
349
|
+
|
|
350
|
+
await run("bun", ["install"]);
|
|
351
|
+
|
|
352
|
+
console.log(`\n✅ Project ready → http://localhost:${port}`);
|
|
353
|
+
}
|
package/jsconfig.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"jsx": "react",
|
|
4
|
-
"jsxFactory": "Vader.createElement",
|
|
5
|
-
"jsxFragmentFactory": "Fragment"
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"jsx": "react",
|
|
4
|
+
"jsxFactory": "Vader.createElement",
|
|
5
|
+
"jsxFragmentFactory": "Fragment"
|
|
6
|
+
}
|
|
7
7
|
}
|