@clearlydev/nx-archweave 0.6.0 → 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 (59) hide show
  1. package/README.md +34 -3
  2. package/dist/bin/review-verdict.js +2 -2
  3. package/dist/eslint/index.js +1 -1
  4. package/dist/generators/_chunks/{chunk-MQNQJOWA.js → chunk-22FVJUNE.js} +4 -2
  5. package/dist/generators/_chunks/{chunk-JNYQTW7S.js → chunk-2ADC6RKP.js} +2 -2
  6. package/dist/generators/_chunks/{chunk-XSALM2IR.js → chunk-6PKKKQMD.js} +55 -11
  7. package/dist/generators/_chunks/chunk-72D3GWHO.js +269 -0
  8. package/dist/generators/_chunks/{chunk-C2WELXMV.js → chunk-736LFDT4.js} +33 -9
  9. package/dist/generators/_chunks/{chunk-VCLVE4EQ.js → chunk-7RTT5NBN.js} +4 -4
  10. package/dist/generators/_chunks/chunk-AOKTOS3U.js +294 -0
  11. package/dist/generators/_chunks/chunk-B6RBCUIL.js +325 -0
  12. package/dist/generators/_chunks/chunk-BDLK2IID.js +10 -0
  13. package/dist/generators/_chunks/{chunk-M7UBCSYL.js → chunk-CHZPA6OE.js} +5 -3
  14. package/dist/generators/_chunks/{chunk-3HSNM6AS.js → chunk-DAXD47YO.js} +9 -7
  15. package/dist/generators/_chunks/{chunk-LJRFVE6B.js → chunk-F5C5HUSI.js} +10 -9
  16. package/dist/generators/_chunks/chunk-GN76UMTK.js +28 -0
  17. package/dist/generators/_chunks/{chunk-ZRHIFPUC.js → chunk-J24X4EOB.js} +1 -1
  18. package/dist/generators/_chunks/{chunk-23NN76E3.js → chunk-JSHZ6VSW.js} +1 -1
  19. package/dist/generators/_chunks/chunk-KNVBFTH4.js +64 -0
  20. package/dist/generators/_chunks/chunk-MF75SQM6.js +98 -0
  21. package/dist/generators/_chunks/chunk-N6SPEKJB.js +106 -0
  22. package/dist/generators/_chunks/chunk-OX7W4SJ2.js +214 -0
  23. package/dist/generators/_chunks/chunk-R2VEJGNP.js +84 -0
  24. package/dist/generators/_chunks/chunk-SBOQHME6.js +140 -0
  25. package/dist/generators/_chunks/{chunk-7EDJKUY4.js → chunk-STGNMZLM.js} +1 -1
  26. package/dist/generators/_chunks/{chunk-XXXON43Z.js → chunk-SZRBDQCU.js} +4 -51
  27. package/dist/generators/_chunks/{chunk-FBCIELXS.js → chunk-W2BBF5MS.js} +5 -86
  28. package/dist/generators/_chunks/{chunk-2WXAGWAJ.js → chunk-YVISD736.js} +3 -1
  29. package/dist/generators/add-agent-rules/generator.js +4 -3
  30. package/dist/generators/add-backend/generator.js +3 -2
  31. package/dist/generators/add-fsd-lite/generator.js +8 -5
  32. package/dist/generators/add-github-templates/generator.js +3 -2
  33. package/dist/generators/add-integration/generator.js +6 -3
  34. package/dist/generators/add-review/generator.js +4 -3
  35. package/dist/generators/add-storybook/files/example/button/button.stories.tsx.template +13 -0
  36. package/dist/generators/add-storybook/files/example/button/button.tsx.template +7 -0
  37. package/dist/generators/add-storybook/files/example/index.ts.template +1 -0
  38. package/dist/generators/add-storybook/files/library/tailwind.css.template +2 -0
  39. package/dist/generators/add-storybook/generator.js +28 -0
  40. package/dist/generators/add-tailwind/files/next/postcss.config.mjs.template +7 -0
  41. package/dist/generators/add-tailwind/files/react-vite/index.css.template +2 -0
  42. package/dist/generators/add-tailwind/generator.js +26 -0
  43. package/dist/generators/allow-builds/generator.js +11 -208
  44. package/dist/generators/doctor/generator.js +444 -61
  45. package/dist/generators/entity/generator.js +5 -3
  46. package/dist/generators/feature/generator.js +5 -3
  47. package/dist/generators/init/generator.js +81 -20
  48. package/dist/generators/install-integration/generator.js +6 -3
  49. package/dist/generators/page/generator.js +5 -3
  50. package/dist/generators/record-integration/generator.js +4 -1
  51. package/dist/generators/shared/generator.js +5 -3
  52. package/dist/generators/widget/generator.js +5 -3
  53. package/dist/migrations/update-0.5.3/add-toolkit-config-lint-input.js +9 -4
  54. package/generators.json +10 -0
  55. package/package.json +6 -1
  56. package/src/generators/add-agent-rules/schema.json +2 -2
  57. package/src/generators/add-storybook/schema.json +33 -0
  58. package/src/generators/add-tailwind/schema.json +18 -0
  59. 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:
