create-fsaa 0.2.3 → 0.2.5
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/lib/init.mjs +44 -5
- package/package.json +2 -2
package/lib/init.mjs
CHANGED
|
@@ -28,6 +28,15 @@ export async function initCmd({ flags, interactive }) {
|
|
|
28
28
|
template = template || "next";
|
|
29
29
|
const manager = "pnpm"; // contract pin (single-lockfile rule lives on pnpm)
|
|
30
30
|
|
|
31
|
+
// wrong answers made impossible, not rejected: normalize a sloppy name first
|
|
32
|
+
if (typeof name === "string" && !/^[a-z0-9][a-z0-9._-]*$/.test(name)) {
|
|
33
|
+
const fixed = normalizeName(name);
|
|
34
|
+
if (fixed && fixed !== name) {
|
|
35
|
+
console.log(` (name normalized: ${name} -> ${fixed})`);
|
|
36
|
+
name = fixed;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
31
40
|
if (typeof flags.dir !== "undefined" && typeof flags.dir !== "string") {
|
|
32
41
|
throw new Error("--dir needs a value: fsaa init --dir ./somewhere");
|
|
33
42
|
}
|
|
@@ -70,7 +79,14 @@ export async function initCmd({ flags, interactive }) {
|
|
|
70
79
|
const win = process.platform === "win32";
|
|
71
80
|
const pnpmBin = win ? "pnpm.cmd" : "pnpm";
|
|
72
81
|
console.log("> installing dependencies (this may take a minute)…");
|
|
73
|
-
|
|
82
|
+
// With shell:true a missing pnpm does NOT set r.error — cmd.exe prints
|
|
83
|
+
// "'pnpm.cmd' is not recognized" and exits non-zero. Probe first so the
|
|
84
|
+
// npx fallback triggers on a real "pnpm missing", not on an install failure.
|
|
85
|
+
const probe = spawnSync(pnpmBin, ["--version"], { cwd: dest, stdio: "ignore", shell: win });
|
|
86
|
+
const pnpmMissing = Boolean(probe.error) || probe.status !== 0;
|
|
87
|
+
let r = pnpmMissing
|
|
88
|
+
? { error: new Error("pnpm not found") }
|
|
89
|
+
: spawnSync(pnpmBin, ["install"], { cwd: dest, stdio: "inherit", shell: win });
|
|
74
90
|
if (r.error) {
|
|
75
91
|
// pnpm missing from PATH — recover INSTEAD of nagging: run the pinned
|
|
76
92
|
// version through npx (npx exists wherever this CLI already runs).
|
|
@@ -122,18 +138,41 @@ export async function initCmd({ flags, interactive }) {
|
|
|
122
138
|
return 0;
|
|
123
139
|
}
|
|
124
140
|
|
|
125
|
-
|
|
141
|
+
/* Normalize an app name into npm/pnpm/kebab-friendly form BEFORE validating:
|
|
142
|
+
invalid input → normalized name (with a notice), not a stack trace.
|
|
143
|
+
"PayOn" -> pay-on (camelCase splits into words)
|
|
144
|
+
"My App" -> my-app (spaces become dashes)
|
|
145
|
+
"MyApp." -> my-app (trailing dots are stripped — Windows paths) */
|
|
146
|
+
function normalizeName(raw) {
|
|
147
|
+
const normalized = String(raw)
|
|
148
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2") // camelCase -> kebab
|
|
149
|
+
.trim()
|
|
150
|
+
.toLowerCase()
|
|
151
|
+
.replace(/[\s_]+/g, "-") // spaces/underscores -> dashes
|
|
152
|
+
.replace(/\.{2,}/g, ".") // squeeze dots
|
|
153
|
+
.replace(/[^a-z0-9._-]/g, "") // drop anything npm/pnpm would reject
|
|
154
|
+
.replace(/^[._-]+/, "").replace(/[._-]+$/, ""); // trim edge dots/dashes
|
|
155
|
+
return normalized;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function validate(name, template) {
|
|
126
159
|
if (!TEMPLATES[template]) {
|
|
127
|
-
|
|
160
|
+
const e = new Error(`unknown template "${template}" — choose: ${Object.keys(TEMPLATES).join(" | ")}`);
|
|
161
|
+
e.userError = true;
|
|
162
|
+
throw e;
|
|
128
163
|
}
|
|
129
164
|
// npm/pnpm require lowercase package names; a strict lowercase regex also
|
|
130
165
|
// keeps the project folder name predictable (no /i flag deliberately).
|
|
131
166
|
if (!/^[a-z0-9][a-z0-9._-]*$/.test(name)) {
|
|
132
|
-
|
|
167
|
+
const e = new Error(`invalid app name "${name}" — could not normalize to a valid one (lowercase letters, digits, dots, dashes, underscores only)\n try: fsaa init --name $(echo ${name} | tr 'A-Z ' 'a-z-')`);
|
|
168
|
+
e.userError = true;
|
|
169
|
+
throw e;
|
|
133
170
|
}
|
|
134
171
|
// Windows: trailing dots/space vanish in paths; reserved device names break mkdir.
|
|
135
172
|
if (/[.\s-]$/.test(name) || /^(con|prn|aux|nul|com\d|lpt\d)$/i.test(name)) {
|
|
136
|
-
|
|
173
|
+
const e = new Error(`invalid app name "${name}" — no trailing dot/space/dash, and no Windows reserved names (con, prn, aux, nul, com1..9, lpt1..9)`);
|
|
174
|
+
e.userError = true;
|
|
175
|
+
throw e;
|
|
137
176
|
}
|
|
138
177
|
}
|
|
139
178
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-fsaa",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "FSAA \u2014 Feature-Sliced Atomic Architecture. Run `npm create fsaa` (this package) to scaffold an FSAA app from the official starter templates; `fsaa g <slice>` generates canonical slices.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Veaceslav Bezusco <Aramex86@users.noreply.github.com>",
|
|
@@ -29,4 +29,4 @@
|
|
|
29
29
|
"scripts": {
|
|
30
30
|
"selfcheck": "node bin/fsaa.mjs --help"
|
|
31
31
|
}
|
|
32
|
-
}
|
|
32
|
+
}
|