create-fsaa 0.2.2 → 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 +48 -9
  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
  }
@@ -79,7 +88,7 @@ export async function initCmd({ flags, interactive }) {
79
88
  console.log(` pnpm not on PATH — running the pinned pnpm@${pinned} through npx…`);
80
89
  r = spawnSync(npxBin, ["-y", `pnpm@${pinned}`, "install"], { cwd: dest, stdio: "inherit", shell: win });
81
90
  if (r.error) {
82
- console.error(`\nfsaa: could not install dependencies automatically (npx unavailable).\n recover by hand: cd ${dest} && npm exec -y pnpm@${pinned} install`);
91
+ console.error(`\nfsaa: could not install dependencies automatically (npx unavailable).\n recover by hand: cd ${dest} && corepack enable && pnpm install\n (or: cd ${dest} && npm exec -y pnpm@${pinned} install)`);
83
92
  const e = new Error("install failed");
84
93
  e.userError = true;
85
94
  throw e;
@@ -106,27 +115,57 @@ export async function initCmd({ flags, interactive }) {
106
115
  gitInit(dest, "feat/init", nameSafe(dest));
107
116
 
108
117
  console.log(`\n${"=".repeat(52)}`);
109
- console.log(` ✔ ${name} is ready (${templateLabel(template)})`);
110
- console.log(` cd ${dest}`);
111
- console.log(` ${manager} run dev`);
118
+ console.log(` ✔ ${name} is ready (${templateLabel(template)}) — dependencies are installed`);
119
+ // Vite-style relative next command (Windows users can paste it as-is);
120
+ // the absolute path goes in parentheses for orientation.
121
+ console.log(` Now run:\n\n cd ${name}\n ${manager} run dev\n`);
122
+ console.log(` (project created at ${dest})`);
112
123
  console.log(` agent contract: AGENTS.md · skills: agents/`);
113
124
  console.log(` generate slices: ${manager === "pnpm" ? "pnpm exec" : "npx"} fsaa g <slice-name> (or: npx create-fsaa g <slice-name>)`);
114
- console.log("=".repeat(52));
125
+ console.log(`${"-".repeat(52)}`);
126
+ console.log(` no pnpm on PATH? enable the one bundled with Node (one-time, no global install):`);
127
+ console.log(` corepack enable`);
128
+ console.log(` or always prefix pnpm with the pinned version:`);
129
+ console.log(` npx -y ${pkg.packageManager || "pnpm@10.34.9"} <command>`);
130
+ console.log(`=`.repeat(52));
115
131
  return 0;
116
132
  }
117
133
 
118
- 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) {
119
152
  if (!TEMPLATES[template]) {
120
- 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;
121
156
  }
122
157
  // npm/pnpm require lowercase package names; a strict lowercase regex also
123
158
  // keeps the project folder name predictable (no /i flag deliberately).
124
159
  if (!/^[a-z0-9][a-z0-9._-]*$/.test(name)) {
125
- 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;
126
163
  }
127
164
  // Windows: trailing dots/space vanish in paths; reserved device names break mkdir.
128
165
  if (/[.\s-]$/.test(name) || /^(con|prn|aux|nul|com\d|lpt\d)$/i.test(name)) {
129
- 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;
130
169
  }
131
170
  }
132
171
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fsaa",
3
- "version": "0.2.2",
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
+ }