@@ -4,7 +4,7 @@ import {
4
4
  REVIEW_WORKFLOW_CONTRACT,
5
5
  VERDICT_MARKER,
6
6
  runVerdictGate
7
- } from "../generators/_chunks/chunk-2WXAGWAJ.js";
7
+ } from "../generators/_chunks/chunk-YVISD736.js";
8
8
  import "../generators/_chunks/chunk-JPS6XKYK.js";
9
9
 
10
10
  // src/bin/review-verdict.ts
@@ -155,7 +155,7 @@ function splitConcatenatedJson(stdout) {
155
155
  if (depth !== 0 || text.slice(start).trim() !== "") return null;
156
156
  return values;
157
157
  }
158
- var invokedAsBin = false;
158
+ var invokedAsBin;
159
159
  try {
160
160
  invokedAsBin = process.argv[1] !== void 0 && realpathSync(process.argv[1]).endsWith("review-verdict.js");
161
161
  } catch {
@@ -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;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  composeReviewSetup,
3
3
  judgeReviewFileConflict
4
- } from "./chunk-2WXAGWAJ.js";
4
+ } from "./chunk-YVISD736.js";
5
5
  import {
6
6
  DEPENDABOT_PATH,
7
7
  renderAddReviewReport,
@@ -17,7 +17,7 @@ import {
17
17
  import {
18
18
  applyJsonEdits,
19
19
  treePackageManager
20
- } from "./chunk-C2WELXMV.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,6 +1,12 @@
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
- } from "./chunk-LJRFVE6B.js";
9
+ } from "./chunk-F5C5HUSI.js";
4
10
  import {
5
11
  renderAddReviewReport
6
12
  } from "./chunk-CSJZ4PP3.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-C2WELXMV.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)"
@@ -306,11 +349,11 @@ function renderInitReport(report) {
306
349
  case "skipped":
307
350
  break;
308
351
  }
309
- if (report.config.notRecorded.length > 0) {
310
- lines.push(` not recorded: ${report.config.notRecorded.map((n) => n.field).join(", ")} \u2014 that section did not apply cleanly`);
311
- lines.push(" this run (aborted, or written as an alternate file). Once resolved, record it with:");
312
- const runNx = report.runNx ?? runNxCommand(report.packageManager);
313
- for (const entry of report.config.notRecorded) lines.push(` ${runNx} g @clearlydev/nx-archweave:${entry.rerun}`);
352
+ const runNx = report.runNx ?? runNxCommand(report.packageManager);
353
+ for (const entry of report.config.notRecorded) {
354
+ const how = entry.reruns.every((rerun) => rerun.note === null) ? `Once resolved, record ${entry.fields.length > 1 ? "them" : "it"} with:` : `Record ${entry.fields.length > 1 ? "them" : "it"} with:`;
355
+ lines.push(` not recorded: ${entry.fields.join(", ")} \u2014 ${entry.reason}. ${how}`);
356
+ for (const { note, rerun } of entry.reruns) lines.push(` ${note === null ? "" : `${note}: `}${runNx} g @clearlydev/nx-archweave:${rerun}`);
314
357
  }
315
358
  }
316
359
  if (report.lintInputs !== void 0) lines.push("", "## nx.json", ...renderLintInputs(report.lintInputs, report.dryRun));
