create-vanilla-vite 1.1.0 → 1.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-vanilla-vite",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Scaffold a React or Vite app with an optional Node.js or Express backend",
5
5
  "type": "module",
6
6
  "repository": {
@@ -17,10 +17,11 @@
17
17
  "files": [
18
18
  "bin/",
19
19
  "scripts/",
20
+ "CHANGELOG.md",
20
21
  "README.md"
21
22
  ],
22
23
  "engines": {
23
- "node": ">=20"
24
+ "node": ">=20.6"
24
25
  },
25
26
  "keywords": [
26
27
  "create",
@@ -45,5 +46,8 @@
45
46
  "license": "ISC",
46
47
  "dependencies": {
47
48
  "cross-spawn": "^7.0.6"
49
+ },
50
+ "scripts": {
51
+ "test:smoke": "node test/smoke.mjs"
48
52
  }
49
53
  }
@@ -1,108 +1,112 @@
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
- });
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
+ const defaultIndex = Math.max(
33
+ 0,
34
+ targets.findIndex((target) => target.workspace?.endsWith("-client")),
35
+ );
36
+ let selectedIndex = defaultIndex;
37
+ emitKeypressEvents(stdin);
38
+
39
+ const selectedTarget = await new Promise((resolveSelection) => {
40
+ function render() {
41
+ const question = "Where should the package be installed?";
42
+ const prompt = stdout.isTTY && process.env.NO_COLOR === undefined
43
+ ? `\x1b[1;36m${question}\x1b[0m`
44
+ : question;
45
+ stdout.write(`\r\x1b[2K${prompt}\n`);
46
+ targets.forEach((target, index) => {
47
+ stdout.write(` ${index === selectedIndex ? "❯" : " "} ${target.label}\n`);
48
+ });
49
+ stdout.write(" Use ↑/↓ to select, Enter to confirm, or Esc to keep the default.\n");
50
+ stdout.write(`\x1b[${targets.length + 2}A`);
51
+ }
52
+
53
+ function finish(target) {
54
+ stdin.off("keypress", onKeypress);
55
+ stdin.setRawMode(false);
56
+ stdin.pause();
57
+ stdout.write(`\x1b[${targets.length + 2}B\n`);
58
+ resolveSelection(target);
59
+ }
60
+
61
+ function onKeypress(_input, key) {
62
+ if (key?.name === "up" || key?.name === "down") {
63
+ selectedIndex =
64
+ (selectedIndex + (key.name === "down" ? 1 : targets.length - 1)) %
65
+ targets.length;
66
+ render();
67
+ } else if (key?.name === "return") finish(targets[selectedIndex]);
68
+ else if (key?.name === "escape") finish(targets[defaultIndex]);
69
+ else if (key?.ctrl && key.name === "c") {
70
+ stdin.off("keypress", onKeypress);
71
+ stdin.setRawMode(false);
72
+ stdin.pause();
73
+ stdout.write("\n");
74
+ resolveSelection(null);
75
+ }
76
+ }
77
+
78
+ stdin.setRawMode(true);
79
+ stdin.resume();
80
+ stdin.on("keypress", onKeypress);
81
+ render();
82
+ });
83
+
84
+ if (!selectedTarget) {
85
+ process.exit(130);
86
+ }
87
+
88
+ const packageManager = process.env.npm_config_user_agent?.startsWith("pnpm/")
89
+ ? "pnpm"
90
+ : "npm";
91
+ const { workspace } = selectedTarget;
92
+ const commandArgs =
93
+ packageManager === "pnpm"
94
+ ? workspace
95
+ ? ["--filter", workspace, "add", ...packages]
96
+ : ["add", "--workspace-root", ...packages]
97
+ : workspace
98
+ ? ["install", ...packages, "--workspace", workspace]
99
+ : ["install", ...packages];
100
+ const child = spawn(packageManager, commandArgs, {
101
+ cwd: root,
102
+ stdio: "inherit",
103
+ env: { ...process.env, VANILLA_VITE_ALLOW_INSTALL: "1" },
104
+ });
105
+
106
+ child.once("error", (error) => {
107
+ console.error(`Unable to run ${packageManager}: ${error.message}`);
108
+ process.exitCode = 1;
109
+ });
110
+ child.once("exit", (code, signal) => {
111
+ process.exitCode = code ?? (signal ? 1 : 0);
112
+ });