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/CHANGELOG.md +34 -0
- package/README.md +195 -124
- package/bin/create-template.mjs +1764 -1122
- package/package.json +6 -2
- package/scripts/add-dependency.mjs +112 -108
- package/scripts/dev.mjs +625 -132
- package/scripts/install-info.mjs +78 -33
- package/scripts/run-app.mjs +40 -45
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-vanilla-vite",
|
|
3
|
-
"version": "1.1
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
stdout.write(
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
child.once("
|
|
107
|
-
|
|
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
|
+
});
|