@clearlydev/nx-archweave 0.6.1 → 0.7.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 (53) hide show
  1. package/README.md +34 -3
  2. package/dist/eslint/index.js +1 -1
  3. package/dist/generators/_chunks/{chunk-MQNQJOWA.js → chunk-22FVJUNE.js} +4 -2
  4. package/dist/generators/_chunks/{chunk-CH5AF5S2.js → chunk-2ADC6RKP.js} +1 -1
  5. package/dist/generators/_chunks/{chunk-2K4JADTK.js → chunk-6PKKKQMD.js} +46 -3
  6. package/dist/generators/_chunks/chunk-72D3GWHO.js +269 -0
  7. package/dist/generators/_chunks/{chunk-2TQWFUMC.js → chunk-736LFDT4.js} +21 -1
  8. package/dist/generators/_chunks/{chunk-D7J7HTND.js → chunk-7RTT5NBN.js} +4 -4
  9. package/dist/generators/_chunks/chunk-AOKTOS3U.js +294 -0
  10. package/dist/generators/_chunks/chunk-B6RBCUIL.js +325 -0
  11. package/dist/generators/_chunks/{chunk-XZM354ZH.js → chunk-CHZPA6OE.js} +5 -3
  12. package/dist/generators/_chunks/{chunk-UAPIAMRL.js → chunk-DAXD47YO.js} +1 -1
  13. package/dist/generators/_chunks/chunk-GN76UMTK.js +28 -0
  14. package/dist/generators/_chunks/{chunk-L52OUT5T.js → chunk-J24X4EOB.js} +1 -1
  15. package/dist/generators/_chunks/{chunk-EHYC6FUR.js → chunk-JSHZ6VSW.js} +1 -1
  16. package/dist/generators/_chunks/chunk-KNVBFTH4.js +64 -0
  17. package/dist/generators/_chunks/chunk-MF75SQM6.js +98 -0
  18. package/dist/generators/_chunks/chunk-N6SPEKJB.js +106 -0
  19. package/dist/generators/_chunks/chunk-OX7W4SJ2.js +214 -0
  20. package/dist/generators/_chunks/chunk-R2VEJGNP.js +84 -0
  21. package/dist/generators/_chunks/chunk-SBOQHME6.js +140 -0
  22. package/dist/generators/_chunks/{chunk-WD2HL2RE.js → chunk-STGNMZLM.js} +1 -1
  23. package/dist/generators/_chunks/{chunk-XXXON43Z.js → chunk-SZRBDQCU.js} +4 -51
  24. package/dist/generators/_chunks/{chunk-LKXSS5E2.js → chunk-W2BBF5MS.js} +3 -86
  25. package/dist/generators/add-agent-rules/generator.js +2 -2
  26. package/dist/generators/add-backend/generator.js +2 -2
  27. package/dist/generators/add-fsd-lite/generator.js +7 -5
  28. package/dist/generators/add-github-templates/generator.js +2 -2
  29. package/dist/generators/add-integration/generator.js +2 -2
  30. package/dist/generators/add-review/generator.js +2 -2
  31. package/dist/generators/add-storybook/files/example/button/button.stories.tsx.template +13 -0
  32. package/dist/generators/add-storybook/files/example/button/button.tsx.template +7 -0
  33. package/dist/generators/add-storybook/files/example/index.ts.template +1 -0
  34. package/dist/generators/add-storybook/files/library/tailwind.css.template +2 -0
  35. package/dist/generators/add-storybook/generator.js +28 -0
  36. package/dist/generators/add-tailwind/files/next/postcss.config.mjs.template +7 -0
  37. package/dist/generators/add-tailwind/files/react-vite/index.css.template +2 -0
  38. package/dist/generators/add-tailwind/generator.js +26 -0
  39. package/dist/generators/allow-builds/generator.js +7 -207
  40. package/dist/generators/doctor/generator.js +388 -29
  41. package/dist/generators/entity/generator.js +4 -3
  42. package/dist/generators/feature/generator.js +4 -3
  43. package/dist/generators/init/generator.js +49 -10
  44. package/dist/generators/install-integration/generator.js +2 -2
  45. package/dist/generators/page/generator.js +4 -3
  46. package/dist/generators/shared/generator.js +4 -3
  47. package/dist/generators/widget/generator.js +4 -3
  48. package/dist/migrations/update-0.5.3/add-toolkit-config-lint-input.js +7 -3
  49. package/generators.json +10 -0
  50. package/package.json +1 -1
  51. package/src/generators/add-storybook/schema.json +33 -0
  52. package/src/generators/add-tailwind/schema.json +18 -0
  53. package/src/generators/init/schema.json +8 -0
