create-fsaa 0.2.3 → 0.2.4

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.
Files changed (2) hide show
  1. package/lib/init.mjs +36 -4
  2. 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
  }
@@ -122,18 +131,41 @@ export async function initCmd({ flags, interactive }) {
122
131
  return 0;
123
132
  }
124
133
 
125
- function validate(name, template) {
134
+ /* Normalize an app name into npm/pnpm/kebab-friendly form BEFORE validating:
135
+ invalid input → normalized name (with a notice), not a stack trace.
136
+ "PayOn" -> pay-on (camelCase splits into words)
137
+ "My App" -> my-app (spaces become dashes)
138
+ "MyApp." -> my-app (trailing dots are stripped — Windows paths) */
139
+ function normalizeName(raw) {
140
+ const normalized = String(raw)
141
+ .replace(/([a-z0-9])([A-Z])/g, "$1-$2") // camelCase -> kebab
142
+ .trim()
143
+ .toLowerCase()
144
+ .replace(/[\s_]+/g, "-") // spaces/underscores -> dashes
145
+ .replace(/\.{2,}/g, ".") // squeeze dots
146
+ .replace(/[^a-z0-9._-]/g, "") // drop anything npm/pnpm would reject
147
+ .replace(/^[._-]+/, "").replace(/[._-]+$/, ""); // trim edge dots/dashes
148
+ return normalized;
149
+ }
150
+
151
+ export function validate(name, template) {
126
152
  if (!TEMPLATES[template]) {
127
- throw new Error(`unknown template "${template}" — choose: ${Object.keys(TEMPLATES).join(" | ")}`);
153
+ const e = new Error(`unknown template "${template}" — choose: ${Object.keys(TEMPLATES).join(" | ")}`);
154
+ e.userError = true;
155
+ throw e;
128
156
  }
129
157
  // npm/pnpm require lowercase package names; a strict lowercase regex also
130
158
  // keeps the project folder name predictable (no /i flag deliberately).
131
159
  if (!/^[a-z0-9][a-z0-9._-]*$/.test(name)) {
132
- throw new Error(`invalid app name "${name}" — lowercase letters, digits, dots, dashes, underscores only`);
160
+ 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-')`);
161
+ e.userError = true;
162
+ throw e;
133
163
  }
134
164
  // Windows: trailing dots/space vanish in paths; reserved device names break mkdir.
135
165
  if (/[.\s-]$/.test(name) || /^(con|prn|aux|nul|com\d|lpt\d)$/i.test(name)) {
136
- throw new Error(`invalid app name "${name}" — no trailing dot/space/dash, and no Windows reserved names (con, prn, aux, nul, com1..9, lpt1..9)`);
166
+ 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)`);
167
+ e.userError = true;
168
+ throw e;
137
169
  }
138
170
  }
139
171
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fsaa",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
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
+ }