create-feltkit 0.3.19 → 0.3.21

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/create.js CHANGED
@@ -1,21 +1,47 @@
1
1
  #!/usr/bin/env node
2
- // npm create feltkit@latest <dir> [-- --template managed]
3
- import { resolve } from "node:path";
2
+ // npm create feltkit@latest <dir> the application-composition interview (the default)
3
+ // npm create feltkit@latest <dir> -- --template <t> a fixed starter, unchanged
4
+ //
5
+ // Two jobs, one of each. The composition interview and the composition pipeline live in `@feltdb/feltkit`; this
6
+ // bootstrapper runs that binary rather than reimplementing any part of it, so there is exactly one interview and one
7
+ // pipeline. The starters it used to be only about are still here, now asked for explicitly with `--template`.
8
+ //
9
+ // Why it runs the composer's binary instead of importing it: `@feltdb/feltkit` does not export its CLI (its public
10
+ // exports are the runtime, not `createCommand`), and a wrapper must not reach past a package's export map. Running
11
+ // the binary also hands the terminal, the signals and the exit code to the composer unchanged, which is what a
12
+ // developer answering questions needs. The binary comes from the declared dependency on disk; nothing is downloaded
13
+ // or installed when this runs.
14
+ import { spawnSync } from "node:child_process";
15
+ import { existsSync, readFileSync } from "node:fs";
16
+ import { dirname, join, resolve } from "node:path";
17
+ import { fileURLToPath } from "node:url";
18
+
4
19
  import { scaffold, TEMPLATES, VERSION } from "../scaffold.js";
5
20
 
6
- const args = process.argv.slice(2);
21
+ // `npm create feltkit <dir> -- --flag` has npm remove the `--` before this runs, but a direct
22
+ // `create-feltkit <dir> -- --flag` does not, and the composer would then read `--` as an argument and miss the flags
23
+ // after it. Dropping a standalone separator makes both spellings mean the same thing.
24
+ const args = process.argv.slice(2).filter((a) => a !== "--");
7
25
  const color = process.stdout.isTTY && !process.env.NO_COLOR;
8
26
  const bold = (s) => (color ? `\u001b[1m${s}\u001b[22m` : s);
9
27
  const dim = (s) => (color ? `\u001b[2m${s}\u001b[22m` : s);
10
28
  const green = (s) => (color ? `\u001b[32m${s}\u001b[39m` : s);
11
29
  const red = (s) => (color ? `\u001b[31m${s}\u001b[39m` : s);
12
30
 
