create-vanilla-vite 1.0.0 → 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 CHANGED
@@ -13,6 +13,8 @@ Create a Vite app with the official interactive setup. Choose React or any other
13
13
  - Node.js 20 or newer
14
14
  - npm or pnpm
15
15
 
16
+ The commands below work in Windows PowerShell or Command Prompt as well as macOS and Linux terminals. pnpm commands require pnpm to be installed; npm is sufficient.
17
+
16
18
  ## Create a project
17
19
 
18
20
  With pnpm:
@@ -35,7 +37,7 @@ pnpm create vanilla-vite@latest
35
37
  npm create vanilla-vite@latest
36
38
  ```
37
39
 
38
- 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.
39
41
 
40
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" }`.
41
43
 
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
4
- import { spawn } from "node:child_process";
3
+ import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
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);
@@ -43,11 +43,12 @@ const clientFolder = `${projectName}-client`;
43
43
  const serverFolder = `${projectName}-server`;
44
44
  const packageRoot = fileURLToPath(new URL("../", import.meta.url));
45
45
  const scriptRoot = fileURLToPath(new URL("../scripts/", import.meta.url));
46
+ const cliPackage = JSON.parse(
47
+ await readFile(join(packageRoot, "package.json"), "utf8"),
48
+ );
46
49
 
47
50
  async function updateIfOutdated() {
48
- const { version: installedVersion } = JSON.parse(
49
- await readFile(join(packageRoot, "package.json"), "utf8"),
50
- );
51
+ const { version: installedVersion } = cliPackage;
51
52
  const registry = (process.env.npm_config_registry || "https://registry.npmjs.org")
52
53
  .replace(/\/$/, "");
53
54
 
@@ -160,6 +161,102 @@ async function selectOption(question, options, defaultIndex = 0) {
160
161
  });
161
162
  }
162
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
+
163
260
  async function copyScript(name) {
164
261
  const source = await readFile(join(scriptRoot, name), "utf8");
165
262
  await writeFile(join(root, "scripts", name), source);
@@ -365,6 +462,7 @@ try {
365
462
  const clientPackage = JSON.parse(await readFile(clientPackagePath, "utf8"));
366
463
  clientPackage.scripts ??= {};
367
464
  clientPackage.scripts.start ??= clientPackage.scripts.dev;
465
+ await configureFrontend(clientRoot, clientPackage);
368
466
  await writeFile(clientPackagePath, `${JSON.stringify(clientPackage, null, 2)}\n`);
369
467
  await writeFile(
370
468
  join(clientRoot, ".env.local"),
@@ -400,6 +498,9 @@ try {
400
498
  ...(includeServer ? { server: "node scripts/run-app.mjs server" } : {}),
401
499
  },
402
500
  type: "module",
501
+ dependencies: {
502
+ "cross-spawn": cliPackage.dependencies["cross-spawn"],
503
+ },
403
504
  };
404
505
  await writeFile(join(root, "package.json"), `${JSON.stringify(rootPackage, null, 2)}\n`);
405
506
  await writeFile(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-vanilla-vite",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Scaffold a React or Vite app with an optional Node.js or Express backend",
5
5
  "type": "module",
6
6
  "repository": {
@@ -42,5 +42,8 @@
42
42
  "javascript",
43
43
  "cli"
44
44
  ],
45
- "license": "ISC"
45
+ "license": "ISC",
46
+ "dependencies": {
47
+ "cross-spawn": "^7.0.6"
48
+ }
46
49
  }
package/scripts/dev.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { spawn } from "node:child_process";
1
+ import spawn from "cross-spawn";
2
2
  import { readFile } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
@@ -1,4 +1,4 @@
1
- import { spawn } from "node:child_process";
1
+ import spawn from "cross-spawn";
2
2
  import { readFile } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";