create-fsaa 0.1.1 → 0.1.2

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/bin/fsaa.mjs CHANGED
@@ -4,6 +4,10 @@ import { run } from "../lib/cli.mjs";
4
4
  run(process.argv.slice(2)).then(
5
5
  (code) => process.exit(code),
6
6
  (err) => {
7
+ if (err && err.userError) {
8
+ console.error("fsaa: " + (err.message || "invalid input"));
9
+ process.exit(1);
10
+ }
7
11
  console.error("fsaa: unexpected error");
8
12
  if (err && err.stack) console.error(err.stack.split("\n").slice(0, 3).join("\n"));
9
13
  else console.error(String(err));
package/lib/cli.mjs CHANGED
@@ -47,8 +47,10 @@ const HELP = `FSAA CLI v0.1 — Feature-Sliced Atomic Architecture
47
47
  help Show this help
48
48
 
49
49
  init usage:
50
- fsaa init # interactive (name, template, manager)
51
- fsaa init --name my-app --template vite --manager npm # non-interactive
50
+ fsaa init # interactive (name, template)
51
+ npx create-fsaa my-app # positional name (create-app convention)
52
+ fsaa init --name my-app --template vite # non-interactive
53
+ (no TTY -> defaults my-app / next; manager is contract-pinned: pnpm)
52
54
 
53
55
  g usage (run inside a project scaffolded by fsaa init):
54
56
  fsaa g <slice-name> # e.g. fsaa g checkout
@@ -65,11 +67,16 @@ export async function run(argv) {
65
67
  const [cmd, ...rest] = argv;
66
68
  const { flags } = parseFlags(rest);
67
69
  switch (cmd) {
68
- case "init":
69
- return initCmd({ flags, interactive: isInteractive(), prompt });
70
+ case "init": {
71
+ const { flags: f2, rest: positionals } = parseFlags(rest);
72
+ if (positionals.length && !f2.name && typeof f2.name !== "string") f2.name = positionals[0]; // create-app convention: npx create-fsaa my-app
73
+ return initCmd({ flags: { ...flags, ...f2 }, interactive: isInteractive() });
74
+ }
70
75
  case "g":
71
- case "generate":
72
- return generateCmd({ args: rest, flags, interactive: isInteractive(), prompt });
76
+ case "generate": {
77
+ const { rest: positionals } = parseFlags(rest);
78
+ return generateCmd({ args: positionals, flags, interactive: isInteractive() });
79
+ }
73
80
  case "help":
74
81
  case "--help":
75
82
  case "-h":
package/lib/download.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  /* fsaa/lib/download.mjs — degit-style fetch of a template repo tarball (zero deps).
2
2
  Downloads the codeload tar.gz, extracts with the system `tar` (ships with
3
3
  Linux, macOS, Windows 10+), then moves the tarball's root folder to the target dir. */
4
- import { mkdtempSync, mkdirSync, readdirSync, writeFileSync, rmSync, renameSync, cpSync, existsSync, readFileSync } from "node:fs";
4
+ import { mkdtempSync, mkdirSync, readdirSync, writeFileSync, rmSync, renameSync, cpSync, existsSync, readFileSync, statSync } from "node:fs";
5
5
  import { tmpdir } from "node:os";
6
6
  import { join } from "node:path";
7
7
  import { spawnSync } from "node:child_process";
@@ -31,9 +31,11 @@ export async function fetchTemplate(template, targetDir) {
31
31
  const msg = (r.stderr || "tar not found on PATH").toString().trim().slice(0, 160);
32
32
  throw new Error(`tar extract failed: ${msg}`);
33
33
  }
34
- const entries = readdirSync(x);
34
+ const entries = readdirSync(x).filter((e) => e !== "pax_global_header");
35
35
  if (entries.length !== 1) throw new Error("unexpected tarball layout");
36
- moveDir(join(x, entries[0]), targetDir);
36
+ const root = join(x, entries[0]);
37
+ if (!statSync(root).isDirectory()) throw new Error("tarball root is not a directory");
38
+ moveDir(root, targetDir);
37
39
  return t.repo;
38
40
  } finally {
39
41
  rmSync(tmp, { recursive: true, force: true });
package/lib/init.mjs CHANGED
@@ -11,12 +11,19 @@ export async function initCmd({ flags, interactive }) {
11
11
  let name = flags.name;
12
12
  let template = flags.template;
13
13
 
14
- if (!name) name = await prompt("App name [my-app]: ", "my-app");
15
- if (!template) {
14
+ if (!name && interactive) name = await prompt("App name [my-app]: ", "my-app");
15
+ if (!template && interactive) {
16
16
  const answer = await prompt("Template — 1) next (Next.js App Router) 2) vite (plain React) [next]: ", "next");
17
17
  template = answer.startsWith("2") ? "vite" : "next";
18
18
  }
19
-
19
+ if (!interactive && (!name || !template)) {
20
+ console.log(" (no TTY — defaults applied: name=my-app, template=next; pin them with --name/--template)");
21
+ }
22
+ if (name === true || template === true) {
23
+ const e = new Error("--name and --template need values: fsaa init --name my-app --template vite");
24
+ e.userError = true;
25
+ throw e;
26
+ }
20
27
  name = name || "my-app";
21
28
  template = template || "next";
22
29
  const manager = "pnpm"; // contract pin (single-lockfile rule lives on pnpm)
@@ -69,7 +76,9 @@ export async function initCmd({ flags, interactive }) {
69
76
  return 1;
70
77
  }
71
78
  if (r.status !== 0) {
72
- console.error("fsaa: dependency install failed — the template files are in place; fix your PATH or run install manually.");
79
+ console.error(`fsaa: dependency install failed — the template files are in place.
80
+ recover by hand: cd ${dest} && pnpm install
81
+ (re-running fsaa init will refuse the non-empty dir; the files are all there)`);
73
82
  return 1;
74
83
  }
75
84
  // single-lockfile contract: the template ships pnpm-lock.yaml — an npm install
@@ -117,13 +126,34 @@ function stamp(dest, { template }) {
117
126
 
118
127
  function gitInit(dest, branch, appName) {
119
128
  const state = (args) => spawnSync("git", args, { cwd: dest, stdio: "pipe" });
120
- if (!existsSync(join(dest, ".git"))) {
121
- state(["init", "-b", branch]);
122
- state(["add", "-A"]);
123
- const c = state(["commit", "-q", "-m", `feat/init — scaffold ${appName} from FSAA starter`]);
124
- if (c.status !== 0) {
125
- console.error(" (git repo initialized but the commit needs identity — set git config user.name/user.email and commit)");
129
+ if (existsSync(dest + "/.git")) return;
130
+ // SECURITY-CRITICAL: run add/commit ONLY inside a repo that we actually
131
+ // created. git init -b wants git >= 2.28; on older git fall back to plain
132
+ // init + symbolic-ref; if git is absent or init fails — skip git entirely
133
+ // (committing into a PARENT repo would stage unrelated files).
134
+ if (state(["rev-parse", "--is-inside-work-tree"]).status === 0) {
135
+ console.error(" (inside an enclosing git repo — skipped git init; create the project repo yourself)");
136
+ return;
137
+ }
138
+ let created = state(["init", "-q", "-b", branch]);
139
+ if (created.error || created.status !== 0) {
140
+ created = state(["init", "-q"]);
141
+ if (created.error || created.status !== 0) {
142
+ console.error(created.error ? " (git not found — files are ready; run git init + commit yourself)"
143
+ : " (git init failed — files are ready; run git init + commit yourself)");
144
+ return;
126
145
  }
146
+ state(["symbolic-ref", "HEAD", "refs/heads/" + branch]);
147
+ }
148
+ const gd = (state(["rev-parse", "--git-dir"]).stdout || "").toString().trim();
149
+ if (state(["rev-parse", "--is-inside-work-tree"]).status !== 0 || gd.includes("../")) {
150
+ console.error(" (git repo resolves outside the project — skipped commit)");
151
+ return;
152
+ }
153
+ state(["add", "-A"]);
154
+ const c = state(["commit", "-q", "-m", `feat/init — scaffold ${appName} from FSAA starter`]);
155
+ if (c.status !== 0) {
156
+ console.error(" (git repo initialized but the commit needs identity — set git config user.name/user.email and commit)");
127
157
  }
128
158
  }
129
159
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fsaa",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
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>",