@diagramers/cli 1.1.6 → 1.1.7
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/README.md +42 -4
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +12 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +4 -0
- package/dist/commands/update.js.map +1 -1
- package/dist/index.js +86 -36
- package/dist/index.js.map +1 -1
- package/dist/services/api-generator.js +139 -47
- package/dist/services/api-generator.js.map +1 -1
- package/dist/services/project-extender.d.ts.map +1 -1
- package/dist/services/project-extender.js +3 -31
- package/dist/services/project-extender.js.map +1 -1
- package/dist/services/project-initializer.d.ts +1 -0
- package/dist/services/project-initializer.d.ts.map +1 -1
- package/dist/services/project-initializer.js +4 -3
- package/dist/services/project-initializer.js.map +1 -1
- package/dist/services/project-updater.d.ts +3 -0
- package/dist/services/project-updater.d.ts.map +1 -1
- package/dist/services/project-updater.js +171 -28
- package/dist/services/project-updater.js.map +1 -1
- package/dist/services/template-processor.d.ts.map +1 -1
- package/dist/services/template-processor.js +23 -2
- package/dist/services/template-processor.js.map +1 -1
- package/dist/services/template-updater.d.ts +1 -0
- package/dist/services/template-updater.d.ts.map +1 -1
- package/dist/services/template-updater.js +7 -4
- package/dist/services/template-updater.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -64,16 +64,24 @@ npm start
|
|
64
64
|
|
65
65
|
#### Initialize New Project
|
66
66
|
```bash
|
67
|
-
diagramers init <template-type> <project-name>
|
67
|
+
diagramers init <template-type> <project-name> [options]
|
68
68
|
```
|
69
69
|
|
70
|
+
**Options:**
|
71
|
+
- `-v, --version <version>` - Specific version of the template to use (e.g., 1.1.17, latest)
|
72
|
+
- `-t, --template <template>` - Template version to use (deprecated, use --version)
|
73
|
+
- `-y, --yes` - Skip prompts and use defaults
|
74
|
+
|
70
75
|
**Examples:**
|
71
76
|
```bash
|
72
|
-
# Create API project
|
77
|
+
# Create API project with latest version
|
73
78
|
diagramers init api my-api-project
|
74
79
|
|
75
|
-
# Create
|
76
|
-
diagramers init
|
80
|
+
# Create API project with specific version
|
81
|
+
diagramers init api my-api-project -v 1.1.17
|
82
|
+
|
83
|
+
# Create admin project with specific version
|
84
|
+
diagramers init admin my-admin-dashboard -v 1.1.16
|
77
85
|
```
|
78
86
|
|
79
87
|
#### Update Project
|
@@ -82,9 +90,39 @@ diagramers update [options]
|
|
82
90
|
```
|
83
91
|
|
84
92
|
**Options:**
|
93
|
+
- `-v, --version <version>` - Specific version to update to (e.g., 1.1.17, latest)
|
85
94
|
- `--force` - Force update even if conflicts detected
|
86
95
|
- `--backup` - Create backup before updating
|
87
96
|
|
97
|
+
**Examples:**
|
98
|
+
```bash
|
99
|
+
# Update to latest version
|
100
|
+
diagramers update
|
101
|
+
|
102
|
+
# Update to specific version
|
103
|
+
diagramers update -v 1.1.17
|
104
|
+
|
105
|
+
# Force update with backup
|
106
|
+
diagramers update -v 1.1.17 --force --backup
|
107
|
+
```
|
108
|
+
|
109
|
+
#### List Available Versions
|
110
|
+
```bash
|
111
|
+
diagramers versions [options]
|
112
|
+
```
|
113
|
+
|
114
|
+
**Options:**
|
115
|
+
- `-a, --all` - Show all versions (default: show last 10)
|
116
|
+
|
117
|
+
**Examples:**
|
118
|
+
```bash
|
119
|
+
# Show last 10 versions
|
120
|
+
diagramers versions
|
121
|
+
|
122
|
+
# Show all available versions
|
123
|
+
diagramers versions --all
|
124
|
+
```
|
125
|
+
|
88
126
|
### Module Management
|
89
127
|
|
90
128
|
#### Generate Module
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,QAuC3C"}
|
package/dist/commands/init.js
CHANGED
@@ -10,7 +10,8 @@ function initCommand(program) {
|
|
10
10
|
program
|
11
11
|
.command('init <template-type> <project-name>')
|
12
12
|
.description('Initialize a new project from the template')
|
13
|
-
.option('-
|
13
|
+
.option('-v, --version <version>', 'Specific version of the template to use (e.g., 1.1.17, latest)', 'latest')
|
14
|
+
.option('-t, --template <template>', 'Template version to use (deprecated, use --version)', 'latest')
|
14
15
|
.option('-y, --yes', 'Skip prompts and use defaults')
|
15
16
|
.action(async (templateType, projectName, options) => {
|
16
17
|
try {
|
@@ -19,8 +20,17 @@ function initCommand(program) {
|
|
19
20
|
if (templateType !== 'api' && templateType !== 'admin') {
|
20
21
|
throw new Error(`Unsupported template type: ${templateType}. Supported types: api, admin`);
|
21
22
|
}
|
23
|
+
// Use --version option, fallback to --template for backwards compatibility
|
24
|
+
const targetVersion = options.version || options.template;
|
25
|
+
if (targetVersion && targetVersion !== 'latest') {
|
26
|
+
console.log(chalk_1.default.yellow(`📌 Using @diagramers/${templateType} version: ${targetVersion}`));
|
27
|
+
}
|
22
28
|
const initializer = new project_initializer_1.ProjectInitializer();
|
23
|
-
await initializer.initialize(projectName, {
|
29
|
+
await initializer.initialize(projectName, {
|
30
|
+
...options,
|
31
|
+
template: templateType,
|
32
|
+
version: targetVersion
|
33
|
+
});
|
24
34
|
console.log(chalk_1.default.green(`✅ Project ${projectName} initialized successfully!`));
|
25
35
|
console.log(chalk_1.default.yellow(`📁 Navigate to the project: cd ${projectName}`));
|
26
36
|
console.log(chalk_1.default.yellow(`🔧 Install dependencies: npm install`));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":";;;;;AAIA,
|
1
|
+
{"version":3,"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AAK,CAAC,aAAa,WAAW,4BAA4B,CAAC,CAAC,CAAC;YAC/E,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,kCAAkC,WAAW,EAAE,CAAC,CAAC,CAAC;YAC3E,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,sCAAsC,CAAC,CAAC,CAAC;YAClE,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,iCAAiC,CAAC,CAAC,CAAC;QAC/D,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,mCAAmC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC7E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../src/commands/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../src/commands/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,QAyB7C"}
|
package/dist/commands/update.js
CHANGED
@@ -10,11 +10,15 @@ function updateCommand(program) {
|
|
10
10
|
program
|
11
11
|
.command('update')
|
12
12
|
.description('Update existing project with latest template features')
|
13
|
+
.option('-v, --version <version>', 'Specific version to update to (e.g., 1.1.17, latest)', 'latest')
|
13
14
|
.option('-f, --force', 'Force update even if conflicts detected')
|
14
15
|
.option('-b, --backup', 'Create backup before updating')
|
15
16
|
.action(async (options) => {
|
16
17
|
try {
|
17
18
|
console.log(chalk_1.default.blue('🔄 Checking for template updates...'));
|
19
|
+
if (options.version && options.version !== 'latest') {
|
20
|
+
console.log(chalk_1.default.yellow(`📌 Updating to version: ${options.version}`));
|
21
|
+
}
|
18
22
|
const updater = new template_updater_1.TemplateUpdater();
|
19
23
|
await updater.update(options);
|
20
24
|
console.log(chalk_1.default.green('✅ Project updated successfully!'));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/commands/update.ts"],"names":[],"mappings":";;;;;AAIA,
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/commands/update.ts"],"names":[],"mappings":";;;;;AAIA,sCAyBC;AA5BD,mEAA+D;AAC/D,kDAA0B;AAE1B,SAAgB,aAAa,CAAC,OAAgB;IAC5C,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,uDAAuD,CAAC;SACpE,MAAM,CAAC,yBAAyB,EAAE,sDAAsD,EAAE,QAAQ,CAAC;SACnG,MAAM,CAAC,aAAa,EAAE,yCAAyC,CAAC;SAChE,MAAM,CAAC,cAAc,EAAE,+BAA+B,CAAC;SACvD,MAAM,CAAC,KAAK,EAAE,OAAY,EAAE,EAAE;QAC7B,IAAI,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC,CAAC;YAE/D,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;gBACpD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,2BAA2B,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC1E,CAAC;YAED,MAAM,OAAO,GAAG,IAAI,kCAAe,EAAE,CAAC;YACtC,MAAM,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAE9B,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC,CAAC;YAC5D,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,iDAAiD,CAAC,CAAC,CAAC;QAC/E,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,+BAA+B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACzE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/dist/index.js
CHANGED
@@ -11,6 +11,7 @@ const extend_1 = require("./commands/extend");
|
|
11
11
|
const chalk_1 = __importDefault(require("chalk"));
|
12
12
|
const fs_1 = require("fs");
|
13
13
|
const path_1 = require("path");
|
14
|
+
const child_process_1 = require("child_process");
|
14
15
|
const program = new commander_1.Command();
|
15
16
|
// Dynamically read CLI version
|
16
17
|
const cliPkg = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '..', 'package.json'), 'utf8'));
|
@@ -53,8 +54,7 @@ function getApiVersion() {
|
|
53
54
|
catch { }
|
54
55
|
// Try to check if it's available via npm (last resort)
|
55
56
|
try {
|
56
|
-
const
|
57
|
-
const npmVersion = execSync('npm view @diagramers/api version', { encoding: 'utf8', timeout: 5000 }).trim();
|
57
|
+
const npmVersion = (0, child_process_1.execSync)('npm view @diagramers/api version', { encoding: 'utf8', timeout: 5000 }).trim();
|
58
58
|
return `${npmVersion} (available on npm)`;
|
59
59
|
}
|
60
60
|
catch { }
|
@@ -82,46 +82,96 @@ program
|
|
82
82
|
}
|
83
83
|
catch { }
|
84
84
|
});
|
85
|
+
// Add commands
|
85
86
|
(0, init_1.initCommand)(program);
|
86
87
|
(0, update_1.updateCommand)(program);
|
87
88
|
(0, extend_1.extendCommand)(program);
|
89
|
+
// Add versions command
|
90
|
+
program
|
91
|
+
.command('versions')
|
92
|
+
.description('List available versions of @diagramers/api')
|
93
|
+
.option('-a, --all', 'Show all versions (default: show last 10)')
|
94
|
+
.action(async (options) => {
|
95
|
+
try {
|
96
|
+
console.log(chalk_1.default.blue('📦 Fetching available versions of @diagramers/api...'));
|
97
|
+
const versionsOutput = (0, child_process_1.execSync)('npm view @diagramers/api versions --json', {
|
98
|
+
encoding: 'utf8',
|
99
|
+
timeout: 10000
|
100
|
+
});
|
101
|
+
const versions = JSON.parse(versionsOutput);
|
102
|
+
console.log(chalk_1.default.green('\n✅ Available versions:'));
|
103
|
+
if (Array.isArray(versions)) {
|
104
|
+
const displayVersions = options.all ? versions : versions.slice(-10);
|
105
|
+
displayVersions.forEach((version) => {
|
106
|
+
console.log(chalk_1.default.yellow(` ${version}`));
|
107
|
+
});
|
108
|
+
if (!options.all && versions.length > 10) {
|
109
|
+
console.log(chalk_1.default.gray(`\n ... and ${versions.length - 10} more versions`));
|
110
|
+
console.log(chalk_1.default.gray(' Use --all to see all versions'));
|
111
|
+
}
|
112
|
+
}
|
113
|
+
else {
|
114
|
+
console.log(chalk_1.default.yellow(` ${versions}`));
|
115
|
+
}
|
116
|
+
// Show current version
|
117
|
+
try {
|
118
|
+
const currentVersion = (0, child_process_1.execSync)('npm view @diagramers/api version', {
|
119
|
+
encoding: 'utf8',
|
120
|
+
timeout: 5000
|
121
|
+
}).trim();
|
122
|
+
console.log(chalk_1.default.green(`\n📌 Latest version: ${currentVersion}`));
|
123
|
+
}
|
124
|
+
catch (error) {
|
125
|
+
// Ignore if we can't get current version
|
126
|
+
}
|
127
|
+
console.log(chalk_1.default.blue('\n📝 Usage examples:'));
|
128
|
+
console.log(chalk_1.default.gray(' diagramers init api my-project --version 1.1.17'));
|
129
|
+
console.log(chalk_1.default.gray(' diagramers update --version 1.1.17'));
|
130
|
+
}
|
131
|
+
catch (error) {
|
132
|
+
console.error(chalk_1.default.red(`❌ Failed to fetch versions: ${error.message}`));
|
133
|
+
console.log(chalk_1.default.yellow('💡 Make sure you have internet connection and npm is installed'));
|
134
|
+
// Fallback: try to get just the latest version
|
135
|
+
try {
|
136
|
+
console.log(chalk_1.default.blue('\n🔄 Trying to get latest version...'));
|
137
|
+
const latestVersion = (0, child_process_1.execSync)('npm view @diagramers/api version', {
|
138
|
+
encoding: 'utf8',
|
139
|
+
timeout: 5000
|
140
|
+
}).trim();
|
141
|
+
console.log(chalk_1.default.green(`✅ Latest version: ${latestVersion}`));
|
142
|
+
}
|
143
|
+
catch (fallbackError) {
|
144
|
+
console.log(chalk_1.default.red('❌ Could not fetch any version information'));
|
145
|
+
}
|
146
|
+
process.exit(1);
|
147
|
+
}
|
148
|
+
});
|
88
149
|
program.addHelpText('after', `
|
89
150
|
${chalk_1.default.bold('Examples:')}
|
151
|
+
${chalk_1.default.gray('# Initialize new API project')}
|
152
|
+
${chalk_1.default.blue('diagramers init api my-new-api')}
|
153
|
+
|
154
|
+
${chalk_1.default.gray('# Initialize with specific version')}
|
155
|
+
${chalk_1.default.blue('diagramers init api my-new-api --version 1.1.17')}
|
156
|
+
|
157
|
+
${chalk_1.default.gray('# Update project to latest version')}
|
158
|
+
${chalk_1.default.blue('diagramers update')}
|
159
|
+
|
160
|
+
${chalk_1.default.gray('# Update to specific version')}
|
161
|
+
${chalk_1.default.blue('diagramers update --version 1.1.17')}
|
162
|
+
|
163
|
+
${chalk_1.default.gray('# Generate new module')}
|
164
|
+
${chalk_1.default.blue('diagramers extend --module products --crud')}
|
165
|
+
|
166
|
+
${chalk_1.default.gray('# Add endpoint to existing module')}
|
167
|
+
${chalk_1.default.blue('diagramers extend --endpoint users:search --method GET')}
|
168
|
+
|
169
|
+
${chalk_1.default.gray('# List available versions')}
|
170
|
+
${chalk_1.default.blue('diagramers versions')}
|
90
171
|
|
91
|
-
${chalk_1.default.
|
92
|
-
$
|
93
|
-
$
|
94
|
-
$ diagramers update # Update project templates
|
95
|
-
|
96
|
-
${chalk_1.default.cyan('Module Management:')}
|
97
|
-
$ diagramers extend --module products --crud # Generate module with CRUD
|
98
|
-
$ diagramers extend --module users --fields email,username,role
|
99
|
-
|
100
|
-
${chalk_1.default.cyan('Table Management:')}
|
101
|
-
$ diagramers extend --table products:categories --fields name,description,slug
|
102
|
-
$ diagramers extend --table users:profiles --fields bio,avatar,birth_date
|
103
|
-
|
104
|
-
${chalk_1.default.cyan('Endpoint Management:')}
|
105
|
-
$ diagramers extend --endpoint products:search --method GET
|
106
|
-
$ diagramers extend --endpoint users:reset-password --method POST
|
107
|
-
|
108
|
-
${chalk_1.default.cyan('Relation Management:')}
|
109
|
-
$ diagramers extend --relation products:category-product
|
110
|
-
$ diagramers extend --relation users:user-profile:one-to-one
|
111
|
-
$ diagramers extend --relation products:product-tag:many-to-many
|
112
|
-
|
113
|
-
${chalk_1.default.cyan('Other Commands:')}
|
114
|
-
$ diagramers extend --list # List available features
|
115
|
-
$ diagramers extend --feature auth # Add authentication feature
|
116
|
-
|
117
|
-
${chalk_1.default.bold('Workflow Example:')}
|
118
|
-
$ diagramers init api ecommerce-api # 1. Create project
|
119
|
-
$ cd ecommerce-api # 2. Navigate to project
|
120
|
-
$ diagramers extend --module products --crud # 3. Generate module
|
121
|
-
$ diagramers extend --table products:categories --fields name,description
|
122
|
-
$ diagramers extend --table products:products --fields name,price,category_id
|
123
|
-
$ diagramers extend --relation products:category-product
|
124
|
-
$ npm install && npm start # 4. Install & start
|
172
|
+
${chalk_1.default.bold('Version Information:')}
|
173
|
+
CLI: ${chalk_1.default.green(cliPkg.version)}
|
174
|
+
API: ${chalk_1.default.green(getApiVersion())}
|
125
175
|
`);
|
126
176
|
// If no command is provided, show help
|
127
177
|
if (!process.argv.slice(2).length) {
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AACpC,0CAA8C;AAC9C,8CAAkD;AAClD,8CAAkD;AAClD,kDAA0B;AAC1B,2BAA8C;AAC9C,+BAA4B;
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],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,CAAC,aAAa,EAAE,CAAC;CACpC,CAAC,CAAC;AAEH,uCAAuC;AACvC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClC,OAAO,CAAC,UAAU,EAAE,CAAC;AACvB,CAAC;AAED,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
@@ -512,7 +512,8 @@ async function generateEndpoint(moduleName, endpointName, options = {}) {
|
|
512
512
|
console.log(`🔗 New endpoint available at: ${method} /api/${moduleName}/${customPath}`);
|
513
513
|
}
|
514
514
|
async function addServiceMethod(modulePath, moduleName, moduleNameCapitalized, endpointName, endpointNameCapitalized, method, description) {
|
515
|
-
|
515
|
+
// Use singular form for file names (convert plural to singular if needed)
|
516
|
+
const singularName = moduleName.endsWith('s') && moduleName.length > 1 ? moduleName.slice(0, -1) : moduleName;
|
516
517
|
const servicePath = path.join(modulePath, 'services', `${singularName}.service.ts`);
|
517
518
|
if (!fs.existsSync(servicePath)) {
|
518
519
|
throw new Error(`Service file not found: ${servicePath}`);
|
@@ -561,24 +562,47 @@ async function addServiceMethod(modulePath, moduleName, moduleNameCapitalized, e
|
|
561
562
|
fs.writeFileSync(servicePath, serviceContent);
|
562
563
|
}
|
563
564
|
async function addControllerMethod(modulePath, moduleName, moduleNameCapitalized, endpointName, endpointNameCapitalized, method, customPath, description) {
|
564
|
-
|
565
|
+
// Use singular form for file names (convert plural to singular if needed)
|
566
|
+
const singularName = moduleName.endsWith('s') && moduleName.length > 1 ? moduleName.slice(0, -1) : moduleName;
|
565
567
|
const controllerPath = path.join(modulePath, 'controllers', `${singularName}.controller.ts`);
|
566
568
|
if (!fs.existsSync(controllerPath)) {
|
567
569
|
throw new Error(`Controller file not found: ${controllerPath}`);
|
568
570
|
}
|
569
571
|
let controllerContent = fs.readFileSync(controllerPath, 'utf8');
|
572
|
+
// Add necessary imports if they don't exist
|
573
|
+
if (!controllerContent.includes('import { Request, Response }')) {
|
574
|
+
controllerContent = `import { Request, Response } from 'express';\n` + controllerContent;
|
575
|
+
}
|
576
|
+
if (!controllerContent.includes('import { handleResponse }')) {
|
577
|
+
controllerContent = `import { handleResponse } from '../../../shared/utils/handle-response';\n` + controllerContent;
|
578
|
+
}
|
579
|
+
if (!controllerContent.includes('import { Result }')) {
|
580
|
+
controllerContent = `import { Result } from '../../../shared/types/result';\n` + controllerContent;
|
581
|
+
}
|
582
|
+
if (!controllerContent.includes('import { v4 as uuidv4 }')) {
|
583
|
+
controllerContent = `import { v4 as uuidv4 } from 'uuid';\n` + controllerContent;
|
584
|
+
}
|
585
|
+
if (!controllerContent.includes('import { ResponseCode }')) {
|
586
|
+
controllerContent = `import { ResponseCode } from '../../../shared/constants/enums';\n` + controllerContent;
|
587
|
+
}
|
570
588
|
// Generate Swagger documentation and controller method
|
571
589
|
let swaggerDoc = '';
|
572
590
|
let controllerMethod = '';
|
573
591
|
switch (method) {
|
574
592
|
case 'GET':
|
575
593
|
swaggerDoc = ` /**
|
576
|
-
* @
|
594
|
+
* @swagger
|
577
595
|
* /api/${moduleName}/${customPath}:
|
578
596
|
* get:
|
579
597
|
* summary: ${endpointNameCapitalized} ${moduleName}
|
580
598
|
* description: ${description}
|
581
|
-
* tags: [${moduleNameCapitalized}
|
599
|
+
* tags: [${moduleNameCapitalized}]
|
600
|
+
* parameters:
|
601
|
+
* - in: query
|
602
|
+
* name: filter
|
603
|
+
* schema:
|
604
|
+
* type: string
|
605
|
+
* description: Filter parameters
|
582
606
|
* responses:
|
583
607
|
* 200:
|
584
608
|
* description: ${endpointNameCapitalized} retrieved successfully
|
@@ -587,27 +611,40 @@ async function addControllerMethod(modulePath, moduleName, moduleNameCapitalized
|
|
587
611
|
* schema:
|
588
612
|
* type: object
|
589
613
|
* properties:
|
590
|
-
*
|
614
|
+
* data:
|
591
615
|
* type: object
|
592
|
-
*
|
616
|
+
* statusCode:
|
593
617
|
* type: integer
|
594
618
|
* example: 1000
|
619
|
+
* errors:
|
620
|
+
* type: array
|
621
|
+
* items:
|
622
|
+
* type: object
|
623
|
+
* requestIdentifier:
|
624
|
+
* type: string
|
595
625
|
* 400:
|
596
626
|
* description: Bad request
|
597
627
|
*/`;
|
598
|
-
controllerMethod = ` async ${endpointName}(req, res) {
|
599
|
-
const
|
600
|
-
|
601
|
-
|
628
|
+
controllerMethod = ` async ${endpointName}(req: Request, res: Response): Promise<void> {
|
629
|
+
const requestIdentifier = req.headers['x-request-id'] || uuidv4();
|
630
|
+
try {
|
631
|
+
const data = await this.service.${endpointName}(req.query);
|
632
|
+
const result = new Result(data, ResponseCode.Ok, [], null, requestIdentifier as string);
|
633
|
+
return handleResponse(res, result);
|
634
|
+
} catch (error: any) {
|
635
|
+
const result = new Result(null, ResponseCode.Error, [{ message: error.message }], null, requestIdentifier as string);
|
636
|
+
return handleResponse(res, result);
|
637
|
+
}
|
638
|
+
}`;
|
602
639
|
break;
|
603
640
|
case 'POST':
|
604
641
|
swaggerDoc = ` /**
|
605
|
-
* @
|
642
|
+
* @swagger
|
606
643
|
* /api/${moduleName}/${customPath}:
|
607
644
|
* post:
|
608
645
|
* summary: ${endpointNameCapitalized} ${moduleName}
|
609
646
|
* description: ${description}
|
610
|
-
* tags: [${moduleNameCapitalized}
|
647
|
+
* tags: [${moduleNameCapitalized}]
|
611
648
|
* requestBody:
|
612
649
|
* required: true
|
613
650
|
* content:
|
@@ -617,34 +654,47 @@ async function addControllerMethod(modulePath, moduleName, moduleNameCapitalized
|
|
617
654
|
* properties:
|
618
655
|
* # Add your request body properties here
|
619
656
|
* responses:
|
620
|
-
*
|
621
|
-
* description: ${endpointNameCapitalized}
|
657
|
+
* 200:
|
658
|
+
* description: ${endpointNameCapitalized} completed successfully
|
622
659
|
* content:
|
623
660
|
* application/json:
|
624
661
|
* schema:
|
625
662
|
* type: object
|
626
663
|
* properties:
|
627
|
-
*
|
664
|
+
* data:
|
628
665
|
* type: object
|
629
|
-
*
|
666
|
+
* statusCode:
|
630
667
|
* type: integer
|
631
668
|
* example: 1000
|
669
|
+
* errors:
|
670
|
+
* type: array
|
671
|
+
* items:
|
672
|
+
* type: object
|
673
|
+
* requestIdentifier:
|
674
|
+
* type: string
|
632
675
|
* 400:
|
633
676
|
* description: Bad request
|
634
677
|
*/`;
|
635
|
-
controllerMethod = ` async ${endpointName}(req, res) {
|
636
|
-
const
|
637
|
-
|
638
|
-
|
678
|
+
controllerMethod = ` async ${endpointName}(req: Request, res: Response): Promise<void> {
|
679
|
+
const requestIdentifier = req.headers['x-request-id'] || uuidv4();
|
680
|
+
try {
|
681
|
+
const data = await this.service.${endpointName}(req.body);
|
682
|
+
const result = new Result(data, ResponseCode.Ok, [], null, requestIdentifier as string);
|
683
|
+
return handleResponse(res, result);
|
684
|
+
} catch (error: any) {
|
685
|
+
const result = new Result(null, ResponseCode.Error, [{ message: error.message }], null, requestIdentifier as string);
|
686
|
+
return handleResponse(res, result);
|
687
|
+
}
|
688
|
+
}`;
|
639
689
|
break;
|
640
690
|
case 'PUT':
|
641
691
|
swaggerDoc = ` /**
|
642
|
-
* @
|
692
|
+
* @swagger
|
643
693
|
* /api/${moduleName}/${customPath}/{id}:
|
644
694
|
* put:
|
645
695
|
* summary: ${endpointNameCapitalized} ${moduleName}
|
646
696
|
* description: ${description}
|
647
|
-
* tags: [${moduleNameCapitalized}
|
697
|
+
* tags: [${moduleNameCapitalized}]
|
648
698
|
* parameters:
|
649
699
|
* - in: path
|
650
700
|
* name: id
|
@@ -668,27 +718,40 @@ async function addControllerMethod(modulePath, moduleName, moduleNameCapitalized
|
|
668
718
|
* schema:
|
669
719
|
* type: object
|
670
720
|
* properties:
|
671
|
-
*
|
721
|
+
* data:
|
672
722
|
* type: object
|
673
|
-
*
|
723
|
+
* statusCode:
|
674
724
|
* type: integer
|
675
725
|
* example: 1000
|
726
|
+
* errors:
|
727
|
+
* type: array
|
728
|
+
* items:
|
729
|
+
* type: object
|
730
|
+
* requestIdentifier:
|
731
|
+
* type: string
|
676
732
|
* 404:
|
677
733
|
* description: ${moduleNameCapitalized} not found
|
678
734
|
*/`;
|
679
|
-
controllerMethod = ` async ${endpointName}(req, res) {
|
680
|
-
const
|
681
|
-
|
682
|
-
|
735
|
+
controllerMethod = ` async ${endpointName}(req: Request, res: Response): Promise<void> {
|
736
|
+
const requestIdentifier = req.headers['x-request-id'] || uuidv4();
|
737
|
+
try {
|
738
|
+
const data = await this.service.${endpointName}(req.params.id, req.body);
|
739
|
+
const result = new Result(data, ResponseCode.Ok, [], null, requestIdentifier as string);
|
740
|
+
return handleResponse(res, result);
|
741
|
+
} catch (error: any) {
|
742
|
+
const result = new Result(null, ResponseCode.Error, [{ message: error.message }], null, requestIdentifier as string);
|
743
|
+
return handleResponse(res, result);
|
744
|
+
}
|
745
|
+
}`;
|
683
746
|
break;
|
684
747
|
case 'DELETE':
|
685
748
|
swaggerDoc = ` /**
|
686
|
-
* @
|
749
|
+
* @swagger
|
687
750
|
* /api/${moduleName}/${customPath}/{id}:
|
688
751
|
* delete:
|
689
752
|
* summary: ${endpointNameCapitalized} ${moduleName}
|
690
753
|
* description: ${description}
|
691
|
-
* tags: [${moduleNameCapitalized}
|
754
|
+
* tags: [${moduleNameCapitalized}]
|
692
755
|
* parameters:
|
693
756
|
* - in: path
|
694
757
|
* name: id
|
@@ -698,51 +761,79 @@ async function addControllerMethod(modulePath, moduleName, moduleNameCapitalized
|
|
698
761
|
* description: ${moduleNameCapitalized} ID
|
699
762
|
* responses:
|
700
763
|
* 200:
|
701
|
-
* description: ${endpointNameCapitalized}
|
764
|
+
* description: ${endpointNameCapitalized} completed successfully
|
702
765
|
* content:
|
703
766
|
* application/json:
|
704
767
|
* schema:
|
705
768
|
* type: object
|
706
769
|
* properties:
|
707
|
-
*
|
770
|
+
* data:
|
708
771
|
* type: object
|
709
|
-
*
|
772
|
+
* statusCode:
|
710
773
|
* type: integer
|
711
774
|
* example: 1000
|
775
|
+
* errors:
|
776
|
+
* type: array
|
777
|
+
* items:
|
778
|
+
* type: object
|
779
|
+
* requestIdentifier:
|
780
|
+
* type: string
|
712
781
|
* 404:
|
713
782
|
* description: ${moduleNameCapitalized} not found
|
714
783
|
*/`;
|
715
|
-
controllerMethod = ` async ${endpointName}(req, res) {
|
716
|
-
const
|
717
|
-
|
718
|
-
|
784
|
+
controllerMethod = ` async ${endpointName}(req: Request, res: Response): Promise<void> {
|
785
|
+
const requestIdentifier = req.headers['x-request-id'] || uuidv4();
|
786
|
+
try {
|
787
|
+
const data = await this.service.${endpointName}(req.params.id);
|
788
|
+
const result = new Result(data, ResponseCode.Ok, [], null, requestIdentifier as string);
|
789
|
+
return handleResponse(res, result);
|
790
|
+
} catch (error: any) {
|
791
|
+
const result = new Result(null, ResponseCode.Error, [{ message: error.message }], null, requestIdentifier as string);
|
792
|
+
return handleResponse(res, result);
|
793
|
+
}
|
794
|
+
}`;
|
719
795
|
break;
|
720
796
|
default:
|
721
797
|
swaggerDoc = ` /**
|
722
|
-
* @
|
798
|
+
* @swagger
|
723
799
|
* /api/${moduleName}/${customPath}:
|
724
800
|
* ${method.toLowerCase()}:
|
725
801
|
* summary: ${endpointNameCapitalized} ${moduleName}
|
726
802
|
* description: ${description}
|
727
|
-
* tags: [${moduleNameCapitalized}
|
803
|
+
* tags: [${moduleNameCapitalized}]
|
728
804
|
* responses:
|
729
805
|
* 200:
|
730
|
-
* description: ${endpointNameCapitalized}
|
806
|
+
* description: ${endpointNameCapitalized} completed successfully
|
731
807
|
* content:
|
732
808
|
* application/json:
|
733
809
|
* schema:
|
734
810
|
* type: object
|
735
811
|
* properties:
|
736
|
-
*
|
812
|
+
* data:
|
737
813
|
* type: object
|
738
|
-
*
|
814
|
+
* statusCode:
|
739
815
|
* type: integer
|
740
816
|
* example: 1000
|
817
|
+
* errors:
|
818
|
+
* type: array
|
819
|
+
* items:
|
820
|
+
* type: object
|
821
|
+
* requestIdentifier:
|
822
|
+
* type: string
|
823
|
+
* 400:
|
824
|
+
* description: Bad request
|
741
825
|
*/`;
|
742
|
-
controllerMethod = ` async ${endpointName}(req, res) {
|
743
|
-
const
|
744
|
-
|
745
|
-
|
826
|
+
controllerMethod = ` async ${endpointName}(req: Request, res: Response): Promise<void> {
|
827
|
+
const requestIdentifier = req.headers['x-request-id'] || uuidv4();
|
828
|
+
try {
|
829
|
+
const data = await this.service.${endpointName}(req.query);
|
830
|
+
const result = new Result(data, ResponseCode.Ok, [], null, requestIdentifier as string);
|
831
|
+
return handleResponse(res, result);
|
832
|
+
} catch (error: any) {
|
833
|
+
const result = new Result(null, ResponseCode.Error, [{ message: error.message }], null, requestIdentifier as string);
|
834
|
+
return handleResponse(res, result);
|
835
|
+
}
|
836
|
+
}`;
|
746
837
|
}
|
747
838
|
// Add method before the closing brace
|
748
839
|
const lastBraceIndex = controllerContent.lastIndexOf('}');
|
@@ -751,7 +842,8 @@ async function addControllerMethod(modulePath, moduleName, moduleNameCapitalized
|
|
751
842
|
fs.writeFileSync(controllerPath, controllerContent);
|
752
843
|
}
|
753
844
|
async function addRoute(modulePath, moduleName, moduleNameCapitalized, endpointName, endpointNameCapitalized, method, customPath) {
|
754
|
-
|
845
|
+
// Use singular form for file names (convert plural to singular if needed)
|
846
|
+
const singularName = moduleName.endsWith('s') && moduleName.length > 1 ? moduleName.slice(0, -1) : moduleName;
|
755
847
|
const routePath = path.join(modulePath, 'routes', `${singularName}.routes.ts`);
|
756
848
|
if (!fs.existsSync(routePath)) {
|
757
849
|
throw new Error(`Route file not found: ${routePath}`);
|