@@ -350,8 +393,9 @@ function renderLintInputs(outcome, dryRun) {
350
393
  "no-plugin": "@nx/eslint/plugin is not registered, so targetDefaults would replace the lint targets' inputs",
351
394
  "several-plugins": `@nx/eslint/plugin is registered more than once, so which ${outcome.target} targets it infers is up to each registration`,
352
395
  "own-targets": `${(outcome.ownTargets ?? []).join(", ")} write their own ${outcome.target} target, which keeps only what targetDefaults lists`,
353
- "run-commands-defaults": `targetDefaults["nx:run-commands"] comes before targetDefaults.${outcome.target} for the inferred ${outcome.target} targets`,
354
- "other-key": `targetDefaults["${outcome.key ?? ""}"] is the entry Nx applies to ${outcome.target}, ahead of targetDefaults.${outcome.target}`,
396
+ // The snippet below says why that entry wins; the reason only names it.
397
+ "run-commands-defaults": `targetDefaults["nx:run-commands"] decides the ${outcome.target} targets' inputs (below)`,
398
+ "other-key": `a glob key in targetDefaults decides the ${outcome.target} targets' inputs (below)`,
355
399
  "list-defaults": `targetDefaults.${outcome.target} is a list of entries, and the input belongs in each one that covers an FSD project`,
356
400
  "unreadable-defaults": `targetDefaults.${outcome.target} is neither an object nor a list of entries`,
357
401
  "existing-inputs": `targetDefaults already gives ${outcome.target} inputs of its own`
@@ -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
+ };
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  detectWorkspacePackageManager
3
3
  } from "./chunk-5Z7VZPES.js";
4
+ import {
5
+ messageOnlyError
6
+ } from "./chunk-BDLK2IID.js";
4
7
 
5
8
  // ../template-engine/dist/ai-hosts/ai-hosts.js
6
9
  var AI_HOSTS = [
@@ -129,13 +132,6 @@ function applyJsonEdits(raw, edits) {
129
132
  return edits.reduce((text, [path, value]) => setJsonValue(text, path, value), raw);
130
133
  }
131
134
 
132
- // src/generators/shared/message-only-error.ts
133
- function messageOnlyError(message) {
134
- const error = new Error(message);
135
- error.stack = "";
136
- return error;
137
- }
138
-
139
135
  // src/generators/shared/toolkit-config-file.ts
140
136
  var TOOLKIT_CONFIG_PATH = "toolkit.config.json";
141
137
  function readToolkitConfigFile(tree) {
@@ -209,6 +205,14 @@ function recordAiHosts(tree, hosts, write) {
209
205
  if (write) tree.write(TOOLKIT_CONFIG_PATH, applyJsonEdits(raw, [[["aiHosts"], [...hosts]]]));
210
206
  return raw === null ? "created" : "updated";
211
207
  }
208
+ function recordTeamRules(tree, teamRules, write) {
209
+ const { raw, parsed } = readToolkitConfigFile(tree);
210
+ if (raw !== null && parsed === null) return "unrecognized";
211
+ const agentRules = parsed?.["agentRules"];
212
+ if (typeof agentRules === "object" && agentRules !== null && agentRules["teamRules"] === teamRules) return "unchanged";
213
+ if (write) tree.write(TOOLKIT_CONFIG_PATH, applyJsonEdits(raw, [[["agentRules", "teamRules"], teamRules]]));
214
+ return raw === null ? "created" : "updated";
215
+ }
212
216
  function recordedFrontends(config) {
213
217
  const frontends = config?.["frontends"];
214
218
  if (!Array.isArray(frontends)) return [];
@@ -216,6 +220,24 @@ function recordedFrontends(config) {
216
220
  (entry) => typeof entry === "object" && entry !== null && typeof entry["project"] === "string" ? [entry.project] : []
217
221
  );
218
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
+ }
219
241
 
220
242
  export {
221
243
  DEFAULT_AI_HOSTS,
@@ -224,7 +246,6 @@ export {
224
246
  setJsonValue,
225
247
  appendJsonArrayItem,
226
248
  applyJsonEdits,
227
- messageOnlyError,
228
249
  TOOLKIT_CONFIG_PATH,
229
250
  readToolkitConfigFile,
230
251
  readToolkitConfig,
@@ -239,5 +260,8 @@ export {
239
260
  treePackageManager,
240
261
  resolveAiHostsOption,
241
262
  recordAiHosts,
242
- recordedFrontends
263
+ recordTeamRules,
264
+ recordedFrontends,
265
+ recordedToolProjects,
266
+ recordToolProject
243
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-FBCIELXS.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-23NN76E3.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-C2WELXMV.js";
34
+ } from "./chunk-736LFDT4.js";
35
35
  import {
36
36
  detectYarnFlavor,
37
37
  packageManagerCommands,