vaderjs-native 1.0.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/LICENSE +21 -0
- package/README.MD +99 -0
- package/app-template/.idea/.name +1 -0
- package/app-template/.idea/AndroidProjectSystem.xml +6 -0
- package/app-template/.idea/codeStyles/Project.xml +123 -0
- package/app-template/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/app-template/.idea/compiler.xml +6 -0
- package/app-template/.idea/deploymentTargetSelector.xml +10 -0
- package/app-template/.idea/gradle.xml +19 -0
- package/app-template/.idea/inspectionProfiles/Project_Default.xml +61 -0
- package/app-template/.idea/migrations.xml +10 -0
- package/app-template/.idea/misc.xml +9 -0
- package/app-template/.idea/runConfigurations.xml +17 -0
- package/app-template/app/build.gradle.kts +54 -0
- package/app-template/app/proguard-rules.pro +21 -0
- package/app-template/app/src/main/AndroidManifest.xml +31 -0
- package/app-template/app/src/main/java/com/example/myapplication/MainActivity.kt +74 -0
- package/app-template/app/src/main/java/com/example/myapplication/ui/theme/Color.kt +11 -0
- package/app-template/app/src/main/java/com/example/myapplication/ui/theme/Theme.kt +34 -0
- package/app-template/app/src/main/java/com/example/myapplication/ui/theme/Type.kt +36 -0
- package/app-template/app/src/main/res/mipmap-hdpi/ic_launcher.webp +0 -0
- package/app-template/app/src/main/res/mipmap-mdpi/ic_launcher.webp +0 -0
- package/app-template/app/src/main/res/mipmap-xhdpi/ic_launcher.webp +0 -0
- package/app-template/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp +0 -0
- package/app-template/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp +0 -0
- package/app-template/app/src/main/res/values/strings.xml +3 -0
- package/app-template/app/src/main/res/values/themes.xml +4 -0
- package/app-template/build.gradle.kts +5 -0
- package/app-template/gradle/libs.versions.toml +30 -0
- package/app-template/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/app-template/gradle/wrapper/gradle-wrapper.properties +9 -0
- package/app-template/gradle.properties +23 -0
- package/app-template/gradlew +251 -0
- package/app-template/gradlew.bat +94 -0
- package/app-template/settings.gradle.kts +23 -0
- package/cli.ts +232 -0
- package/config/index.ts +14 -0
- package/index.ts +1083 -0
- package/jsconfig.json +7 -0
- package/logo.png +0 -0
- package/main.js +643 -0
- package/package.json +20 -0
- package/plugins/index.ts +63 -0
- package/plugins/tailwind.ts +53 -0
package/cli.ts
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
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 * as Vader from "vader-native";
|
|
76
|
+
|
|
77
|
+
function Counter() {
|
|
78
|
+
let [count, setCount] = Vader.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
|
+
Vader.render(Vader.createElement(Counter, null), document.getElementById("app"));
|
|
94
|
+
`
|
|
95
|
+
: `import * as Vader from "vader-native";
|
|
96
|
+
|
|
97
|
+
function Counter() {
|
|
98
|
+
let [count, setCount] = Vader.useState(0);
|
|
99
|
+
return (
|
|
100
|
+
<div style={{ maxWidth: "300px", margin: "auto", padding: "1rem", background: "#eee", borderRadius: "8px", textAlign: "center" }}>
|
|
101
|
+
<h1 style={{ fontWeight: "bold", marginBottom: "1rem" }}>Counter Example</h1>
|
|
102
|
+
<p style={{ fontSize: "1.25rem", marginBottom: "1rem" }}>Count: {count}</p>
|
|
103
|
+
<button onClick={() => setCount(count + 1)}>Increment</button>
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
Vader.render(Vader.createElement(Counter, null), document.getElementById("app"));
|
|
109
|
+
`;
|
|
110
|
+
|
|
111
|
+
await fs.writeFile(path.join(appDir, "index.jsx"), counterCode);
|
|
112
|
+
console.log(`Created example route: ${path.join("app", "index.jsx")}`);
|
|
113
|
+
|
|
114
|
+
// Create public/styles.css
|
|
115
|
+
if (wantsTailwind) {
|
|
116
|
+
await fs.writeFile(path.join(publicDir, "styles.css"), `@import 'tailwindcss';\n`);
|
|
117
|
+
} else {
|
|
118
|
+
await fs.writeFile(path.join(publicDir, "styles.css"), `/* Add your styles here */\n`);
|
|
119
|
+
}
|
|
120
|
+
console.log(`Created public/styles.css`);
|
|
121
|
+
|
|
122
|
+
// Create minimal package.json if not exist
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
// Install dependencies: vaderjs + optionally tailwindcss, postcss plugins, autoprefixer
|
|
126
|
+
console.log("Installing dependencies with Bun...");
|
|
127
|
+
const deps = ["vaderjs", "autoprefixer"];
|
|
128
|
+
if (wantsTailwind) {
|
|
129
|
+
deps.push("tailwindcss@4", "@tailwindcss/postcss", "postcss-cli");
|
|
130
|
+
}
|
|
131
|
+
await run("bun", ["install", ...deps]);
|
|
132
|
+
console.log("ā
Dependencies installed.");
|
|
133
|
+
|
|
134
|
+
// If Tailwind requested, create minimal tailwind.config.cjs and postcss.config.cjs
|
|
135
|
+
if (wantsTailwind) {
|
|
136
|
+
const tailwindConfig = `module.exports = {
|
|
137
|
+
content: ["./app/**/*.{js,jsx,ts,tsx}"],
|
|
138
|
+
theme: {
|
|
139
|
+
extend: {},
|
|
140
|
+
},
|
|
141
|
+
plugins: [],
|
|
142
|
+
};`;
|
|
143
|
+
await fs.writeFile(path.join(projectDir, "tailwind.config.cjs"), tailwindConfig);
|
|
144
|
+
console.log("Created tailwind.config.cjs");
|
|
145
|
+
|
|
146
|
+
const postcssConfig = `export default {
|
|
147
|
+
plugins: {
|
|
148
|
+
"@tailwindcss/postcss": {},
|
|
149
|
+
autoprefixer: {},
|
|
150
|
+
}
|
|
151
|
+
};`;
|
|
152
|
+
await fs.writeFile(path.join(projectDir, "postcss.config.cjs"), postcssConfig);
|
|
153
|
+
console.log("Created postcss.config.cjs");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Create vaderjs.config.ts regardless, add Tailwind plugin if needed
|
|
157
|
+
const vaderConfig = `import defineConfig from "vader-native/config";
|
|
158
|
+
${wantsTailwind ? 'import tailwind from "vader-native/plugins/tailwind";' : ''}
|
|
159
|
+
|
|
160
|
+
export default defineConfig({
|
|
161
|
+
port: 3000,
|
|
162
|
+
plugins: [${wantsTailwind ? "tailwind" : ""}],
|
|
163
|
+
});`;
|
|
164
|
+
|
|
165
|
+
await fs.writeFile(path.join(projectDir, "vaderjs.config.ts"), vaderConfig);
|
|
166
|
+
console.log("Created vaderjs.config.ts");
|
|
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
|
+
const pkgJsonPath = path.join(projectDir, "package.json");
|
|
181
|
+
|
|
182
|
+
if (!fsSync.existsSync(pkgJsonPath)) {
|
|
183
|
+
// If package.json doesn't exist, create it with basic content
|
|
184
|
+
const pkg = {
|
|
185
|
+
name: path.basename(projectDir),
|
|
186
|
+
version: "1.0.0",
|
|
187
|
+
scripts: {
|
|
188
|
+
start: "bun run vaderjs build && bun run vaderjs serve",
|
|
189
|
+
build: "bun run vaderjs build",
|
|
190
|
+
dev: "bun run vaderjs dev",
|
|
191
|
+
},
|
|
192
|
+
dependencies: {
|
|
193
|
+
vaderjs: "latest",
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// If Tailwind is requested, add it to the dependencies
|
|
198
|
+
if (wantsTailwind) {
|
|
199
|
+
pkg.dependencies.tailwindcss = "latest";
|
|
200
|
+
pkg.dependencies["@tailwindcss/postcss"] = "latest";
|
|
201
|
+
pkg.dependencies.postcss = "latest";
|
|
202
|
+
pkg.dependencies.autoprefixer = "latest";
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
await fs.writeFile(pkgJsonPath, JSON.stringify(pkg, null, 2));
|
|
206
|
+
console.log(`Created package.json`);
|
|
207
|
+
} else {
|
|
208
|
+
// If package.json exists, update it by adding Tailwind if it's not there
|
|
209
|
+
const pkgJson = JSON.parse(await fs.readFile(pkgJsonPath, "utf8"));
|
|
210
|
+
|
|
211
|
+
// Only update the dependencies and scripts if Tailwind is enabled
|
|
212
|
+
if (wantsTailwind && !pkgJson.dependencies.tailwindcss) {
|
|
213
|
+
pkgJson.dependencies.tailwindcss = "latest";
|
|
214
|
+
pkgJson.dependencies["@tailwindcss/postcss"] = "latest";
|
|
215
|
+
pkgJson.dependencies.postcss = "latest";
|
|
216
|
+
pkgJson.dependencies.autoprefixer = "latest";
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Ensure the scripts are in place (if they're not there already)
|
|
220
|
+
if (!pkgJson.scripts) pkgJson.scripts = {};
|
|
221
|
+
pkgJson.scripts.start = pkgJson.scripts.start || "bun run vaderjs build && bun run vaderjs serve";
|
|
222
|
+
pkgJson.scripts.build = pkgJson.scripts.build || "bun run vaderjs build";
|
|
223
|
+
pkgJson.scripts.dev = pkgJson.scripts.dev || "bun run vaderjs dev";
|
|
224
|
+
|
|
225
|
+
await fs.writeFile(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
|
|
226
|
+
console.log(`Updated package.json`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
console.log(`\nš Vader.js project initialized at:\n${projectDir}`);
|
|
230
|
+
console.log(`Run cd ${projectDir} to navigate into the project folder`);
|
|
231
|
+
console.log("Run `bun run dev` or your build script to get started.");
|
|
232
|
+
}
|
package/config/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type Config = {
|
|
2
|
+
port: number,
|
|
3
|
+
host?: string,
|
|
4
|
+
plugins?: any[],
|
|
5
|
+
generateTypes?: boolean,
|
|
6
|
+
host_provider?: 'vercel' | 'netlify' | 'aws' | 'gcp' | 'azure' | 'heroku' | 'custom' | 'apache' | 'none',
|
|
7
|
+
host_provider_options?: {
|
|
8
|
+
[key: string]: any
|
|
9
|
+
},
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default function defineConfig(config: Config) {
|
|
13
|
+
return config
|
|
14
|
+
}
|