create-creact 0.0.0-stage → 0.1.0

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 (49) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +17 -2
  3. package/dist/create.js +257 -0
  4. package/dist/layer.js +633 -0
  5. package/dist/main.js +61 -0
  6. package/dist/options.js +262 -0
  7. package/dist/shell.js +117 -0
  8. package/dist/stacks.js +42 -0
  9. package/dist/ui.js +506 -0
  10. package/dist/version.js +7 -0
  11. package/layer/base/all/.oxfmtrc.json.layer +65 -0
  12. package/layer/base/all/AGENTS.md.layer +22 -0
  13. package/layer/base/all/CLAUDE.md.layer +1 -0
  14. package/layer/base/all/apps/web/src/styles/tokens.css.layer +15 -0
  15. package/layer/base/all/commitlint.config.ts.layer +12 -0
  16. package/layer/base/all/oxlint.config.ts.layer +556 -0
  17. package/layer/base/next/AGENTS.md.layer +4 -0
  18. package/layer/base/next/apps/web/CLAUDE.md.layer +1 -0
  19. package/layer/base/react-router/AGENTS.md.layer +3 -0
  20. package/layer/standalone/all/.husky/commit-msg.layer +2 -0
  21. package/layer/standalone/all/.husky/pre-commit.layer +2 -0
  22. package/layer/standalone/all/.lintstagedrc.json.layer +4 -0
  23. package/layer/standalone/all/AGENTS.md.layer +9 -0
  24. package/layer/standalone/all/vitest.config.ts.layer +14 -0
  25. package/layer/stylex/all/AGENTS.md.layer +4 -0
  26. package/layer/stylex/all/apps/web/src/styles/tokens.stylex.ts.layer +15 -0
  27. package/layer/stylex/all/apps/web/src/styles/tokens.test.ts.layer +32 -0
  28. package/layer/stylex/all/oxlint.styling.ts.layer +20 -0
  29. package/layer/stylex/all/vitest.styling.ts.layer +18 -0
  30. package/layer/stylex/next/apps/web/babel.config.js.layer +25 -0
  31. package/layer/stylex/next/apps/web/postcss.config.js.layer +16 -0
  32. package/layer/stylex/next/apps/web/src/app/layout.tsx.layer +20 -0
  33. package/layer/stylex/next/apps/web/src/app/page.tsx.layer +48 -0
  34. package/layer/stylex/next/apps/web/src/index.css.layer +45 -0
  35. package/layer/stylex/react-router/apps/web/src/index.css.layer +27 -0
  36. package/layer/stylex/react-router/apps/web/src/root.tsx.layer +94 -0
  37. package/layer/stylex/react-router/apps/web/src/routes/_index.tsx.layer +56 -0
  38. package/layer/stylex/react-router/apps/web/vite.config.ts.layer +22 -0
  39. package/layer/tailwind/all/AGENTS.md.layer +4 -0
  40. package/layer/tailwind/all/apps/web/src/index.css.layer +3 -0
  41. package/layer/tailwind/all/apps/web/src/styles/tokens.tailwind.css.layer +7 -0
  42. package/layer/tailwind/all/apps/web/src/styles/tokens.test.ts.layer +35 -0
  43. package/layer/tailwind/all/oxlint.styling.ts.layer +69 -0
  44. package/layer/tailwind/all/vitest.styling.ts.layer +5 -0
  45. package/layer/vite-plus/all/.vite-hooks/commit-msg.layer +2 -0
  46. package/layer/vite-plus/all/.vite-hooks/pre-commit.layer +2 -0
  47. package/layer/vite-plus/all/AGENTS.md.layer +11 -0
  48. package/layer/vite-plus/all/vite.config.ts.layer +25 -0
  49. package/package.json +37 -4
