domain-driver 0.0.5 → 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.
- package/dist/commands/component.js +10 -11
- package/dist/commands/container.js +22 -15
- package/dist/commands/feature.js +27 -24
- package/dist/commands/hook.js +107 -16
- package/dist/commands/repository.js +32 -18
- package/dist/commands/schema.js +4 -8
- package/dist/commands/service.js +49 -24
- package/dist/commands/types.js +57 -0
- package/dist/index.js +111 -53
- package/dist/utils.js +132 -0
- package/package.json +10 -9
- package/src/__tests__/utils.test.ts +128 -0
- package/src/commands/__tests__/feature.test.ts +85 -0
- package/src/commands/__tests__/imports.test.ts +115 -0
- package/src/commands/__tests__/individual.test.ts +137 -0
- package/src/commands/component.ts +12 -15
- package/src/commands/container.ts +24 -18
- package/src/commands/feature.ts +31 -25
- package/src/commands/hook.ts +109 -19
- package/src/commands/repository.ts +35 -21
- package/src/commands/schema.ts +5 -10
- package/src/commands/service.ts +52 -27
- package/src/commands/types.ts +25 -0
- package/src/index.ts +96 -45
- package/src/utils.ts +115 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +7 -0
|
@@ -34,11 +34,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.makeComponent = makeComponent;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
37
|
const path = __importStar(require("path"));
|
|
38
|
+
const utils_1 = require("../utils");
|
|
39
39
|
function renderComponent(name, type) {
|
|
40
40
|
const directive = type === 'client' ? "'use client';\n\n" : '';
|
|
41
|
-
return `${directive}
|
|
41
|
+
return `${directive}interface ${name}Props {
|
|
42
|
+
id: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default function ${name}({ id }: ${name}Props) {
|
|
42
46
|
return (
|
|
43
47
|
<div>
|
|
44
48
|
<h1>${name}</h1>
|
|
@@ -48,16 +52,11 @@ function renderComponent(name, type) {
|
|
|
48
52
|
`;
|
|
49
53
|
}
|
|
50
54
|
function makeComponent(feature, name, type = 'client') {
|
|
51
|
-
const base =
|
|
52
|
-
if (!fs.existsSync(base)) {
|
|
53
|
-
console.error(`❌ Feature "${feature}" does not exist. Run make:feature ${feature} first.`);
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}
|
|
55
|
+
const base = (0, utils_1.ensureFeatureExists)(feature, `components/${type}`);
|
|
56
56
|
const filePath = path.join(base, `${name}.tsx`);
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
process.exit(1);
|
|
57
|
+
if ((0, utils_1.fileExists)(filePath)) {
|
|
58
|
+
throw new Error(`Component "${name}" already exists at ${filePath}`);
|
|
60
59
|
}
|
|
61
|
-
|
|
60
|
+
(0, utils_1.writeFileSafe)(filePath, renderComponent(name, type));
|
|
62
61
|
console.log(`✅ Component "${name}" created at ${filePath}`);
|
|
63
62
|
}
|
|
@@ -34,33 +34,40 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.makeContainer = makeContainer;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
37
|
const path = __importStar(require("path"));
|
|
39
|
-
|
|
38
|
+
const utils_1 = require("../utils");
|
|
39
|
+
function renderContainer(containerName, name, feature) {
|
|
40
|
+
const hookName = `use${name}`;
|
|
41
|
+
const hookPath = (0, utils_1.resolveImport)(feature, `hooks/${hookName}`);
|
|
42
|
+
const componentPath = (0, utils_1.resolveImport)(feature, `components/client/${name}`);
|
|
40
43
|
return `'use client';
|
|
41
44
|
|
|
42
|
-
|
|
45
|
+
import { ${hookName} } from '${hookPath}';
|
|
46
|
+
import ${name} from '${componentPath}';
|
|
47
|
+
|
|
48
|
+
export default function ${containerName}() {
|
|
49
|
+
const { items, loading, error } = ${hookName}();
|
|
50
|
+
|
|
51
|
+
if (loading) return <div>Loading...</div>;
|
|
52
|
+
if (error) return <div>Error: {error}</div>;
|
|
43
53
|
|
|
44
|
-
export default function ${name}({ }: Props) {
|
|
45
54
|
return (
|
|
46
55
|
<div>
|
|
47
|
-
|
|
56
|
+
{items.map((item) => (
|
|
57
|
+
<${name} key={item.id} {...item} />
|
|
58
|
+
))}
|
|
48
59
|
</div>
|
|
49
60
|
);
|
|
50
61
|
}
|
|
51
62
|
`;
|
|
52
63
|
}
|
|
53
|
-
function makeContainer(feature, name) {
|
|
54
|
-
const base =
|
|
55
|
-
if (!fs.existsSync(base)) {
|
|
56
|
-
console.error(`❌ Feature "${feature}" does not exist. Run make:feature ${feature} first.`);
|
|
57
|
-
process.exit(1);
|
|
58
|
-
}
|
|
64
|
+
function makeContainer(feature, name, pascalName) {
|
|
65
|
+
const base = (0, utils_1.ensureFeatureExists)(feature, 'containers');
|
|
59
66
|
const filePath = path.join(base, `${name}.tsx`);
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
process.exit(1);
|
|
67
|
+
if ((0, utils_1.fileExists)(filePath)) {
|
|
68
|
+
throw new Error(`Container "${name}" already exists at ${filePath}`);
|
|
63
69
|
}
|
|
64
|
-
|
|
70
|
+
const entityName = pascalName ?? name.replace(/Container$/, '');
|
|
71
|
+
(0, utils_1.writeFileSafe)(filePath, renderContainer(name, entityName, feature));
|
|
65
72
|
console.log(`✅ Container "${name}" created at ${filePath}`);
|
|
66
73
|
}
|
package/dist/commands/feature.js
CHANGED
|
@@ -34,14 +34,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.makeFeature = makeFeature;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
37
|
const path = __importStar(require("path"));
|
|
38
|
+
const utils_1 = require("../utils");
|
|
39
39
|
const component_1 = require("./component");
|
|
40
40
|
const hook_1 = require("./hook");
|
|
41
41
|
const service_1 = require("./service");
|
|
42
42
|
const repository_1 = require("./repository");
|
|
43
43
|
const schema_1 = require("./schema");
|
|
44
44
|
const container_1 = require("./container");
|
|
45
|
+
const types_1 = require("./types");
|
|
45
46
|
const FEATURE_DIRS = [
|
|
46
47
|
'components/server',
|
|
47
48
|
'components/client',
|
|
@@ -50,46 +51,48 @@ const FEATURE_DIRS = [
|
|
|
50
51
|
'services',
|
|
51
52
|
'repositories',
|
|
52
53
|
'schemas',
|
|
54
|
+
'types',
|
|
53
55
|
];
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
function renderPage(name) {
|
|
61
|
-
const componentName = toPascalCase(name);
|
|
62
|
-
return `export default function ${componentName}Page() {
|
|
56
|
+
function renderPage(name, pascalName) {
|
|
57
|
+
const containerPath = (0, utils_1.resolveImport)(name, `containers/${pascalName}Container`, true);
|
|
58
|
+
return `import ${pascalName}Container from '${containerPath}';
|
|
59
|
+
|
|
60
|
+
export default function ${pascalName}Page() {
|
|
63
61
|
return (
|
|
64
62
|
<div>
|
|
65
|
-
|
|
63
|
+
<${pascalName}Container />
|
|
66
64
|
</div>
|
|
67
65
|
);
|
|
68
66
|
}
|
|
69
67
|
`;
|
|
70
68
|
}
|
|
71
69
|
async function makeFeature(name, all = false) {
|
|
72
|
-
const base =
|
|
73
|
-
const pascalName = toPascalCase(name);
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
process.exit(1);
|
|
70
|
+
const base = (0, utils_1.featureBasePath)(name);
|
|
71
|
+
const pascalName = (0, utils_1.toPascalCase)(name);
|
|
72
|
+
if ((0, utils_1.fileExists)(base)) {
|
|
73
|
+
throw new Error(`Feature "${name}" already exists at ${base}`);
|
|
77
74
|
}
|
|
78
75
|
for (const dir of FEATURE_DIRS) {
|
|
79
|
-
|
|
76
|
+
(0, utils_1.mkdirSafe)(path.join(base, dir));
|
|
80
77
|
if (!all) {
|
|
81
|
-
|
|
78
|
+
(0, utils_1.writeFileSafe)(path.join(base, dir, '.gitkeep'), '');
|
|
82
79
|
}
|
|
83
80
|
}
|
|
84
|
-
|
|
81
|
+
if (all) {
|
|
82
|
+
(0, utils_1.writeFileSafe)(path.join(base, 'page.tsx'), renderPage(name, pascalName));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
(0, utils_1.writeFileSafe)(path.join(base, 'page.tsx'), `export default function ${pascalName}Page() {\n return (\n <div>\n <h1>${pascalName}</h1>\n </div>\n );\n}\n`);
|
|
86
|
+
}
|
|
85
87
|
console.log(`✅ Feature "${name}" scaffolded at ${base}`);
|
|
86
88
|
if (all) {
|
|
87
|
-
(0,
|
|
88
|
-
(0,
|
|
89
|
-
(0,
|
|
89
|
+
(0, types_1.makeTypes)(name, pascalName);
|
|
90
|
+
(0, schema_1.makeSchema)(name, pascalName);
|
|
91
|
+
(0, repository_1.makeRepository)(name, pascalName);
|
|
90
92
|
(0, service_1.makeService)(name, pascalName);
|
|
91
|
-
(0,
|
|
92
|
-
(0,
|
|
93
|
+
(0, hook_1.makeHook)(name, `use${pascalName}`, pascalName);
|
|
94
|
+
(0, component_1.makeComponent)(name, pascalName, 'client');
|
|
95
|
+
(0, container_1.makeContainer)(name, `${pascalName}Container`, pascalName);
|
|
93
96
|
console.log(`✅ All files scaffolded for "${name}"`);
|
|
94
97
|
}
|
|
95
98
|
}
|
package/dist/commands/hook.js
CHANGED
|
@@ -34,29 +34,120 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.makeHook = makeHook;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
37
|
const path = __importStar(require("path"));
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const utils_1 = require("../utils");
|
|
39
|
+
function renderHook(hookName, name, feature) {
|
|
40
|
+
const typePath = (0, utils_1.resolveImport)(feature, `types/${name}.types`);
|
|
41
|
+
const svcPath = (op) => (0, utils_1.resolveImport)(feature, `services/${op}${name}.service`);
|
|
42
|
+
const schemaPath = (op) => (0, utils_1.resolveImport)(feature, `schemas/${op}${name}.schema`);
|
|
43
|
+
return `'use client';
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
46
|
+
import { ${name} } from '${typePath}';
|
|
47
|
+
import { List${name}Service } from '${svcPath('List')}';
|
|
48
|
+
import { Show${name}Service } from '${svcPath('Show')}';
|
|
49
|
+
import { Create${name}Service } from '${svcPath('Create')}';
|
|
50
|
+
import { Update${name}Service } from '${svcPath('Update')}';
|
|
51
|
+
import { Delete${name}Service } from '${svcPath('Delete')}';
|
|
52
|
+
import { Create${name} } from '${schemaPath('Create')}';
|
|
53
|
+
import { Update${name} } from '${schemaPath('Update')}';
|
|
44
54
|
|
|
45
|
-
|
|
55
|
+
const listService = new List${name}Service();
|
|
56
|
+
const showService = new Show${name}Service();
|
|
57
|
+
const createService = new Create${name}Service();
|
|
58
|
+
const updateService = new Update${name}Service();
|
|
59
|
+
const deleteService = new Delete${name}Service();
|
|
60
|
+
|
|
61
|
+
export function ${hookName}() {
|
|
62
|
+
const [items, setItems] = useState<${name}[]>([]);
|
|
63
|
+
const [selected, setSelected] = useState<${name} | null>(null);
|
|
64
|
+
const [loading, setLoading] = useState(false);
|
|
65
|
+
const [error, setError] = useState<string | null>(null);
|
|
66
|
+
|
|
67
|
+
const fetchAll = useCallback(async () => {
|
|
68
|
+
setLoading(true);
|
|
69
|
+
setError(null);
|
|
70
|
+
try {
|
|
71
|
+
const data = await listService.handle();
|
|
72
|
+
setItems(data);
|
|
73
|
+
} catch (err: unknown) {
|
|
74
|
+
setError(err instanceof Error ? err.message : 'Failed to fetch');
|
|
75
|
+
} finally {
|
|
76
|
+
setLoading(false);
|
|
77
|
+
}
|
|
78
|
+
}, []);
|
|
79
|
+
|
|
80
|
+
const fetchOne = useCallback(async (id: string) => {
|
|
81
|
+
setLoading(true);
|
|
82
|
+
setError(null);
|
|
83
|
+
try {
|
|
84
|
+
const data = await showService.handle(id);
|
|
85
|
+
setSelected(data);
|
|
86
|
+
} catch (err: unknown) {
|
|
87
|
+
setError(err instanceof Error ? err.message : 'Failed to fetch');
|
|
88
|
+
} finally {
|
|
89
|
+
setLoading(false);
|
|
90
|
+
}
|
|
91
|
+
}, []);
|
|
92
|
+
|
|
93
|
+
const create = useCallback(async (data: Create${name}) => {
|
|
94
|
+
setLoading(true);
|
|
95
|
+
setError(null);
|
|
96
|
+
try {
|
|
97
|
+
const created = await createService.handle(data);
|
|
98
|
+
setItems((prev) => [...prev, created]);
|
|
99
|
+
return created;
|
|
100
|
+
} catch (err: unknown) {
|
|
101
|
+
setError(err instanceof Error ? err.message : 'Failed to create');
|
|
102
|
+
return null;
|
|
103
|
+
} finally {
|
|
104
|
+
setLoading(false);
|
|
105
|
+
}
|
|
106
|
+
}, []);
|
|
107
|
+
|
|
108
|
+
const update = useCallback(async (id: string, data: Update${name}) => {
|
|
109
|
+
setLoading(true);
|
|
110
|
+
setError(null);
|
|
111
|
+
try {
|
|
112
|
+
const updated = await updateService.handle(id, data);
|
|
113
|
+
setItems((prev) => prev.map((item) => (item.id === id ? updated : item)));
|
|
114
|
+
return updated;
|
|
115
|
+
} catch (err: unknown) {
|
|
116
|
+
setError(err instanceof Error ? err.message : 'Failed to update');
|
|
117
|
+
return null;
|
|
118
|
+
} finally {
|
|
119
|
+
setLoading(false);
|
|
120
|
+
}
|
|
121
|
+
}, []);
|
|
122
|
+
|
|
123
|
+
const remove = useCallback(async (id: string) => {
|
|
124
|
+
setLoading(true);
|
|
125
|
+
setError(null);
|
|
126
|
+
try {
|
|
127
|
+
await deleteService.handle(id);
|
|
128
|
+
setItems((prev) => prev.filter((item) => item.id !== id));
|
|
129
|
+
} catch (err: unknown) {
|
|
130
|
+
setError(err instanceof Error ? err.message : 'Failed to delete');
|
|
131
|
+
} finally {
|
|
132
|
+
setLoading(false);
|
|
133
|
+
}
|
|
134
|
+
}, []);
|
|
135
|
+
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
fetchAll();
|
|
138
|
+
}, [fetchAll]);
|
|
139
|
+
|
|
140
|
+
return { items, selected, loading, error, fetchAll, fetchOne, create, update, remove };
|
|
46
141
|
}
|
|
47
142
|
`;
|
|
48
143
|
}
|
|
49
|
-
function makeHook(feature, name) {
|
|
50
|
-
const base =
|
|
51
|
-
if (!fs.existsSync(base)) {
|
|
52
|
-
console.error(`❌ Feature "${feature}" does not exist. Run make:feature ${feature} first.`);
|
|
53
|
-
process.exit(1);
|
|
54
|
-
}
|
|
144
|
+
function makeHook(feature, name, pascalName) {
|
|
145
|
+
const base = (0, utils_1.ensureFeatureExists)(feature, 'hooks');
|
|
55
146
|
const filePath = path.join(base, `${name}.ts`);
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
process.exit(1);
|
|
147
|
+
if ((0, utils_1.fileExists)(filePath)) {
|
|
148
|
+
throw new Error(`Hook "${name}" already exists at ${filePath}`);
|
|
59
149
|
}
|
|
60
|
-
|
|
150
|
+
const entityName = pascalName ?? name.replace(/^use/, '');
|
|
151
|
+
(0, utils_1.writeFileSafe)(filePath, renderHook(name, entityName, feature));
|
|
61
152
|
console.log(`✅ Hook "${name}" created at ${filePath}`);
|
|
62
153
|
}
|
|
@@ -34,74 +34,88 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.makeRepository = makeRepository;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
37
|
const path = __importStar(require("path"));
|
|
38
|
+
const utils_1 = require("../utils");
|
|
39
39
|
const REPOSITORY_ACTIONS = ['List', 'Create', 'Update', 'Delete', 'Show'];
|
|
40
40
|
function renderRepository(action, name, feature) {
|
|
41
|
+
const typePath = (0, utils_1.resolveImport)(feature, `types/${name}.types`);
|
|
42
|
+
const schemaPath = (op) => (0, utils_1.resolveImport)(feature, `schemas/${op}${name}.schema`);
|
|
41
43
|
switch (action) {
|
|
42
44
|
case 'List':
|
|
43
|
-
return `
|
|
44
|
-
|
|
45
|
+
return `import { ${name} } from '${typePath}';
|
|
46
|
+
|
|
47
|
+
export class List${name}Repository {
|
|
48
|
+
async handle(): Promise<${name}[]> {
|
|
45
49
|
const response = await fetch('/api/${feature}');
|
|
50
|
+
if (!response.ok) throw new Error('Failed to fetch ${name} list');
|
|
46
51
|
return response.json();
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
`;
|
|
50
55
|
case 'Show':
|
|
51
|
-
return `
|
|
52
|
-
|
|
56
|
+
return `import { ${name} } from '${typePath}';
|
|
57
|
+
|
|
58
|
+
export class Show${name}Repository {
|
|
59
|
+
async handle(id: string): Promise<${name}> {
|
|
53
60
|
const response = await fetch(\`/api/${feature}/\${id}\`);
|
|
61
|
+
if (!response.ok) throw new Error('Failed to fetch ${name}');
|
|
54
62
|
return response.json();
|
|
55
63
|
}
|
|
56
64
|
}
|
|
57
65
|
`;
|
|
58
66
|
case 'Create':
|
|
59
|
-
return `
|
|
60
|
-
|
|
67
|
+
return `import { ${name} } from '${typePath}';
|
|
68
|
+
import { Create${name} } from '${schemaPath('Create')}';
|
|
69
|
+
|
|
70
|
+
export class Create${name}Repository {
|
|
71
|
+
async handle(data: Create${name}): Promise<${name}> {
|
|
61
72
|
const response = await fetch('/api/${feature}', {
|
|
62
73
|
method: 'POST',
|
|
74
|
+
headers: { 'Content-Type': 'application/json' },
|
|
63
75
|
body: JSON.stringify(data),
|
|
64
76
|
});
|
|
77
|
+
if (!response.ok) throw new Error('Failed to create ${name}');
|
|
65
78
|
return response.json();
|
|
66
79
|
}
|
|
67
80
|
}
|
|
68
81
|
`;
|
|
69
82
|
case 'Update':
|
|
70
|
-
return `
|
|
71
|
-
|
|
83
|
+
return `import { ${name} } from '${typePath}';
|
|
84
|
+
import { Update${name} } from '${schemaPath('Update')}';
|
|
85
|
+
|
|
86
|
+
export class Update${name}Repository {
|
|
87
|
+
async handle(id: string, data: Update${name}): Promise<${name}> {
|
|
72
88
|
const response = await fetch(\`/api/${feature}/\${id}\`, {
|
|
73
89
|
method: 'PUT',
|
|
90
|
+
headers: { 'Content-Type': 'application/json' },
|
|
74
91
|
body: JSON.stringify(data),
|
|
75
92
|
});
|
|
93
|
+
if (!response.ok) throw new Error('Failed to update ${name}');
|
|
76
94
|
return response.json();
|
|
77
95
|
}
|
|
78
96
|
}
|
|
79
97
|
`;
|
|
80
98
|
case 'Delete':
|
|
81
99
|
return `export class Delete${name}Repository {
|
|
82
|
-
async handle(id: string) {
|
|
100
|
+
async handle(id: string): Promise<void> {
|
|
83
101
|
const response = await fetch(\`/api/${feature}/\${id}\`, {
|
|
84
102
|
method: 'DELETE',
|
|
85
103
|
});
|
|
86
|
-
|
|
104
|
+
if (!response.ok) throw new Error('Failed to delete ${name}');
|
|
87
105
|
}
|
|
88
106
|
}
|
|
89
107
|
`;
|
|
90
108
|
}
|
|
91
109
|
}
|
|
92
110
|
function makeRepository(feature, name) {
|
|
93
|
-
const base =
|
|
94
|
-
if (!fs.existsSync(base)) {
|
|
95
|
-
console.error(`❌ Feature "${feature}" does not exist. Run make:feature ${feature} first.`);
|
|
96
|
-
process.exit(1);
|
|
97
|
-
}
|
|
111
|
+
const base = (0, utils_1.ensureFeatureExists)(feature, 'repositories');
|
|
98
112
|
for (const action of REPOSITORY_ACTIONS) {
|
|
99
113
|
const filePath = path.join(base, `${action}${name}.repository.ts`);
|
|
100
|
-
if (
|
|
114
|
+
if ((0, utils_1.fileExists)(filePath)) {
|
|
101
115
|
console.warn(`⚠️ Skipping "${action}${name}.repository.ts" — already exists`);
|
|
102
116
|
continue;
|
|
103
117
|
}
|
|
104
|
-
|
|
118
|
+
(0, utils_1.writeFileSafe)(filePath, renderRepository(action, name, feature));
|
|
105
119
|
}
|
|
106
120
|
console.log(`✅ Repositories for "${name}" created at ${base}`);
|
|
107
121
|
}
|
package/dist/commands/schema.js
CHANGED
|
@@ -34,8 +34,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.makeSchema = makeSchema;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
37
|
const path = __importStar(require("path"));
|
|
38
|
+
const utils_1 = require("../utils");
|
|
39
39
|
const SCHEMA_ACTIONS = ['Create', 'Update'];
|
|
40
40
|
function renderSchema(action, name) {
|
|
41
41
|
switch (action) {
|
|
@@ -61,18 +61,14 @@ export type Update${name} = z.infer<typeof Update${name}Schema>;
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
function makeSchema(feature, name) {
|
|
64
|
-
const base =
|
|
65
|
-
if (!fs.existsSync(base)) {
|
|
66
|
-
console.error(`❌ Feature "${feature}" does not exist. Run make:feature ${feature} first.`);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
64
|
+
const base = (0, utils_1.ensureFeatureExists)(feature, 'schemas');
|
|
69
65
|
for (const action of SCHEMA_ACTIONS) {
|
|
70
66
|
const filePath = path.join(base, `${action}${name}.schema.ts`);
|
|
71
|
-
if (
|
|
67
|
+
if ((0, utils_1.fileExists)(filePath)) {
|
|
72
68
|
console.warn(`⚠️ Skipping "${action}${name}.schema.ts" — already exists`);
|
|
73
69
|
continue;
|
|
74
70
|
}
|
|
75
|
-
|
|
71
|
+
(0, utils_1.writeFileSafe)(filePath, renderSchema(action, name));
|
|
76
72
|
}
|
|
77
73
|
console.log(`✅ Schemas for "${name}" created at ${base}`);
|
|
78
74
|
}
|
package/dist/commands/service.js
CHANGED
|
@@ -34,61 +34,86 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.makeService = makeService;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
37
|
const path = __importStar(require("path"));
|
|
38
|
+
const utils_1 = require("../utils");
|
|
39
39
|
const SERVICE_ACTIONS = ['List', 'Create', 'Update', 'Delete', 'Show'];
|
|
40
|
-
function renderService(action, name) {
|
|
40
|
+
function renderService(action, name, feature) {
|
|
41
|
+
const typePath = (0, utils_1.resolveImport)(feature, `types/${name}.types`);
|
|
42
|
+
const repoPath = (op) => (0, utils_1.resolveImport)(feature, `repositories/${op}${name}.repository`);
|
|
43
|
+
const schemaPath = (op) => (0, utils_1.resolveImport)(feature, `schemas/${op}${name}.schema`);
|
|
41
44
|
switch (action) {
|
|
42
45
|
case 'List':
|
|
43
|
-
return `
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
return `import { ${name} } from '${typePath}';
|
|
47
|
+
import { List${name}Repository } from '${repoPath('List')}';
|
|
48
|
+
|
|
49
|
+
const repository = new List${name}Repository();
|
|
50
|
+
|
|
51
|
+
export class List${name}Service {
|
|
52
|
+
async handle(): Promise<${name}[]> {
|
|
53
|
+
return repository.handle();
|
|
46
54
|
}
|
|
47
55
|
}
|
|
48
56
|
`;
|
|
49
57
|
case 'Show':
|
|
50
|
-
return `
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
return `import { ${name} } from '${typePath}';
|
|
59
|
+
import { Show${name}Repository } from '${repoPath('Show')}';
|
|
60
|
+
|
|
61
|
+
const repository = new Show${name}Repository();
|
|
62
|
+
|
|
63
|
+
export class Show${name}Service {
|
|
64
|
+
async handle(id: string): Promise<${name}> {
|
|
65
|
+
return repository.handle(id);
|
|
53
66
|
}
|
|
54
67
|
}
|
|
55
68
|
`;
|
|
56
69
|
case 'Create':
|
|
57
|
-
return `
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
return `import { ${name} } from '${typePath}';
|
|
71
|
+
import { Create${name} } from '${schemaPath('Create')}';
|
|
72
|
+
import { Create${name}Repository } from '${repoPath('Create')}';
|
|
73
|
+
|
|
74
|
+
const repository = new Create${name}Repository();
|
|
75
|
+
|
|
76
|
+
export class Create${name}Service {
|
|
77
|
+
async handle(data: Create${name}): Promise<${name}> {
|
|
78
|
+
return repository.handle(data);
|
|
60
79
|
}
|
|
61
80
|
}
|
|
62
81
|
`;
|
|
63
82
|
case 'Update':
|
|
64
|
-
return `
|
|
65
|
-
|
|
66
|
-
|
|
83
|
+
return `import { ${name} } from '${typePath}';
|
|
84
|
+
import { Update${name} } from '${schemaPath('Update')}';
|
|
85
|
+
import { Update${name}Repository } from '${repoPath('Update')}';
|
|
86
|
+
|
|
87
|
+
const repository = new Update${name}Repository();
|
|
88
|
+
|
|
89
|
+
export class Update${name}Service {
|
|
90
|
+
async handle(id: string, data: Update${name}): Promise<${name}> {
|
|
91
|
+
return repository.handle(id, data);
|
|
67
92
|
}
|
|
68
93
|
}
|
|
69
94
|
`;
|
|
70
95
|
case 'Delete':
|
|
71
|
-
return `
|
|
72
|
-
|
|
73
|
-
|
|
96
|
+
return `import { Delete${name}Repository } from '${repoPath('Delete')}';
|
|
97
|
+
|
|
98
|
+
const repository = new Delete${name}Repository();
|
|
99
|
+
|
|
100
|
+
export class Delete${name}Service {
|
|
101
|
+
async handle(id: string): Promise<void> {
|
|
102
|
+
return repository.handle(id);
|
|
74
103
|
}
|
|
75
104
|
}
|
|
76
105
|
`;
|
|
77
106
|
}
|
|
78
107
|
}
|
|
79
108
|
function makeService(feature, name) {
|
|
80
|
-
const base =
|
|
81
|
-
if (!fs.existsSync(base)) {
|
|
82
|
-
console.error(`❌ Feature "${feature}" does not exist. Run make:feature ${feature} first.`);
|
|
83
|
-
process.exit(1);
|
|
84
|
-
}
|
|
109
|
+
const base = (0, utils_1.ensureFeatureExists)(feature, 'services');
|
|
85
110
|
for (const action of SERVICE_ACTIONS) {
|
|
86
111
|
const filePath = path.join(base, `${action}${name}.service.ts`);
|
|
87
|
-
if (
|
|
112
|
+
if ((0, utils_1.fileExists)(filePath)) {
|
|
88
113
|
console.warn(`⚠️ Skipping "${action}${name}.service.ts" — already exists`);
|
|
89
114
|
continue;
|
|
90
115
|
}
|
|
91
|
-
|
|
116
|
+
(0, utils_1.writeFileSafe)(filePath, renderService(action, name, feature));
|
|
92
117
|
}
|
|
93
118
|
console.log(`✅ Services for "${name}" created at ${base}`);
|
|
94
119
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.makeTypes = makeTypes;
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const utils_1 = require("../utils");
|
|
39
|
+
function renderTypes(name) {
|
|
40
|
+
return `export interface ${name} {
|
|
41
|
+
id: string;
|
|
42
|
+
// add ${name} fields here
|
|
43
|
+
createdAt: string;
|
|
44
|
+
updatedAt: string;
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
function makeTypes(feature, name) {
|
|
49
|
+
const base = (0, utils_1.ensureFeatureExists)(feature, 'types');
|
|
50
|
+
const filePath = path.join(base, `${name}.types.ts`);
|
|
51
|
+
if ((0, utils_1.fileExists)(filePath)) {
|
|
52
|
+
console.warn(`⚠️ Skipping "${name}.types.ts" — already exists`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
(0, utils_1.writeFileSafe)(filePath, renderTypes(name));
|
|
56
|
+
console.log(`✅ Types for "${name}" created at ${filePath}`);
|
|
57
|
+
}
|