package/README.md CHANGED
@@ -68,13 +68,15 @@ pnpm nx g @clearlydev/nx-archweave:init --preset=quick-start --frontend=next --a
68
68
 
69
69
  | Generator | What it does |
70
70
  | --- | --- |
71
- | `init` | Runs the five `add-*` generators by preset |
71
+ | `init` | Runs the five `add-*` generators by preset, plus `add-tailwind` and `add-storybook` when asked |
72
72
  | `doctor` | Read-only diagnosis; never writes |
73
73
  | `add-fsd-lite` | Wires in the FSD boundaries ESLint rule |
74
74
  | `add-agent-rules` | Writes rules into each AI host's file |
75
75
  | `add-github-templates` | Issue Forms, PR template, CODEOWNERS |
76
76
  | `add-review` | AI PR review workflow |
77
77
  | `add-backend` | Wires a backend app in |
78
+ | `add-tailwind` | Tailwind CSS v4 for a React (Vite) or Next.js app |
79
+ | `add-storybook` | Finishes an app's or a library's Nx Storybook setup for FSD |
78
80
  | `page` / `widget` / `feature` / `entity` / `shared` | Scaffold an FSD slice or segment |
79
81
  | `add-integration` | Previews a catalog plugin's install flow |
80
82
  | `install-integration` | Installs a catalog plugin (with `--apply`) |
@@ -88,9 +90,9 @@ In the option lists below:
88
90
 
89
91
  ### `init`
90
92
 
91
- A preset-driven pipeline over the five `add-*` generators: `add-fsd-lite`, `add-agent-rules`, `add-github-templates`, `add-review` and `add-backend`. After the run, `init` does a best-effort validation (actionlint, `nx graph`).
93
+ A preset-driven pipeline over the five `add-*` generators: `add-fsd-lite`, `add-agent-rules`, `add-github-templates`, `add-review` and `add-backend`. `--tailwind` runs `add-tailwind` for the app, and `--storybook` runs `add-storybook` once Nx's Storybook setup is there (otherwise the report lists its steps); left out, both run again for the projects they recorded. `init` never passes `--tailwind` to `add-storybook`. After the run, `init` does a best-effort validation (actionlint, `nx graph`).
92
94
 
93
- Options: `--preset`†, `--frontend`†, `--backend`, `--packageManager`, `--locale`, `--aiHosts`, `--reviewProvider`, `--fsd`, `--agentRules`, `--githubTemplates`, `--review`, `--applyEslint`, `--allowDirty`, `--dryRun`
95
+ Options: `--preset`†, `--frontend`†, `--backend`, `--packageManager`, `--locale`, `--aiHosts`, `--reviewProvider`, `--fsd`, `--agentRules`, `--githubTemplates`, `--review`, `--tailwind`, `--storybook`, `--applyEslint`, `--allowDirty`, `--dryRun`
94
96
 
95
97
  ### `doctor`
96
98
 
@@ -102,6 +104,8 @@ A read-only diagnosis. `doctor` never writes. It checks:
102
104
  - FSD-like structure
103
105
  - review consistency
104
106
  - drift states
107
+ - the Tailwind setup of each app `add-tailwind` recorded
108
+ - the Storybook setup of each app and library `add-storybook` recorded
105
109
 
106
110
  Options: `--liveIntegrations`, `--json`
107
111
 
@@ -153,6 +157,33 @@ If the `api` project is missing, the generator refuses and gives you the officia
153
157
 
154
158
  Options: `--backend`\*, `--apiName`, `--frontendProject`, `--applyEslint`, `--dryRun`
155
159
 
