json-crud-ui 1.1.1
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/LICENSE +21 -0
- package/README.md +225 -0
- package/bin/cli.js +12 -0
- package/bin/core/getLatestVersion.js +13 -0
- package/bin/core/loadRunner.js +9 -0
- package/bin/v10/commands/exportCommands/endPointsJs.js +5 -0
- package/bin/v10/core/createFolder.js +34 -0
- package/bin/v10/core/parseInput.js +9 -0
- package/bin/v10/core/resolveCommand.js +13 -0
- package/bin/v10/core/showUsage.js +39 -0
- package/bin/v10/start.js +22 -0
- package/bin/v10/tasks/actions/EndPointsJs/Distinct/index.js +32 -0
- package/bin/v10/tasks/actions/EndPointsJs/Distinct/insertImport.js +15 -0
- package/bin/v10/tasks/actions/EndPointsJs/Distinct/insertUsage.js +15 -0
- package/bin/v10/tasks/actions/EndPointsJs/Insert/index.js +33 -0
- package/bin/v10/tasks/actions/EndPointsJs/Insert/insertImport.js +15 -0
- package/bin/v10/tasks/actions/EndPointsJs/Insert/insertUsage.js +15 -0
- package/bin/v10/tasks/actions/EndPointsJs/ShowAll/index.js +33 -0
- package/bin/v10/tasks/actions/EndPointsJs/ShowAll/insertImport.js +15 -0
- package/bin/v10/tasks/actions/EndPointsJs/ShowAll/insertUsage.js +15 -0
- package/bin/v10/tasks/actions/EndPointsJs/index.js +37 -0
- package/bin/v10/tasks/actions/EndPointsJs/showUsage.js +38 -0
- package/bin/v10/tasks/actions/appJs.js +6 -0
- package/bin/v10/tasks/common/SourceEditor.js +66 -0
- package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/index.js +9 -0
- package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/index.js +41 -0
- package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/buildUseLine.js +11 -0
- package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +8 -0
- package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/index.js +42 -0
- package/bin/v10/tasks/tables/AddTableName/steps/announce.js +9 -0
- package/bin/v10/tasks/tables/AddTableName/steps/createFolder.js +7 -0
- package/bin/v10/tasks/tables/AddTableName/steps/decideTemplate.js +3 -0
- package/bin/v10/tasks/tables/AddTableName/steps/locateDestination.js +6 -0
- package/bin/v10/tasks/tables/AddTableName/steps/locateSource.js +13 -0
- package/bin/v10/tasks/tables/AddTableName/steps/resolveFolderName.js +20 -0
- package/bin/v10/tasks/tables/AddTableName/steps/updateConfig.js +16 -0
- package/bin/v10/tasks/tables/AddTableName/steps/updateEndPointsFile.js +30 -0
- package/bin/v10/tasks/tables/AddTableName/steps/updateTableName.js +30 -0
- package/bin/v10/tasks/tables/AddTableName/template/Config/schema.json +3 -0
- package/bin/v10/tasks/tables/AddTableName/template/end-points.js +7 -0
- package/bin/v10/tasks/tables/addTableName.js +56 -0
- package/bin/v11/commands/loadCommand.js +7 -0
- package/bin/v11/config/actions.json +35 -0
- package/bin/v11/config/actionsV1.json +20 -0
- package/bin/v11/config/actionsV2.json +27 -0
- package/bin/v11/core/createFolder.js +34 -0
- package/bin/v11/core/parseInput.js +8 -0
- package/bin/v11/core/resolveCommand.js +13 -0
- package/bin/v11/core/showUsage.js +39 -0
- package/bin/v11/start.js +29 -0
- package/bin/v11/tasks/actions/EndPointsJs/AlterJsFile/index.js +31 -0
- package/bin/v11/tasks/actions/EndPointsJs/AlterJsFile/insertImport.js +15 -0
- package/bin/v11/tasks/actions/EndPointsJs/AlterJsFile/insertUsage.js +15 -0
- package/bin/v11/tasks/actions/EndPointsJs/Distinct/index.js +32 -0
- package/bin/v11/tasks/actions/EndPointsJs/Distinct/insertImport.js +15 -0
- package/bin/v11/tasks/actions/EndPointsJs/Distinct/insertUsage.js +15 -0
- package/bin/v11/tasks/actions/EndPointsJs/Insert/index.js +33 -0
- package/bin/v11/tasks/actions/EndPointsJs/Insert/insertImport.js +15 -0
- package/bin/v11/tasks/actions/EndPointsJs/Insert/insertUsage.js +15 -0
- package/bin/v11/tasks/actions/EndPointsJs/ShowAll/index.js +33 -0
- package/bin/v11/tasks/actions/EndPointsJs/ShowAll/insertImport.js +15 -0
- package/bin/v11/tasks/actions/EndPointsJs/ShowAll/insertUsage.js +15 -0
- package/bin/v11/tasks/actions/EndPointsJs/index.js +19 -0
- package/bin/v11/tasks/actions/EndPointsJs/showUsage.js +38 -0
- package/bin/v11/tasks/actions/appJs.js +6 -0
- package/bin/v11/tasks/common/SourceEditor.js +66 -0
- package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/index.js +9 -0
- package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/index.js +41 -0
- package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/buildUseLine.js +11 -0
- package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +8 -0
- package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/index.js +42 -0
- package/bin/v11/tasks/tables/AddTableName/steps/announce.js +9 -0
- package/bin/v11/tasks/tables/AddTableName/steps/createFolder.js +7 -0
- package/bin/v11/tasks/tables/AddTableName/steps/decideTemplate.js +3 -0
- package/bin/v11/tasks/tables/AddTableName/steps/locateDestination.js +6 -0
- package/bin/v11/tasks/tables/AddTableName/steps/locateSource.js +13 -0
- package/bin/v11/tasks/tables/AddTableName/steps/resolveFolderName.js +20 -0
- package/bin/v11/tasks/tables/AddTableName/steps/updateConfig.js +16 -0
- package/bin/v11/tasks/tables/AddTableName/steps/updateEndPointsFile.js +30 -0
- package/bin/v11/tasks/tables/AddTableName/steps/updateTableName.js +30 -0
- package/bin/v11/tasks/tables/AddTableName/template/Config/schema.json +3 -0
- package/bin/v11/tasks/tables/AddTableName/template/end-points.js +7 -0
- package/bin/v11/tasks/tables/addTableName.js +56 -0
- package/bin/v12/commands/loadCommand.js +7 -0
- package/bin/v12/config/actions.json +46 -0
- package/bin/v12/config/actionsV1.json +20 -0
- package/bin/v12/config/actionsV2.json +27 -0
- package/bin/v12/config/actionsV3.json +35 -0
- package/bin/v12/config/actionsV4.json +35 -0
- package/bin/v12/core/createFolder.js +34 -0
- package/bin/v12/core/parseInput.js +8 -0
- package/bin/v12/core/resolveCommand.js +13 -0
- package/bin/v12/core/showUsage.js +39 -0
- package/bin/v12/start.js +21 -0
- package/bin/v12/tasks/actions/EndPointsJs/AlterJsFile/index.js +31 -0
- package/bin/v12/tasks/actions/EndPointsJs/AlterJsFile/insertImport.js +15 -0
- package/bin/v12/tasks/actions/EndPointsJs/AlterJsFile/insertUsage.js +15 -0
- package/bin/v12/tasks/actions/EndPointsJs/index.js +19 -0
- package/bin/v12/tasks/actions/EndPointsJs/showUsage.js +38 -0
- package/bin/v12/tasks/actions/appJs.js +6 -0
- package/bin/v12/tasks/common/SourceEditor.js +66 -0
- package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/index.js +9 -0
- package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/index.js +41 -0
- package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/buildUseLine.js +11 -0
- package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +8 -0
- package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/index.js +42 -0
- package/bin/v12/tasks/tables/AddTableName/steps/announce.js +9 -0
- package/bin/v12/tasks/tables/AddTableName/steps/createFolder.js +7 -0
- package/bin/v12/tasks/tables/AddTableName/steps/decideTemplate.js +3 -0
- package/bin/v12/tasks/tables/AddTableName/steps/locateDestination.js +6 -0
- package/bin/v12/tasks/tables/AddTableName/steps/locateSource.js +13 -0
- package/bin/v12/tasks/tables/AddTableName/steps/resolveFolderName.js +20 -0
- package/bin/v12/tasks/tables/AddTableName/steps/updateConfig.js +16 -0
- package/bin/v12/tasks/tables/AddTableName/steps/updateEndPointsFile.js +30 -0
- package/bin/v12/tasks/tables/AddTableName/steps/updateTableName.js +30 -0
- package/bin/v12/tasks/tables/AddTableName/template/Config/schema.json +3 -0
- package/bin/v12/tasks/tables/AddTableName/template/end-points.js +7 -0
- package/bin/v12/tasks/tables/addTableName.js +56 -0
- package/index.js +5 -0
- package/package.json +35 -0
package/bin/v11/start.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import parseInput from "./core/parseInput.js";
|
|
2
|
+
// import resolveCommand from "./core/resolveCommand.js";
|
|
3
|
+
import showUsage from './core/showUsage.js';
|
|
4
|
+
|
|
5
|
+
import resolveCommand from "./tasks/actions/EndPointsJs/index.js";
|
|
6
|
+
|
|
7
|
+
import pkg from '../../package.json' with { type: 'json' };
|
|
8
|
+
|
|
9
|
+
const version = pkg.version;
|
|
10
|
+
|
|
11
|
+
const run = async () => {
|
|
12
|
+
const input = parseInput();
|
|
13
|
+
console.log("bbbb : ", input);
|
|
14
|
+
|
|
15
|
+
// if (!input.cmd) return showUsage(version);
|
|
16
|
+
|
|
17
|
+
if (input.action === "--help" || input.action === "-h" || input.action === "help") return showUsage(version);
|
|
18
|
+
|
|
19
|
+
await resolveCommand({
|
|
20
|
+
action: input.action,
|
|
21
|
+
toPath: input.toPath
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// if (!command) return (console.log(`Unknown command: ${input.cmd}\n`), showUsage(version));
|
|
25
|
+
|
|
26
|
+
// await command(input);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default run;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// bin/v9/tasks/actions/EndPointsJs/index.js
|
|
2
|
+
|
|
3
|
+
import SourceEditor from "../../../common/SourceEditor.js";
|
|
4
|
+
|
|
5
|
+
import insertImport from "./insertImport.js";
|
|
6
|
+
import insertUsage from "./insertUsage.js";
|
|
7
|
+
|
|
8
|
+
export default ({ inImportLine, inUsageLine, toPath }) => {
|
|
9
|
+
|
|
10
|
+
const path = `${toPath}/end-points.js`;
|
|
11
|
+
|
|
12
|
+
const editor = new SourceEditor(path);
|
|
13
|
+
|
|
14
|
+
const importLine = inImportLine;
|
|
15
|
+
|
|
16
|
+
const usageLine = inUsageLine;
|
|
17
|
+
|
|
18
|
+
insertImport({
|
|
19
|
+
editor,
|
|
20
|
+
importLine
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
editor.save();
|
|
24
|
+
|
|
25
|
+
insertUsage({
|
|
26
|
+
editor,
|
|
27
|
+
usageLine
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
editor.save();
|
|
31
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// insertImport.js
|
|
2
|
+
|
|
3
|
+
export default ({ editor, importLine }) => {
|
|
4
|
+
|
|
5
|
+
if (!editor.hasLine(importLine)) {
|
|
6
|
+
|
|
7
|
+
const lastImportLine =
|
|
8
|
+
editor.findLastLine("import ");
|
|
9
|
+
|
|
10
|
+
editor.insertAfter({
|
|
11
|
+
line: lastImportLine,
|
|
12
|
+
content: importLine
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// insertUsage.js
|
|
2
|
+
export default ({ editor, usageLine }) => {
|
|
3
|
+
|
|
4
|
+
if (!editor.hasLine(usageLine)) {
|
|
5
|
+
|
|
6
|
+
const exportLine =
|
|
7
|
+
editor.findLastLine("const router = ");
|
|
8
|
+
console.log("exportLine : ", exportLine);
|
|
9
|
+
|
|
10
|
+
editor.insertAfter({
|
|
11
|
+
line: exportLine,
|
|
12
|
+
content: usageLine
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import SourceEditor from "../../../common/SourceEditor.js";
|
|
2
|
+
|
|
3
|
+
import insertImport from "./insertImport.js";
|
|
4
|
+
import insertUsage from "./insertUsage.js";
|
|
5
|
+
|
|
6
|
+
export default ({ action = "", toPath }) => {
|
|
7
|
+
const funcName = "getFunc";
|
|
8
|
+
|
|
9
|
+
const path = `${toPath}/end-points.js`;
|
|
10
|
+
|
|
11
|
+
const editor = new SourceEditor(path);
|
|
12
|
+
|
|
13
|
+
const importLine =
|
|
14
|
+
`import { ${funcName} } from "./${action}/controller.js";`;
|
|
15
|
+
|
|
16
|
+
const usageLine =
|
|
17
|
+
`router.get('/${action}/:columnName', (req, res) => ${funcName}({ req, res, inTableName: tableName }));`
|
|
18
|
+
|
|
19
|
+
insertImport({
|
|
20
|
+
editor,
|
|
21
|
+
importLine
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
editor.save();
|
|
25
|
+
|
|
26
|
+
insertUsage({
|
|
27
|
+
editor,
|
|
28
|
+
usageLine
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
editor.save();
|
|
32
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// insertImport.js
|
|
2
|
+
|
|
3
|
+
export default ({ editor, importLine }) => {
|
|
4
|
+
|
|
5
|
+
if (!editor.hasLine(importLine)) {
|
|
6
|
+
|
|
7
|
+
const lastImportLine =
|
|
8
|
+
editor.findLastLine("import ");
|
|
9
|
+
|
|
10
|
+
editor.insertAfter({
|
|
11
|
+
line: lastImportLine,
|
|
12
|
+
content: importLine
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// insertUsage.js
|
|
2
|
+
export default ({ editor, usageLine }) => {
|
|
3
|
+
|
|
4
|
+
if (!editor.hasLine(usageLine)) {
|
|
5
|
+
|
|
6
|
+
const exportLine =
|
|
7
|
+
editor.findLastLine("const router = ");
|
|
8
|
+
console.log("exportLine : ", exportLine);
|
|
9
|
+
|
|
10
|
+
editor.insertAfter({
|
|
11
|
+
line: exportLine,
|
|
12
|
+
content: usageLine
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// bin/v9/tasks/actions/EndPointsJs/index.js
|
|
2
|
+
|
|
3
|
+
import SourceEditor from "../../../common/SourceEditor.js";
|
|
4
|
+
|
|
5
|
+
import insertImport from "./insertImport.js";
|
|
6
|
+
import insertUsage from "./insertUsage.js";
|
|
7
|
+
|
|
8
|
+
export default ({ action = "", toPath }) => {
|
|
9
|
+
|
|
10
|
+
const path = `${toPath}/end-points.js`;
|
|
11
|
+
|
|
12
|
+
const editor = new SourceEditor(path);
|
|
13
|
+
|
|
14
|
+
const importLine =
|
|
15
|
+
`import { postFunc } from "./${action}/controller.js";`;
|
|
16
|
+
|
|
17
|
+
const usageLine =
|
|
18
|
+
`router.post('/${action}', express.json(), (req, res) => postFunc({ req, res, inTableName: tableName }));`
|
|
19
|
+
|
|
20
|
+
insertImport({
|
|
21
|
+
editor,
|
|
22
|
+
importLine
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
editor.save();
|
|
26
|
+
|
|
27
|
+
insertUsage({
|
|
28
|
+
editor,
|
|
29
|
+
usageLine
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
editor.save();
|
|
33
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// insertImport.js
|
|
2
|
+
|
|
3
|
+
export default ({ editor, importLine }) => {
|
|
4
|
+
|
|
5
|
+
if (!editor.hasLine(importLine)) {
|
|
6
|
+
|
|
7
|
+
const lastImportLine =
|
|
8
|
+
editor.findLastLine("import ");
|
|
9
|
+
|
|
10
|
+
editor.insertAfter({
|
|
11
|
+
line: lastImportLine,
|
|
12
|
+
content: importLine
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// insertUsage.js
|
|
2
|
+
export default ({ editor, usageLine }) => {
|
|
3
|
+
|
|
4
|
+
if (!editor.hasLine(usageLine)) {
|
|
5
|
+
|
|
6
|
+
const exportLine =
|
|
7
|
+
editor.findLastLine("const router = ");
|
|
8
|
+
console.log("exportLine : ", exportLine);
|
|
9
|
+
|
|
10
|
+
editor.insertAfter({
|
|
11
|
+
line: exportLine,
|
|
12
|
+
content: usageLine
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// bin/v9/tasks/actions/EndPointsJs/index.js
|
|
2
|
+
|
|
3
|
+
import SourceEditor from "../../../common/SourceEditor.js";
|
|
4
|
+
|
|
5
|
+
import insertImport from "./insertImport.js";
|
|
6
|
+
import insertUsage from "./insertUsage.js";
|
|
7
|
+
|
|
8
|
+
export default ({ action = "", toPath }) => {
|
|
9
|
+
|
|
10
|
+
const path = `${toPath}/end-points.js`;
|
|
11
|
+
|
|
12
|
+
const editor = new SourceEditor(path);
|
|
13
|
+
|
|
14
|
+
const importLine =
|
|
15
|
+
`import { getFunc } from "./${action}/controller.js";`;
|
|
16
|
+
|
|
17
|
+
const usageLine =
|
|
18
|
+
`router.get('/${action}', (req, res) => getFunc({ res, inTableName : tableName}));`;
|
|
19
|
+
|
|
20
|
+
insertImport({
|
|
21
|
+
editor,
|
|
22
|
+
importLine
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
editor.save();
|
|
26
|
+
|
|
27
|
+
insertUsage({
|
|
28
|
+
editor,
|
|
29
|
+
usageLine
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
editor.save();
|
|
33
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// insertImport.js
|
|
2
|
+
|
|
3
|
+
export default ({ editor, importLine }) => {
|
|
4
|
+
|
|
5
|
+
if (!editor.hasLine(importLine)) {
|
|
6
|
+
|
|
7
|
+
const lastImportLine =
|
|
8
|
+
editor.findLastLine("import ");
|
|
9
|
+
|
|
10
|
+
editor.insertAfter({
|
|
11
|
+
line: lastImportLine,
|
|
12
|
+
content: importLine
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// insertUsage.js
|
|
2
|
+
export default ({ editor, usageLine }) => {
|
|
3
|
+
|
|
4
|
+
if (!editor.hasLine(usageLine)) {
|
|
5
|
+
|
|
6
|
+
const exportLine =
|
|
7
|
+
editor.findLastLine("const router = ");
|
|
8
|
+
console.log("exportLine : ", exportLine);
|
|
9
|
+
|
|
10
|
+
editor.insertAfter({
|
|
11
|
+
line: exportLine,
|
|
12
|
+
content: usageLine
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// bin/v11/tasks/actions/EndPointsJs/index.js
|
|
2
|
+
|
|
3
|
+
import showUsage from "./showUsage.js";
|
|
4
|
+
import actions from "../../../config/actions.json" with { type: "json" };
|
|
5
|
+
import alterJsFile from "./AlterJsFile/index.js";
|
|
6
|
+
|
|
7
|
+
export default async ({ action, toPath }) => {
|
|
8
|
+
const matchedAction = actions.find(
|
|
9
|
+
({ cmd }) => cmd === action
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
if (matchedAction) {
|
|
13
|
+
alterJsFile({
|
|
14
|
+
inImportLine: matchedAction.endPointsJs.importLine,
|
|
15
|
+
inUsageLine: matchedAction.endPointsJs.usageLine,
|
|
16
|
+
toPath
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
KSchema CLI – Entry Flow
|
|
3
|
+
|
|
4
|
+
1. Read user input from terminal (parseInput)
|
|
5
|
+
2. If no command → show usage (first-time user safety)
|
|
6
|
+
3. If help flags → show usage (quick guidance)
|
|
7
|
+
4. Resolve command dynamically (no hardcoding logic)
|
|
8
|
+
5. If command not found → inform + guide back to usage
|
|
9
|
+
6. Execute command with parsed input
|
|
10
|
+
|
|
11
|
+
Goal:
|
|
12
|
+
- Zero confusion for user
|
|
13
|
+
- Single source of truth (showUsage)
|
|
14
|
+
- Easy to extend (just add commands, no core changes)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export default function showUsage() {
|
|
18
|
+
const g = "\x1b[32m";
|
|
19
|
+
const y = "\x1b[33m";
|
|
20
|
+
const c = "\x1b[36m";
|
|
21
|
+
const gray = "\x1b[90m";
|
|
22
|
+
const r = "\x1b[0m";
|
|
23
|
+
|
|
24
|
+
console.log(`
|
|
25
|
+
${y}Usage:${r}
|
|
26
|
+
${g}npx kschema-api-gen endPointsJs${r} [options]
|
|
27
|
+
|
|
28
|
+
${y}options:${r}
|
|
29
|
+
${g}ShowAll${r} the action for get
|
|
30
|
+
${g}Insert${r} the action for post
|
|
31
|
+
${g}Distinct${r} the action for get and request param columnName
|
|
32
|
+
|
|
33
|
+
${y}Examples:${r}
|
|
34
|
+
${gray}npx kschema-api-gen endPointsJs ShowAll${r}
|
|
35
|
+
${gray}npx kschema-api-gen endPointsJs Insert${r}
|
|
36
|
+
${gray}npx kschema-api-gen endPointsJs Distinct${r}
|
|
37
|
+
`);
|
|
38
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// SourceEditor.js
|
|
2
|
+
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
|
|
5
|
+
class SourceEditor {
|
|
6
|
+
|
|
7
|
+
constructor(path) {
|
|
8
|
+
|
|
9
|
+
this.path = path;
|
|
10
|
+
|
|
11
|
+
this.content = fs.readFileSync(path, "utf-8");
|
|
12
|
+
|
|
13
|
+
this.lines = this.content.split("\n");
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
findLine(searchText) {
|
|
17
|
+
|
|
18
|
+
const index = this.lines.findIndex(line =>
|
|
19
|
+
line.includes(searchText)
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return index === -1
|
|
23
|
+
? null
|
|
24
|
+
: index + 1;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
findLastLine(searchText) {
|
|
28
|
+
|
|
29
|
+
let found = null;
|
|
30
|
+
|
|
31
|
+
this.lines.forEach((line, index) => {
|
|
32
|
+
|
|
33
|
+
if (line.includes(searchText)) {
|
|
34
|
+
|
|
35
|
+
found = index + 1;
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return found;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
hasLine(searchText) {
|
|
43
|
+
|
|
44
|
+
return this.findLine(searchText) !== null;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
insertAfter({ line, content }) {
|
|
48
|
+
|
|
49
|
+
this.lines.splice(line, 0, content);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
insertBefore({ line, content }) {
|
|
53
|
+
|
|
54
|
+
this.lines.splice(line - 1, 0, content);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
save() {
|
|
58
|
+
|
|
59
|
+
fs.writeFileSync(
|
|
60
|
+
this.path,
|
|
61
|
+
this.lines.join("\n")
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default SourceEditor;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import updateImports from "./updateImports/index.js";
|
|
2
|
+
import updateAppUse from "./updateUse/index.js";
|
|
3
|
+
|
|
4
|
+
const startFunc = ({ appJsPath, endpoint }) => {
|
|
5
|
+
updateImports({ appJsPath, endpoint });
|
|
6
|
+
updateAppUse({ appJsPath, endpoint });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default startFunc;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const buildImport = (inEndpoint) => {
|
|
2
|
+
const localEndpoint = inEndpoint;
|
|
3
|
+
|
|
4
|
+
const safeName = localEndpoint.replace(/[^a-zA-Z0-9]/g, "_");
|
|
5
|
+
|
|
6
|
+
return `import { router as routerFrom${safeName} } from "./${localEndpoint}/end-points.js";`;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default buildImport;
|
package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/findInsertIndex.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const findInsertIndex = (inContent) => {
|
|
2
|
+
const localContent = inContent;
|
|
3
|
+
|
|
4
|
+
const matches = [...localContent.matchAll(/^\s*import.*$/gm)];
|
|
5
|
+
const last = matches.at(-1);
|
|
6
|
+
|
|
7
|
+
return last ? last.index + last[0].length : 0;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default findInsertIndex;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import readFile from "../common/readFile.js";
|
|
2
|
+
import buildImport from "./buildImport.js";
|
|
3
|
+
import checkDuplicate from "./checkDuplicate.js";
|
|
4
|
+
import findInsertIndex from "./findInsertIndex.js";
|
|
5
|
+
import writeFile from "../common/writeFile.js";
|
|
6
|
+
|
|
7
|
+
const updateImports = ({ appJsPath, endpoint, showLog }) => {
|
|
8
|
+
const summary = {
|
|
9
|
+
import: { added: false, line: null },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const content = readFile(appJsPath);
|
|
13
|
+
const importLine = buildImport(endpoint);
|
|
14
|
+
|
|
15
|
+
if (checkDuplicate(content, endpoint)) {
|
|
16
|
+
summary.import.skipped = true;
|
|
17
|
+
|
|
18
|
+
if (showLog) console.log(summary);
|
|
19
|
+
|
|
20
|
+
return summary;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const index = findInsertIndex(content);
|
|
24
|
+
|
|
25
|
+
const before = content.slice(0, index);
|
|
26
|
+
const lineNumber = before.split("\n").length + 1;
|
|
27
|
+
|
|
28
|
+
const updated =
|
|
29
|
+
before + "\n" + importLine + content.slice(index);
|
|
30
|
+
|
|
31
|
+
writeFile(appJsPath, updated);
|
|
32
|
+
|
|
33
|
+
summary.import.added = true;
|
|
34
|
+
summary.import.line = lineNumber;
|
|
35
|
+
|
|
36
|
+
if (showLog) console.log(summary);
|
|
37
|
+
|
|
38
|
+
return summary;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default updateImports;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const appOrRouter = "router";
|
|
2
|
+
|
|
3
|
+
const buildUseLine = (inEndpoint) => {
|
|
4
|
+
const localEndpoint = inEndpoint;
|
|
5
|
+
|
|
6
|
+
const safeName = localEndpoint.replace(/[^a-zA-Z0-9]/g, "_");
|
|
7
|
+
|
|
8
|
+
return `${appOrRouter}.use("/${localEndpoint}", routerFrom${safeName});`;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default buildUseLine;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const findUseInsertIndex = (inContent) => {
|
|
2
|
+
const localContent = inContent;
|
|
3
|
+
|
|
4
|
+
const matches = [...localContent.matchAll(/const\s+router\s*=\s*express\.Router\(\)/g)];
|
|
5
|
+
const match = matches.at(0);
|
|
6
|
+
|
|
7
|
+
return match ? match.index + match[0].length : localContent.length;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default findUseInsertIndex;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import readFile from "../common/readFile.js";
|
|
2
|
+
import writeFile from "../common/writeFile.js";
|
|
3
|
+
|
|
4
|
+
import buildUseLine from "./buildUseLine.js";
|
|
5
|
+
import checkDuplicate from "./checkDuplicate.js";
|
|
6
|
+
import findUseInsertIndex from "./findInsertIndex.js";
|
|
7
|
+
|
|
8
|
+
const updateAppUse = ({ appJsPath, endpoint, showLog }) => {
|
|
9
|
+
const summary = {
|
|
10
|
+
use: { added: false, skipped: false, line: null }
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const content = readFile(appJsPath);
|
|
14
|
+
const useLine = buildUseLine(endpoint);
|
|
15
|
+
|
|
16
|
+
if (checkDuplicate(content, endpoint)) {
|
|
17
|
+
summary.use.skipped = true;
|
|
18
|
+
|
|
19
|
+
if (showLog) console.log(summary);
|
|
20
|
+
|
|
21
|
+
return summary;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const index = findUseInsertIndex(content);
|
|
25
|
+
|
|
26
|
+
const before = content.slice(0, index);
|
|
27
|
+
const lineNumber = before.split("\n").length + 1;
|
|
28
|
+
|
|
29
|
+
const updated =
|
|
30
|
+
before + "\n" + useLine + content.slice(index);
|
|
31
|
+
|
|
32
|
+
writeFile(appJsPath, updated);
|
|
33
|
+
|
|
34
|
+
summary.use.added = true;
|
|
35
|
+
summary.use.line = lineNumber;
|
|
36
|
+
|
|
37
|
+
if (showLog) console.log(summary);
|
|
38
|
+
|
|
39
|
+
return summary;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default updateAppUse;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const announce = ({ inResolvedFolderName }) => {
|
|
2
|
+
console.log(`[keshavsoft] Folder created: ${inResolvedFolderName}`);
|
|
3
|
+
|
|
4
|
+
console.log("");
|
|
5
|
+
console.log("Next:");
|
|
6
|
+
console.log("");
|
|
7
|
+
console.log(`cd ${inResolvedFolderName}`);
|
|
8
|
+
console.log(`npx kschema-api-gen AddSubRoute`);
|
|
9
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = path.dirname(__filename);
|
|
6
|
+
|
|
7
|
+
export const locateSource = () => {
|
|
8
|
+
return path.join(
|
|
9
|
+
__dirname,
|
|
10
|
+
"..",
|
|
11
|
+
"template"
|
|
12
|
+
);
|
|
13
|
+
};
|