package/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (C) 2026 Joshua Booth
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted.
5
+
6
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
7
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
8
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
9
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
10
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
11
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
12
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,18 @@
1
- # Temporary Holding Version
1
+ # create-creact
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Starts a React monorepo set up the way [creact](https://github.com/Joshua-Booth/creact) is: lint, format, strict tsconfig, git hooks, tests and the agent setup, all passing from the first commit.
4
+
5
+ ```sh
6
+ pnpm create creact my-app
7
+ ```
8
+
9
+ It asks for nothing. Pick a stack with a flag, or pass `--yes` for React Router on Tailwind:
10
+
11
+ ```sh
12
+ pnpm create creact my-app --stack next --styling stylex
13
+ pnpm create creact my-app --yes
14
+ ```
15
+
16
+ In a terminal it shows each step as it runs. Piped, in CI or in an agent's shell, it prints one plain line per step, and `--json` prints one object. `--help` lists every flag.
17
+
18
+ It needs Node 24 and pnpm. The full guide is in [docs/CREATE-CREACT.md](https://github.com/Joshua-Booth/creact/blob/master/docs/CREATE-CREACT.md).
package/dist/create.js ADDED
@@ -0,0 +1,257 @@
1
+ /* oxlint-disable security/detect-non-literal-fs-filename -- every path is the directory the caller named, an ancestor of it, its sibling staging dir, or inside one of them */
2
+ import { existsSync } from "node:fs";
3
+ import { mkdir, readdir, realpath, rename, rm, stat } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { apply, JSON_FILES, loadLayer, lockedSkills, plan, readState, SKILLS_CLI, SKILLS_DIR, STATE_FILE, writeState, } from "./layer.js";
6
+ import { projectName, resolveChoices, UsageError, } from "./options.js";
7
+ import { CommandFailed, run, succeeds } from "./shell.js";
8
+ import { BTS, btsArgs, STACKS } from "./stacks.js";
9
+ import { VERSION } from "./version.js";
10
+ export const STEPS = [
11
+ "monorepo",
12
+ "tooling",
13
+ "git",
14
+ "install",
15
+ "skills",
16
+ ];
17
+ function unheard() {
18
+ // A caller that passes no Progress, such as the scaffold test, hears nothing.
19
+ }
20
+ const SILENT = { begin: unheard, start: unheard, finish: unheard };
21
+ export const RESTORE = [
22
+ "pnpm",
23
+ `--package=${SKILLS_CLI}`,
24
+ "dlx",
25
+ "skills",
26
+ "experimental_install",
27
+ ];
28
+ export async function create(request, layerDir, { progress = SILENT, log } = {}) {
29
+ const target = await inspect(request.dir);
30
+ const recorded = target.kind === "project" ? target.state : undefined;
31
+ const choices = resolveChoices(request, recorded);
32
+ const name = recorded?.name ?? projectName(request.dir);
33
+ const ids = [
34
+ "base",
35
+ choices.toolchain,
36
+ choices.styling,
37
+ ...choices.extras,
38
+ ];
39
+ const ops = plan(await loadLayer(layerDir, ids, choices.stack), ids, {
40
+ stack: choices.stack,
41
+ monorepo: choices.monorepo,
42
+ toolchain: choices.toolchain,
43
+ name,
44
+ });
45
+ progress.begin(request.dir, choices);
46
+ const ms = {};
47
+ let report = { dir: request.dir, choices, ms };
48
+ const step = async (id, work) => {
49
+ progress.start(id);
50
+ const started = performance.now();
51
+ const result = await work();
52
+ ms[id] = Math.round(performance.now() - started);
53
+ report = { ...report, ...result };
54
+ progress.finish(id, report);
55
+ return result;
56
+ };
57
+ let layer;
58
+ if (target.kind === "fresh") {
59
+ const staging = path.join(path.dirname(request.dir), `.${name}.creact-staging`);
60
+ await rm(staging, { recursive: true, force: true });
61
+ try {
62
+ let made = "";
63
+ await step("monorepo", async () => {
64
+ made = await obtainBase(staging, choices, name, log);
65
+ return { base: "created" };
66
+ });
67
+ ({ layer } = await step("tooling", async () => ({
68
+ layer: await applyLayer(made, ops, { kind: "upstream-only" }, { name, choices }),
69
+ })));
70
+ await place(made, request.dir, target.exists);
71
+ }
72
+ finally {
73
+ await rm(staging, { recursive: true, force: true });
74
+ }
75
+ }
76
+ else {
77
+ await step("monorepo", () => ({ base: "kept" }));
78
+ ({ layer } = await step("tooling", async () => ({
79
+ layer: await applyLayer(request.dir, ops, { kind: "recorded", hashes: target.state.hashes }, { name, choices }),
80
+ })));
81
+ }
82
+ const { git } = await step("git", async () => ({
83
+ git: request.git ? await initGit(request.dir, log) : "skipped",
84
+ }));
85
+ await step("install", async () => {
86
+ if (request.install) {
87
+ await install(request.dir, layer.missing, log);
88
+ await fixThenFormat(request.dir, log);
89
+ }
90
+ return {
91
+ install: request.install ? "done" : "skipped",
92
+ };
93
+ });
94
+ const { skills, skillCount } = await step("skills", async () => request.install
95
+ ? restoreSkills(request.dir, log)
96
+ : { skills: "skipped", skillCount: 0 });
97
+ return {
98
+ dir: request.dir,
99
+ choices,
100
+ base: target.kind === "fresh" ? "created" : "kept",
101
+ layer,
102
+ git,
103
+ install: request.install ? "done" : "skipped",
104
+ skills,
105
+ skillCount,
106
+ ms,
107
+ };
108
+ }
109
+ async function inspect(dir) {
110
+ const nearest = nearestExisting(dir);
111
+ if (!(await stat(nearest)).isDirectory()) {
112
+ throw new UsageError(nearest === dir
113
+ ? `${dir} is a file. Give a directory for the project.`
114
+ : `${dir} would sit under the file ${nearest}. Give a directory for the project.`);
115
+ }
116
+ const exists = nearest === dir;
117
+ const repo = await outerRepo(dir, nearest);
118
+ if (repo !== undefined) {
119
+ throw new UsageError(`${dir} is inside the git repository at ${repo}, so the project would get no repository of its own. Pick a directory outside it.`);
120
+ }
121
+ if (!exists)
122
+ return { kind: "fresh", exists: false };
123
+ const state = await readState(dir);
124
+ if (state !== undefined)
125
+ return { kind: "project", state };
126
+ if ((await readdir(dir)).length === 0)
127
+ return { kind: "fresh", exists: true };
128
+ throw new UsageError(`${dir} isn't empty and has no ${STATE_FILE}, so create-creact didn't make it. Pick a new directory.`);
129
+ }
130
+ function nearestExisting(dir) {
131
+ let nearest = dir;
132
+ while (!existsSync(nearest))
133
+ nearest = path.dirname(nearest);
134
+ return nearest;
135
+ }
136
+ // A walk for a .git entry, so --no-git needs no git on PATH. It starts from
137
+ // the real path, as a symlink into a repository would otherwise pass.
138
+ async function outerRepo(dir, nearest) {
139
+ const real = await realpath(nearest);
140
+ for (let probe = nearest === dir ? path.dirname(real) : real; probe !== path.dirname(probe); probe = path.dirname(probe)) {
141
+ if (existsSync(path.join(probe, ".git")))
142
+ return probe;
143
+ }
144
+ return undefined;
145
+ }
146
+ // Better-T-Stack keeps a history of every project it makes in its data
147
+ // directory under HOME (XDG_DATA_HOME on Linux), so it gets an empty one.
148
+ // pnpm keeps the real HOME and its store.
149
+ export async function obtainBase(staging, choices, name, log) {
150
+ const home = path.join(staging, ".home");
151
+ await mkdir(home, { recursive: true });
152
+ await run("pnpm", [
153
+ `--package=${BTS}`,
154
+ "dlx",
155
+ "env",
156
+ `HOME=${home}`,
157
+ `XDG_DATA_HOME=${path.join(home, ".local", "share")}`,
158
+ "create-better-t-stack",
159
+ ...btsArgs(name, choices.stack, choices.monorepo),
160
+ ], staging, log);
161
+ return path.join(staging, name);
162
+ }
163
+ async function applyLayer(dir, ops, prior, project) {
164
+ const missing = [STACKS[project.choices.stack].signature, ...JSON_FILES]
165
+ .filter((file) => !existsSync(path.join(dir, file)))
166
+ .join(", ");
167
+ if (missing !== "") {
168
+ throw prior.kind === "upstream-only"
169
+ ? new CommandFailed(`${BTS} finished without writing ${missing}, so its output changed shape`)
170
+ : new UsageError(`${dir} is missing ${missing}, which the layer builds on, so create-creact can't update it`);
171
+ }
172
+ const layer = await apply(dir, ops, prior);
173
+ await writeState(dir, {
174
+ schema: 2,
175
+ creact: VERSION,
176
+ name: project.name,
177
+ ...project.choices,
178
+ hashes: layer.hashes,
179
+ });
180
+ return layer;
181
+ }
182
+ // An existing empty target may be the caller's cwd, so it keeps its inode
183
+ // and receives the entries instead.
184
+ async function place(base, target, exists) {
185
+ if (!exists) {
186
+ await rename(base, target);
187
+ return;
188
+ }
189
+ const stateDir = path.dirname(STATE_FILE);
190
+ for (const entry of await readdir(base)) {
191
+ if (entry !== stateDir) {
192
+ await rename(path.join(base, entry), path.join(target, entry));
193
+ }
194
+ }
195
+ await rename(path.join(base, stateDir), path.join(target, stateDir));
196
+ }
197
+ // Before install, because husky's prepare script needs .git to set the hooks.
198
+ async function initGit(dir, log) {
199
+ if (await succeeds("git", ["rev-parse", "--is-inside-work-tree"], dir)) {
200
+ return "existing";
201
+ }
202
+ await run("git", ["init", "--quiet"], dir, log);
203
+ return "initialised";
204
+ }
205
+ // Better-T-Stack pins the caller's pnpm, and pnpm 10's add installs only the
206
+ // package it adds to, so the install after it fills in the rest of the
207
+ // workspace. pnpm add skips the project's own prepare script, which installs
208
+ // the git hooks.
209
+ async function install(dir, missing, log) {
210
+ for (const { manifest, dependencies, devDependencies } of missing) {
211
+ const cwd = path.join(dir, path.dirname(manifest));
212
+ const root = manifest === "package.json" ? ["--workspace-root"] : [];
213
+ if (dependencies.length > 0) {
214
+ await run("pnpm", ["add", ...root, ...dependencies], cwd, log);
215
+ }
216
+ if (devDependencies.length > 0) {
217
+ await run("pnpm", ["add", ...root, "--save-dev", ...devDependencies], cwd, log);
218
+ }
219
+ }
220
+ await run("pnpm", ["install"], dir, log);
221
+ await run("pnpm", ["run", "prepare"], dir, log);
222
+ }
223
+ // oxlint applies one fix per overlapping range in a pass, so the shadcn code
224
+ // Better-T-Stack writes needs a second pass before lint passes.
225
+ async function fixThenFormat(dir, log) {
226
+ if (!(await succeeds("pnpm", ["run", "lint", "--fix"], dir))) {
227
+ await run("pnpm", ["run", "lint", "--fix"], dir, log);
228
+ }
229
+ await run("pnpm", ["run", "format"], dir, log);
230
+ }
231
+ // Only when a locked skill is missing, so a rerun neither clones nor lets the
232
+ // restore rewrite the project's lock.
233
+ async function restoreSkills(dir, log) {
234
+ const ids = await lockedSkills(dir);
235
+ const skillCount = ids.size;
236
+ if ([...ids].every((id) => existsSync(path.join(dir, SKILLS_DIR, id)))) {
237
+ return { skills: "present", skillCount };
238
+ }
239
+ const [command, ...args] = RESTORE;
240
+ try {
241
+ await run(command, args, dir, log);
242
+ }
243
+ catch (error) {
244
+ if (!(error instanceof CommandFailed))
245
+ throw error;
246
+ const where = log === undefined ? "above" : `in ${log.file}`;
247
+ return {
248
+ skills: {
249
+ failed: (await succeeds("git", ["--version"], dir))
250
+ ? `${error.message}. Its output is ${where}`
251
+ : "git isn't on PATH, and the restore clones the skills with it",
252
+ },
253
+ skillCount,
254
+ };
255
+ }
256
+ return { skills: "restored", skillCount };
257
+ }