lazy-api-cli-remi 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +43 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -34,7 +34,7 @@ const generateData = () => ({
34
34
  });
35
35
 
36
36
  // --- 2. TEMPLATE SERVER.JS ---
37
- const serverTemplate = `
37
+ const serverJsContent = `
38
38
  require('dotenv').config();
39
39
  const express = require('express');
40
40
  const bodyParser = require('body-parser');
@@ -157,6 +157,40 @@ app.listen(PORT, () => {
157
157
  const spinner = ora('🚀 Đang lắp ráp các bộ phận...').start();
158
158
 
159
159
  try {
160
+ // --- POSTMAN COLLECTION GENERATOR ---
161
+ const generatePostman = (projectName, resources) => {
162
+ const baseUrl = "http://localhost:3000";
163
+ const collection = {
164
+ info: {
165
+ name: `${projectName} Collection`,
166
+ description: "Generated by Lazy-API-CLI-Remi",
167
+ schema: "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
168
+ },
169
+ item: resources.map(res => ({
170
+ name: res.charAt(0).toUpperCase() + res.slice(1),
171
+ item: [
172
+ {
173
+ name: `Get all ${res}`,
174
+ request: { method: "GET", url: { raw: `${baseUrl}/api/${res}` } }
175
+ },
176
+ {
177
+ name: `Create ${res}`,
178
+ request: {
179
+ method: "POST",
180
+ header: [{ key: "Content-Type", value: "application/json" }],
181
+ body: { mode: "raw", raw: JSON.stringify({ name: "New Item" }, null, 2) },
182
+ url: { raw: `${baseUrl}/api/${res}` }
183
+ }
184
+ },
185
+ {
186
+ name: `Delete ${res}`,
187
+ request: { method: "DELETE", url: { raw: `${baseUrl}/api/${res}/123` } }
188
+ }
189
+ ]
190
+ }))
191
+ };
192
+ return JSON.stringify(collection, null, 2);
193
+ };
160
194
  fs.mkdirSync(projectDir);
161
195
  fs.writeFileSync(path.join(projectDir, 'db.json'), JSON.stringify(generateData(), null, 2));
162
196
  fs.writeFileSync(path.join(projectDir, 'server.js'), serverJsContent);
@@ -172,6 +206,14 @@ try {
172
206
  const doc = { info: { title: '${projectName}', description: 'Lazy Auto API' }, host: 'localhost:3000', schemes: ['http'] };
173
207
  swaggerAutogen('./swagger_output.json', ['./server.js'], doc).then(() => require('./server.js'));
174
208
  `);
209
+ // Lấy danh sách resource từ mockData đã tạo ở trên
210
+ const resourceNames = Object.keys(mockData);
211
+
212
+ // Ghi file Postman
213
+ fs.writeFileSync(
214
+ path.join(projectDir, 'postman_collection.json'),
215
+ generatePostman(projectName, resourceNames)
216
+ );
175
217
 
176
218
  spinner.succeed(chalk.green('Tạo project thành công!'));
177
219
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lazy-api-cli-remi",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "bin": {
5
5
  "lazy-api": "./index.js"
6
6
  },