create-vanilla-vite 1.0.1 → 1.0.2
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 +1 -1
- package/bin/create-template.mjs +99 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ pnpm create vanilla-vite@latest
|
|
|
37
37
|
npm create vanilla-vite@latest
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
The generator starts the official `create-vite@latest` wizard in `my-app-client`. Choose **React** for a React application, then select JavaScript or TypeScript. You can instead choose any other template offered by Vite. Afterward, choose whether to add a backend (frontend-only is the default). The frontend wizard may install dependencies temporarily; the generator removes nested install files and Git metadata, configures one shared workspace, and installs all dependencies from the project root.
|
|
40
|
+
The generator starts the official `create-vite@latest` wizard in `my-app-client`. Choose **React** for a React application, then select JavaScript or TypeScript. You can instead choose any other template offered by Vite. Afterward, choose whether to install Tailwind CSS v4 and Axios. For React templates, you can also choose React Icons, `@animateicons/react`, or no icon library. These options default to **No**. The generator then asks whether to add a backend (frontend-only is the default). The frontend wizard may install dependencies temporarily; the generator removes nested install files and Git metadata, configures one shared workspace, and installs all dependencies from the project root.
|
|
41
41
|
|
|
42
42
|
The optional backend supports JavaScript or TypeScript, either basic Node.js or Express, and a simple or module-based folder layout. Both layouts create the `src/app` and `src/server` entry points. The simple layout has `routes`, `controllers`, `middleware`, and `config` folders; the module-based layout has `module`, `config`, `middleware`, and `utils` folders plus `mainRouter`. Express adds Express and dotenv, enables JSON parsing, and provides `GET /api/health`, returning `{ "status": "ok" }`.
|
|
43
43
|
|
package/bin/create-template.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
4
4
|
import spawn from "cross-spawn";
|
|
5
5
|
import { emitKeypressEvents } from "node:readline";
|
|
6
6
|
import { createInterface } from "node:readline/promises";
|
|
7
7
|
import { stdin, stdout } from "node:process";
|
|
8
|
-
import { join, resolve } from "node:path";
|
|
8
|
+
import { dirname, join, resolve } from "node:path";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
|
|
11
11
|
const args = process.argv.slice(2);
|
|
@@ -161,6 +161,102 @@ async function selectOption(question, options, defaultIndex = 0) {
|
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
async function configureTailwind(clientRoot) {
|
|
165
|
+
const viteConfigName = (await readdir(clientRoot)).find((file) =>
|
|
166
|
+
/^vite\.config\.(?:[cm]?[jt]s)$/.test(file),
|
|
167
|
+
);
|
|
168
|
+
if (!viteConfigName) {
|
|
169
|
+
throw new Error("Could not find the Vite config to configure Tailwind CSS.");
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const viteConfigPath = join(clientRoot, viteConfigName);
|
|
173
|
+
let viteConfig = await readFile(viteConfigPath, "utf8");
|
|
174
|
+
if (!viteConfig.includes("@tailwindcss/vite")) {
|
|
175
|
+
viteConfig = `import tailwindcss from "@tailwindcss/vite";\n${viteConfig}`;
|
|
176
|
+
const plugins = /(\bplugins\s*:\s*\[)/;
|
|
177
|
+
if (plugins.test(viteConfig)) {
|
|
178
|
+
viteConfig = viteConfig.replace(plugins, "$1tailwindcss(), ");
|
|
179
|
+
} else {
|
|
180
|
+
const configObject = /(\bdefineConfig\s*\(\s*\{)/;
|
|
181
|
+
if (!configObject.test(viteConfig)) {
|
|
182
|
+
throw new Error("Could not add Tailwind CSS to the Vite config.");
|
|
183
|
+
}
|
|
184
|
+
viteConfig = viteConfig.replace(configObject, "$1\n plugins: [tailwindcss()],");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
await writeFile(viteConfigPath, viteConfig);
|
|
188
|
+
|
|
189
|
+
let entryPath;
|
|
190
|
+
for (const directory of [join(clientRoot, "src"), clientRoot]) {
|
|
191
|
+
let files;
|
|
192
|
+
try {
|
|
193
|
+
files = await readdir(directory);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
if (error.code === "ENOENT") continue;
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
const entryFile = files.find((file) => /^main\.[cm]?[jt]sx?$/.test(file));
|
|
199
|
+
if (entryFile) {
|
|
200
|
+
entryPath = join(directory, entryFile);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (!entryPath) {
|
|
205
|
+
throw new Error("Could not find the frontend entry file to configure Tailwind CSS.");
|
|
206
|
+
}
|
|
207
|
+
const entry = await readFile(entryPath, "utf8");
|
|
208
|
+
const cssImport = entry.match(/import\s+["']([^"']+\.css)["']/);
|
|
209
|
+
if (!cssImport) {
|
|
210
|
+
throw new Error("Could not find a CSS import to configure Tailwind CSS.");
|
|
211
|
+
}
|
|
212
|
+
const cssPath = resolve(dirname(entryPath), cssImport[1]);
|
|
213
|
+
const css = await readFile(cssPath, "utf8");
|
|
214
|
+
if (!css.includes('@import "tailwindcss";')) {
|
|
215
|
+
await writeFile(cssPath, `@import "tailwindcss";\n${css}`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function configureFrontend(clientRoot, clientPackage) {
|
|
220
|
+
const tailwind = await selectOption("Would you like to install Tailwind CSS?", [
|
|
221
|
+
{ label: "Yes — add Tailwind CSS v4", value: true },
|
|
222
|
+
{ label: "No (default)", value: false },
|
|
223
|
+
], 1);
|
|
224
|
+
const axios = await selectOption("Would you like to install Axios?", [
|
|
225
|
+
{ label: "Yes — add Axios", value: true },
|
|
226
|
+
{ label: "No (default)", value: false },
|
|
227
|
+
], 1);
|
|
228
|
+
const isReact = Boolean(
|
|
229
|
+
clientPackage.dependencies?.react || clientPackage.devDependencies?.react,
|
|
230
|
+
);
|
|
231
|
+
const installIcons =
|
|
232
|
+
isReact &&
|
|
233
|
+
(await selectOption("Would you like to install an icon library?", [
|
|
234
|
+
{ label: "Yes", value: true },
|
|
235
|
+
{ label: "No (default)", value: false },
|
|
236
|
+
], 1));
|
|
237
|
+
const icons = installIcons
|
|
238
|
+
? await selectOption("Which React icon library would you like to install?", [
|
|
239
|
+
{ label: "React Icons (default)", value: ["react-icons", "^5.7.0"] },
|
|
240
|
+
{ label: "@animateicons/react", value: ["@animateicons/react", "^0.13.0"] },
|
|
241
|
+
])
|
|
242
|
+
: null;
|
|
243
|
+
|
|
244
|
+
if (tailwind) {
|
|
245
|
+
clientPackage.devDependencies ??= {};
|
|
246
|
+
clientPackage.devDependencies["@tailwindcss/vite"] = "^4.3.4";
|
|
247
|
+
clientPackage.devDependencies.tailwindcss = "^4.3.4";
|
|
248
|
+
await configureTailwind(clientRoot);
|
|
249
|
+
}
|
|
250
|
+
if (axios) {
|
|
251
|
+
clientPackage.dependencies ??= {};
|
|
252
|
+
clientPackage.dependencies.axios = "^1.21.0";
|
|
253
|
+
}
|
|
254
|
+
if (icons) {
|
|
255
|
+
clientPackage.dependencies ??= {};
|
|
256
|
+
clientPackage.dependencies[icons[0]] = icons[1];
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
164
260
|
async function copyScript(name) {
|
|
165
261
|
const source = await readFile(join(scriptRoot, name), "utf8");
|
|
166
262
|
await writeFile(join(root, "scripts", name), source);
|
|
@@ -366,6 +462,7 @@ try {
|
|
|
366
462
|
const clientPackage = JSON.parse(await readFile(clientPackagePath, "utf8"));
|
|
367
463
|
clientPackage.scripts ??= {};
|
|
368
464
|
clientPackage.scripts.start ??= clientPackage.scripts.dev;
|
|
465
|
+
await configureFrontend(clientRoot, clientPackage);
|
|
369
466
|
await writeFile(clientPackagePath, `${JSON.stringify(clientPackage, null, 2)}\n`);
|
|
370
467
|
await writeFile(
|
|
371
468
|
join(clientRoot, ".env.local"),
|