create-volt 0.2.0 → 0.3.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/README.md +22 -8
- package/index.js +47 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,18 +27,32 @@ Edit `public/app.js` and save — the page hot-reloads itself.
|
|
|
27
27
|
|
|
28
28
|
## Options
|
|
29
29
|
|
|
30
|
-
| Flag
|
|
31
|
-
|
|
|
32
|
-
| `--
|
|
33
|
-
| `--
|
|
34
|
-
| `--
|
|
35
|
-
| `--
|
|
36
|
-
|
|
|
37
|
-
| `-
|
|
30
|
+
| Flag | Effect |
|
|
31
|
+
| ----------------- | ------------------------------------------------------- |
|
|
32
|
+
| `--port <number>` | Dev port for the app (default: derived from today's date)|
|
|
33
|
+
| `--skip-install` | Don't run the install step (scaffold files only) |
|
|
34
|
+
| `--no-git` | Don't initialize a git repository |
|
|
35
|
+
| `--dry-run` | Show what would be created without writing anything |
|
|
36
|
+
| `--force` | Scaffold into an existing non-empty directory |
|
|
37
|
+
| `-h`, `--help` | Show help |
|
|
38
|
+
| `-v`, `--version` | Print the create-volt version |
|
|
38
39
|
|
|
39
40
|
By default the new project is initialized as a git repository with one initial
|
|
40
41
|
commit (skip with `--no-git`).
|
|
41
42
|
|
|
43
|
+
### Dev port
|
|
44
|
+
|
|
45
|
+
Each app's dev port is baked into its `server.js`. By default it's derived from
|
|
46
|
+
**today's date** — two-digit year + month + two-digit day (e.g. `2026-06-28` →
|
|
47
|
+
`26628`) — so apps created on different days never collide. Scaffolding more than
|
|
48
|
+
one app on the same day? Give them distinct ports with `--port`:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm create volt@latest api-app -- --port 26630
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The runtime `PORT` env var still overrides it at launch.
|
|
55
|
+
|
|
42
56
|
The installer auto-detects whichever package manager invoked it
|
|
43
57
|
(npm / pnpm / yarn / bun) and uses it for `install`.
|
|
44
58
|
|
package/index.js
CHANGED
|
@@ -36,6 +36,7 @@ ${bold("Usage")}
|
|
|
36
36
|
npx create-volt <project-directory> [options]
|
|
37
37
|
|
|
38
38
|
${bold("Options")}
|
|
39
|
+
--port <number> Dev port for the app (default: derived from today's date)
|
|
39
40
|
--skip-install Don't run the package manager install step
|
|
40
41
|
--no-git Don't initialize a git repository
|
|
41
42
|
--dry-run Show what would be created without writing anything
|
|
@@ -48,10 +49,18 @@ ${bold("Example")}
|
|
|
48
49
|
cd my-app && npm run dev
|
|
49
50
|
`;
|
|
50
51
|
|
|
51
|
-
// --- arg parsing ---
|
|
52
|
+
// --- arg parsing (supports `--port <n>` and `--port=<n>`) ---
|
|
52
53
|
const argv = process.argv.slice(2);
|
|
53
|
-
const flags = new Set(
|
|
54
|
-
const positionals =
|
|
54
|
+
const flags = new Set();
|
|
55
|
+
const positionals = [];
|
|
56
|
+
let portArg = null;
|
|
57
|
+
for (let i = 0; i < argv.length; i++) {
|
|
58
|
+
const a = argv[i];
|
|
59
|
+
if (a === "--port") portArg = argv[++i];
|
|
60
|
+
else if (a.startsWith("--port=")) portArg = a.slice("--port=".length);
|
|
61
|
+
else if (a.startsWith("-")) flags.add(a);
|
|
62
|
+
else positionals.push(a);
|
|
63
|
+
}
|
|
55
64
|
|
|
56
65
|
if (flags.has("-h") || flags.has("--help")) {
|
|
57
66
|
console.log(HELP);
|
|
@@ -67,6 +76,28 @@ const force = flags.has("--force");
|
|
|
67
76
|
const dryRun = flags.has("--dry-run");
|
|
68
77
|
const noGit = flags.has("--no-git");
|
|
69
78
|
|
|
79
|
+
// Resolve the dev port: --port wins, else derive it from today's date as
|
|
80
|
+
// two-digit-year + month (no leading zero) + two-digit-day (house convention),
|
|
81
|
+
// so apps scaffolded on different days don't collide on the same port.
|
|
82
|
+
function datePort(d) {
|
|
83
|
+
const yy = String(d.getFullYear()).slice(-2);
|
|
84
|
+
const mm = String(d.getMonth() + 1);
|
|
85
|
+
const dd = String(d.getDate()).padStart(2, "0");
|
|
86
|
+
return Number(`${yy}${mm}${dd}`);
|
|
87
|
+
}
|
|
88
|
+
let port;
|
|
89
|
+
if (portArg != null) {
|
|
90
|
+
port = Number(portArg);
|
|
91
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
92
|
+
die(`Invalid --port "${portArg}" — use a whole number between 1 and 65535.`);
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
port = datePort(new Date());
|
|
96
|
+
if (port > 65535) {
|
|
97
|
+
die(`The date-derived port (${port}) is above 65535 — pass --port <1-65535>.`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
70
101
|
const rawName = positionals[0];
|
|
71
102
|
if (!rawName) die(`Please specify a project directory:\n ${cyan("npm create volt@latest")} ${green("<project-directory>")}`);
|
|
72
103
|
|
|
@@ -113,6 +144,7 @@ if (dryRun) {
|
|
|
113
144
|
console.log("");
|
|
114
145
|
console.log(dim(`Would ${skipInstall ? "skip dependency install" : "install dependencies"}.`));
|
|
115
146
|
console.log(dim(`Would ${noGit ? "skip git init" : "initialize a git repository with an initial commit"}.`));
|
|
147
|
+
console.log(dim(`Would set the dev port to ${port}.`));
|
|
116
148
|
console.log(`\n${green("✔")} Dry run complete — nothing was written.\n`);
|
|
117
149
|
process.exit(0);
|
|
118
150
|
}
|
|
@@ -137,6 +169,17 @@ const appPkg = JSON.parse(fs.readFileSync(appPkgPath, "utf8"));
|
|
|
137
169
|
appPkg.name = appName;
|
|
138
170
|
fs.writeFileSync(appPkgPath, JSON.stringify(appPkg, null, 2) + "\n");
|
|
139
171
|
|
|
172
|
+
// --- stamp the chosen dev port into server.js + README ---
|
|
173
|
+
const serverPath = path.join(targetDir, "server.js");
|
|
174
|
+
fs.writeFileSync(
|
|
175
|
+
serverPath,
|
|
176
|
+
fs.readFileSync(serverPath, "utf8").replace(/(Number\(process\.env\.PORT\)\s*\|\|\s*)\d+/, `$1${port}`),
|
|
177
|
+
);
|
|
178
|
+
const appReadme = path.join(targetDir, "README.md");
|
|
179
|
+
if (fs.existsSync(appReadme)) {
|
|
180
|
+
fs.writeFileSync(appReadme, fs.readFileSync(appReadme, "utf8").replace(/localhost:\d+/g, `localhost:${port}`));
|
|
181
|
+
}
|
|
182
|
+
|
|
140
183
|
const created = [
|
|
141
184
|
"public/volt.js — the Volt library (no build step)",
|
|
142
185
|
"public/app.js — your app (Counter + Todos demo)",
|
|
@@ -205,4 +248,4 @@ console.log(`\n${green("✔")} ${bold("Done!")} Next steps:\n`);
|
|
|
205
248
|
console.log(` ${cyan("cd")} ${projectName}`);
|
|
206
249
|
if (!installed) console.log(` ${cyan(installCmd)}`);
|
|
207
250
|
console.log(` ${cyan(runCmd)}`);
|
|
208
|
-
console.log(`\nThen open ${cyan("http://localhost:
|
|
251
|
+
console.log(`\nThen open ${cyan("http://localhost:" + port)} and edit ${bold("public/app.js")}.\n`);
|