31
+ const COMPOSER = "@feltdb/feltkit";
32
+
13
33
  if (args.includes("--help") || args.includes("-h")) {
14
- console.log(`npm create feltkit@latest <directory> [-- --name <app-name>] [-- --template <starter>]
34
+ console.log(`npm create feltkit@latest <directory>
15
35
 
16
- Creates a FeltKit application you can run immediately.
36
+ Composes a FeltKit application: it asks what kind of application you are building, who the data belongs to,
37
+ who uses it and which capabilities it needs, then generates the foundation from your answers.
38
+ Every \`feltkit create\` flag works here too; pass them after \`--\`.
17
39
 
18
- Starters (--template):
40
+ npm create feltkit@latest my-app
41
+ npm create feltkit@latest my-app -- --yes --data-belongs-to individuals (no questions)
42
+ npm create feltkit@latest my-app -- --help (every composition flag)
43
+
44
+ Starters instead of composing (--template), each a complete application you can run immediately:
19
45
  ${Object.entries(TEMPLATES).map(([name, { description }]) => ` ${name.padEnd(9)}${description}`).join("\n")}
20
46
 
21
47
  --managed is short for --template managed.`);
@@ -25,15 +51,89 @@ if (args.includes("--version")) {
25
51
  console.log(VERSION);
26
52
  process.exit(0);
27
53
  }
54
+
28
55
  const VALUE_FLAGS = ["--name", "--template"];
29
56
  const valueOf = (flag) => {
30
57
  const index = args.indexOf(flag);
31
58
  return index >= 0 ? args[index + 1] : undefined;
32
59
  };
33
- const name = valueOf("--name");
34
- const template = args.includes("--managed") ? "managed" : (valueOf("--template") ?? "tasks");
35
- const dir = args.find((a, i) => !a.startsWith("-") && !VALUE_FLAGS.includes(args[i - 1])) ?? "my-feltkit-app";
36
60
 
61
+ /**
62
+ * The composer's executable, from this package's declared dependency.
63
+ *
64
+ * Resolved by walking up from the dependency's own entry point to the directory that holds its `package.json`, which
65
+ * works whatever the package's export map allows: `require.resolve("<pkg>/package.json")` throws for a package whose
66
+ * exports do not list it, and most now do not.
67
+ */
68
+ function composerBin() {
69
+ let from;
70
+ try {
71
+ from = fileURLToPath(import.meta.resolve(COMPOSER));
72
+ } catch {
73
+ return null;
74
+ }
75
+ for (let dir = dirname(from); ; dir = dirname(dir)) {
76
+ const manifest = join(dir, "package.json");
77
+ if (existsSync(manifest)) {
78
+ try {
79
+ if (JSON.parse(readFileSync(manifest, "utf8")).name === COMPOSER) {
80
+ const bin = join(dir, "bin", "feltkit.js");
81
+ return existsSync(bin) ? bin : null;
82
+ }
83
+ } catch {
84
+ return null;
85
+ }
86
+ }
87
+ if (dirname(dir) === dir) return null;
88
+ }
89
+ }
90
+
91
+ const template = args.includes("--managed") ? "managed" : valueOf("--template");
92
+ // The destination is the first argument that is neither a flag nor a flag's value. Its index is kept so only that
93
+ // one argument is replaced when the rest is forwarded: a `--name my-app` whose value happens to equal the directory
94
+ // must survive.
95
+ const dirIndex = args.findIndex((a, i) => !a.startsWith("-") && !VALUE_FLAGS.includes(args[i - 1]));
96
+ const dir = dirIndex >= 0 ? args[dirIndex] : "my-feltkit-app";
97
+
98
+ if (!template) {
99
+ // The default: compose. Everything after the directory is the composer's to interpret, so a flag added to
100
+ // `feltkit create` works here the day it ships, without this file knowing about it.
101
+ //
102
+ // With no terminal, and nothing in the arguments saying what to do instead, refuse here rather than letting the
103
+ // composer refuse. Both refuse for the same good reason — an interview needs someone to answer it — but the
104
+ // composer answers in its own vocabulary, telling the reader to run `feltkit create …`, which is not a command
105
+ // someone who typed `npm create feltkit` has. This is the caller that most often has no terminal (a script, a
106
+ // container build, a test), so it is the caller whose routes the message should name.
107
+ if (!process.stdin.isTTY && !args.includes("--yes") && !args.includes("--interactive")) {
108
+ console.error(`${red("✗")} Not a terminal, so the composition interview cannot be answered. Nothing was written.`);
109
+ console.error(" Choose one:");
110
+ console.error(` npm create feltkit@latest ${dir} -- --template tasks a complete starter, no questions`);
111
+ console.error(` npm create feltkit@latest ${dir} -- --yes --param identity.accounts.emailFrom=auth@example.com`);
112
+ console.error(" compose from flags, no questions");
113
+ console.error(` npm create feltkit@latest ${dir} -- --interactive answer the questions over a pipe`);
114
+ console.error(dim(` Starters: ${Object.keys(TEMPLATES).join(", ")}. Every composition flag: npm create feltkit@latest ${dir} -- --help`));
115
+ process.exit(1);
116
+ }
117
+ const bin = composerBin();
118
+ if (!bin) {
119
+ console.error(`${red("✗")} ${COMPOSER} is not installed beside this package, so the composition interview cannot be started.`);
120
+ console.error(` hint: run \`npm create feltkit@latest ${dir}\` again (npm installs this package's dependencies), or scaffold a starter instead: \`npm create feltkit@latest ${dir} -- --template tasks\``);
121
+ process.exit(1);
122
+ }
123
+ const forwarded = args.filter((_, i) => i !== dirIndex);
124
+ const result = spawnSync(process.execPath, [bin, "create", dir, ...forwarded], { stdio: "inherit" });
125
+ // The composer owns the outcome: its exit code, and a signal that stopped it, pass through unchanged so a
126
+ // cancelled interview is a cancelled command here too.
127
+ if (result.error) {
128
+ console.error(`${red("✗")} could not start the composition interview: ${result.error.message}`);
129
+ process.exit(1);
130
+ }
131
+ if (result.signal) process.kill(process.pid, result.signal);
132
+ process.exit(result.status ?? 1);
133
+ }
134
+
135
+ // A starter, asked for explicitly. Unchanged behaviour, including every message.
136
+ const name = valueOf("--name");
37
137
  try {
38
138
  const result = scaffold({ target: resolve(process.cwd(), dir), template, ...(name ? { name } : {}) });
39
139
  console.log(`${green("✓")} Created ${bold(result.name)} in ${result.dir}${template === "tasks" ? "" : ` (${template} starter)`}\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-feltkit",
3
- "version": "0.3.19",
3
+ "version": "0.3.21",
4
4
  "description": "Create a FeltKit application: npm create feltkit@latest my-app (add -- --template managed for Managed FeltDB)",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,5 +35,8 @@
35
35
  "prepack": "node sync-template.mjs",
36
36
  "test": "node --test test/*.test.mjs"
37
37
  },
38
- "homepage": "https://www.npmjs.com/package/create-feltkit"
38
+ "homepage": "https://www.npmjs.com/package/create-feltkit",
39
+ "dependencies": {
40
+ "@feltdb/feltkit": "0.3.21"
41
+ }
39
42
  }
@@ -13,7 +13,7 @@
13
13
  "typecheck": "tsc --noEmit"
14
14
  },
15
15
  "dependencies": {
16
- "@feltdb/feltkit": "0.3.19",
16
+ "@feltdb/feltkit": "0.3.21",
17
17
  "react": "19.2.0",
18
18
  "react-dom": "19.2.0"
19
19
  },
@@ -16,7 +16,7 @@
16
16
  "compose:plan": "feltkit compose plan"
17
17
  },
18
18
  "dependencies": {
19
- "@feltdb/feltkit": "0.3.18",
19
+ "@feltdb/feltkit": "0.3.21",
20
20
  "react": "19.2.0",
21
21
  "react-dom": "19.2.0"
22
22
  },
@@ -20,7 +20,7 @@
20
20
  "deploy:fly": "node scripts/deploy-fly.mjs"
21
21
  },
22
22
  "dependencies": {
23
- "@feltdb/feltkit": "0.3.19"
23
+ "@feltdb/feltkit": "0.3.21"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@feltdb/core": ">=0.21.0 <1.0.0",