4bnode 3.5.2 → 4.0.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/README.md +139 -114
- package/add-api.js +288 -156
- package/add-crud.js +226 -0
- package/add-login.js +152 -319
- package/add-mongo-delete.js +67 -138
- package/add-mongo-insert.js +87 -204
- package/add-mongo-read.js +100 -216
- package/add-mongo-schema.js +431 -199
- package/add-mongo-update.js +89 -202
- package/add-mongo.js +125 -218
- package/add-serialport.js +53 -98
- package/add-socket.js +43 -66
- package/add-websocket.js +68 -140
- package/index.js +288 -155
- package/lib/env.js +18 -0
- package/lib/indexFile.js +87 -0
- package/lib/names.js +21 -0
- package/lib/project.js +122 -0
- package/lib/routeFile.js +56 -0
- package/lib/ui.js +161 -0
- package/package.json +9 -16
- package/skeleton/dev-api.js +2785 -0
- package/skeleton/index.js +10 -3
- package/skeleton/package.json +9 -5
- package/skeleton/public/fonts/NotoSans-Bold.woff2 +0 -0
- package/skeleton/public/fonts/NotoSans-Light.woff2 +0 -0
- package/skeleton/public/fonts/NotoSans-Medium.woff2 +0 -0
- package/skeleton/public/fonts/NotoSans-Regular.woff2 +0 -0
- package/skeleton/public/fonts/NotoSans-SemiBold.woff2 +0 -0
- package/skeleton/public/images/mongo.png +0 -0
- package/skeleton/public/images/mysql.png +0 -0
- package/skeleton/public/images/postgresql.png +0 -0
- package/skeleton/public/images/sqlite.png +0 -0
- package/skeleton/public/index.html +7562 -64
- package/README_4bnode.md +0 -197
- package/src/auth/passport.js +0 -21
- package/src/db.js +0 -13
- package/test-server/.env.development +0 -1
- package/test-server/.env.production +0 -1
- package/test-server/index.js +0 -82
- package/test-server/package-lock.json +0 -1267
- package/test-server/package.json +0 -20
- package/test-server/public/index.html +0 -90
package/add-mongo-delete.js
CHANGED
|
@@ -1,153 +1,82 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import fs from "fs";
|
|
4
3
|
import path from "path";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
import { select } from "@inquirer/prompts";
|
|
5
|
+
import { toPascalCase } from "./lib/names.js";
|
|
6
|
+
import { listRoutes, listModels } from "./lib/project.js";
|
|
7
|
+
import {
|
|
8
|
+
getRouteFilePath,
|
|
9
|
+
addImportToRoute,
|
|
10
|
+
insertCodeIntoRoute,
|
|
11
|
+
} from "./lib/routeFile.js";
|
|
12
|
+
import {
|
|
13
|
+
showHeader,
|
|
14
|
+
showTaskDone,
|
|
15
|
+
showError,
|
|
16
|
+
showFileAction,
|
|
17
|
+
} from "./lib/ui.js";
|
|
18
|
+
|
|
19
|
+
async function main() {
|
|
20
|
+
showHeader("add-mongo-delete", "Add data deletion route");
|
|
21
|
+
|
|
22
|
+
const routeFiles = listRoutes();
|
|
23
23
|
if (routeFiles.length === 0) {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
showError("No route files found in src/routes.");
|
|
25
|
+
process.exit(1);
|
|
26
26
|
}
|
|
27
|
-
return routeFiles;
|
|
28
|
-
}
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
const projectRoot = process.cwd();
|
|
32
|
-
const modelsDir = path.join(projectRoot, "src", "models");
|
|
33
|
-
if (!fs.existsSync(modelsDir)) {
|
|
34
|
-
console.error(chalk.red("No models directory found in src/models"));
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
const modelFiles = fs
|
|
38
|
-
.readdirSync(modelsDir)
|
|
39
|
-
.filter((file) => file.endsWith(".js"));
|
|
28
|
+
const modelFiles = listModels();
|
|
40
29
|
if (modelFiles.length === 0) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
return modelFiles;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function addDeleteTemplateToRoute(routeFile, modelName) {
|
|
48
|
-
const projectRoot = process.cwd();
|
|
49
|
-
const routeFilePath = path.join(projectRoot, "src", "routes", routeFile);
|
|
50
|
-
const pascalModelName =
|
|
51
|
-
modelName.charAt(0).toUpperCase() + modelName.slice(1);
|
|
52
|
-
const deleteTemplateImport = `
|
|
53
|
-
import ${pascalModelName} from '../models/${modelName}.js';
|
|
54
|
-
`;
|
|
55
|
-
|
|
56
|
-
const deleteTemplateFunction = `
|
|
57
|
-
// Data deletion logic
|
|
58
|
-
try {
|
|
59
|
-
const deletedDocument = await ${pascalModelName}.findByIdAndDelete(req.params.id);
|
|
60
|
-
if (!deletedDocument) {
|
|
61
|
-
return res.status(404).json({ message: "Document not found" });
|
|
30
|
+
showError("No model files found in src/models.");
|
|
31
|
+
process.exit(1);
|
|
62
32
|
}
|
|
63
|
-
res.json({ message: "Data deleted successfully", data: deletedDocument });
|
|
64
|
-
} catch (err) {
|
|
65
|
-
console.error(err);
|
|
66
|
-
res.status(500).json({ message: "Server error" });
|
|
67
|
-
}
|
|
68
|
-
`;
|
|
69
|
-
|
|
70
|
-
if (!fs.existsSync(routeFilePath)) {
|
|
71
|
-
console.error(
|
|
72
|
-
chalk.red(`The specified route file does not exist: ${routeFilePath}`)
|
|
73
|
-
);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
let routeContent = fs.readFileSync(routeFilePath, "utf8");
|
|
78
33
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
34
|
+
const selectedRoute = await select({
|
|
35
|
+
message: "Select route file to modify:",
|
|
36
|
+
choices: routeFiles.map((f) => ({ name: f, value: f })),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const selectedModelFile = await select({
|
|
40
|
+
message: "Select model file to use:",
|
|
41
|
+
choices: modelFiles.map((f) => ({ name: f, value: f })),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const modelName = path.basename(selectedModelFile, ".js");
|
|
45
|
+
const pascalName = toPascalCase(modelName);
|
|
46
|
+
const routeFilePath = getRouteFilePath(selectedRoute);
|
|
47
|
+
|
|
48
|
+
console.log();
|
|
49
|
+
|
|
50
|
+
addImportToRoute(
|
|
51
|
+
routeFilePath,
|
|
52
|
+
`import ${pascalName} from '../models/${modelName}.js';`
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const deleteCode = `
|
|
56
|
+
router.delete('/:id', async (req, res) => {
|
|
57
|
+
try {
|
|
58
|
+
const deletedDocument = await ${pascalName}.findByIdAndDelete(req.params.id);
|
|
59
|
+
if (!deletedDocument) {
|
|
60
|
+
return res.status(404).json({ message: 'Document not found' });
|
|
61
|
+
}
|
|
62
|
+
res.json({ message: 'Data deleted successfully', data: deletedDocument });
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.error(err);
|
|
65
|
+
res.status(500).json({ message: 'Server error' });
|
|
94
66
|
}
|
|
67
|
+
});`;
|
|
95
68
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const routeFiles = listRoutes();
|
|
101
|
-
if (routeFiles.length === 0) {
|
|
102
|
-
rl.close();
|
|
103
|
-
process.exit(0);
|
|
104
|
-
}
|
|
69
|
+
insertCodeIntoRoute(routeFilePath, deleteCode);
|
|
70
|
+
showFileAction("updated", `src/routes/${selectedRoute}`);
|
|
105
71
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
72
|
+
showTaskDone("Delete route added", [
|
|
73
|
+
`Route: DELETE /:id in ${selectedRoute}`,
|
|
74
|
+
`Model: ${modelName}`,
|
|
75
|
+
]);
|
|
110
76
|
}
|
|
111
77
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
78
|
+
main().catch((err) => {
|
|
79
|
+
if (err.name === "ExitPromptError") process.exit(0);
|
|
80
|
+
showError(err.message);
|
|
81
|
+
process.exit(1);
|
|
115
82
|
});
|
|
116
|
-
|
|
117
|
-
rl.question(
|
|
118
|
-
chalk.yellow("Enter the number of the route file: "),
|
|
119
|
-
(routeAnswer) => {
|
|
120
|
-
const routeIndex = parseInt(routeAnswer, 10) - 1;
|
|
121
|
-
if (routeIndex >= 0 && routeIndex < routeFiles.length) {
|
|
122
|
-
const selectedRoute = routeFiles[routeIndex];
|
|
123
|
-
|
|
124
|
-
console.log(chalk.cyan("Select the model file to use:"));
|
|
125
|
-
modelFiles.forEach((file, index) => {
|
|
126
|
-
console.log(chalk.cyan(`${index + 1}. ${file}`));
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
rl.question(
|
|
130
|
-
chalk.yellow("Enter the number of the model file: "),
|
|
131
|
-
(modelAnswer) => {
|
|
132
|
-
const modelIndex = parseInt(modelAnswer, 10) - 1;
|
|
133
|
-
if (modelIndex >= 0 && modelIndex < modelFiles.length) {
|
|
134
|
-
const selectedModel = path.basename(modelFiles[modelIndex], ".js");
|
|
135
|
-
|
|
136
|
-
addDeleteTemplateToRoute(selectedRoute, selectedModel);
|
|
137
|
-
rl.close();
|
|
138
|
-
} else {
|
|
139
|
-
console.error(
|
|
140
|
-
chalk.red("Invalid selection. Please choose a valid number.")
|
|
141
|
-
);
|
|
142
|
-
rl.close();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
);
|
|
146
|
-
} else {
|
|
147
|
-
console.error(
|
|
148
|
-
chalk.red("Invalid selection. Please choose a valid number.")
|
|
149
|
-
);
|
|
150
|
-
rl.close();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
);
|
package/add-mongo-insert.js
CHANGED
|
@@ -1,231 +1,114 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import fs from "fs";
|
|
4
3
|
import path from "path";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
import { select } from "@inquirer/prompts";
|
|
5
|
+
import { toPascalCase } from "./lib/names.js";
|
|
6
|
+
import { listRoutes, listModels, getModelSchema } from "./lib/project.js";
|
|
7
|
+
import {
|
|
8
|
+
getRouteFilePath,
|
|
9
|
+
addImportToRoute,
|
|
10
|
+
insertCodeIntoRoute,
|
|
11
|
+
detectHttpMethod,
|
|
12
|
+
getRequestDataSource,
|
|
13
|
+
} from "./lib/routeFile.js";
|
|
14
|
+
import {
|
|
15
|
+
showHeader,
|
|
16
|
+
showTaskDone,
|
|
17
|
+
showError,
|
|
18
|
+
showFileAction,
|
|
19
|
+
installDeps,
|
|
20
|
+
} from "./lib/ui.js";
|
|
21
|
+
|
|
22
|
+
async function main() {
|
|
23
|
+
showHeader("add-mongo-insert", "Add data insertion route");
|
|
24
|
+
|
|
25
|
+
const routeFiles = listRoutes();
|
|
24
26
|
if (routeFiles.length === 0) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
showError("No route files found in src/routes.");
|
|
28
|
+
process.exit(1);
|
|
27
29
|
}
|
|
28
|
-
return routeFiles;
|
|
29
|
-
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
const projectRoot = process.cwd();
|
|
33
|
-
const modelsDir = path.join(projectRoot, "src", "models");
|
|
34
|
-
if (!fs.existsSync(modelsDir)) {
|
|
35
|
-
console.error(chalk.red("No models directory found in src/models"));
|
|
36
|
-
return [];
|
|
37
|
-
}
|
|
38
|
-
const modelFiles = fs
|
|
39
|
-
.readdirSync(modelsDir)
|
|
40
|
-
.filter((file) => file.endsWith(".js"));
|
|
31
|
+
const modelFiles = listModels();
|
|
41
32
|
if (modelFiles.length === 0) {
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
showError("No model files found in src/models.");
|
|
34
|
+
process.exit(1);
|
|
44
35
|
}
|
|
45
|
-
return modelFiles;
|
|
46
|
-
}
|
|
47
36
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"src",
|
|
53
|
-
"models",
|
|
54
|
-
modelName + ".js"
|
|
55
|
-
);
|
|
56
|
-
const modelFileContent = fs.readFileSync(modelFilePath, "utf8");
|
|
57
|
-
|
|
58
|
-
// Improved regex to handle beautified code
|
|
59
|
-
const schemaRegex = /new mongoose\.Schema\s*\(\s*\{([\s\S]*?)\}\s*\)/m;
|
|
60
|
-
const match = modelFileContent.match(schemaRegex);
|
|
61
|
-
|
|
62
|
-
if (match) {
|
|
63
|
-
try {
|
|
64
|
-
const schemaContent = match[1];
|
|
65
|
-
const fieldRegex = /(\w+):\s*\{[\s\S]*?\}/g;
|
|
66
|
-
const schemaKeys = [];
|
|
67
|
-
let fieldMatch;
|
|
68
|
-
while ((fieldMatch = fieldRegex.exec(schemaContent)) !== null) {
|
|
69
|
-
schemaKeys.push(fieldMatch[1]);
|
|
70
|
-
}
|
|
71
|
-
return schemaKeys;
|
|
72
|
-
} catch (error) {
|
|
73
|
-
console.error(chalk.red("Error parsing schema: "), error);
|
|
74
|
-
return [];
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
console.error(chalk.red("Schema not found in model file."));
|
|
78
|
-
return [];
|
|
79
|
-
}
|
|
80
|
-
}
|
|
37
|
+
const selectedRoute = await select({
|
|
38
|
+
message: "Select route file to modify:",
|
|
39
|
+
choices: routeFiles.map((f) => ({ name: f, value: f })),
|
|
40
|
+
});
|
|
81
41
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
modelName.charAt(0).toUpperCase() + modelName.slice(1);
|
|
42
|
+
const selectedModelFile = await select({
|
|
43
|
+
message: "Select model file to use:",
|
|
44
|
+
choices: modelFiles.map((f) => ({ name: f, value: f })),
|
|
45
|
+
});
|
|
87
46
|
|
|
88
|
-
|
|
47
|
+
const modelName = path.basename(selectedModelFile, ".js");
|
|
48
|
+
const pascalName = toPascalCase(modelName);
|
|
49
|
+
const fields = getModelSchema(modelName);
|
|
89
50
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
`import bcrypt from 'bcrypt';\n` + insertTemplateImport;
|
|
94
|
-
passwordHashingLogic = `
|
|
95
|
-
if (newData.password) {
|
|
96
|
-
const salt = await bcrypt.genSalt(10);
|
|
97
|
-
newData.password = await bcrypt.hash(newData.password, salt);
|
|
98
|
-
}
|
|
99
|
-
`;
|
|
51
|
+
if (fields.length === 0) {
|
|
52
|
+
showError("No fields found in the selected model.");
|
|
53
|
+
process.exit(1);
|
|
100
54
|
}
|
|
101
55
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
56
|
+
console.log();
|
|
57
|
+
|
|
58
|
+
const routeFilePath = getRouteFilePath(selectedRoute);
|
|
59
|
+
const method = detectHttpMethod(routeFilePath);
|
|
60
|
+
const dataSource = getRequestDataSource(method);
|
|
108
61
|
|
|
109
|
-
let
|
|
62
|
+
let importBlock = `import ${pascalName} from '../models/${modelName}.js';`;
|
|
63
|
+
let passwordLogic = "";
|
|
110
64
|
|
|
111
|
-
if (
|
|
112
|
-
|
|
65
|
+
if (fields.includes("password")) {
|
|
66
|
+
importBlock = `import bcrypt from 'bcrypt';\n${importBlock}`;
|
|
67
|
+
passwordLogic = `
|
|
68
|
+
if (newData.password) {
|
|
69
|
+
const salt = await bcrypt.genSalt(10);
|
|
70
|
+
newData.password = await bcrypt.hash(newData.password, salt);
|
|
71
|
+
}`;
|
|
113
72
|
}
|
|
114
73
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
const newDocument = new ${pascalModelName}(newData);
|
|
136
|
-
await newDocument.save();
|
|
137
|
-
res.json({ message: "Data inserted successfully", data: newDocument });
|
|
138
|
-
} catch (err) {
|
|
139
|
-
console.error(err);
|
|
140
|
-
res.status(500).json({ message: "Server error" });
|
|
141
|
-
}
|
|
142
|
-
`;
|
|
143
|
-
|
|
144
|
-
// Insert the logic before the last closing `});`
|
|
145
|
-
const lastCloseIndex = routeContent.lastIndexOf("});");
|
|
146
|
-
if (lastCloseIndex !== -1) {
|
|
147
|
-
const updatedContent = [
|
|
148
|
-
routeContent.slice(0, lastCloseIndex),
|
|
149
|
-
insertTemplateFunction,
|
|
150
|
-
routeContent.slice(lastCloseIndex),
|
|
151
|
-
].join("\n");
|
|
152
|
-
|
|
153
|
-
routeContent = updatedContent;
|
|
154
|
-
} else {
|
|
155
|
-
routeContent += `\n${insertTemplateFunction}\n`;
|
|
74
|
+
addImportToRoute(routeFilePath, importBlock);
|
|
75
|
+
|
|
76
|
+
const fieldAssignments = fields
|
|
77
|
+
.map((f) => ` ${f}: ${dataSource}.${f}`)
|
|
78
|
+
.join(",\n");
|
|
79
|
+
|
|
80
|
+
const insertCode = `
|
|
81
|
+
router.post('/create', async (req, res) => {
|
|
82
|
+
const newData = {
|
|
83
|
+
${fieldAssignments}
|
|
84
|
+
};
|
|
85
|
+
${passwordLogic}
|
|
86
|
+
try {
|
|
87
|
+
const newDocument = new ${pascalName}(newData);
|
|
88
|
+
await newDocument.save();
|
|
89
|
+
res.json({ message: 'Data inserted successfully', data: newDocument });
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.error(err);
|
|
92
|
+
res.status(500).json({ message: 'Server error' });
|
|
156
93
|
}
|
|
94
|
+
});`;
|
|
157
95
|
|
|
158
|
-
|
|
159
|
-
|
|
96
|
+
insertCodeIntoRoute(routeFilePath, insertCode);
|
|
97
|
+
showFileAction("updated", `src/routes/${selectedRoute}`);
|
|
160
98
|
|
|
161
|
-
// Install bcrypt if needed
|
|
162
99
|
if (fields.includes("password")) {
|
|
163
|
-
|
|
164
|
-
execSync("npm install bcrypt", { stdio: "inherit" });
|
|
100
|
+
await installDeps("bcrypt");
|
|
165
101
|
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const routeFiles = listRoutes();
|
|
169
|
-
if (routeFiles.length === 0) {
|
|
170
|
-
rl.close();
|
|
171
|
-
process.exit(0);
|
|
172
|
-
}
|
|
173
102
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
103
|
+
showTaskDone("Insert route added", [
|
|
104
|
+
`Route: POST /create in ${selectedRoute}`,
|
|
105
|
+
`Model: ${modelName}`,
|
|
106
|
+
`Fields: ${fields.join(", ")}`,
|
|
107
|
+
]);
|
|
178
108
|
}
|
|
179
109
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
110
|
+
main().catch((err) => {
|
|
111
|
+
if (err.name === "ExitPromptError") process.exit(0);
|
|
112
|
+
showError(err.message);
|
|
113
|
+
process.exit(1);
|
|
183
114
|
});
|
|
184
|
-
|
|
185
|
-
rl.question(
|
|
186
|
-
chalk.yellow("Enter the number of the route file: "),
|
|
187
|
-
(routeAnswer) => {
|
|
188
|
-
const routeIndex = parseInt(routeAnswer, 10) - 1;
|
|
189
|
-
if (routeIndex >= 0 && routeIndex < routeFiles.length) {
|
|
190
|
-
const selectedRoute = routeFiles[routeIndex];
|
|
191
|
-
|
|
192
|
-
console.log(chalk.cyan("Select the model file to use:"));
|
|
193
|
-
modelFiles.forEach((file, index) => {
|
|
194
|
-
console.log(chalk.cyan(`${index + 1}. ${file}`));
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
rl.question(
|
|
198
|
-
chalk.yellow("Enter the number of the model file: "),
|
|
199
|
-
(modelAnswer) => {
|
|
200
|
-
const modelIndex = parseInt(modelAnswer, 10) - 1;
|
|
201
|
-
if (modelIndex >= 0 && modelIndex < modelFiles.length) {
|
|
202
|
-
const selectedModel = path.basename(modelFiles[modelIndex], ".js");
|
|
203
|
-
const schemaFields = getModelSchema(selectedModel);
|
|
204
|
-
|
|
205
|
-
if (schemaFields.length === 0) {
|
|
206
|
-
rl.close();
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
addInsertTemplateToRoute(
|
|
211
|
-
selectedRoute,
|
|
212
|
-
schemaFields,
|
|
213
|
-
selectedModel
|
|
214
|
-
);
|
|
215
|
-
rl.close();
|
|
216
|
-
} else {
|
|
217
|
-
console.error(
|
|
218
|
-
chalk.red("Invalid selection. Please choose a valid number.")
|
|
219
|
-
);
|
|
220
|
-
rl.close();
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
);
|
|
224
|
-
} else {
|
|
225
|
-
console.error(
|
|
226
|
-
chalk.red("Invalid selection. Please choose a valid number.")
|
|
227
|
-
);
|
|
228
|
-
rl.close();
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
);
|