create-vanilla-vite 1.0.1 → 1.1.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/README.md CHANGED
@@ -4,9 +4,9 @@ Create a Vite app with the official interactive setup. Choose React or any other
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/create-vanilla-vite)](https://www.npmjs.com/package/create-vanilla-vite)
6
6
  [![npm downloads](https://img.shields.io/npm/dm/create-vanilla-vite)](https://www.npmjs.com/package/create-vanilla-vite)
7
- [![GitHub repository](https://img.shields.io/badge/GitHub-Wasib--2005%2Fvanilla--vite-181717?logo=github)](https://github.com/Wasib-2005/vanilla-vite)
7
+ [![GitHub repository](https://img.shields.io/badge/GitHub-Wasib--2005%2FVanilla--Vite-181717?logo=github)](https://github.com/Wasib-2005/Vanilla-Vite)
8
8
 
9
- **Links:** [npm package](https://www.npmjs.com/package/create-vanilla-vite) · [GitHub repository](https://github.com/Wasib-2005/vanilla-vite) · [Report an issue](https://github.com/Wasib-2005/vanilla-vite/issues)
9
+ **Links:** [npm package](https://www.npmjs.com/package/create-vanilla-vite) · [GitHub repository](https://github.com/Wasib-2005/Vanilla-Vite) · [Report an issue](https://github.com/Wasib-2005/Vanilla-Vite/issues)
10
10
 
11
11
  ## Requirements
12
12
 
@@ -37,9 +37,9 @@ 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 Router, which adds a `MainRouter` with Home and Login pages and navigation. The router starter uses Tailwind utility classes when Tailwind is selected, or a standalone stylesheet otherwise. You can also choose React Icons or `@animateicons/react`. The Yes option is preselected for each yes/no prompt, including adding a backend; choose No to skip an option. Frontend setup questions appear in cyan, and backend setup questions appear in yellow. 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
- 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" }`.
42
+ The optional backend supports JavaScript or TypeScript, either basic Node.js or Express, and a simple or module-based folder layout. Express and the module-based layout are preselected by default; Express adds Express and dotenv, enables JSON parsing, and provides `GET /api/health`, returning `{ "status": "ok" }`. 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`. The `--default` flag selects the simple layout without prompting.
43
43
 
44
44
  Pass `--default` after the project name to use the simple backend folder layout without prompting:
45
45
 
@@ -63,7 +63,8 @@ The frontend gets a `.env.local` file with `VITE_API_URL=http://localhost:4000`.
63
63
 
64
64
  ## Run the project
65
65
 
66
- From the project root:
66
+ The generator starts the development server automatically after creating the
67
+ project. To start it again later, run this from the project root:
67
68
 
68
69
  ```bash
69
70
  pnpm dev
@@ -71,7 +72,7 @@ pnpm dev
71
72
  npm run dev
72
73
  ```
73
74
 
74
- This starts the frontend and, if selected, the backend together. In an interactive terminal, press `r` to restart both apps, `c` to clear the terminal, or Ctrl+C to stop.
75
+ This starts the frontend (bound to network interfaces with Vite's `--host` flag) and, if selected, the backend together. In an interactive terminal, press `r` to restart both apps, `c` to clear the terminal, or Ctrl+C to stop.
75
76
 
76
77
  Run one workspace individually:
77
78
 
@@ -91,28 +92,31 @@ The server commands are only available if you chose a backend. Add `-dev` to run
91
92
 
92
93
  ## Add dependencies
93
94
 
94
- With pnpm:
95
+ Always use one of these commands to add dependencies. The prompt lets you
96
+ choose the project root, client, or server (if you created one):
95
97
 
96
98
  ```bash
97
- pnpm client add <package>
98
- pnpm server add <package>
99
+ pnpm adD <package>
100
+ pnpm add-dependency <package>
101
+ npm run adD -- <package>
102
+ npm run add-dependency -- <package>
99
103
  ```
100
104
 
101
- With npm:
102
-
103
- ```bash
104
- npm install <package> --workspace=my-app-client
105
- npm install <package> --workspace=my-app-server
106
- ```
105
+ Do not use `npm install`, `npm add`, `pnpm install`, or `pnpm add` directly to
106
+ add packages. They bypass the location prompt or are blocked by the workspace
107
+ install guard. npm requires `run` to invoke a project script, so `npm adD`
108
+ without `run` is not valid.
107
109
 
108
110
  ## Development
109
111
 
110
- To test the source before publishing:
112
+ To test from the source:
111
113
 
112
114
  ```bash
113
- pnpm exec node ./bin/create-template.mjs my-app
115
+ git clone https://github.com/Wasib-2005/Vanilla-Vite
116
+
117
+ pnpm exec node [Stored Path]/Vanilla-Vite/bin/create-template.mjs my-app
114
118
  # or
115
- npm exec -- node ./bin/create-template.mjs my-app
119
+ npm exec -- node [Stored Path]/Vanilla-Vite/bin/create-template.mjs my-app
116
120
  ```
117
121
 
118
122
  ## License
@@ -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);
@@ -104,9 +104,9 @@ async function updateIfOutdated() {
104
104
  process.exit(0);
105
105
  }
106
106
 
107
- function run(command, commandArgs, cwd) {
107
+ function run(command, commandArgs, cwd, env = process.env) {
108
108
  return new Promise((resolveRun, rejectRun) => {
109
- const child = spawn(command, commandArgs, { cwd, stdio: "inherit" });
109
+ const child = spawn(command, commandArgs, { cwd, stdio: "inherit", env });
110
110
  child.once("error", rejectRun);
111
111
  child.once("close", (code, signal) => {
112
112
  if (code === 0) resolveRun();
@@ -119,14 +119,17 @@ function run(command, commandArgs, cwd) {
119
119
  });
120
120
  }
121
121
 
122
- async function selectOption(question, options, defaultIndex = 0) {
122
+ async function selectOption(question, options, defaultIndex = 0, color = "cyan") {
123
123
  if (!stdin.isTTY) return options[defaultIndex].value;
124
124
  let selected = defaultIndex;
125
125
  emitKeypressEvents(stdin);
126
126
 
127
127
  return new Promise((resolveSelection) => {
128
128
  function render() {
129
- stdout.write(`\r\x1b[2K${question}\n`);
129
+ const prompt = stdout.isTTY && process.env.NO_COLOR === undefined
130
+ ? `\x1b[1;${color === "cyan" ? "36" : "33"}m${question}\x1b[0m`
131
+ : question;
132
+ stdout.write(`\r\x1b[2K${prompt}\n`);
130
133
  for (const [index, option] of options.entries()) {
131
134
  stdout.write(` ${index === selected ? "❯" : " "} ${option.label}\n`);
132
135
  }
@@ -161,6 +164,643 @@ async function selectOption(question, options, defaultIndex = 0) {
161
164
  });
162
165
  }
163
166
 
167
+ async function configureTailwind(clientRoot) {
168
+ const viteConfigName = (await readdir(clientRoot)).find((file) =>
169
+ /^vite\.config\.(?:[cm]?[jt]s)$/.test(file),
170
+ );
171
+ if (!viteConfigName) {
172
+ throw new Error("Could not find the Vite config to configure Tailwind CSS.");
173
+ }
174
+
175
+ const viteConfigPath = join(clientRoot, viteConfigName);
176
+ let viteConfig = await readFile(viteConfigPath, "utf8");
177
+ if (!viteConfig.includes("@tailwindcss/vite")) {
178
+ viteConfig = `import tailwindcss from "@tailwindcss/vite";\n${viteConfig}`;
179
+ const plugins = /(\bplugins\s*:\s*\[)/;
180
+ if (plugins.test(viteConfig)) {
181
+ viteConfig = viteConfig.replace(plugins, "$1tailwindcss(), ");
182
+ } else {
183
+ const configObject = /(\bdefineConfig\s*\(\s*\{)/;
184
+ if (!configObject.test(viteConfig)) {
185
+ throw new Error("Could not add Tailwind CSS to the Vite config.");
186
+ }
187
+ viteConfig = viteConfig.replace(configObject, "$1\n plugins: [tailwindcss()],");
188
+ }
189
+ }
190
+ await writeFile(viteConfigPath, viteConfig);
191
+
192
+ let entryPath;
193
+ for (const directory of [join(clientRoot, "src"), clientRoot]) {
194
+ let files;
195
+ try {
196
+ files = await readdir(directory);
197
+ } catch (error) {
198
+ if (error.code === "ENOENT") continue;
199
+ throw error;
200
+ }
201
+ const entryFile = files.find((file) => /^main\.[cm]?[jt]sx?$/.test(file));
202
+ if (entryFile) {
203
+ entryPath = join(directory, entryFile);
204
+ break;
205
+ }
206
+ }
207
+ if (!entryPath) {
208
+ throw new Error("Could not find the frontend entry file to configure Tailwind CSS.");
209
+ }
210
+ const entry = await readFile(entryPath, "utf8");
211
+ const cssImport = entry.match(/import\s+["']([^"']+\.css)["']/);
212
+ if (!cssImport) {
213
+ throw new Error("Could not find a CSS import to configure Tailwind CSS.");
214
+ }
215
+ const cssPath = resolve(dirname(entryPath), cssImport[1]);
216
+ const css = await readFile(cssPath, "utf8");
217
+ if (!css.includes('@import "tailwindcss";')) {
218
+ await writeFile(cssPath, `@import "tailwindcss";\n${css}`);
219
+ }
220
+ }
221
+
222
+ async function scaffoldReactRouter(clientRoot, useTailwind) {
223
+ const sourceRoot = join(clientRoot, "src");
224
+ const sourceFiles = await readdir(sourceRoot);
225
+ const appFile = sourceFiles.find((file) => /^App\.(?:jsx|tsx)$/.test(file));
226
+ const entryFile = sourceFiles.find((file) => /^main\.(?:jsx|tsx)$/.test(file));
227
+ if (!appFile || !entryFile) {
228
+ throw new Error("Could not find the React app and entry files to configure routing.");
229
+ }
230
+
231
+ const typed = appFile.endsWith(".tsx");
232
+ const extension = typed ? "tsx" : "jsx";
233
+ const appPath = join(sourceRoot, appFile);
234
+ const entryPath = join(sourceRoot, entryFile);
235
+ const entry = await readFile(entryPath, "utf8");
236
+ const cssImport = entry.match(/import\s+["']([^"']+\.css)["']/);
237
+ if (!cssImport) {
238
+ throw new Error("Could not find a CSS import for the React Router starter.");
239
+ }
240
+
241
+ const cssPath = resolve(sourceRoot, cssImport[1]);
242
+ const tailwindImport = (await readFile(cssPath, "utf8"))
243
+ .includes('@import "tailwindcss";')
244
+ ? '@import "tailwindcss";\n'
245
+ : "";
246
+ const styles = useTailwind
247
+ ? {
248
+ shell: "min-h-screen flex flex-col bg-[#f5f7f4] text-[#17231f]",
249
+ container: "w-[calc(100%_-_2rem)] sm:w-[calc(100%_-_3rem)] max-w-[1040px] mx-auto",
250
+ header: "min-h-[72px] sm:min-h-[84px] flex items-center justify-between border-b border-[#dfe6df]",
251
+ brand: "flex items-center gap-[10px] text-sm font-bold text-[#17231f] no-underline",
252
+ brandMark: "w-[30px] h-[30px] grid place-items-center rounded-[9px] bg-[#315d4a] text-white",
253
+ nav: "flex items-center gap-2",
254
+ navLink: "min-h-10 flex items-center px-[10px] sm:px-[14px] rounded-lg text-sm text-[#5b6861] no-underline hover:bg-[#e7eee8] hover:text-[#244b39]",
255
+ navActive: "bg-[#e7eee8] text-[#244b39]",
256
+ page: "flex-1",
257
+ footer: "py-6 border-t border-[#dfe6df] text-[13px] text-[#78857d]",
258
+ home: "py-[72px] sm:py-[clamp(72px,12vw,132px)] pb-[84px]",
259
+ eyebrow: "text-xs font-bold tracking-[0.12em] text-[#557663]",
260
+ title: "max-w-[680px] my-[18px] text-[clamp(40px,7vw,68px)] font-semibold leading-[1.05] tracking-[-0.055em]",
261
+ authTitle: "max-w-[680px] my-[18px] text-[clamp(38px,7vw,52px)] font-semibold leading-[1.05] tracking-[-0.055em]",
262
+ copy: "max-w-[550px] mb-7 text-[17px] leading-[1.7] text-[#627068]",
263
+ button: "min-h-[46px] inline-flex items-center justify-center gap-[14px] px-[18px] rounded-lg font-semibold no-underline cursor-pointer",
264
+ buttonPrimary: "bg-[#315d4a] text-white hover:bg-[#244b39]",
265
+ grid: "grid grid-cols-1 sm:grid-cols-2 gap-4 mt-14 sm:mt-[72px]",
266
+ card: "min-h-[164px] p-6 border border-[#dfe6df] rounded-xl bg-[#fbfcfa]",
267
+ cardIndex: "text-xs font-bold tracking-[0.12em] text-[#557663]",
268
+ cardTitle: "mt-4 mb-2 text-lg",
269
+ cardCopy: "m-0 leading-[1.6] text-[#627068]",
270
+ code: "text-[#315d4a]",
271
+ auth: "w-full max-w-[440px] mx-auto py-[88px] pb-[72px]",
272
+ authIntro: "",
273
+ authCopy: "max-w-[550px] mb-8 text-[17px] leading-[1.7] text-[#627068]",
274
+ form: "grid gap-[10px]",
275
+ label: "mt-2 text-sm font-semibold text-[#35443c]",
276
+ input: "w-full min-h-[46px] px-[13px] border border-[#ccd7ce] rounded-lg bg-white text-[#17231f] focus:border-[#557663] focus:outline-3 focus:outline-[#dce8df]",
277
+ formButton: "mt-3",
278
+ notice: "min-h-6 m-0 text-sm leading-[1.5] text-[#557663]",
279
+ back: "inline-block mt-[18px] text-sm text-[#486353] hover:underline",
280
+ }
281
+ : {
282
+ shell: "app-shell",
283
+ container: "layout-container",
284
+ header: "site-header",
285
+ brand: "brand",
286
+ brandMark: "brand-mark",
287
+ nav: "site-nav",
288
+ navLink: "nav-link",
289
+ navActive: "is-active",
290
+ page: "page-content",
291
+ footer: "site-footer",
292
+ home: "home-page",
293
+ eyebrow: "eyebrow",
294
+ title: "",
295
+ authTitle: "",
296
+ copy: "hero-copy",
297
+ button: "button",
298
+ buttonPrimary: "button-primary",
299
+ grid: "route-grid",
300
+ card: "route-card",
301
+ cardIndex: "card-index",
302
+ cardTitle: "",
303
+ cardCopy: "",
304
+ code: "",
305
+ auth: "auth-page",
306
+ authIntro: "auth-intro",
307
+ authCopy: "hero-copy",
308
+ form: "login-form",
309
+ label: "",
310
+ input: "",
311
+ formButton: "",
312
+ notice: "form-notice",
313
+ back: "back-link",
314
+ };
315
+ const appCssImport = useTailwind ? "" : 'import "./App.css";\n';
316
+ const homeDirectory = join(sourceRoot, "Pages", "Home");
317
+ const authDirectory = join(sourceRoot, "Pages", "Auth");
318
+ await Promise.all([
319
+ mkdir(homeDirectory, { recursive: true }),
320
+ mkdir(authDirectory, { recursive: true }),
321
+ ]);
322
+ await Promise.all([
323
+ writeFile(
324
+ join(sourceRoot, `MainRouter.${extension}`),
325
+ `import { createBrowserRouter } from "react-router";
326
+ import App from "./App";
327
+ import Home from "./Pages/Home/Home";
328
+ import AuthPage from "./Pages/Auth/AuthPage";
329
+
330
+ const MainRouter = createBrowserRouter([
331
+ {
332
+ path: "/",
333
+ element: <App />,
334
+ children: [
335
+ { index: true, element: <Home /> },
336
+ { path: "login", element: <AuthPage /> },
337
+ ],
338
+ },
339
+ ]);
340
+
341
+ export default MainRouter;
342
+ `,
343
+ ),
344
+ writeFile(
345
+ appPath,
346
+ `import { NavLink, Outlet } from "react-router";
347
+ ${appCssImport}
348
+
349
+ function App() {
350
+ return (
351
+ <div className="${styles.shell}">
352
+ <header className="${styles.container} ${styles.header}">
353
+ <NavLink className="${styles.brand}" to="/" end>
354
+ <span className="${styles.brandMark}" aria-hidden="true">V</span>
355
+ <span>Workspace starter</span>
356
+ </NavLink>
357
+ <nav className="${styles.nav}" aria-label="Main navigation">
358
+ <NavLink to="/" end className={({ isActive }) => isActive ? "${styles.navLink} ${styles.navActive}" : "${styles.navLink}"}>
359
+ Home
360
+ </NavLink>
361
+ <NavLink to="/login" className={({ isActive }) => isActive ? "${styles.navLink} ${styles.navActive}" : "${styles.navLink}"}>
362
+ Login
363
+ </NavLink>
364
+ </nav>
365
+ </header>
366
+ <main className="${styles.container} ${styles.page}">
367
+ <Outlet />
368
+ </main>
369
+ <footer className="${styles.container} ${styles.footer}">A small starting point for your next project.</footer>
370
+ </div>
371
+ );
372
+ }
373
+
374
+ export default App;
375
+ `,
376
+ ),
377
+ writeFile(
378
+ join(homeDirectory, `Home.${extension}`),
379
+ `import { Link } from "react-router";
380
+
381
+ function Home() {
382
+ return (
383
+ <section className="${styles.container} ${styles.home}">
384
+ <p className="${styles.eyebrow}">YOUR PROJECT STARTS HERE</p>
385
+ <h1 className="${styles.title}">A faster start for your next project.</h1>
386
+ <p className="${styles.copy}">
387
+ This starter makes setting up your development environment quick and
388
+ straightforward. React Router is ready with Home and Login pages so you
389
+ can test navigation right away.
390
+ </p>
391
+ <Link className="${styles.button} ${styles.buttonPrimary}" to="/login">Visit the login page <span aria-hidden="true">→</span></Link>
392
+ <div className="${styles.grid}">
393
+ <article className="${styles.card}">
394
+ <span className="${styles.cardIndex}">01</span>
395
+ <h2 className="${styles.cardTitle}">Home</h2>
396
+ <p className="${styles.cardCopy}">An example landing page at <code className="${styles.code}">/</code> to help you get started.</p>
397
+ </article>
398
+ <article className="${styles.card}">
399
+ <span className="${styles.cardIndex}">02</span>
400
+ <h2 className="${styles.cardTitle}">Login</h2>
401
+ <p className="${styles.cardCopy}">A sample page at <code className="${styles.code}">/login</code> for checking route navigation.</p>
402
+ </article>
403
+ </div>
404
+ </section>
405
+ );
406
+ }
407
+
408
+ export default Home;
409
+ `,
410
+ ),
411
+ writeFile(
412
+ join(authDirectory, `AuthPage.${extension}`),
413
+ `import { useState${typed ? ", type FormEvent" : ""} } from "react";
414
+ import { Link } from "react-router";
415
+
416
+ function AuthPage() {
417
+ const [notice, setNotice] = useState("");
418
+
419
+ function handleSubmit(event${typed ? ": FormEvent<HTMLFormElement>" : ""}) {
420
+ event.preventDefault();
421
+ setNotice("This starter form is ready to connect to your authentication service.");
422
+ }
423
+
424
+ return (
425
+ <section className="${styles.auth}">
426
+ <div className="${styles.authIntro}">
427
+ <p className="${styles.eyebrow}">WELCOME BACK</p>
428
+ <h1 className="${styles.authTitle}">Login</h1>
429
+ <p className="${styles.authCopy}">Sign in to continue to your workspace.</p>
430
+ </div>
431
+ <form className="${styles.form}" onSubmit={handleSubmit}>
432
+ <label className="${styles.label}" htmlFor="email">Email address</label>
433
+ <input className="${styles.input}" id="email" name="email" type="email" autoComplete="email" placeholder="you@example.com" required />
434
+ <label className="${styles.label}" htmlFor="password">Password</label>
435
+ <input className="${styles.input}" id="password" name="password" type="password" autoComplete="current-password" placeholder="Enter your password" required />
436
+ <button className="${styles.button} ${styles.buttonPrimary} ${styles.formButton}" type="submit">Continue</button>
437
+ <p className="${styles.notice}" role="status">{notice}</p>
438
+ </form>
439
+ <Link className="${styles.back}" to="/">← Back to home</Link>
440
+ </section>
441
+ );
442
+ }
443
+
444
+ export default AuthPage;
445
+ `,
446
+ ),
447
+ writeFile(
448
+ cssPath,
449
+ useTailwind
450
+ ? tailwindImport
451
+ : `${tailwindImport}:root {
452
+ font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
453
+ color: #17231f;
454
+ background: #f5f7f4;
455
+ font-synthesis: none;
456
+ text-rendering: optimizeLegibility;
457
+ -webkit-font-smoothing: antialiased;
458
+ -moz-osx-font-smoothing: grayscale;
459
+ }
460
+
461
+ * {
462
+ box-sizing: border-box;
463
+ }
464
+
465
+ body {
466
+ min-width: 320px;
467
+ min-height: 100vh;
468
+ margin: 0;
469
+ }
470
+
471
+ button,
472
+ input {
473
+ font: inherit;
474
+ }
475
+
476
+ a {
477
+ color: inherit;
478
+ }
479
+ `,
480
+ ),
481
+ writeFile(
482
+ join(sourceRoot, "App.css"),
483
+ useTailwind
484
+ ? ""
485
+ : `.app-shell {
486
+ min-height: 100vh;
487
+ display: flex;
488
+ flex-direction: column;
489
+ }
490
+
491
+ .layout-container,
492
+ .site-header,
493
+ .page-content,
494
+ .site-footer {
495
+ width: min(100% - 48px, 1040px);
496
+ margin-inline: auto;
497
+ }
498
+
499
+ .site-header {
500
+ min-height: 84px;
501
+ display: flex;
502
+ align-items: center;
503
+ justify-content: space-between;
504
+ border-bottom: 1px solid #dfe6df;
505
+ }
506
+
507
+ .brand,
508
+ .site-nav,
509
+ .nav-link {
510
+ display: flex;
511
+ align-items: center;
512
+ }
513
+
514
+ .brand {
515
+ gap: 10px;
516
+ color: #17231f;
517
+ font-size: 14px;
518
+ font-weight: 700;
519
+ text-decoration: none;
520
+ }
521
+
522
+ .brand-mark {
523
+ width: 30px;
524
+ height: 30px;
525
+ display: grid;
526
+ place-items: center;
527
+ border-radius: 9px;
528
+ background: #315d4a;
529
+ color: #fff;
530
+ }
531
+
532
+ .site-nav {
533
+ gap: 8px;
534
+ }
535
+
536
+ .nav-link {
537
+ min-height: 40px;
538
+ padding: 0 14px;
539
+ border-radius: 8px;
540
+ color: #5b6861;
541
+ font-size: 14px;
542
+ text-decoration: none;
543
+ }
544
+
545
+ .nav-link:hover,
546
+ .nav-link.is-active {
547
+ background: #e7eee8;
548
+ color: #244b39;
549
+ }
550
+
551
+ .page-content {
552
+ flex: 1;
553
+ }
554
+
555
+ .home-page {
556
+ padding: clamp(72px, 12vw, 132px) 0 84px;
557
+ }
558
+
559
+ .eyebrow,
560
+ .card-index {
561
+ color: #557663;
562
+ font-size: 12px;
563
+ font-weight: 700;
564
+ letter-spacing: 0.12em;
565
+ }
566
+
567
+ .home-page h1,
568
+ .auth-intro h1 {
569
+ max-width: 680px;
570
+ margin: 18px 0;
571
+ font-size: clamp(40px, 7vw, 68px);
572
+ font-weight: 600;
573
+ letter-spacing: -0.055em;
574
+ line-height: 1.05;
575
+ }
576
+
577
+ .hero-copy {
578
+ max-width: 550px;
579
+ margin: 0 0 28px;
580
+ color: #627068;
581
+ font-size: 17px;
582
+ line-height: 1.7;
583
+ }
584
+
585
+ .button {
586
+ min-height: 46px;
587
+ display: inline-flex;
588
+ align-items: center;
589
+ justify-content: center;
590
+ gap: 14px;
591
+ padding: 0 18px;
592
+ border: 0;
593
+ border-radius: 8px;
594
+ cursor: pointer;
595
+ font-weight: 600;
596
+ text-decoration: none;
597
+ }
598
+
599
+ .button-primary {
600
+ background: #315d4a;
601
+ color: white;
602
+ }
603
+
604
+ .button-primary:hover {
605
+ background: #244b39;
606
+ }
607
+
608
+ .route-grid {
609
+ display: grid;
610
+ grid-template-columns: repeat(2, minmax(0, 1fr));
611
+ gap: 16px;
612
+ margin-top: 72px;
613
+ }
614
+
615
+ .route-card {
616
+ min-height: 164px;
617
+ padding: 24px;
618
+ border: 1px solid #dfe6df;
619
+ border-radius: 12px;
620
+ background: #fbfcfa;
621
+ }
622
+
623
+ .route-card h2 {
624
+ margin: 16px 0 8px;
625
+ font-size: 18px;
626
+ }
627
+
628
+ .route-card p {
629
+ margin: 0;
630
+ color: #627068;
631
+ line-height: 1.6;
632
+ }
633
+
634
+ .route-card code {
635
+ color: #315d4a;
636
+ }
637
+
638
+ .auth-page {
639
+ width: min(100%, 440px);
640
+ margin: 0 auto;
641
+ padding: 88px 0 72px;
642
+ }
643
+
644
+ .auth-intro h1 {
645
+ font-size: clamp(38px, 7vw, 52px);
646
+ }
647
+
648
+ .auth-intro .hero-copy {
649
+ margin-bottom: 32px;
650
+ }
651
+
652
+ .login-form {
653
+ display: grid;
654
+ gap: 10px;
655
+ }
656
+
657
+ .login-form label {
658
+ margin-top: 8px;
659
+ color: #35443c;
660
+ font-size: 14px;
661
+ font-weight: 600;
662
+ }
663
+
664
+ .login-form input {
665
+ width: 100%;
666
+ min-height: 46px;
667
+ padding: 0 13px;
668
+ border: 1px solid #ccd7ce;
669
+ border-radius: 8px;
670
+ background: #fff;
671
+ color: #17231f;
672
+ }
673
+
674
+ .login-form input:focus {
675
+ border-color: #557663;
676
+ outline: 3px solid #dce8df;
677
+ }
678
+
679
+ .login-form .button {
680
+ margin-top: 12px;
681
+ }
682
+
683
+ .form-notice {
684
+ min-height: 24px;
685
+ margin: 2px 0 0;
686
+ color: #557663;
687
+ font-size: 14px;
688
+ line-height: 1.5;
689
+ }
690
+
691
+ .back-link {
692
+ display: inline-block;
693
+ margin-top: 18px;
694
+ color: #486353;
695
+ font-size: 14px;
696
+ text-decoration: none;
697
+ }
698
+
699
+ .back-link:hover {
700
+ text-decoration: underline;
701
+ }
702
+
703
+ .site-footer {
704
+ padding: 24px 0;
705
+ border-top: 1px solid #dfe6df;
706
+ color: #78857d;
707
+ font-size: 13px;
708
+ }
709
+
710
+ @media (max-width: 560px) {
711
+ .site-header,
712
+ .page-content,
713
+ .site-footer {
714
+ width: min(100% - 32px, 1040px);
715
+ }
716
+
717
+ .site-header {
718
+ min-height: 72px;
719
+ }
720
+
721
+ .nav-link {
722
+ padding: 0 10px;
723
+ }
724
+
725
+ .route-grid {
726
+ grid-template-columns: 1fr;
727
+ margin-top: 56px;
728
+ }
729
+ }
730
+ `,
731
+ ),
732
+ writeFile(
733
+ entryPath,
734
+ `import { StrictMode } from "react";
735
+ import { createRoot } from "react-dom/client";
736
+ import { RouterProvider } from "react-router/dom";
737
+ import MainRouter from "./MainRouter";
738
+ ${cssImport[0]};
739
+
740
+ createRoot(document.getElementById("root")${typed ? "!" : ""}).render(
741
+ <StrictMode>
742
+ <RouterProvider router={MainRouter} />
743
+ </StrictMode>,
744
+ );
745
+ `,
746
+ ),
747
+ ]);
748
+
749
+ return true;
750
+ }
751
+
752
+ async function configureFrontend(clientRoot, clientPackage) {
753
+ const tailwind = await selectOption("Would you like to install Tailwind CSS?", [
754
+ { label: "Yes — add Tailwind CSS v4", value: true },
755
+ { label: "No", value: false },
756
+ ]);
757
+ const axios = await selectOption("Would you like to install Axios?", [
758
+ { label: "Yes — add Axios", value: true },
759
+ { label: "No", value: false },
760
+ ]);
761
+ const isReact = Boolean(
762
+ clientPackage.dependencies?.react || clientPackage.devDependencies?.react,
763
+ );
764
+ const installRouter =
765
+ isReact &&
766
+ (await selectOption("Would you like to install React Router?", [
767
+ { label: "Yes — add Home and Login pages with navigation", value: true },
768
+ { label: "No", value: false },
769
+ ]));
770
+ const installIcons =
771
+ isReact &&
772
+ (await selectOption("Would you like to install an icon library?", [
773
+ { label: "Yes", value: true },
774
+ { label: "No", value: false },
775
+ ]));
776
+ const icons = installIcons
777
+ ? await selectOption("Which React icon library would you like to install?", [
778
+ { label: "React Icons (default)", value: ["react-icons", "^5.7.0"] },
779
+ { label: "@animateicons/react", value: ["@animateicons/react", "^0.13.0"] },
780
+ ])
781
+ : null;
782
+
783
+ if (tailwind) {
784
+ clientPackage.devDependencies ??= {};
785
+ clientPackage.devDependencies["@tailwindcss/vite"] = "^4.3.4";
786
+ clientPackage.devDependencies.tailwindcss = "^4.3.4";
787
+ await configureTailwind(clientRoot);
788
+ }
789
+ if (axios) {
790
+ clientPackage.dependencies ??= {};
791
+ clientPackage.dependencies.axios = "^1.21.0";
792
+ }
793
+ if (icons) {
794
+ clientPackage.dependencies ??= {};
795
+ clientPackage.dependencies[icons[0]] = icons[1];
796
+ }
797
+ if (installRouter) {
798
+ clientPackage.dependencies ??= {};
799
+ clientPackage.dependencies["react-router"] = "^7";
800
+ await scaffoldReactRouter(clientRoot, tailwind);
801
+ }
802
+ }
803
+
164
804
  async function copyScript(name) {
165
805
  const source = await readFile(join(scriptRoot, name), "utf8");
166
806
  await writeFile(join(root, "scripts", name), source);
@@ -215,17 +855,17 @@ async function createBackend(serverRoot) {
215
855
  const language = await selectOption("Select a language for the backend:", [
216
856
  { label: "JavaScript", value: "js" },
217
857
  { label: "TypeScript", value: "ts" },
218
- ]);
858
+ ], 0, "yellow");
219
859
  const framework = await selectOption("Select a backend framework:", [
220
860
  { label: "Basic Node.js — no additional framework", value: "basic" },
221
- { label: "Express — install Express and dotenv", value: "express" },
222
- ]);
861
+ { label: "Express — install Express and dotenv (default)", value: "express" },
862
+ ], 1, "yellow");
223
863
  const structure = useDefaultStructure
224
864
  ? "simple"
225
865
  : await selectOption("Select a backend folder structure:", [
226
- { label: "Simple — standard folders (default)", value: "simple" },
227
- { label: "Module-based — organized by feature", value: "module" },
228
- ]);
866
+ { label: "Simple — standard folders", value: "simple" },
867
+ { label: "Module-based — organized by feature (default)", value: "module" },
868
+ ], 1, "yellow");
229
869
  const typed = language === "ts";
230
870
  let { app, server } = backendFiles(language, framework);
231
871
  const sourceRoot = join(serverRoot, "src");
@@ -366,6 +1006,10 @@ try {
366
1006
  const clientPackage = JSON.parse(await readFile(clientPackagePath, "utf8"));
367
1007
  clientPackage.scripts ??= {};
368
1008
  clientPackage.scripts.start ??= clientPackage.scripts.dev;
1009
+ if (clientPackage.scripts.dev && !clientPackage.scripts.dev.includes("--host")) {
1010
+ clientPackage.scripts.dev += " --host";
1011
+ }
1012
+ await configureFrontend(clientRoot, clientPackage);
369
1013
  await writeFile(clientPackagePath, `${JSON.stringify(clientPackage, null, 2)}\n`);
370
1014
  await writeFile(
371
1015
  join(clientRoot, ".env.local"),
@@ -377,9 +1021,10 @@ try {
377
1021
  "Would you like to add a separate backend server?",
378
1022
  [
379
1023
  { label: "Yes — include a backend workspace", value: true },
380
- { label: "No — create a frontend-only project (default)", value: false },
1024
+ { label: "No — create a frontend-only project", value: false },
381
1025
  ],
382
- 1,
1026
+ 0,
1027
+ "yellow",
383
1028
  );
384
1029
  const workspaces = [clientFolder];
385
1030
  if (includeServer) {
@@ -388,7 +1033,9 @@ try {
388
1033
  }
389
1034
 
390
1035
  await mkdir(join(root, "scripts"), { recursive: true });
391
- await Promise.all(["dev.mjs", "run-app.mjs", "install-info.mjs"].map(copyScript));
1036
+ await Promise.all(
1037
+ ["dev.mjs", "run-app.mjs", "install-info.mjs", "add-dependency.mjs"].map(copyScript),
1038
+ );
392
1039
  const rootPackage = {
393
1040
  name: projectName,
394
1041
  version: "1.0.0",
@@ -398,6 +1045,8 @@ try {
398
1045
  preinstall: "node scripts/install-info.mjs",
399
1046
  dev: "node scripts/dev.mjs",
400
1047
  client: "node scripts/run-app.mjs client",
1048
+ adD: "node scripts/add-dependency.mjs",
1049
+ "add-dependency": "node scripts/add-dependency.mjs",
401
1050
  ...(includeServer ? { server: "node scripts/run-app.mjs server" } : {}),
402
1051
  },
403
1052
  type: "module",
@@ -442,9 +1091,30 @@ try {
442
1091
  );
443
1092
 
444
1093
  console.log(`\nInstalling dependencies for ${workspaces.join(" and ")}...`);
445
- await run(packageManager, ["install"], root);
1094
+ await run(packageManager, ["install"], root, {
1095
+ ...process.env,
1096
+ VANILLA_VITE_ALLOW_INSTALL: "1",
1097
+ });
1098
+ const dependencyCommands =
1099
+ packageManager === "pnpm"
1100
+ ? ["pnpm adD <package>", "pnpm add-dependency <package>"]
1101
+ : ["npm run adD -- <package>", "npm run add-dependency -- <package>"];
1102
+ const useColor = process.stdout.isTTY && process.env.NO_COLOR === undefined;
1103
+ const heading = ">>> ADD DEPENDENCIES LATER <<<";
1104
+ const dependencyNotice = [
1105
+ useColor ? `\x1b[1;33m${heading}\x1b[0m` : heading,
1106
+ ...dependencyCommands.map((command) =>
1107
+ useColor ? `\x1b[1;36m > ${command}\x1b[0m` : ` > ${command}`,
1108
+ ),
1109
+ ].join("\n");
1110
+ console.log(`\n${dependencyNotice}\n`);
446
1111
  console.log(
447
- `\nProject created successfully: ${projectName}/\n\nTo get started:\n cd ${projectName}\n ${packageManager} dev`,
1112
+ `\nProject created successfully: ${projectName}/\nStarting the development server...\n`,
1113
+ );
1114
+ await run(
1115
+ packageManager,
1116
+ packageManager === "pnpm" ? ["dev"] : ["run", "dev"],
1117
+ root,
448
1118
  );
449
1119
  } catch (error) {
450
1120
  console.error(`\nProject creation failed: ${error.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-vanilla-vite",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Scaffold a React or Vite app with an optional Node.js or Express backend",
5
5
  "type": "module",
6
6
  "repository": {
@@ -46,4 +46,4 @@
46
46
  "dependencies": {
47
47
  "cross-spawn": "^7.0.6"
48
48
  }
49
- }
49
+ }
@@ -0,0 +1,108 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { emitKeypressEvents } from "node:readline";
5
+ import { stdin, stdout } from "node:process";
6
+ import spawn from "cross-spawn";
7
+
8
+ const root = fileURLToPath(new URL("../", import.meta.url));
9
+ const project = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
10
+ const packages = process.argv.slice(2);
11
+
12
+ if (packages.length === 0) {
13
+ console.error(
14
+ "Usage: pnpm adD|add-dependency <package...> | npm run adD|add-dependency -- <package...>",
15
+ );
16
+ process.exit(1);
17
+ }
18
+
19
+ if (!stdin.isTTY) {
20
+ console.error("Choose an install location in an interactive terminal.");
21
+ process.exit(1);
22
+ }
23
+
24
+ const targets = [
25
+ { label: `Project root (${project.name})`, workspace: null },
26
+ ...project.workspaces.map((workspace) => ({
27
+ label: workspace,
28
+ workspace,
29
+ })),
30
+ ];
31
+
32
+ let selectedIndex = 0;
33
+ emitKeypressEvents(stdin);
34
+
35
+ const selectedTarget = await new Promise((resolveSelection) => {
36
+ function render() {
37
+ const question = "Where should the package be installed?";
38
+ const prompt = stdout.isTTY && process.env.NO_COLOR === undefined
39
+ ? `\x1b[1;36m${question}\x1b[0m`
40
+ : question;
41
+ stdout.write(`\r\x1b[2K${prompt}\n`);
42
+ targets.forEach((target, index) => {
43
+ stdout.write(` ${index === selectedIndex ? "❯" : " "} ${target.label}\n`);
44
+ });
45
+ stdout.write(" Use ↑/↓ to select, Enter to confirm, or Esc to keep the default.\n");
46
+ stdout.write(`\x1b[${targets.length + 2}A`);
47
+ }
48
+
49
+ function finish(target) {
50
+ stdin.off("keypress", onKeypress);
51
+ stdin.setRawMode(false);
52
+ stdin.pause();
53
+ stdout.write(`\x1b[${targets.length + 2}B\n`);
54
+ resolveSelection(target);
55
+ }
56
+
57
+ function onKeypress(_input, key) {
58
+ if (key?.name === "up" || key?.name === "down") {
59
+ selectedIndex =
60
+ (selectedIndex + (key.name === "down" ? 1 : targets.length - 1)) %
61
+ targets.length;
62
+ render();
63
+ } else if (key?.name === "return") finish(targets[selectedIndex]);
64
+ else if (key?.name === "escape") finish(targets[0]);
65
+ else if (key?.ctrl && key.name === "c") {
66
+ stdin.off("keypress", onKeypress);
67
+ stdin.setRawMode(false);
68
+ stdin.pause();
69
+ stdout.write("\n");
70
+ resolveSelection(null);
71
+ }
72
+ }
73
+
74
+ stdin.setRawMode(true);
75
+ stdin.resume();
76
+ stdin.on("keypress", onKeypress);
77
+ render();
78
+ });
79
+
80
+ if (!selectedTarget) {
81
+ process.exit(130);
82
+ }
83
+
84
+ const packageManager = process.env.npm_config_user_agent?.startsWith("pnpm/")
85
+ ? "pnpm"
86
+ : "npm";
87
+ const { workspace } = selectedTarget;
88
+ const commandArgs =
89
+ packageManager === "pnpm"
90
+ ? workspace
91
+ ? ["--filter", workspace, "add", ...packages]
92
+ : ["add", "--workspace-root", ...packages]
93
+ : workspace
94
+ ? ["install", ...packages, "--workspace", workspace]
95
+ : ["install", ...packages, "--workspace-root"];
96
+ const child = spawn(packageManager, commandArgs, {
97
+ cwd: root,
98
+ stdio: "inherit",
99
+ env: { ...process.env, VANILLA_VITE_ALLOW_INSTALL: "1" },
100
+ });
101
+
102
+ child.once("error", (error) => {
103
+ console.error(`Unable to run ${packageManager}: ${error.message}`);
104
+ process.exitCode = 1;
105
+ });
106
+ child.once("exit", (code, signal) => {
107
+ process.exitCode = code ?? (signal ? 1 : 0);
108
+ });
@@ -5,6 +5,14 @@ import { fileURLToPath } from "node:url";
5
5
  const root = fileURLToPath(new URL("../", import.meta.url));
6
6
  const project = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
7
7
 
8
+ if (process.env.VANILLA_VITE_ALLOW_INSTALL !== "1") {
9
+ console.error(
10
+ "\nDirect installs are disabled to keep dependencies in the intended workspace.\n" +
11
+ "Use `pnpm adD <package>` or `pnpm add-dependency <package>`; with npm, use `npm run adD -- <package>` or `npm run add-dependency -- <package>`.",
12
+ );
13
+ process.exit(1);
14
+ }
15
+
8
16
  console.log("Installing workspace dependencies:");
9
17
  for (const workspace of project.workspaces) {
10
18
  const manifest = JSON.parse(