create-volt 0.1.0 → 0.2.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 +5 -0
- package/index.js +57 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,10 +30,15 @@ Edit `public/app.js` and save — the page hot-reloads itself.
|
|
|
30
30
|
| Flag | Effect |
|
|
31
31
|
| ---------------- | ------------------------------------------------------- |
|
|
32
32
|
| `--skip-install` | Don't run the install step (scaffold files only) |
|
|
33
|
+
| `--no-git` | Don't initialize a git repository |
|
|
34
|
+
| `--dry-run` | Show what would be created without writing anything |
|
|
33
35
|
| `--force` | Scaffold into an existing non-empty directory |
|
|
34
36
|
| `-h`, `--help` | Show help |
|
|
35
37
|
| `-v`, `--version`| Print the create-volt version |
|
|
36
38
|
|
|
39
|
+
By default the new project is initialized as a git repository with one initial
|
|
40
|
+
commit (skip with `--no-git`).
|
|
41
|
+
|
|
37
42
|
The installer auto-detects whichever package manager invoked it
|
|
38
43
|
(npm / pnpm / yarn / bun) and uses it for `install`.
|
|
39
44
|
|
package/index.js
CHANGED
|
@@ -37,6 +37,8 @@ ${bold("Usage")}
|
|
|
37
37
|
|
|
38
38
|
${bold("Options")}
|
|
39
39
|
--skip-install Don't run the package manager install step
|
|
40
|
+
--no-git Don't initialize a git repository
|
|
41
|
+
--dry-run Show what would be created without writing anything
|
|
40
42
|
--force Scaffold into an existing non-empty directory
|
|
41
43
|
-h, --help Show this help
|
|
42
44
|
-v, --version Show the create-volt version
|
|
@@ -62,6 +64,8 @@ if (flags.has("-v") || flags.has("--version")) {
|
|
|
62
64
|
|
|
63
65
|
const skipInstall = flags.has("--skip-install");
|
|
64
66
|
const force = flags.has("--force");
|
|
67
|
+
const dryRun = flags.has("--dry-run");
|
|
68
|
+
const noGit = flags.has("--no-git");
|
|
65
69
|
|
|
66
70
|
const rawName = positionals[0];
|
|
67
71
|
if (!rawName) die(`Please specify a project directory:\n ${cyan("npm create volt@latest")} ${green("<project-directory>")}`);
|
|
@@ -79,16 +83,42 @@ const targetDir = path.resolve(process.cwd(), projectName);
|
|
|
79
83
|
const appName = path.basename(targetDir);
|
|
80
84
|
const templateDir = path.join(__dirname, "template");
|
|
81
85
|
|
|
86
|
+
// List every file in the template, relative to its root (for dry-run preview).
|
|
87
|
+
function listTemplateFiles(dir, base = dir) {
|
|
88
|
+
const out = [];
|
|
89
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
90
|
+
const full = path.join(dir, entry.name);
|
|
91
|
+
if (entry.isDirectory()) out.push(...listTemplateFiles(full, base));
|
|
92
|
+
else out.push(path.relative(base, full));
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
|
|
82
97
|
// --- target directory checks ---
|
|
83
98
|
if (fs.existsSync(targetDir)) {
|
|
84
99
|
const existing = fs.readdirSync(targetDir).filter((f) => f !== ".git");
|
|
85
100
|
if (existing.length && !force) {
|
|
86
101
|
die(`Directory ${green(projectName)} already exists and is not empty.\n Pass ${cyan("--force")} to scaffold into it anyway.`);
|
|
87
102
|
}
|
|
88
|
-
} else {
|
|
89
|
-
fs.mkdirSync(targetDir, { recursive: true });
|
|
90
103
|
}
|
|
91
104
|
|
|
105
|
+
// --- dry run: print the plan and exit without writing anything ---
|
|
106
|
+
if (dryRun) {
|
|
107
|
+
console.log(`\n${bold("⚡ Dry run")} — would create a Volt app in ${cyan(targetDir)}\n`);
|
|
108
|
+
console.log("Would write:");
|
|
109
|
+
for (const f of listTemplateFiles(templateDir).sort()) {
|
|
110
|
+
// the shipped "gitignore" is renamed to ".gitignore" on scaffold
|
|
111
|
+
console.log(" " + dim(f === "gitignore" ? ".gitignore" : f));
|
|
112
|
+
}
|
|
113
|
+
console.log("");
|
|
114
|
+
console.log(dim(`Would ${skipInstall ? "skip dependency install" : "install dependencies"}.`));
|
|
115
|
+
console.log(dim(`Would ${noGit ? "skip git init" : "initialize a git repository with an initial commit"}.`));
|
|
116
|
+
console.log(`\n${green("✔")} Dry run complete — nothing was written.\n`);
|
|
117
|
+
process.exit(0);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true });
|
|
121
|
+
|
|
92
122
|
console.log(`\n${bold("⚡ Creating a new Volt app in")} ${cyan(targetDir)}\n`);
|
|
93
123
|
|
|
94
124
|
// --- copy the template tree (recursive, cross-platform) ---
|
|
@@ -143,6 +173,31 @@ if (!skipInstall) {
|
|
|
143
173
|
}
|
|
144
174
|
}
|
|
145
175
|
|
|
176
|
+
// --- initialize a git repository (unless skipped or already inside one) ---
|
|
177
|
+
if (!noGit) {
|
|
178
|
+
const git = (gitArgs) =>
|
|
179
|
+
spawnSync("git", gitArgs, {
|
|
180
|
+
cwd: targetDir,
|
|
181
|
+
stdio: "ignore",
|
|
182
|
+
shell: process.platform === "win32",
|
|
183
|
+
});
|
|
184
|
+
const gitAvailable = git(["--version"]).status === 0;
|
|
185
|
+
const insideRepo = gitAvailable && git(["rev-parse", "--is-inside-work-tree"]).status === 0;
|
|
186
|
+
if (gitAvailable && !insideRepo) {
|
|
187
|
+
const initOk = git(["init", "-b", "main"]).status === 0 || git(["init"]).status === 0;
|
|
188
|
+
if (initOk) {
|
|
189
|
+
git(["add", "-A"]);
|
|
190
|
+
const committed = git(["commit", "-m", "Initial commit from create-volt"]).status === 0;
|
|
191
|
+
console.log(
|
|
192
|
+
green("✔") +
|
|
193
|
+
(committed
|
|
194
|
+
? " Initialized a git repository (1 commit)\n"
|
|
195
|
+
: " Initialized a git repository (commit skipped — set git user.name/email)\n"),
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
146
201
|
// --- next steps ---
|
|
147
202
|
const runCmd = pm === "npm" ? "npm run dev" : `${pm} dev`;
|
|
148
203
|
const installCmd = pm === "yarn" ? "yarn" : `${pm} install`;
|