@clearlydev/nx-archweave 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 (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +265 -2
  3. package/dist/bin/review-verdict.js +330 -0
  4. package/dist/eslint/fsd-boundaries.d.ts +119 -0
  5. package/dist/eslint/fsd-boundaries.js +144 -0
  6. package/dist/eslint/index.d.ts +78 -0
  7. package/dist/eslint/index.js +256 -0
  8. package/dist/eslint/tsconfig-aliases.d.ts +18 -0
  9. package/dist/eslint/tsconfig-aliases.js +114 -0
  10. package/dist/generators/add-agent-rules/generator.js +550 -0
  11. package/dist/generators/add-agent-rules/render.js +46 -0
  12. package/dist/generators/add-backend/generator.js +784 -0
  13. package/dist/generators/add-backend/render.js +102 -0
  14. package/dist/generators/add-fsd-lite/generator.js +553 -0
  15. package/dist/generators/add-fsd-lite/render.js +72 -0
  16. package/dist/generators/add-github-templates/files/en/codeowners/.github/CODEOWNERS.template +4 -0
  17. package/dist/generators/add-github-templates/files/en/issue/.github/ISSUE_TEMPLATE/bug-report.yml.template +28 -0
  18. package/dist/generators/add-github-templates/files/en/issue/.github/ISSUE_TEMPLATE/feature-request.yml.template +17 -0
  19. package/dist/generators/add-github-templates/files/en/pr/.github/PULL_REQUEST_TEMPLATE.md.template +12 -0
  20. package/dist/generators/add-github-templates/files/ko/codeowners/.github/CODEOWNERS.template +4 -0
  21. package/dist/generators/add-github-templates/files/ko/issue/.github/ISSUE_TEMPLATE/bug-report.yml.template +28 -0
  22. package/dist/generators/add-github-templates/files/ko/issue/.github/ISSUE_TEMPLATE/feature-request.yml.template +17 -0
  23. package/dist/generators/add-github-templates/files/ko/pr/.github/PULL_REQUEST_TEMPLATE.md.template +12 -0
  24. package/dist/generators/add-github-templates/generator.js +125 -0
  25. package/dist/generators/add-github-templates/render.js +26 -0
  26. package/dist/generators/add-integration/generator.js +849 -0
  27. package/dist/generators/add-integration/render.js +34 -0
  28. package/dist/generators/add-review/generator.js +921 -0
  29. package/dist/generators/add-review/render.js +96 -0
  30. package/dist/generators/allow-builds/generator.js +436 -0
  31. package/dist/generators/allow-builds/render.js +82 -0
  32. package/dist/generators/doctor/generator.js +2462 -0
  33. package/dist/generators/doctor/integration-report.js +70 -0
  34. package/dist/generators/doctor/render.js +10 -0
  35. package/dist/generators/entity/generator.js +395 -0
  36. package/dist/generators/feature/generator.js +395 -0
  37. package/dist/generators/init/generator.js +3211 -0
  38. package/dist/generators/init/render.js +125 -0
  39. package/dist/generators/init/validation.js +74 -0
  40. package/dist/generators/install-integration/generator.js +1265 -0
  41. package/dist/generators/install-integration/render.js +128 -0
  42. package/dist/generators/page/generator.js +395 -0
  43. package/dist/generators/record-integration/generator.js +883 -0
  44. package/dist/generators/record-integration/render.js +31 -0
  45. package/dist/generators/shared/dry-run.js +12 -0
  46. package/dist/generators/shared/frontend-app.js +57 -0
  47. package/dist/generators/shared/generator.js +395 -0
  48. package/dist/generators/shared/project-type.js +39 -0
  49. package/dist/generators/shared/record-pipeline.js +34 -0
  50. package/dist/generators/shared/run-nx.js +24 -0
  51. package/dist/generators/shared/template-files.js +38 -0
  52. package/dist/generators/shared/toolkit-config-file.js +110 -0
  53. package/dist/generators/slice/core.js +185 -0
  54. package/dist/generators/slice/files/index/index.ts.template +14 -0
  55. package/dist/generators/slice/files/module/__name__.spec.ts.template +11 -0
  56. package/dist/generators/slice/files/module/__name__.ts.template +11 -0
  57. package/dist/generators/slice/files/segment/index.ts.template +20 -0
  58. package/dist/generators/slice/render.js +70 -0
  59. package/dist/generators/widget/generator.js +395 -0
  60. package/dist/index.d.ts +2 -0
  61. package/dist/index.js +711 -0
  62. package/dist/lib/nx-plugin.d.ts +2 -0
  63. package/dist/lib/nx-plugin.js +7 -0
  64. package/dist/runtime/integrations-composition-root.js +20 -0
  65. package/dist/runtime/node-command-runner.js +81 -0
  66. package/generators.json +85 -0
  67. package/package.json +96 -4
  68. package/src/generators/add-agent-rules/schema.json +43 -0
  69. package/src/generators/add-backend/schema.json +39 -0
  70. package/src/generators/add-fsd-lite/schema.json +43 -0
  71. package/src/generators/add-github-templates/schema.json +35 -0
  72. package/src/generators/add-integration/schema.json +35 -0
  73. package/src/generators/add-review/schema.json +72 -0
  74. package/src/generators/allow-builds/schema.json +20 -0
  75. package/src/generators/doctor/schema.json +20 -0
  76. package/src/generators/entity/schema.json +37 -0
  77. package/src/generators/feature/schema.json +37 -0
  78. package/src/generators/init/schema.json +98 -0
  79. package/src/generators/install-integration/schema.json +35 -0
  80. package/src/generators/page/schema.json +53 -0
  81. package/src/generators/record-integration/schema.json +26 -0
  82. package/src/generators/shared/schema.json +32 -0
  83. package/src/generators/widget/schema.json +45 -0
@@ -0,0 +1,110 @@
1
+ import { DEFAULT_AI_HOSTS, detectWorkspacePackageManager, isAiHost } from '@nx-archweave/template-engine';
2
+ export const TOOLKIT_CONFIG_PATH = 'toolkit.config.json';
3
+ /** The indentation unit an existing JSON file uses, so an update preserves the
4
+ * author's formatting: the first indented line's leading run of tabs or spaces,
5
+ * else two spaces (e.g. minified JSON or no file). */
6
+ export function detectIndent(raw) {
7
+ for (const line of raw.split('\n')) {
8
+ const match = /^(\t+| +)/.exec(line);
9
+ if (match)
10
+ return match[1];
11
+ }
12
+ return ' ';
13
+ }
14
+ /** Best-effort read of toolkit.config.json. Never throws: the generators that read
15
+ * defaults from it (locale, boundaries, teamRules) must not abort on a broken file
16
+ * they do not own, and the ones that merge into it refuse to rewrite an
17
+ * unrecognized shape — both decide from this one result. */
18
+ export function readToolkitConfigFile(tree) {
19
+ const raw = tree.read(TOOLKIT_CONFIG_PATH, 'utf-8');
20
+ if (raw === null)
21
+ return { raw: null, parsed: null };
22
+ try {
23
+ const parsed = JSON.parse(raw);
24
+ return {
25
+ raw,
26
+ parsed: typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed) ? parsed : null,
27
+ };
28
+ }
29
+ catch {
30
+ return { raw, parsed: null };
31
+ }
32
+ }
33
+ /** The parsed object only — for readers that just want defaults. */
34
+ export function readToolkitConfig(tree) {
35
+ return readToolkitConfigFile(tree).parsed;
36
+ }
37
+ /** option > toolkit.config.json `locale` > 'en' — the fallback every content
38
+ * generator shares; anything that is not ko/en is ignored, never an abort. */
39
+ export function resolveLocaleOption(option, config) {
40
+ if (option)
41
+ return option;
42
+ const locale = config?.['locale'];
43
+ return locale === 'ko' || locale === 'en' ? locale : 'en';
44
+ }
45
+ /** A recorded choice init wrote, when it is one of `allowed`; anything else is ignored. */
46
+ export function recordedChoice(config, key, allowed) {
47
+ const value = config?.[key];
48
+ return typeof value === 'string' && allowed.includes(value) ? value : undefined;
49
+ }
50
+ export const RECORDED_FRONTENDS = ['react-vite', 'next', 'none'];
51
+ export const RECORDED_BACKENDS = ['express', 'nest', 'none'];
52
+ export const RECORDED_PRESETS = ['quick-start', 'solo', 'team'];
53
+ export const RECORDED_PACKAGE_MANAGERS = ['pnpm', 'npm', 'yarn', 'bun'];
54
+ /** option > toolkit.config.json `frontend` (init records it); a run without either cannot
55
+ * pick the layer set, so it stops with the flag to pass. A backend-only workspace
56
+ * (`frontend: none`) has no frontend to structure, which stops the FSD generators too. */
57
+ export function resolveFrontendOption(option, config, generator) {
58
+ const frontend = option ?? recordedChoice(config, 'frontend', RECORDED_FRONTENDS);
59
+ if (frontend === undefined) {
60
+ throw new Error(`${generator}: pass --frontend=react-vite|next (toolkit.config.json records none — init writes it).`);
61
+ }
62
+ if (frontend === 'none') {
63
+ throw new Error(`${generator}: this is a backend-only workspace (toolkit.config.json frontend: none) — FSD structures a frontend app. Pass --frontend=react-vite|next if you added one.`);
64
+ }
65
+ return frontend;
66
+ }
67
+ /** init's frontend axis: like resolveFrontendOption, but `none` (backend-only) is a choice. */
68
+ export function resolveInitFrontend(option, config) {
69
+ const frontend = option ?? recordedChoice(config, 'frontend', RECORDED_FRONTENDS);
70
+ if (frontend === undefined) {
71
+ throw new Error('init: pass --frontend=react-vite|next|none (toolkit.config.json records none — init writes it).');
72
+ }
73
+ return frontend;
74
+ }
75
+ /** The workspace's package manager: its lockfiles first (they are what installs run with,
76
+ * even after a switch), then the one init recorded; null when neither says. */
77
+ export function workspacePackageManager(exists, read, config) {
78
+ return detectWorkspacePackageManager(exists, read) ?? recordedChoice(config, 'packageManager', RECORDED_PACKAGE_MANAGERS) ?? null;
79
+ }
80
+ export function treePackageManager(tree, config) {
81
+ return workspacePackageManager((p) => tree.exists(p), (p) => tree.read(p, 'utf-8'), config);
82
+ }
83
+ /** Option (non-empty, deduped) > toolkit.config.json `aiHosts`
84
+ * (its known ids) > Claude Code. Shared by add-agent-rules and init, so a standalone run of
85
+ * either keeps the hosts a workspace was set up for. */
86
+ export function resolveAiHostsOption(option, config) {
87
+ if (option !== undefined && option.length > 0)
88
+ return [...new Set(option)];
89
+ const recorded = config?.['aiHosts'];
90
+ const fromConfig = Array.isArray(recorded) ? [...new Set(recorded.filter(isAiHost))] : [];
91
+ return fromConfig.length > 0 ? fromConfig : [...DEFAULT_AI_HOSTS];
92
+ }
93
+ /** Writes `aiHosts` into toolkit.config.json: merge-preserving (every other key survives),
94
+ * indent-preserving, idempotent; a file that is not a JSON object is never rewritten. */
95
+ export function recordAiHosts(tree, hosts, write) {
96
+ const { raw, parsed } = readToolkitConfigFile(tree);
97
+ if (raw !== null && parsed === null)
98
+ return 'unrecognized';
99
+ const existing = parsed ?? {};
100
+ const recorded = existing['aiHosts'];
101
+ if (Array.isArray(recorded) && recorded.length === hosts.length && recorded.every((id, index) => id === hosts[index])) {
102
+ return 'unchanged';
103
+ }
104
+ if (write) {
105
+ const indent = raw === null ? ' ' : detectIndent(raw);
106
+ const body = JSON.stringify({ ...existing, aiHosts: [...hosts] }, null, indent);
107
+ tree.write(TOOLKIT_CONFIG_PATH, raw === null || raw.endsWith('\n') ? `${body}\n` : body);
108
+ }
109
+ return raw === null ? 'created' : 'updated';
110
+ }
@@ -0,0 +1,185 @@
1
+ import { join } from 'node:path';
2
+ import { isEssenceSegmentName, isUsableSliceApiName, resolveSlicePublicApiName, SEGMENT_NAME_PATTERN, } from '@nx-archweave/template-engine';
3
+ import { readToolkitConfig, RECORDED_FRONTENDS, resolveLocaleOption } from "../shared/toolkit-config-file.js";
4
+ import { resolveFrontendApp } from "../shared/frontend-app.js";
5
+ import { generatorFilesDir, renderTemplateFiles } from "../shared/template-files.js";
6
+ /**
7
+ * A slice on a sliced layer, from this generator's `files/`:
8
+ * <src>/<layer>/<name>/index.ts public API (files/index)
9
+ * <src>/<layer>/<name>/model/<name>.ts the stub (files/module)
10
+ * <src>/<layer>/<name>/model/<name>.spec.ts
11
+ * <src>/<layer>/<name>/<segment>/index.ts per --segments (files/segment)
12
+ * A shared segment holds no segments of its own, so its stub sits next to the index.
13
+ */
14
+ export function composeSlice(input) {
15
+ const files = generatorFilesDir('slice', import.meta.url);
16
+ const directory = `${input.sourceRoot}/${input.layerDirName}/${input.name}`;
17
+ const shared = input.layer === 'shared';
18
+ const values = {
19
+ name: input.name,
20
+ publicApiName: input.publicApiName,
21
+ layer: input.layer,
22
+ locale: input.locale,
23
+ modulePath: shared ? `./${input.name}` : `./model/${input.name}`,
24
+ };
25
+ const module = renderTemplateFiles(join(files, 'module'), shared ? directory : `${directory}/model`, values)
26
+ // the stub before its test
27
+ .sort((a, b) => Number(a.filePath.endsWith('.spec.ts')) - Number(b.filePath.endsWith('.spec.ts')));
28
+ const segments = shared
29
+ ? []
30
+ : Array.from(new Set(input.segments))
31
+ .filter((segment) => segment !== 'model')
32
+ .flatMap((segment) => renderTemplateFiles(join(files, 'segment'), `${directory}/${segment}`, { ...values, segment }));
33
+ return {
34
+ directory,
35
+ publicApiName: input.publicApiName,
36
+ files: [...renderTemplateFiles(join(files, 'index'), directory, values), ...module, ...segments],
37
+ };
38
+ }
39
+ /** Lowercase letters/digits, single hyphens, no leading/trailing/doubled hyphen, must
40
+ * start with a letter (so `toCamelCase`/directory names stay valid identifiers). */
41
+ const KEBAB_CASE = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
42
+ /** Next.js reads `src/pages` as its Pages Router, so FSD's Next.js guide puts the pages
43
+ * layer in `_pages/` there (as add-fsd-lite's guide says). Every other layer is its id. */
44
+ function layerDirNameFor(layer, frontend) {
45
+ return layer === 'pages' && frontend === 'next' ? '_pages' : layer;
46
+ }
47
+ function layerDirFor(layer, sourceRoot, frontend = 'react-vite') {
48
+ return `${sourceRoot}/${layerDirNameFor(layer, frontend)}`;
49
+ }
50
+ const NEXT_CONFIG_FILES = ['next.config.js', 'next.config.mjs', 'next.config.ts', 'next.config.cjs'];
51
+ /** option > toolkit.config.json's frontend (init records it) > a next.config file in the app
52
+ * (Nx's Next.js app always has one) > react-vite. Best-effort: it only moves `pages` to
53
+ * `_pages`, so a wrong guess costs a rename, never a broken file. */
54
+ function resolveFrontendForApp(option, config, appRoot, tree) {
55
+ if (option === 'react-vite' || option === 'next')
56
+ return option;
57
+ const recorded = config?.['frontend'];
58
+ if (typeof recorded === 'string' && RECORDED_FRONTENDS.includes(recorded) && recorded !== 'none') {
59
+ return recorded;
60
+ }
61
+ const prefix = appRoot === '' || appRoot === '.' ? '' : `${appRoot}/`;
62
+ return NEXT_CONFIG_FILES.some((file) => tree.exists(`${prefix}${file}`)) ? 'next' : 'react-vite';
63
+ }
64
+ /** A slice directory is:
65
+ * - 'created' when it doesn't exist yet;
66
+ * - 'unchanged' when it exists and contains exactly our generated files, byte-for-byte;
67
+ * - 'skipped' for anything else (same-name slice already there with different/extra
68
+ * content — a name collision is a signal to pick a new name; merge is never proposed). */
69
+ /** Every file under `dir`, as paths relative to it (the generated set spans model/). */
70
+ function listFilesUnder(tree, dir, prefix = '') {
71
+ return tree.children(dir).flatMap((child) => {
72
+ const path = `${dir}/${child}`;
73
+ return tree.isFile(path) ? [`${prefix}${child}`] : listFilesUnder(tree, path, `${prefix}${child}/`);
74
+ });
75
+ }
76
+ function computeSliceAction(tree, plan) {
77
+ if (!tree.exists(plan.directory))
78
+ return 'created';
79
+ const expectedNames = plan.files.map((f) => f.filePath.slice(plan.directory.length + 1)).sort();
80
+ const actualNames = listFilesUnder(tree, plan.directory).sort();
81
+ if (actualNames.length !== expectedNames.length || !actualNames.every((n, i) => n === expectedNames[i])) {
82
+ return 'skipped';
83
+ }
84
+ const allMatch = plan.files.every((f) => tree.read(f.filePath, 'utf-8') === f.content);
85
+ return allMatch ? 'unchanged' : 'skipped';
86
+ }
87
+ function refusal(reason, dryRun, layer, name, app, extra = {}) {
88
+ const layerDir = layerDirFor(layer, app.sourceRoot);
89
+ return {
90
+ dryRun,
91
+ layer,
92
+ name,
93
+ project: app.project,
94
+ layerDir,
95
+ directory: `${layerDir}/${name}`,
96
+ publicApiName: null,
97
+ refused: true,
98
+ refusalReason: reason,
99
+ action: null,
100
+ files: [],
101
+ ...extra,
102
+ };
103
+ }
104
+ /**
105
+ * Pure core shared by the `page` / `widget` / `feature` / `entity` / `shared` generators.
106
+ * `layer` is fixed per top-level generator — only the option parsing, tree reads, and
107
+ * report shape are shared here.
108
+ *
109
+ * The layer directory (`<app sourceRoot>/<layer>`) appears with its first slice (canonical
110
+ * FSD) — nothing has to exist beforehand but the frontend app.
111
+ */
112
+ export function runFsdSlice(tree, layer, options) {
113
+ const dryRun = options.dryRun ?? false;
114
+ // Placeholder location for refusals raised before an app is picked.
115
+ const unresolved = { project: null, sourceRoot: '<app>/src' };
116
+ if (!KEBAB_CASE.test(options.name)) {
117
+ return refusal('invalid-name', dryRun, layer, options.name, unresolved);
118
+ }
119
+ // Validate the SAME effective value the composer will embed — an explicit
120
+ // publicApiName that isn't an identifier, or a slice name whose camelCase
121
+ // default is a reserved word (e.g. "class", "delete"), would otherwise
122
+ // silently produce syntactically broken TypeScript.
123
+ if (!isUsableSliceApiName(resolveSlicePublicApiName(options.name, options.publicApiName))) {
124
+ return refusal('invalid-public-api-name', dryRun, layer, options.name, unresolved);
125
+ }
126
+ // canonical FSD: a shared segment is named by purpose (ui, api, model, lib, config), never
127
+ // by what it contains.
128
+ if (layer === 'shared' && isEssenceSegmentName(options.name)) {
129
+ return refusal('segment-by-essence', dryRun, layer, options.name, unresolved);
130
+ }
131
+ // --segments: a shared segment holds no segments; elsewhere each
132
+ // name must be a directory-safe name by purpose, like the shared generator's own names.
133
+ const segments = Array.from(new Set(options.segments ?? []));
134
+ if (segments.length > 0 && layer === 'shared') {
135
+ return refusal('segments-on-shared', dryRun, layer, options.name, unresolved);
136
+ }
137
+ const badSegment = segments.find((segment) => !SEGMENT_NAME_PATTERN.test(segment));
138
+ if (badSegment !== undefined)
139
+ return refusal('invalid-segment', dryRun, layer, options.name, unresolved, { detail: badSegment });
140
+ const essenceSegment = segments.find((segment) => isEssenceSegmentName(segment));
141
+ if (essenceSegment !== undefined)
142
+ return refusal('segment-by-essence', dryRun, layer, options.name, unresolved, { detail: essenceSegment });
143
+ const app = resolveFrontendApp(tree, options.project);
144
+ if (app.kind === 'not-found')
145
+ return refusal('project-not-found', dryRun, layer, options.name, { project: app.project, sourceRoot: unresolved.sourceRoot });
146
+ if (app.kind === 'ambiguous')
147
+ return refusal('ambiguous-frontend', dryRun, layer, options.name, unresolved, { candidates: app.candidates });
148
+ if (app.kind === 'invalid-project-json')
149
+ return refusal('invalid-project-json', dryRun, layer, options.name, unresolved, { detail: app.detail });
150
+ if (app.kind === 'none')
151
+ return refusal('no-frontend-app', dryRun, layer, options.name, unresolved);
152
+ // The layer directory is created with its first slice (canonical FSD) — add-fsd-lite makes
153
+ // no folders. tree.write creates every missing parent.
154
+ const config = readToolkitConfig(tree);
155
+ const frontend = resolveFrontendForApp(options.frontend, config, app.root, tree);
156
+ const layerDir = layerDirFor(layer, app.sourceRoot, frontend);
157
+ const locale = resolveLocaleOption(options.locale, config);
158
+ const plan = composeSlice({
159
+ layer,
160
+ name: options.name,
161
+ publicApiName: resolveSlicePublicApiName(options.name, options.publicApiName),
162
+ locale,
163
+ sourceRoot: app.sourceRoot,
164
+ layerDirName: layerDirNameFor(layer, frontend),
165
+ segments,
166
+ });
167
+ const action = computeSliceAction(tree, plan);
168
+ if (action === 'created' && !dryRun) {
169
+ for (const file of plan.files)
170
+ tree.write(file.filePath, file.content);
171
+ }
172
+ return {
173
+ dryRun,
174
+ layer,
175
+ name: options.name,
176
+ project: app.project,
177
+ layerDir,
178
+ directory: plan.directory,
179
+ publicApiName: plan.publicApiName,
180
+ refused: false,
181
+ refusalReason: null,
182
+ action,
183
+ files: plan.files,
184
+ };
185
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ <% if (locale === 'ko') { -%>
3
+ * "<%- name %>"의 공개 API ("<%- layer %>" 레이어, FSD).
4
+ *
5
+ * 다른 슬라이스/레이어가 import할 수 있는 유일한 진입점입니다 — 밖으로 노출할 것은 모두 여기서
6
+ * 재export하고, 내부 파일(model/, ui/, api/ …)은 밖에서 직접 import하지 않습니다.
7
+ <% } else { -%>
8
+ * Public API of "<%- name %>" (the "<%- layer %>" layer, FSD).
9
+ *
10
+ * The only entry point other slices and layers may import — re-export everything exposed
11
+ * from here; internal files (model/, ui/, api/ …) are never imported from outside.
12
+ <% } -%>
13
+ */
14
+ export { <%- publicApiName %> } from '<%- modulePath %>';
@@ -0,0 +1,11 @@
1
+ import { <%- publicApiName %> } from './<%- name %>.js';
2
+
3
+ describe('<%- name %>', () => {
4
+ <% if (locale === 'ko') { -%>
5
+ it('스캐폴드된 스텁을 호출할 수 있다 (실제 assertion으로 교체하세요)', () => {
6
+ <% } else { -%>
7
+ it('is scaffolded and callable (replace with real assertions)', () => {
8
+ <% } -%>
9
+ expect(() => <%- publicApiName %>()).not.toThrow();
10
+ });
11
+ });
@@ -0,0 +1,11 @@
1
+ <% if (locale === 'ko') { -%>
2
+ // TODO: "<%- name %>"의 실제 동작을 구현하세요.
3
+ export function <%- publicApiName %>(): void {
4
+ // TODO: 이 스텁 본문을 실제 구현으로 교체하세요.
5
+ }
6
+ <% } else { -%>
7
+ // TODO: implement the real behavior of "<%- name %>".
8
+ export function <%- publicApiName %>(): void {
9
+ // TODO: replace this stub body with the real implementation.
10
+ }
11
+ <% } -%>
@@ -0,0 +1,20 @@
1
+ <%
2
+ const purposes = locale === 'ko'
3
+ ? { ui: '이 슬라이스의 컴포넌트·뷰·스타일', model: '이 슬라이스의 상태·비즈니스 로직·타입', api: '이 슬라이스의 요청과 데이터 매퍼', lib: '이 슬라이스 안에서만 쓰는 헬퍼', config: '이 슬라이스의 상수와 플래그' }
4
+ : { ui: 'components, views and styles of this slice', model: 'state, business logic and types of this slice', api: 'requests and data mappers of this slice', lib: 'helpers used only inside this slice', config: 'constants and flags of this slice' };
5
+ const purpose = purposes[segment] ? ` — ${purposes[segment]}` : '';
6
+ -%>
7
+ /**
8
+ <% if (locale === 'ko') { -%>
9
+ * "<%- name %>" 슬라이스의 "<%- segment %>" 세그먼트<%- purpose %>.
10
+ *
11
+ * 슬라이스 내부용입니다: 같은 슬라이스의 파일에서만 import하고(예: `../<%- segment %>`), 다른 슬라이스는
12
+ * 이 슬라이스의 index.ts를 통해서만 접근합니다. 밖으로 노출할 것은 index.ts에서 재export하세요.
13
+ <% } else { -%>
14
+ * The "<%- segment %>" segment of the "<%- name %>" slice<%- purpose %>.
15
+ *
16
+ * Internal to the slice: import it from the slice's own files only (e.g. `../<%- segment %>`); other
17
+ * slices go through this slice's index.ts. Re-export from index.ts whatever should be public.
18
+ <% } -%>
19
+ */
20
+ export {};
@@ -0,0 +1,70 @@
1
+ const ACTION_LINES = {
2
+ created: 'created',
3
+ unchanged: 'unchanged (already matches the generated content)',
4
+ skipped: 'skipped — a slice with this name already exists with different content',
5
+ };
6
+ export function renderSliceReport(report) {
7
+ const lines = [];
8
+ const label = `${report.layer} "${report.name}"`;
9
+ if (report.refused) {
10
+ lines.push(`${label}: refused — nothing was written.`);
11
+ lines.push('');
12
+ if (report.refusalReason === 'invalid-name') {
13
+ lines.push(` "${report.name}" is not a valid kebab-case slice name.`);
14
+ lines.push(' Use lowercase letters, digits, and single hyphens, starting with a letter (e.g. "add-to-cart").');
15
+ }
16
+ else if (report.refusalReason === 'invalid-public-api-name') {
17
+ lines.push(' The public API name is not a usable JavaScript identifier (or is a reserved word).');
18
+ lines.push(' Pass --publicApiName with a valid identifier, e.g. "addToCart" (this also happens when');
19
+ lines.push(' the slice name camelCases into a reserved word, like "class" or "delete").');
20
+ }
21
+ else if (report.refusalReason === 'project-not-found') {
22
+ lines.push(` --project=${report.project} names no project in this workspace.`);
23
+ }
24
+ else if (report.refusalReason === 'ambiguous-frontend') {
25
+ lines.push(' More than one frontend app was found — rerun with --project=<one of them>:');
26
+ for (const name of report.candidates ?? [])
27
+ lines.push(` - ${name}`);
28
+ }
29
+ else if (report.refusalReason === 'invalid-project-json') {
30
+ lines.push(` A project.json could not be parsed (${report.detail ?? 'unknown'}) — fix it, then rerun.`);
31
+ }
32
+ else if (report.refusalReason === 'no-frontend-app') {
33
+ lines.push(' The workspace has no frontend application to hold FSD layers — create one, or pass --project.');
34
+ }
35
+ else if (report.refusalReason === 'invalid-segment') {
36
+ lines.push(` --segments: "${report.detail ?? ''}" is not a valid segment name.`);
37
+ lines.push(' Use lowercase letters, digits, and single hyphens, starting with a letter (e.g. ui, api, lib).');
38
+ }
39
+ else if (report.refusalReason === 'segments-on-shared') {
40
+ lines.push(' --segments does not apply to shared: a shared segment holds no segments of its own.');
41
+ lines.push(' Run the generator once per segment instead (e.g. --name=ui, then --name=api).');
42
+ }
43
+ else {
44
+ const offender = report.detail ?? report.name;
45
+ lines.push(` "${offender}" names what a segment contains, not what it is for.`);
46
+ lines.push(' Canonical FSD names segments by purpose — ui, api, model, lib, config — so the code stays');
47
+ lines.push(' findable by what it does (e.g. a date helper lives in shared/lib, a Button in shared/ui).');
48
+ }
49
+ return lines.join('\n');
50
+ }
51
+ if (report.dryRun) {
52
+ lines.push('dry-run — no files were written.');
53
+ lines.push('');
54
+ }
55
+ lines.push(`${label}: ${ACTION_LINES[report.action]}`);
56
+ if (report.action === 'skipped') {
57
+ lines.push(` ${report.directory} already exists and does not exactly match the generated content.`);
58
+ lines.push(' Pick a new slice name (a name collision is a signal to rename, not to merge)');
59
+ lines.push(' — or remove the existing directory manually first if you intended to replace it.');
60
+ return lines.join('\n');
61
+ }
62
+ if (report.dryRun) {
63
+ for (const file of report.files) {
64
+ lines.push('');
65
+ lines.push(`${file.filePath}:`);
66
+ lines.push(file.content);
67
+ }
68
+ }
69
+ return lines.join('\n');
70
+ }