160
+ ### `add-tailwind`
161
+
162
+ Adds Tailwind CSS v4 to one React (Vite) or Next.js app:
163
+
164
+ - React (Vite): the `@tailwindcss/vite` plugin and `src/app/styles/index.css`, imported from the app module. If the app already loads Tailwind from a stylesheet, that file is used instead.
165
+ - Next.js: a `postcss.config.mjs` with `@tailwindcss/postcss`, and the stylesheet the root layout imports.
166
+ - An `@source` line for the workspace libraries, and the missing devDependencies.
167
+
168
+ Every file gets only the line it needs; a shape the generator doesn't recognise is left alone and the lines to add are reported. It refuses an app on Tailwind v3 or with Sass global styles, and records the app in `toolkit.config.json` so `doctor` can check it.
169
+
170
+ Options: `--project`, `--dryRun`
171
+
172
+ ### `add-storybook`
173
+
174
+ Finishes Nx's Storybook setup (`@nx/storybook:configuration`, which runs first) of one React (Vite) or Next.js app for FSD:
175
+
176
+ - stories reach the whole source root (Nx's React (Vite) glob covers only `src/app/**`)
177
+ - `eslint-plugin-storybook` and a `storybook-static` ignore in the app's ESLint config (written only with `--applyEslint`)
178
+ - for an app add-tailwind recorded, the preview imports the app's Tailwind stylesheet first
179
+ - `--example`: a Button, its story and the `shared/ui` public API
180
+
181
+ Without Nx's setup it writes nothing and lists the commands, including the pnpm 11 × Next.js core-js-pure step. The app is recorded in `toolkit.config.json` so `doctor` can check it.
182
+
183
+ A React (Vite) library is taken when named with `--project` (its `.storybook/main` on `@storybook/react-vite`, or naming no framework; `@storybook/nextjs` is refused with the steps that switch it, any other framework is refused). `--tailwind` loads Tailwind in the library's Storybook (the Vite plugin in `viteFinal`, in the Vite config `viteConfigPath` names, or else in the library's one `vite.config`, a `.storybook/tailwind.css`, the preview import) and records it under `storybook.tailwind`; a rerun keeps those lines, so taking Tailwind out is by hand. `--example` is for apps.
184
+
185
+ Options: `--project`, `--example`, `--tailwind`, `--applyEslint`, `--dryRun`
186
+
156
187
  ### `page` / `widget` / `feature` / `entity` / `shared`
157
188
 
