domain-driver 0.0.3 → 0.0.5
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/.github/workflows/publish.yml +3 -1
- package/README.md +173 -28
- package/dist/commands/component.js +63 -0
- package/dist/commands/container.js +66 -0
- package/dist/commands/feature.js +30 -6
- package/dist/commands/hook.js +62 -0
- package/dist/commands/repository.js +107 -0
- package/dist/commands/schema.js +78 -0
- package/dist/commands/service.js +94 -0
- package/dist/index.js +60 -9
- package/package.json +1 -1
- package/src/commands/component.ts +36 -0
- package/src/commands/container.ts +36 -0
- package/src/commands/feature.ts +33 -7
- package/src/commands/hook.ts +32 -0
- package/src/commands/repository.ts +81 -0
- package/src/commands/schema.ts +52 -0
- package/src/commands/service.ts +68 -0
- package/src/index.ts +67 -8
|
@@ -0,0 +1,78 @@
|
|
|
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.makeSchema = makeSchema;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const SCHEMA_ACTIONS = ['Create', 'Update'];
|
|
40
|
+
function renderSchema(action, name) {
|
|
41
|
+
switch (action) {
|
|
42
|
+
case 'Create':
|
|
43
|
+
return `import { z } from 'zod';
|
|
44
|
+
|
|
45
|
+
export const Create${name}Schema = z.object({
|
|
46
|
+
// add create fields here
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export type Create${name} = z.infer<typeof Create${name}Schema>;
|
|
50
|
+
`;
|
|
51
|
+
case 'Update':
|
|
52
|
+
return `import { z } from 'zod';
|
|
53
|
+
|
|
54
|
+
export const Update${name}Schema = z.object({
|
|
55
|
+
id: z.string(),
|
|
56
|
+
// add update fields here
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export type Update${name} = z.infer<typeof Update${name}Schema>;
|
|
60
|
+
`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function makeSchema(feature, name) {
|
|
64
|
+
const base = path.join(process.cwd(), 'app', feature, 'schemas');
|
|
65
|
+
if (!fs.existsSync(base)) {
|
|
66
|
+
console.error(`❌ Feature "${feature}" does not exist. Run make:feature ${feature} first.`);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
for (const action of SCHEMA_ACTIONS) {
|
|
70
|
+
const filePath = path.join(base, `${action}${name}.schema.ts`);
|
|
71
|
+
if (fs.existsSync(filePath)) {
|
|
72
|
+
console.warn(`⚠️ Skipping "${action}${name}.schema.ts" — already exists`);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
fs.writeFileSync(filePath, renderSchema(action, name));
|
|
76
|
+
}
|
|
77
|
+
console.log(`✅ Schemas for "${name}" created at ${base}`);
|
|
78
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
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.makeService = makeService;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const SERVICE_ACTIONS = ['List', 'Create', 'Update', 'Delete', 'Show'];
|
|
40
|
+
function renderService(action, name) {
|
|
41
|
+
switch (action) {
|
|
42
|
+
case 'List':
|
|
43
|
+
return `export class List${name}Service {
|
|
44
|
+
async handle() {
|
|
45
|
+
// fetch all ${name}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
case 'Show':
|
|
50
|
+
return `export class Show${name}Service {
|
|
51
|
+
async handle(id: string) {
|
|
52
|
+
// fetch single ${name}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
case 'Create':
|
|
57
|
+
return `export class Create${name}Service {
|
|
58
|
+
async handle(data: unknown) {
|
|
59
|
+
// create ${name}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
case 'Update':
|
|
64
|
+
return `export class Update${name}Service {
|
|
65
|
+
async handle(id: string, data: unknown) {
|
|
66
|
+
// update ${name}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
case 'Delete':
|
|
71
|
+
return `export class Delete${name}Service {
|
|
72
|
+
async handle(id: string) {
|
|
73
|
+
// delete ${name}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function makeService(feature, name) {
|
|
80
|
+
const base = path.join(process.cwd(), 'app', feature, 'services');
|
|
81
|
+
if (!fs.existsSync(base)) {
|
|
82
|
+
console.error(`❌ Feature "${feature}" does not exist. Run make:feature ${feature} first.`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
for (const action of SERVICE_ACTIONS) {
|
|
86
|
+
const filePath = path.join(base, `${action}${name}.service.ts`);
|
|
87
|
+
if (fs.existsSync(filePath)) {
|
|
88
|
+
console.warn(`⚠️ Skipping "${action}${name}.service.ts" — already exists`);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
fs.writeFileSync(filePath, renderService(action, name));
|
|
92
|
+
}
|
|
93
|
+
console.log(`✅ Services for "${name}" created at ${base}`);
|
|
94
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -2,15 +2,66 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const feature_1 = require("./commands/feature");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const component_1 = require("./commands/component");
|
|
6
|
+
const hook_1 = require("./commands/hook");
|
|
7
|
+
const service_1 = require("./commands/service");
|
|
8
|
+
const schema_1 = require("./commands/schema");
|
|
9
|
+
const repository_1 = require("./commands/repository");
|
|
10
|
+
const container_1 = require("./commands/container");
|
|
11
|
+
const [, , command, feature, name] = process.argv;
|
|
12
|
+
if (!command || !feature) {
|
|
13
|
+
console.error('Usage: domain-driver <command> [options]');
|
|
8
14
|
process.exit(1);
|
|
9
15
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
switch (command) {
|
|
17
|
+
case 'make:feature':
|
|
18
|
+
const all = process.argv.includes('-a') || process.argv.includes('-A');
|
|
19
|
+
(0, feature_1.makeFeature)(feature, all).then(() => { });
|
|
20
|
+
break;
|
|
21
|
+
case 'make:component':
|
|
22
|
+
if (!name) {
|
|
23
|
+
console.error('Usage: domain-driver make:component <feature> <name> [client|server]');
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
const type = process.argv[5] || 'client';
|
|
27
|
+
(0, component_1.makeComponent)(feature, name, type);
|
|
28
|
+
break;
|
|
29
|
+
case 'make:hook':
|
|
30
|
+
if (!name) {
|
|
31
|
+
console.error('Usage: domain-driver make:hook <feature> <name>');
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
(0, hook_1.makeHook)(feature, name);
|
|
35
|
+
break;
|
|
36
|
+
case 'make:service':
|
|
37
|
+
if (!name) {
|
|
38
|
+
console.error('Usage: domain-driver make:service <feature> <name>');
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
(0, service_1.makeService)(feature, name);
|
|
42
|
+
break;
|
|
43
|
+
case 'make:schema':
|
|
44
|
+
if (!name) {
|
|
45
|
+
console.error('Usage: domain-driver make:schema <feature> <name>');
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
(0, schema_1.makeSchema)(feature, name);
|
|
49
|
+
break;
|
|
50
|
+
case 'make:repository':
|
|
51
|
+
if (!name) {
|
|
52
|
+
console.error('Usage: domain-driver make:repository <feature> <name>');
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
(0, repository_1.makeRepository)(feature, name);
|
|
56
|
+
break;
|
|
57
|
+
case 'make:container':
|
|
58
|
+
if (!name) {
|
|
59
|
+
console.error('Usage: domain-driver make:container <feature> <name>');
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
(0, container_1.makeContainer)(feature, name);
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
console.error(`Unknown command: ${command}`);
|
|
66
|
+
process.exit(1);
|
|
16
67
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
type ComponentType = 'client' | 'server';
|
|
5
|
+
|
|
6
|
+
function renderComponent(name: string, type: ComponentType): string {
|
|
7
|
+
const directive = type === 'client' ? "'use client';\n\n" : '';
|
|
8
|
+
|
|
9
|
+
return `${directive}export default function ${name}() {
|
|
10
|
+
return (
|
|
11
|
+
<div>
|
|
12
|
+
<h1>${name}</h1>
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function makeComponent(feature: string, name: string, type: ComponentType = 'client') {
|
|
20
|
+
const base = path.join(process.cwd(), 'app', feature, 'components', type);
|
|
21
|
+
|
|
22
|
+
if (!fs.existsSync(base)) {
|
|
23
|
+
console.error(`❌ Feature "${feature}" does not exist. Run make:feature ${feature} first.`);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const filePath = path.join(base, `${name}.tsx`);
|
|
28
|
+
|
|
29
|
+
if (fs.existsSync(filePath)) {
|
|
30
|
+
console.error(`❌ Component "${name}" already exists at ${filePath}`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fs.writeFileSync(filePath, renderComponent(name, type));
|
|
35
|
+
console.log(`✅ Component "${name}" created at ${filePath}`);
|
|
36
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
function renderContainer(name: string): string {
|
|
5
|
+
return `'use client';
|
|
6
|
+
|
|
7
|
+
interface Props {}
|
|
8
|
+
|
|
9
|
+
export default function ${name}({ }: Props) {
|
|
10
|
+
return (
|
|
11
|
+
<div>
|
|
12
|
+
<h1>${name}</h1>
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function makeContainer(feature: string, name: string) {
|
|
20
|
+
const base = path.join(process.cwd(), 'app', feature, 'containers');
|
|
21
|
+
|
|
22
|
+
if (!fs.existsSync(base)) {
|
|
23
|
+
console.error(`❌ Feature "${feature}" does not exist. Run make:feature ${feature} first.`);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const filePath = path.join(base, `${name}.tsx`);
|
|
28
|
+
|
|
29
|
+
if (fs.existsSync(filePath)) {
|
|
30
|
+
console.error(`❌ Container "${name}" already exists at ${filePath}`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fs.writeFileSync(filePath, renderContainer(name));
|
|
35
|
+
console.log(`✅ Container "${name}" created at ${filePath}`);
|
|
36
|
+
}
|
package/src/commands/feature.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
+
import { makeComponent } from './component';
|
|
4
|
+
import { makeHook } from './hook';
|
|
5
|
+
import { makeService } from './service';
|
|
6
|
+
import { makeRepository } from './repository';
|
|
7
|
+
import { makeSchema } from './schema';
|
|
8
|
+
import { makeContainer } from './container';
|
|
3
9
|
|
|
4
10
|
const FEATURE_DIRS = [
|
|
5
11
|
'components/server',
|
|
@@ -11,12 +17,15 @@ const FEATURE_DIRS = [
|
|
|
11
17
|
'schemas',
|
|
12
18
|
];
|
|
13
19
|
|
|
14
|
-
function
|
|
15
|
-
|
|
20
|
+
function toPascalCase(name: string): string {
|
|
21
|
+
return name
|
|
16
22
|
.split('-')
|
|
17
23
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
18
24
|
.join('');
|
|
25
|
+
}
|
|
19
26
|
|
|
27
|
+
function renderPage(name: string): string {
|
|
28
|
+
const componentName = toPascalCase(name);
|
|
20
29
|
return `export default function ${componentName}Page() {
|
|
21
30
|
return (
|
|
22
31
|
<div>
|
|
@@ -27,16 +36,33 @@ function renderTemplate(name: string): string {
|
|
|
27
36
|
`;
|
|
28
37
|
}
|
|
29
38
|
|
|
30
|
-
export async function makeFeature(name: string) {
|
|
39
|
+
export async function makeFeature(name: string, all: boolean = false) {
|
|
31
40
|
const base = path.join(process.cwd(), 'app', name);
|
|
41
|
+
const pascalName = toPascalCase(name);
|
|
42
|
+
|
|
43
|
+
if (fs.existsSync(base)) {
|
|
44
|
+
console.error(`❌ Feature "${name}" already exists at ${base}`);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
32
47
|
|
|
33
48
|
for (const dir of FEATURE_DIRS) {
|
|
34
49
|
fs.mkdirSync(path.join(base, dir), { recursive: true });
|
|
35
|
-
|
|
50
|
+
if (!all) {
|
|
51
|
+
fs.writeFileSync(path.join(base, dir, '.gitkeep'), '');
|
|
52
|
+
}
|
|
36
53
|
}
|
|
37
54
|
|
|
38
|
-
|
|
39
|
-
fs.writeFileSync(path.join(base, 'page.tsx'), page);
|
|
40
|
-
|
|
55
|
+
fs.writeFileSync(path.join(base, 'page.tsx'), renderPage(name));
|
|
41
56
|
console.log(`✅ Feature "${name}" scaffolded at ${base}`);
|
|
57
|
+
|
|
58
|
+
if (all) {
|
|
59
|
+
makeComponent(name, pascalName, 'client');
|
|
60
|
+
makeContainer(name, `${pascalName}Container`);
|
|
61
|
+
makeHook(name, `use${pascalName}`);
|
|
62
|
+
makeService(name, pascalName);
|
|
63
|
+
makeRepository(name, `${pascalName}Repository`);
|
|
64
|
+
makeSchema(name, `${pascalName}Schema`);
|
|
65
|
+
|
|
66
|
+
console.log(`✅ All files scaffolded for "${name}"`);
|
|
67
|
+
}
|
|
42
68
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
function renderHook(name: string): string {
|
|
5
|
+
return `import { useState } from 'react';
|
|
6
|
+
|
|
7
|
+
export function ${name}() {
|
|
8
|
+
const [data, setData] = useState(null);
|
|
9
|
+
|
|
10
|
+
return { data };
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function makeHook(feature: string, name: string) {
|
|
16
|
+
const base = path.join(process.cwd(), 'app', feature, 'hooks');
|
|
17
|
+
|
|
18
|
+
if (!fs.existsSync(base)) {
|
|
19
|
+
console.error(`❌ Feature "${feature}" does not exist. Run make:feature ${feature} first.`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const filePath = path.join(base, `${name}.ts`);
|
|
24
|
+
|
|
25
|
+
if (fs.existsSync(filePath)) {
|
|
26
|
+
console.error(`❌ Hook "${name}" already exists at ${filePath}`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fs.writeFileSync(filePath, renderHook(name));
|
|
31
|
+
console.log(`✅ Hook "${name}" created at ${filePath}`);
|
|
32
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
type RepositoryAction = 'List' | 'Create' | 'Update' | 'Delete' | 'Show';
|
|
5
|
+
|
|
6
|
+
const REPOSITORY_ACTIONS: RepositoryAction[] = ['List', 'Create', 'Update', 'Delete', 'Show'];
|
|
7
|
+
|
|
8
|
+
function renderRepository(action: RepositoryAction, name: string, feature: string): string {
|
|
9
|
+
switch (action) {
|
|
10
|
+
case 'List':
|
|
11
|
+
return `export class List${name}Repository {
|
|
12
|
+
async handle() {
|
|
13
|
+
const response = await fetch('/api/${feature}');
|
|
14
|
+
return response.json();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
case 'Show':
|
|
19
|
+
return `export class Show${name}Repository {
|
|
20
|
+
async handle(id: string) {
|
|
21
|
+
const response = await fetch(\`/api/${feature}/\${id}\`);
|
|
22
|
+
return response.json();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
case 'Create':
|
|
27
|
+
return `export class Create${name}Repository {
|
|
28
|
+
async handle(data: unknown) {
|
|
29
|
+
const response = await fetch('/api/${feature}', {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
body: JSON.stringify(data),
|
|
32
|
+
});
|
|
33
|
+
return response.json();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
case 'Update':
|
|
38
|
+
return `export class Update${name}Repository {
|
|
39
|
+
async handle(id: string, data: unknown) {
|
|
40
|
+
const response = await fetch(\`/api/${feature}/\${id}\`, {
|
|
41
|
+
method: 'PUT',
|
|
42
|
+
body: JSON.stringify(data),
|
|
43
|
+
});
|
|
44
|
+
return response.json();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
case 'Delete':
|
|
49
|
+
return `export class Delete${name}Repository {
|
|
50
|
+
async handle(id: string) {
|
|
51
|
+
const response = await fetch(\`/api/${feature}/\${id}\`, {
|
|
52
|
+
method: 'DELETE',
|
|
53
|
+
});
|
|
54
|
+
return response.json();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function makeRepository(feature: string, name: string) {
|
|
62
|
+
const base = path.join(process.cwd(), 'app', feature, 'repositories');
|
|
63
|
+
|
|
64
|
+
if (!fs.existsSync(base)) {
|
|
65
|
+
console.error(`❌ Feature "${feature}" does not exist. Run make:feature ${feature} first.`);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
for (const action of REPOSITORY_ACTIONS) {
|
|
70
|
+
const filePath = path.join(base, `${action}${name}.repository.ts`);
|
|
71
|
+
|
|
72
|
+
if (fs.existsSync(filePath)) {
|
|
73
|
+
console.warn(`⚠️ Skipping "${action}${name}.repository.ts" — already exists`);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fs.writeFileSync(filePath, renderRepository(action, name, feature));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
console.log(`✅ Repositories for "${name}" created at ${base}`);
|
|
81
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
type SchemaAction = 'Create' | 'Update';
|
|
5
|
+
|
|
6
|
+
const SCHEMA_ACTIONS: SchemaAction[] = ['Create', 'Update'];
|
|
7
|
+
|
|
8
|
+
function renderSchema(action: SchemaAction, name: string): string {
|
|
9
|
+
switch (action) {
|
|
10
|
+
case 'Create':
|
|
11
|
+
return `import { z } from 'zod';
|
|
12
|
+
|
|
13
|
+
export const Create${name}Schema = z.object({
|
|
14
|
+
// add create fields here
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export type Create${name} = z.infer<typeof Create${name}Schema>;
|
|
18
|
+
`;
|
|
19
|
+
case 'Update':
|
|
20
|
+
return `import { z } from 'zod';
|
|
21
|
+
|
|
22
|
+
export const Update${name}Schema = z.object({
|
|
23
|
+
id: z.string(),
|
|
24
|
+
// add update fields here
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export type Update${name} = z.infer<typeof Update${name}Schema>;
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function makeSchema(feature: string, name: string) {
|
|
33
|
+
const base = path.join(process.cwd(), 'app', feature, 'schemas');
|
|
34
|
+
|
|
35
|
+
if (!fs.existsSync(base)) {
|
|
36
|
+
console.error(`❌ Feature "${feature}" does not exist. Run make:feature ${feature} first.`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for (const action of SCHEMA_ACTIONS) {
|
|
41
|
+
const filePath = path.join(base, `${action}${name}.schema.ts`);
|
|
42
|
+
|
|
43
|
+
if (fs.existsSync(filePath)) {
|
|
44
|
+
console.warn(`⚠️ Skipping "${action}${name}.schema.ts" — already exists`);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fs.writeFileSync(filePath, renderSchema(action, name));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
console.log(`✅ Schemas for "${name}" created at ${base}`);
|
|
52
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
type ServiceAction = 'List' | 'Create' | 'Update' | 'Delete' | 'Show';
|
|
5
|
+
|
|
6
|
+
const SERVICE_ACTIONS: ServiceAction[] = ['List', 'Create', 'Update', 'Delete', 'Show'];
|
|
7
|
+
|
|
8
|
+
function renderService(action: ServiceAction, name: string): string {
|
|
9
|
+
switch (action) {
|
|
10
|
+
case 'List':
|
|
11
|
+
return `export class List${name}Service {
|
|
12
|
+
async handle() {
|
|
13
|
+
// fetch all ${name}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
case 'Show':
|
|
18
|
+
return `export class Show${name}Service {
|
|
19
|
+
async handle(id: string) {
|
|
20
|
+
// fetch single ${name}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
case 'Create':
|
|
25
|
+
return `export class Create${name}Service {
|
|
26
|
+
async handle(data: unknown) {
|
|
27
|
+
// create ${name}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
case 'Update':
|
|
32
|
+
return `export class Update${name}Service {
|
|
33
|
+
async handle(id: string, data: unknown) {
|
|
34
|
+
// update ${name}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
case 'Delete':
|
|
39
|
+
return `export class Delete${name}Service {
|
|
40
|
+
async handle(id: string) {
|
|
41
|
+
// delete ${name}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function makeService(feature: string, name: string) {
|
|
49
|
+
const base = path.join(process.cwd(), 'app', feature, 'services');
|
|
50
|
+
|
|
51
|
+
if (!fs.existsSync(base)) {
|
|
52
|
+
console.error(`❌ Feature "${feature}" does not exist. Run make:feature ${feature} first.`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
for (const action of SERVICE_ACTIONS) {
|
|
57
|
+
const filePath = path.join(base, `${action}${name}.service.ts`);
|
|
58
|
+
|
|
59
|
+
if (fs.existsSync(filePath)) {
|
|
60
|
+
console.warn(`⚠️ Skipping "${action}${name}.service.ts" — already exists`);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fs.writeFileSync(filePath, renderService(action, name));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log(`✅ Services for "${name}" created at ${base}`);
|
|
68
|
+
}
|