create-fsaa 0.1.7 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +159 -160
- package/bin/fsaa.mjs +15 -15
- package/lib/cli.mjs +97 -92
- package/lib/download.mjs +66 -66
- package/lib/generate.mjs +316 -161
- package/lib/init.mjs +171 -171
- package/lib/net.mjs +12 -12
- package/lib/snippets.mjs +283 -221
- package/package.json +32 -32
package/lib/snippets.mjs
CHANGED
|
@@ -1,221 +1,283 @@
|
|
|
1
|
-
/* fsaa/lib/snippets.mjs — canonical slice file templates.
|
|
2
|
-
These mirror agents/add-module.md and the seeded canon of both starter
|
|
3
|
-
templates: a generated slice = a full entity (index/types/api/slice with
|
|
4
|
-
mock data + a real test) + a thin feature (index/ui/config with a real
|
|
5
|
-
test) + a thin route file. Data access lives ONLY in the entity. */
|
|
6
|
-
|
|
7
|
-
export function entityFiles(name) {
|
|
8
|
-
const Noun = pascal(name);
|
|
9
|
-
return {
|
|
10
|
-
"index.ts": entityIndex(name),
|
|
11
|
-
"types.ts": entityTypes(Noun),
|
|
12
|
-
"api.ts": entityApi(name, Noun),
|
|
13
|
-
"slice.ts": entitySlice(name, Noun),
|
|
14
|
-
[`__tests__/${name}.test.ts`]: entityTest(name, Noun),
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function featureFiles(name, template) {
|
|
19
|
-
const Title = pascal(name);
|
|
20
|
-
return {
|
|
21
|
-
"index.ts": featureIndex(name),
|
|
22
|
-
[`ui/${Title}Overview.tsx`]: featureComponent(name, Title, template),
|
|
23
|
-
[`config/${camel(name)}Columns.tsx`]: featureColumns(name),
|
|
24
|
-
[`__tests__/${name}.test.tsx`]: featureTest(name, template),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/* ---------- entity ---------- */
|
|
29
|
-
|
|
30
|
-
function entityIndex(name) {
|
|
31
|
-
return `export type { ${pascal(name)}Record } from './types';
|
|
32
|
-
export { get${pascal(name)}s } from './api';
|
|
33
|
-
export { selectOpen${pascal(name)}s, select${pascal(name)}Total } from './slice';
|
|
34
|
-
`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function entityTypes(Noun) {
|
|
38
|
-
return `export type ${Noun}Status = 'pending' | 'paid' | 'cancelled';
|
|
39
|
-
|
|
40
|
-
export type ${Noun}Record = {
|
|
41
|
-
id: string;
|
|
42
|
-
reference: string;
|
|
43
|
-
projectName: string;
|
|
44
|
-
amount: number;
|
|
45
|
-
status: ${Noun}Status;
|
|
46
|
-
};
|
|
47
|
-
`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function entityApi(name, Noun) {
|
|
51
|
-
return `/* entities/${name} — data access. Swap for a real API without touching features. */
|
|
52
|
-
|
|
53
|
-
import type { ${Noun}Record } from './types';
|
|
54
|
-
|
|
55
|
-
export const ${CONST(name)}_RECORDS: ${Noun}Record[] = [
|
|
56
|
-
{ id: 'r1', reference: 'REF-2026-001', projectName: 'Core Banking Migration', amount: 18500, status: 'paid' },
|
|
57
|
-
{ id: 'r2', reference: 'REF-2026-002', projectName: 'Mobile App v2', amount: 6200, status: 'pending' },
|
|
58
|
-
{ id: 'r3', reference: 'REF-2026-003', projectName: 'Mobile App v2', amount: 12400, status: 'pending' },
|
|
59
|
-
{ id: 'r4', reference: 'REF-2026-004', projectName: 'Legacy CRM Sunset', amount: 3100, status: 'cancelled' },
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
export function get${Noun}s(): Promise<${Noun}Record[]> {
|
|
63
|
-
return Promise.resolve(${CONST(name)}_RECORDS);
|
|
64
|
-
}
|
|
65
|
-
`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function entitySlice(name, Noun) {
|
|
69
|
-
return `/* entities/${name}/slice — business logic (no UI knowledge, fully testable). */
|
|
70
|
-
|
|
71
|
-
import type { ${Noun}Record } from './types';
|
|
72
|
-
|
|
73
|
-
export function selectOpen${Noun}s(records: ${Noun}Record[]) {
|
|
74
|
-
return records.filter((record) => record.status !== 'cancelled');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function select${Noun}Total(records: ${Noun}Record[]) {
|
|
78
|
-
return records.reduce((sum, record) => sum + record.amount, 0);
|
|
79
|
-
}
|
|
80
|
-
`;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function entityTest(name, Noun) {
|
|
84
|
-
return `import { describe, expect, it } from 'vitest';
|
|
85
|
-
import { get${Noun}s, selectOpen${Noun}s, select${Noun}Total } from '../index';
|
|
86
|
-
|
|
87
|
-
describe('entities/${name}', () => {
|
|
88
|
-
it('returns records with valid ids, amounts and statuses', async () => {
|
|
89
|
-
const records = await get${Noun}s();
|
|
90
|
-
expect(records.length).toBeGreaterThan(0);
|
|
91
|
-
for (const record of records) {
|
|
92
|
-
expect(record.id).toBeTruthy();
|
|
93
|
-
expect(record.amount).toBeGreaterThan(0);
|
|
94
|
-
expect(['pending', 'paid', 'cancelled'] as const).toContain(record.status);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('derives open records and total through the slice', async () => {
|
|
99
|
-
const records = await get${Noun}s();
|
|
100
|
-
expect(selectOpen${Noun}s(records).every((record) => record.status !== 'cancelled')).toBe(true);
|
|
101
|
-
expect(select${Noun}Total(records)).toBe(records.reduce((sum, record) => sum + record.amount, 0));
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/* ---------- feature ---------- */
|
|
108
|
-
|
|
109
|
-
function featureIndex(name) {
|
|
110
|
-
return `export { ${pascal(name)}Overview } from './ui/${pascal(name)}Overview';
|
|
111
|
-
`;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function featureComponent(name, Title, template) {
|
|
115
|
-
return `${template === "next" ? "'use client';\n\n" : ""}import { useEffect, useState } from 'react';
|
|
116
|
-
import { DataTable } from '@shared/ui/molecules/table/DataTable';
|
|
117
|
-
import { get${pascal(name)}s, type ${pascal(name)}Record } from '@entities/${name}';
|
|
118
|
-
import { ${camel(name)}Columns } from '../config/${camel(name)}Columns';
|
|
119
|
-
|
|
120
|
-
/* features/${name}/ui/${Title}Overview — thin composition: entity data + config. */
|
|
121
|
-
|
|
122
|
-
export function ${Title}Overview() {
|
|
123
|
-
const [records, setRecords] = useState<${pascal(name)}Record[] | null>(null);
|
|
124
|
-
|
|
125
|
-
useEffect(() => {
|
|
126
|
-
let alive = true;
|
|
127
|
-
get${pascal(name)}s().then((data) => {
|
|
128
|
-
if (alive) setRecords(data);
|
|
129
|
-
});
|
|
130
|
-
return () => {
|
|
131
|
-
alive = false;
|
|
132
|
-
};
|
|
133
|
-
}, []);
|
|
134
|
-
|
|
135
|
-
return (
|
|
136
|
-
<section>
|
|
137
|
-
<h2>${Title}</h2>
|
|
138
|
-
{records && <DataTable columns={${camel(name)}Columns} data={records} rowKey={(row) => row.id} />}
|
|
139
|
-
</section>
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
`;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function featureColumns(name) {
|
|
146
|
-
const Noun = pascal(name);
|
|
147
|
-
return `import type { Column } from '@shared/ui/molecules/table/DataTable';
|
|
148
|
-
import type { ${Noun}Record } from '@entities/${name}';
|
|
149
|
-
|
|
150
|
-
/* features/${name}/config — plain data of the scenario, no UI knowledge. */
|
|
151
|
-
|
|
152
|
-
export const ${camel(name)}Columns: Column<${Noun}Record>[] = [
|
|
153
|
-
{
|
|
154
|
-
header: 'Reference',
|
|
155
|
-
render: (row) => <strong>{row.reference}</strong>,
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
header: 'Project',
|
|
159
|
-
render: (row) => row.projectName,
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
header: 'Amount',
|
|
163
|
-
align: 'right',
|
|
164
|
-
render: (row) => \`$\${row.amount.toLocaleString('en-US')}\`,
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
header: 'Status',
|
|
168
|
-
render: (row) =>
|
|
169
|
-
row.status === 'paid' ? '✅ paid' : row.status === 'pending' ? '⏳ pending' : '❌ cancelled',
|
|
170
|
-
},
|
|
171
|
-
];
|
|
172
|
-
`;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function featureTest(name, template) {
|
|
176
|
-
return `import { describe, it, expect } from 'vitest';
|
|
177
|
-
import { ${pascal(name)}Overview } from '../index';
|
|
178
|
-
import { ${camel(name)}Columns } from '../config/${camel(name)}Columns';
|
|
179
|
-
import type { ${pascal(name)}Record } from '@entities/${name}';
|
|
180
|
-
|
|
181
|
-
/* Scenario slice test: the component exists and the plain column config
|
|
182
|
-
renders a record. Pure logic — no jsdom needed. */
|
|
183
|
-
|
|
184
|
-
const record: ${pascal(name)}Record = {
|
|
185
|
-
id: 'r1',
|
|
186
|
-
reference: 'REF-2026-001',
|
|
187
|
-
projectName: 'Demo',
|
|
188
|
-
amount: 100,
|
|
189
|
-
status: 'pending',
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
describe('features/${name}', () => {
|
|
193
|
-
it('exports the scenario component', () => {
|
|
194
|
-
expect(typeof ${pascal(name)}Overview).toBe('function');
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('renders records through the plain column config', () => {
|
|
198
|
-
expect(${camel(name)}Columns.length).toBeGreaterThan(0);
|
|
199
|
-
for (const column of ${camel(name)}Columns) {
|
|
200
|
-
expect(column.render(record)).toBeTruthy();
|
|
201
|
-
}
|
|
202
|
-
expect(String(${camel(name)}Columns[1].render(record))).toBe(record.projectName);
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
`;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/* ---------- helpers ---------- */
|
|
209
|
-
|
|
210
|
-
export function pascal(name) {
|
|
211
|
-
return name.split("-").map((s) => s[0].toUpperCase() + s.slice(1)).join("");
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/* camelCase, canon-style: invoices-overview -> 'invoicesOverviewColumns' (orderColumns style) */
|
|
215
|
-
export function camel(name) {
|
|
216
|
-
const [first, ...rest] = name.split("-");
|
|
217
|
-
return first + rest.map((s) => s[0].toUpperCase() + s.slice(1)).join("");
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const CONST = (name) => name.split("-").join("_").toUpperCase();
|
|
1
|
+
/* fsaa/lib/snippets.mjs — canonical slice file templates.
|
|
2
|
+
These mirror agents/add-module.md and the seeded canon of both starter
|
|
3
|
+
templates: a generated slice = a full entity (index/types/api/slice with
|
|
4
|
+
mock data + a real test) + a thin feature (index/ui/config with a real
|
|
5
|
+
test) + a thin route file. Data access lives ONLY in the entity. */
|
|
6
|
+
|
|
7
|
+
export function entityFiles(name) {
|
|
8
|
+
const Noun = pascal(name);
|
|
9
|
+
return {
|
|
10
|
+
"index.ts": entityIndex(name),
|
|
11
|
+
"types.ts": entityTypes(Noun),
|
|
12
|
+
"api.ts": entityApi(name, Noun),
|
|
13
|
+
"slice.ts": entitySlice(name, Noun),
|
|
14
|
+
[`__tests__/${name}.test.ts`]: entityTest(name, Noun),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function featureFiles(name, template) {
|
|
19
|
+
const Title = pascal(name);
|
|
20
|
+
return {
|
|
21
|
+
"index.ts": featureIndex(name),
|
|
22
|
+
[`ui/${Title}Overview.tsx`]: featureComponent(name, Title, template),
|
|
23
|
+
[`config/${camel(name)}Columns.tsx`]: featureColumns(name),
|
|
24
|
+
[`__tests__/${name}.test.tsx`]: featureTest(name, template),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* ---------- entity ---------- */
|
|
29
|
+
|
|
30
|
+
function entityIndex(name) {
|
|
31
|
+
return `export type { ${pascal(name)}Record } from './types';
|
|
32
|
+
export { get${pascal(name)}s } from './api';
|
|
33
|
+
export { selectOpen${pascal(name)}s, select${pascal(name)}Total } from './slice';
|
|
34
|
+
`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function entityTypes(Noun) {
|
|
38
|
+
return `export type ${Noun}Status = 'pending' | 'paid' | 'cancelled';
|
|
39
|
+
|
|
40
|
+
export type ${Noun}Record = {
|
|
41
|
+
id: string;
|
|
42
|
+
reference: string;
|
|
43
|
+
projectName: string;
|
|
44
|
+
amount: number;
|
|
45
|
+
status: ${Noun}Status;
|
|
46
|
+
};
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function entityApi(name, Noun) {
|
|
51
|
+
return `/* entities/${name} — data access. Swap for a real API without touching features. */
|
|
52
|
+
|
|
53
|
+
import type { ${Noun}Record } from './types';
|
|
54
|
+
|
|
55
|
+
export const ${CONST(name)}_RECORDS: ${Noun}Record[] = [
|
|
56
|
+
{ id: 'r1', reference: 'REF-2026-001', projectName: 'Core Banking Migration', amount: 18500, status: 'paid' },
|
|
57
|
+
{ id: 'r2', reference: 'REF-2026-002', projectName: 'Mobile App v2', amount: 6200, status: 'pending' },
|
|
58
|
+
{ id: 'r3', reference: 'REF-2026-003', projectName: 'Mobile App v2', amount: 12400, status: 'pending' },
|
|
59
|
+
{ id: 'r4', reference: 'REF-2026-004', projectName: 'Legacy CRM Sunset', amount: 3100, status: 'cancelled' },
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
export function get${Noun}s(): Promise<${Noun}Record[]> {
|
|
63
|
+
return Promise.resolve(${CONST(name)}_RECORDS);
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function entitySlice(name, Noun) {
|
|
69
|
+
return `/* entities/${name}/slice — business logic (no UI knowledge, fully testable). */
|
|
70
|
+
|
|
71
|
+
import type { ${Noun}Record } from './types';
|
|
72
|
+
|
|
73
|
+
export function selectOpen${Noun}s(records: ${Noun}Record[]) {
|
|
74
|
+
return records.filter((record) => record.status !== 'cancelled');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function select${Noun}Total(records: ${Noun}Record[]) {
|
|
78
|
+
return records.reduce((sum, record) => sum + record.amount, 0);
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function entityTest(name, Noun) {
|
|
84
|
+
return `import { describe, expect, it } from 'vitest';
|
|
85
|
+
import { get${Noun}s, selectOpen${Noun}s, select${Noun}Total } from '../index';
|
|
86
|
+
|
|
87
|
+
describe('entities/${name}', () => {
|
|
88
|
+
it('returns records with valid ids, amounts and statuses', async () => {
|
|
89
|
+
const records = await get${Noun}s();
|
|
90
|
+
expect(records.length).toBeGreaterThan(0);
|
|
91
|
+
for (const record of records) {
|
|
92
|
+
expect(record.id).toBeTruthy();
|
|
93
|
+
expect(record.amount).toBeGreaterThan(0);
|
|
94
|
+
expect(['pending', 'paid', 'cancelled'] as const).toContain(record.status);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('derives open records and total through the slice', async () => {
|
|
99
|
+
const records = await get${Noun}s();
|
|
100
|
+
expect(selectOpen${Noun}s(records).every((record) => record.status !== 'cancelled')).toBe(true);
|
|
101
|
+
expect(select${Noun}Total(records)).toBe(records.reduce((sum, record) => sum + record.amount, 0));
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* ---------- feature ---------- */
|
|
108
|
+
|
|
109
|
+
function featureIndex(name) {
|
|
110
|
+
return `export { ${pascal(name)}Overview } from './ui/${pascal(name)}Overview';
|
|
111
|
+
`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function featureComponent(name, Title, template) {
|
|
115
|
+
return `${template === "next" ? "'use client';\n\n" : ""}import { useEffect, useState } from 'react';
|
|
116
|
+
import { DataTable } from '@shared/ui/molecules/table/DataTable';
|
|
117
|
+
import { get${pascal(name)}s, type ${pascal(name)}Record } from '@entities/${name}';
|
|
118
|
+
import { ${camel(name)}Columns } from '../config/${camel(name)}Columns';
|
|
119
|
+
|
|
120
|
+
/* features/${name}/ui/${Title}Overview — thin composition: entity data + config. */
|
|
121
|
+
|
|
122
|
+
export function ${Title}Overview() {
|
|
123
|
+
const [records, setRecords] = useState<${pascal(name)}Record[] | null>(null);
|
|
124
|
+
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
let alive = true;
|
|
127
|
+
get${pascal(name)}s().then((data) => {
|
|
128
|
+
if (alive) setRecords(data);
|
|
129
|
+
});
|
|
130
|
+
return () => {
|
|
131
|
+
alive = false;
|
|
132
|
+
};
|
|
133
|
+
}, []);
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<section>
|
|
137
|
+
<h2>${Title}</h2>
|
|
138
|
+
{records && <DataTable columns={${camel(name)}Columns} data={records} rowKey={(row) => row.id} />}
|
|
139
|
+
</section>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function featureColumns(name) {
|
|
146
|
+
const Noun = pascal(name);
|
|
147
|
+
return `import type { Column } from '@shared/ui/molecules/table/DataTable';
|
|
148
|
+
import type { ${Noun}Record } from '@entities/${name}';
|
|
149
|
+
|
|
150
|
+
/* features/${name}/config — plain data of the scenario, no UI knowledge. */
|
|
151
|
+
|
|
152
|
+
export const ${camel(name)}Columns: Column<${Noun}Record>[] = [
|
|
153
|
+
{
|
|
154
|
+
header: 'Reference',
|
|
155
|
+
render: (row) => <strong>{row.reference}</strong>,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
header: 'Project',
|
|
159
|
+
render: (row) => row.projectName,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
header: 'Amount',
|
|
163
|
+
align: 'right',
|
|
164
|
+
render: (row) => \`$\${row.amount.toLocaleString('en-US')}\`,
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
header: 'Status',
|
|
168
|
+
render: (row) =>
|
|
169
|
+
row.status === 'paid' ? '✅ paid' : row.status === 'pending' ? '⏳ pending' : '❌ cancelled',
|
|
170
|
+
},
|
|
171
|
+
];
|
|
172
|
+
`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function featureTest(name, template) {
|
|
176
|
+
return `import { describe, it, expect } from 'vitest';
|
|
177
|
+
import { ${pascal(name)}Overview } from '../index';
|
|
178
|
+
import { ${camel(name)}Columns } from '../config/${camel(name)}Columns';
|
|
179
|
+
import type { ${pascal(name)}Record } from '@entities/${name}';
|
|
180
|
+
|
|
181
|
+
/* Scenario slice test: the component exists and the plain column config
|
|
182
|
+
renders a record. Pure logic — no jsdom needed. */
|
|
183
|
+
|
|
184
|
+
const record: ${pascal(name)}Record = {
|
|
185
|
+
id: 'r1',
|
|
186
|
+
reference: 'REF-2026-001',
|
|
187
|
+
projectName: 'Demo',
|
|
188
|
+
amount: 100,
|
|
189
|
+
status: 'pending',
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
describe('features/${name}', () => {
|
|
193
|
+
it('exports the scenario component', () => {
|
|
194
|
+
expect(typeof ${pascal(name)}Overview).toBe('function');
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('renders records through the plain column config', () => {
|
|
198
|
+
expect(${camel(name)}Columns.length).toBeGreaterThan(0);
|
|
199
|
+
for (const column of ${camel(name)}Columns) {
|
|
200
|
+
expect(column.render(record)).toBeTruthy();
|
|
201
|
+
}
|
|
202
|
+
expect(String(${camel(name)}Columns[1].render(record))).toBe(record.projectName);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/* ---------- helpers ---------- */
|
|
209
|
+
|
|
210
|
+
export function pascal(name) {
|
|
211
|
+
return name.split("-").map((s) => s[0].toUpperCase() + s.slice(1)).join("");
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/* camelCase, canon-style: invoices-overview -> 'invoicesOverviewColumns' (orderColumns style) */
|
|
215
|
+
export function camel(name) {
|
|
216
|
+
const [first, ...rest] = name.split("-");
|
|
217
|
+
return first + rest.map((s) => s[0].toUpperCase() + s.slice(1)).join("");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
const CONST = (name) => name.split("-").join("_").toUpperCase();
|
|
222
|
+
|
|
223
|
+
/* ---------- atoms & molecules (shared/ui) ---------- */
|
|
224
|
+
|
|
225
|
+
/** src/shared/ui/atoms/<Name>.tsx — stateless UI primitive. */
|
|
226
|
+
export function atomFile(Name) {
|
|
227
|
+
return `import type { ReactNode } from 'react';
|
|
228
|
+
|
|
229
|
+
/* shared/ui/atoms/${Name} — stateless UI primitive. No data access, no
|
|
230
|
+
domain knowledge: a primitive takes props and renders. If this file grows
|
|
231
|
+
domain logic, it belongs to a feature slice instead. */
|
|
232
|
+
|
|
233
|
+
export function ${Name}(props: {
|
|
234
|
+
label?: string;
|
|
235
|
+
children?: ReactNode;
|
|
236
|
+
}) {
|
|
237
|
+
return (
|
|
238
|
+
<div>
|
|
239
|
+
{props.label ? <span>{props.label}</span> : null}
|
|
240
|
+
{props.children}
|
|
241
|
+
</div>
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
`;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** src/shared/ui/molecules/<Name>/ — composed primitive (index + component + test). */
|
|
248
|
+
export function moleculeFiles(Name) {
|
|
249
|
+
return {
|
|
250
|
+
"index.ts": `export { ${Name} } from './${Name}';
|
|
251
|
+
`,
|
|
252
|
+
[`${Name}.tsx`]: `import type { ReactNode } from 'react';
|
|
253
|
+
|
|
254
|
+
/* shared/ui/molecules/${Name} — atoms composed with light, reusable
|
|
255
|
+
presentation logic (no domain data, no API calls). */
|
|
256
|
+
|
|
257
|
+
export function ${Name}(props: {
|
|
258
|
+
title: string;
|
|
259
|
+
children?: ReactNode;
|
|
260
|
+
}) {
|
|
261
|
+
return (
|
|
262
|
+
<div>
|
|
263
|
+
<h3>{props.title}</h3>
|
|
264
|
+
<div>{props.children}</div>
|
|
265
|
+
</div>
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
`,
|
|
269
|
+
[`__tests__/${Name.toLowerCase()}.test.ts`]: `import { describe, expect, it } from 'vitest';
|
|
270
|
+
import { ${Name} } from '../index';
|
|
271
|
+
|
|
272
|
+
/* molecules/${Name}: the primitive exists; render tree stays presentable.
|
|
273
|
+
(This shared layer earns its place on the SECOND confirmed duplication —
|
|
274
|
+
before that, keep the code feature-local. See the graduation section.) */
|
|
275
|
+
|
|
276
|
+
describe('shared/ui/molecules/${Name}', () => {
|
|
277
|
+
it('exports the composed primitive', () => {
|
|
278
|
+
expect(typeof ${Name}).toBe('function');
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
`,
|
|
282
|
+
};
|
|
283
|
+
}
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "create-fsaa",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "FSAA \u2014 Feature-Sliced Atomic Architecture. Run `npm create fsaa` (this package) to scaffold an FSAA app from the official starter templates; `fsaa g <slice>` generates canonical slices.",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"author": "Veaceslav Bezusco <Aramex86@users.noreply.github.com>",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"bin": {
|
|
9
|
-
"fsaa": "bin/fsaa.mjs"
|
|
10
|
-
},
|
|
11
|
-
"files": [
|
|
12
|
-
"bin",
|
|
13
|
-
"lib"
|
|
14
|
-
],
|
|
15
|
-
"engines": {
|
|
16
|
-
"node": ">=20"
|
|
17
|
-
},
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/Aramex86/fsaa.git"
|
|
21
|
-
},
|
|
22
|
-
"keywords": [
|
|
23
|
-
"fsaa",
|
|
24
|
-
"feature-sliced",
|
|
25
|
-
"atomic-design",
|
|
26
|
-
"architecture",
|
|
27
|
-
"scaffold"
|
|
28
|
-
],
|
|
29
|
-
"scripts": {
|
|
30
|
-
"selfcheck": "node bin/fsaa.mjs --help"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "create-fsaa",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "FSAA \u2014 Feature-Sliced Atomic Architecture. Run `npm create fsaa` (this package) to scaffold an FSAA app from the official starter templates; `fsaa g <slice>` generates canonical slices.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Veaceslav Bezusco <Aramex86@users.noreply.github.com>",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"fsaa": "bin/fsaa.mjs"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin",
|
|
13
|
+
"lib"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/Aramex86/fsaa.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"fsaa",
|
|
24
|
+
"feature-sliced",
|
|
25
|
+
"atomic-design",
|
|
26
|
+
"architecture",
|
|
27
|
+
"scaffold"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"selfcheck": "node bin/fsaa.mjs --help"
|
|
31
|
+
}
|
|
32
|
+
}
|