158
189
  `page`, `widget`, `feature` and `entity` scaffold a slice: `index.ts` + `model/`, plus `--segments` extras. `shared` scaffolds a purpose-named segment instead. Each generator writes to its own layer in the app:
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  fsdBoundariesRule
3
- } from "../generators/_chunks/chunk-MQNQJOWA.js";
3
+ } from "../generators/_chunks/chunk-22FVJUNE.js";
4
4
  import {
5
5
  readRecordedFsd,
6
6
  resolveFsdPolicy
@@ -30,8 +30,10 @@ var SEGMENTS = [
30
30
  "context"
31
31
  ];
32
32
  var IGNORED = /^(\.|readme(\.|$))/i;
33
+ var SAME_TICK_MS = 2e3;
33
34
  var listings = /* @__PURE__ */ new Map();
34
35
  function list(dir) {
36
+ const readAtMs = Date.now();
35
37
  let mtimeMs;
36
38
  try {
37
39
  mtimeMs = statSync(dir).mtimeMs;
@@ -40,10 +42,10 @@ function list(dir) {
40
42
  return null;
41
43
  }
42
44
  const cached = listings.get(dir);
43
- if (cached !== void 0 && cached.mtimeMs === mtimeMs) return cached.entries;
45
+ if (cached !== void 0 && cached.mtimeMs === mtimeMs && cached.readAtMs - mtimeMs >= SAME_TICK_MS) return cached.entries;
44
46
  try {
45
47
  const entries = readdirSync(dir, { withFileTypes: true }).map((entry) => ({ name: entry.name, directory: entry.isDirectory() }));
46
- listings.set(dir, { mtimeMs, entries });
48
+ listings.set(dir, { mtimeMs, readAtMs, entries });
47
49
  return entries;
48
50
  } catch {
49
51
  return null;
@@ -17,7 +17,7 @@ import {
17
17
  import {
18
18
  applyJsonEdits,
19
19
  treePackageManager
20
- } from "./chunk-2TQWFUMC.js";
20
+ } from "./chunk-736LFDT4.js";
21
21
 
22
22
  // src/generators/add-review/generator.ts
23
23
  var CONFIG_PATH = "toolkit.config.json";
@@ -1,3 +1,9 @@
1
+ import {
2
+ renderAddStorybookReport
3
+ } from "./chunk-SBOQHME6.js";
4
+ import {
5
+ renderAddTailwindReport
6
+ } from "./chunk-N6SPEKJB.js";
1
7
  import {
2
8
  renderAddAgentRulesReport
3
9
  } from "./chunk-F5C5HUSI.js";
@@ -18,7 +24,7 @@ import {
18
24
  lintInputsTargetDefaultsSnippet,
19
25
  readTargetDefaults,
20
26
  resolveTargetDefaults
21
- } from "./chunk-XXXON43Z.js";
27
+ } from "./chunk-SZRBDQCU.js";
22
28
  import {
23
29
  ESLINT_CONFIG_CANDIDATES
24
30
  } from "./chunk-6ZTIUBB2.js";
@@ -27,7 +33,7 @@ import {
27
33
  } from "./chunk-FZGN5NEP.js";
28
34
  import {
29
35
  applyJsonEdits
30
- } from "./chunk-2TQWFUMC.js";
36
+ } from "./chunk-736LFDT4.js";
31
37
  import {
32
38
  packageManagerCommands,
33
39
  runNxCommand
@@ -88,6 +94,33 @@ function leftForYou(report) {
88
94
  if (review.dependabot === "proposed") manual.push(".github/dependabot.yml: add the github-actions entry shown above");
89
95
  break;
90
96
  }
97
+ case "tailwind": {
98
+ const tailwind = sectionReport.report;
99
+ if (tailwind.refusal !== null) {
100
+ manual.push(`add-tailwind refused${tailwind.project === null ? "" : ` for ${tailwind.project}`} \u2014 its report above says why and what to do`);
101
+ break;
102
+ }
103
+ for (const step of tailwind.steps) {
104
+ if (step.outcome === "not-wired") manual.push(`${step.file}: add the Tailwind lines add-tailwind shows above yourself`);
105
+ }
106
+ break;
107
+ }
108
+ case "storybook": {
109
+ const storybook = sectionReport.report;
110
+ const refusal = storybook.refusal;
111
+ if (refusal?.reason === "no-storybook-config") {
112
+ manual.push(`${refusal.project}: set up Storybook with Nx's generator, then run add-storybook \u2014 the steps are in add-storybook's report above`);
113
+ break;
114
+ }
115
+ if (refusal !== null) {
116
+ manual.push(`add-storybook refused${storybook.project === null ? "" : ` for ${storybook.project}`} \u2014 its report above says why and what to do`);
117
+ break;
118
+ }
119
+ for (const step of storybook.steps) {
120
+ if (step.outcome === "not-wired" && step.reason !== "without-apply-eslint") manual.push(`${step.file}: add the lines add-storybook shows above yourself`);
121
+ }
122
+ break;
123
+ }
91
124
  case "backend": {
92
125
  const backend = sectionReport.report;
93
126
  if (backend.refused !== void 0) break;
@@ -224,7 +257,9 @@ var SECTION_TITLES = {
224
257
  agentRules: "add-agent-rules",
225
258
  githubTemplates: "add-github-templates",
226
259
  review: "add-review",
227
- backend: "add-backend"
260
+ backend: "add-backend",
261
+ tailwind: "add-tailwind",
262
+ storybook: "add-storybook"
228
263
  };
229
264
  function renderSectionReport(report) {
230
265
  switch (report.kind) {
@@ -238,6 +273,10 @@ function renderSectionReport(report) {
238
273
  return renderAddReviewReport(report.report);
239
274
  case "backend":
240
275
  return renderAddBackendBody(report.report);
276
+ case "tailwind":
277
+ return renderAddTailwindReport(report.report);
278
+ case "storybook":
279
+ return renderAddStorybookReport(report.report);
241
280
  }
242
281
  }
243
282
  function sectionAborted(section) {
@@ -268,6 +307,10 @@ function renderInitReport(report) {
268
307
  if (section.id === "backend" && !section.enabled) continue;
269
308
  lines.push("");
270
309
  lines.push(`## ${SECTION_TITLES[section.id]}`);
310
+ if (!section.enabled && section.skippedBecause !== void 0) {
311
+ lines.push(` skipped (${section.skippedBecause})`);
312
+ continue;
313
+ }
271
314
  if (!section.enabled) {
272
315
  lines.push(
273
316
  section.id === "fsd" && report.frontend === "none" ? " skipped (backend-only workspace \u2014 no frontend to structure)" : " skipped (disabled for this run)"
@@ -0,0 +1,269 @@
1
+ import {
2
+ renderAddTailwindReport
3
+ } from "./chunk-N6SPEKJB.js";
4
+ import {
5
+ resolveToolTarget,
6
+ storybookPreviewStep,
7
+ treeFiles
8
+ } from "./chunk-MF75SQM6.js";
9
+ import {
10
+ TAILWIND_CSS_IMPORT,
11
+ TAILWIND_DEPENDENCIES,
12
+ TAILWIND_VITE_IMPORT,
13
+ TAILWIND_VITE_PLUGIN,
14
+ ensureTailwindCss,
15
+ layoutStylesheet,
16
+ loadedViteStylesheets,
17
+ postcssHasTailwind,
18
+ prependStylesheetImport,
19
+ stylesheetImportLine,
20
+ tailwindEntryStylesheet,
21
+ tailwindSourceLine,
22
+ viteAppLayerStylesheet,
23
+ viteTailwindEntry,
24
+ wireTailwindVitePlugin
25
+ } from "./chunk-B6RBCUIL.js";
26
+ import {
27
+ generatorFilesDir,
28
+ renderTemplateFiles
29
+ } from "./chunk-YNMLB4DL.js";
30
+ import {
31
+ resolveDryRun
32
+ } from "./chunk-TUN34LAQ.js";
33
+ import {
34
+ applyJsonEdits,
35
+ readToolkitConfig,
36
+ recordToolProject,
37
+ recordedToolProjects,
38
+ treePackageManager
39
+ } from "./chunk-736LFDT4.js";
40
+ import {
41
+ detectYarnFlavor,
42
+ packageManagerCommands
43
+ } from "./chunk-5Z7VZPES.js";
44
+
45
+ // src/generators/add-tailwind/generator.ts
46
+ import { posix } from "node:path";
47
+ import { readNxJson } from "@nx/devkit";
48
+ var VITE_CONFIGS = ["vite.config.mts", "vite.config.ts", "vite.config.mjs", "vite.config.js", "vite.config.cts", "vite.config.cjs"];
49
+ var POSTCSS_CONFIGS = ["postcss.config.mjs", "postcss.config.js", "postcss.config.cjs", "postcss.config.ts", "postcss.config.mts", "postcss.config.json"];
50
+ var TAILWIND_V3_CONFIGS = ["tailwind.config.js", "tailwind.config.cjs", "tailwind.config.mjs", "tailwind.config.ts"];
51
+ var VITE_STYLESHEET_SPEC = "./styles/index.css";
52
+ var prefixOf = (root) => root === "" || root === "." ? "" : `${root}/`;
53
+ var firstExisting = (tree, candidates) => candidates.find((path) => tree.exists(path)) ?? null;
54
+ function localStyleImports(text) {
55
+ return [...text.matchAll(/^\s*import\s+['"](\.\.?\/[^'"]+\.(?:css|scss|sass))['"]/gm)].map((match) => match[1]);
56
+ }
57
+ var isSass = (path) => /\.s[ac]ss$/.test(path);
58
+ function readJsonObject(tree, path) {
59
+ const raw = tree.read(path, "utf-8");
60
+ if (raw === null) return null;
61
+ try {
62
+ const parsed = JSON.parse(raw);
63
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? { raw, parsed } : null;
64
+ } catch {
65
+ return null;
66
+ }
67
+ }
68
+ function tailwindV3Evidence(tree, app) {
69
+ const evidence = [];
70
+ for (const path of [.../* @__PURE__ */ new Set(["package.json", `${prefixOf(app.root)}package.json`])]) {
71
+ const pkg = readJsonObject(tree, path)?.parsed;
72
+ for (const field of ["dependencies", "devDependencies"]) {
73
+ const range = pkg?.[field]?.["tailwindcss"];
74
+ const major = typeof range === "string" ? /(\d+)/.exec(range)?.[1] : void 0;
75
+ if (typeof range === "string" && major !== void 0 && Number(major) < 4) evidence.push(`${path}: tailwindcss ${range}`);
76
+ }
77
+ }
78
+ for (const dir of [.../* @__PURE__ */ new Set([prefixOf(app.root), ""])]) {
79
+ for (const name of TAILWIND_V3_CONFIGS) if (tree.exists(`${dir}${name}`)) evidence.push(`${dir}${name}`);
80
+ }
81
+ return evidence;
82
+ }
83
+ function sassEvidence(tree, app) {
84
+ const evidence = [];
85
+ const src = prefixOf(app.sourceRoot);
86
+ if (app.framework === "react-vite") {
87
+ const html = tree.read(`${prefixOf(app.root)}index.html`, "utf-8");
88
+ for (const match of html?.matchAll(/<link\b[^>]*\bhref=["']([^"']+\.s[ac]ss)["'][^>]*>/gi) ?? []) {
89
+ evidence.push(`${prefixOf(app.root)}index.html links ${match[1]}`);
90
+ }
91
+ for (const name of ["styles.scss", "styles.sass"]) if (tree.exists(`${src}${name}`)) evidence.push(`${src}${name}`);
92
+ for (const module of ["main.tsx", "main.jsx", "main.ts", "main.js", "app/app.tsx", "app/app.jsx"]) {
93
+ const text = tree.read(`${src}${module}`, "utf-8");
94
+ for (const spec of text === null ? [] : localStyleImports(text).filter((spec2) => isSass(spec2) && !/\.module\.s[ac]ss$/.test(spec2))) {
95
+ evidence.push(`${src}${module} imports ${spec}`);
96
+ }
97
+ }
98
+ } else {
99
+ const layout = firstExisting(tree, [`${src}app/layout.tsx`, `${src}app/layout.jsx`]);
100
+ const text = layout === null ? null : tree.read(layout, "utf-8");
101
+ for (const spec of text === null ? [] : localStyleImports(text).filter(isSass)) evidence.push(`${layout} imports ${spec}`);
102
+ }
103
+ return evidence;
104
+ }
105
+ function tailwindStylesheet(tree, app) {
106
+ return tailwindEntryStylesheet(app, treeFiles(tree));
107
+ }
108
+ function sourceLineFor(tree, stylesheet) {
109
+ const libsDir = readNxJson(tree)?.workspaceLayout?.libsDir ?? "libs";
110
+ return tailwindSourceLine(posix.relative(posix.dirname(stylesheet), libsDir));
111
+ }
112
+ function stylesheetStep(tree, path, sourceLine, write) {
113
+ const existing = tree.read(path, "utf-8");
114
+ if (existing === null) {
115
+ if (write) {
116
+ const [file] = renderTemplateFiles(posix.join(generatorFilesDir("add-tailwind", import.meta.url), "react-vite"), posix.dirname(path), {
117
+ tailwindImport: TAILWIND_CSS_IMPORT,
118
+ sourceLine
119
+ });
120
+ tree.write(path, file.content);
121
+ }
122
+ return { file: path, outcome: "created" };
123
+ }
124
+ const result = ensureTailwindCss(existing, sourceLine);
125
+ if (result.status === "applied" && write) tree.write(path, result.text);
126
+ return result.status === "unrecognized" ? { file: path, outcome: "not-wired", reason: result.reason, lines: [TAILWIND_CSS_IMPORT, sourceLine] } : { file: path, outcome: result.status };
127
+ }
128
+ function wireReactVite(tree, app, write) {
129
+ const steps = [];
130
+ const appDir = prefixOf(app.root);
131
+ const viteLines = [TAILWIND_VITE_IMPORT, `${TAILWIND_VITE_PLUGIN} // in the plugins array, right after react()`];
132
+ const configs = VITE_CONFIGS.map((name) => `${appDir}${name}`).filter((path) => tree.exists(path));
133
+ if (configs.length !== 1) {
134
+ steps.push({ file: configs[0] ?? `${appDir}vite.config.mts`, outcome: "not-wired", reason: configs.length === 0 ? "no-vite-config" : "several-vite-configs", lines: viteLines });
135
+ } else {
136
+ const result = wireTailwindVitePlugin(tree.read(configs[0], "utf-8") ?? "");
137
+ if (result.status === "applied" && write) tree.write(configs[0], result.text);
138
+ steps.push(result.status === "unrecognized" ? { file: configs[0], outcome: "not-wired", reason: result.reason, lines: viteLines } : { file: configs[0], outcome: result.status });
139
+ }
140
+ const appLayer = viteAppLayerStylesheet(app.sourceRoot);
141
+ const loaded = loadedViteStylesheets(app, treeFiles(tree));
142
+ const entry = viteTailwindEntry(app, treeFiles(tree), loaded);
143
+ if (entry !== null && entry !== appLayer) {
144
+ steps.push(stylesheetStep(tree, entry, sourceLineFor(tree, entry), write));
145
+ return { steps, handWired: entry };
146
+ }
147
+ steps.push(stylesheetStep(tree, appLayer, sourceLineFor(tree, appLayer), write));
148
+ if (loaded.includes(appLayer)) return { steps, handWired: null };
149
+ const importLine = stylesheetImportLine(VITE_STYLESHEET_SPEC);
150
+ const module = firstExisting(tree, [`${prefixOf(app.sourceRoot)}app/app.tsx`, `${prefixOf(app.sourceRoot)}app/app.jsx`]);
151
+ if (module === null) {
152
+ steps.push({ file: `${prefixOf(app.sourceRoot)}app/app.tsx`, outcome: "not-wired", reason: "no-app-module", lines: [importLine] });
153
+ } else {
154
+ const result = prependStylesheetImport(tree.read(module, "utf-8") ?? "", VITE_STYLESHEET_SPEC);
155
+ if (result.status === "applied" && write) tree.write(module, result.text);
156
+ steps.push(result.status === "unrecognized" ? { file: module, outcome: "not-wired", reason: result.reason, lines: [importLine] } : { file: module, outcome: result.status });
157
+ }
158
+ return { steps, handWired: null };
159
+ }
160
+ function wireNext(tree, app, write) {
161
+ const steps = [];
162
+ const appDir = prefixOf(app.root);
163
+ const postcss = firstExisting(tree, POSTCSS_CONFIGS.map((name) => `${appDir}${name}`));
164
+ if (postcss === null) {
165
+ const path = `${appDir}postcss.config.mjs`;
166
+ if (write) {
167
+ const [file] = renderTemplateFiles(posix.join(generatorFilesDir("add-tailwind", import.meta.url), "next"), appDir === "" ? "." : app.root, {});
168
+ tree.write(path, file.content);
169
+ }
170
+ steps.push({ file: path, outcome: "created" });
171
+ } else if (postcssHasTailwind(tree.read(postcss, "utf-8") ?? "")) {
172
+ steps.push({ file: postcss, outcome: "already-applied" });
173
+ } else {
174
+ steps.push({ file: postcss, outcome: "not-wired", reason: "postcss-config-without-tailwind", lines: ["'@tailwindcss/postcss': {}, // in the plugins object"] });
175
+ }
176
+ const src = prefixOf(app.sourceRoot);
177
+ const layout = firstExisting(tree, [`${src}app/layout.tsx`, `${src}app/layout.jsx`]);
178
+ const assumed = `${src}app/global.css`;
179
+ const cssLines = (stylesheet2) => [TAILWIND_CSS_IMPORT, sourceLineFor(tree, stylesheet2)];
180
+ const target = "the stylesheet the root layout imports";
181
+ if (layout === null) {
182
+ steps.push({ file: `${src}app/layout.tsx`, outcome: "not-wired", reason: "no-root-layout", lines: cssLines(assumed), target });
183
+ return steps;
184
+ }
185
+ const found = layoutStylesheet(tree.read(layout, "utf-8") ?? "");
186
+ if (found.status === "unrecognized") {
187
+ steps.push({ file: layout, outcome: "not-wired", reason: found.reason, lines: cssLines(assumed), target });
188
+ return steps;
189
+ }
190
+ const stylesheet = posix.normalize(posix.join(posix.dirname(layout), found.spec));
191
+ if (!tree.exists(stylesheet)) {
192
+ steps.push({ file: stylesheet, outcome: "not-wired", reason: "stylesheet-missing", lines: cssLines(stylesheet) });
193
+ return steps;
194
+ }
195
+ steps.push(stylesheetStep(tree, stylesheet, sourceLineFor(tree, stylesheet), write));
196
+ return steps;
197
+ }
198
+ function addDependencies(tree, app, write) {
199
+ const framework = app.framework;
200
+ const pkg = readJsonObject(tree, "package.json");
201
+ if (pkg === null) return { dependencies: "unrecognized", added: [] };
202
+ const appPkg = prefixOf(app.root) === "" ? null : readJsonObject(tree, `${prefixOf(app.root)}package.json`)?.parsed;
203
+ const declared = Object.assign(
204
+ {},
205
+ ...[pkg.parsed, appPkg].flatMap((manifest) => ["dependencies", "devDependencies"].map((field) => manifest?.[field]))
206
+ );
207
+ const missing = Object.entries({ ...TAILWIND_DEPENDENCIES.common, ...TAILWIND_DEPENDENCIES[framework] }).filter(([name]) => declared[name] === void 0);
208
+ if (missing.length === 0) return { dependencies: "present", added: [] };
209
+ if (write) tree.write("package.json", applyJsonEdits(pkg.raw, missing.map(([name, range]) => [["devDependencies", name], range])));
210
+ return { dependencies: "added", added: missing.map(([name]) => name) };
211
+ }
212
+ var refusedReport = (dryRun, refusal) => ({
213
+ dryRun,
214
+ refusal,
215
+ project: null,
216
+ framework: null,
217
+ steps: [],
218
+ dependencies: null,
219
+ added: [],
220
+ record: null,
221
+ replacedSection: false,
222
+ installCommand: null
223
+ });
224
+ function runAddTailwind(tree, options) {
225
+ const dryRun = options.dryRun ?? false;
226
+ const write = !dryRun;
227
+ const target = resolveToolTarget(tree, options.project);
228
+ if (target.kind === "refused") return refusedReport(dryRun, target.refusal);
229
+ const app = { root: target.root, sourceRoot: target.sourceRoot, framework: target.framework };
230
+ const v3 = tailwindV3Evidence(tree, app);
231
+ if (v3.length > 0) return refusedReport(dryRun, { reason: "tailwind-v3", evidence: v3 });
232
+ const sass = sassEvidence(tree, app);
233
+ if (sass.length > 0) return refusedReport(dryRun, { reason: "sass", evidence: sass });
234
+ const { steps, handWired } = app.framework === "react-vite" ? wireReactVite(tree, app, write) : { steps: wireNext(tree, app, write), handWired: null };
235
+ if (recordedToolProjects(readToolkitConfig(tree), "storybook").includes(target.project)) steps.push(storybookPreviewStep(tree, app, write));
236
+ const { dependencies, added } = addDependencies(tree, app, write);
237
+ const config = readToolkitConfig(tree);
238
+ const section = config?.["tailwind"];
239
+ const replacedSection = section !== void 0 && (typeof section !== "object" || section === null || Array.isArray(section));
240
+ const record = recordToolProject(tree, "tailwind", target.project, write);
241
+ const known = treePackageManager(tree, config);
242
+ const pm = known ?? "pnpm";
243
+ const install = packageManagerCommands(pm, pm === "yarn" ? detectYarnFlavor((p) => tree.exists(p), (p) => tree.read(p, "utf-8")) : void 0).install;
244
+ return {
245
+ dryRun,
246
+ refusal: null,
247
+ project: target.project,
248
+ framework: app.framework,
249
+ steps,
250
+ dependencies,
251
+ added,
252
+ record,
253
+ replacedSection: replacedSection && record !== "unrecognized",
254
+ installCommand: dependencies === "added" ? install : null,
255
+ ...dependencies === "added" && known === null ? { installAssumed: true } : {},
256
+ ...handWired !== null ? { handWiredStylesheet: handWired } : {}
257
+ };
258
+ }
259
+ async function addTailwindGenerator(tree, options) {
260
+ console.log(renderAddTailwindReport(runAddTailwind(tree, { ...options, dryRun: resolveDryRun(options) })));
261
+ }
262
+ var generator_default = addTailwindGenerator;
263
+
264
+ export {
265
+ tailwindStylesheet,
266
+ runAddTailwind,
267
+ addTailwindGenerator,
268
+ generator_default
269
+ };
@@ -220,6 +220,24 @@ function recordedFrontends(config) {
220
220
  (entry) => typeof entry === "object" && entry !== null && typeof entry["project"] === "string" ? [entry.project] : []
221
221
  );
222
222
  }
223
+ function recordedToolProjects(config, key, field = "projects") {
224
+ const section = config?.[key];
225
+ if (typeof section !== "object" || section === null) return [];
226
+ const projects = section[field];
227
+ return Array.isArray(projects) ? projects.filter((entry) => typeof entry === "string") : [];
228
+ }
229
+ function recordToolProject(tree, key, project, write, field = "projects") {
230
+ const { raw, parsed } = readToolkitConfigFile(tree);
231
+ if (raw !== null && parsed === null) return "unrecognized";
232
+ if (recordedToolProjects(parsed, key, field).includes(project)) return "unchanged";
233
+ if (write) {
234
+ const section = parsed?.[key];
235
+ const projects = typeof section === "object" && section !== null ? section[field] : void 0;
236
+ const text = raw !== null && Array.isArray(projects) ? appendJsonArrayItem(raw, [key, field], project) : typeof section === "object" && section !== null && !Array.isArray(section) ? applyJsonEdits(raw, [[[key, field], [project]]]) : applyJsonEdits(raw, [[[key], { [field]: [project] }]]);
237
+ tree.write(TOOLKIT_CONFIG_PATH, text);
238
+ }
239
+ return raw === null ? "created" : "updated";
240
+ }
223
241
 
224
242
  export {
225
243
  DEFAULT_AI_HOSTS,
@@ -243,5 +261,7 @@ export {
243
261
  resolveAiHostsOption,
244
262
  recordAiHosts,
245
263
  recordTeamRules,
246
- recordedFrontends
264
+ recordedFrontends,
265
+ recordedToolProjects,
266
+ recordToolProject
247
267
  };
@@ -5,10 +5,10 @@ import {
5
5
  applyFsdEslintConfig,
6
6
  buildFsdEslintPasteSnippet,
7
7
  composeFsdLayerGuide
8
- } from "./chunk-XXXON43Z.js";
8
+ } from "./chunk-SZRBDQCU.js";
9
9
  import {
10
10
  resolveFrontendApp
11
- } from "./chunk-LKXSS5E2.js";
11
+ } from "./chunk-W2BBF5MS.js";
12
12
  import {
13
13
  profileById
14
14
  } from "./chunk-YEMQFSL6.js";
@@ -23,7 +23,7 @@ import {
23
23
  } from "./chunk-TUN34LAQ.js";
24
24
  import {
25
25
  runNxFor
26
- } from "./chunk-EHYC6FUR.js";
26
+ } from "./chunk-JSHZ6VSW.js";
27
27
  import {
28
28
  applyJsonEdits,
29
29
  readToolkitConfig,
@@ -31,7 +31,7 @@ import {
31
31
  resolveLocaleOption,
32
32
  setJsonValue,
33
33
  treePackageManager
34
- } from "./chunk-2TQWFUMC.js";
34
+ } from "./chunk-736LFDT4.js";
35
35
  import {
36
36
  detectYarnFlavor,
37
37
  packageManagerCommands,