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.
Files changed (138) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +225 -0
  3. package/bin/cli.js +12 -0
  4. package/bin/core/getLatestVersion.js +13 -0
  5. package/bin/core/loadRunner.js +9 -0
  6. package/bin/v10/commands/exportCommands/endPointsJs.js +5 -0
  7. package/bin/v10/core/createFolder.js +34 -0
  8. package/bin/v10/core/parseInput.js +9 -0
  9. package/bin/v10/core/resolveCommand.js +13 -0
  10. package/bin/v10/core/showUsage.js +39 -0
  11. package/bin/v10/start.js +22 -0
  12. package/bin/v10/tasks/actions/EndPointsJs/Distinct/index.js +32 -0
  13. package/bin/v10/tasks/actions/EndPointsJs/Distinct/insertImport.js +15 -0
  14. package/bin/v10/tasks/actions/EndPointsJs/Distinct/insertUsage.js +15 -0
  15. package/bin/v10/tasks/actions/EndPointsJs/Insert/index.js +33 -0
  16. package/bin/v10/tasks/actions/EndPointsJs/Insert/insertImport.js +15 -0
  17. package/bin/v10/tasks/actions/EndPointsJs/Insert/insertUsage.js +15 -0
  18. package/bin/v10/tasks/actions/EndPointsJs/ShowAll/index.js +33 -0
  19. package/bin/v10/tasks/actions/EndPointsJs/ShowAll/insertImport.js +15 -0
  20. package/bin/v10/tasks/actions/EndPointsJs/ShowAll/insertUsage.js +15 -0
  21. package/bin/v10/tasks/actions/EndPointsJs/index.js +37 -0
  22. package/bin/v10/tasks/actions/EndPointsJs/showUsage.js +38 -0
  23. package/bin/v10/tasks/actions/appJs.js +6 -0
  24. package/bin/v10/tasks/common/SourceEditor.js +66 -0
  25. package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/common/readFile.js +8 -0
  26. package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/common/writeFile.js +10 -0
  27. package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/index.js +9 -0
  28. package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
  29. package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
  30. package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
  31. package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/index.js +41 -0
  32. package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/buildUseLine.js +11 -0
  33. package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +8 -0
  34. package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
  35. package/bin/v10/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/index.js +42 -0
  36. package/bin/v10/tasks/tables/AddTableName/steps/announce.js +9 -0
  37. package/bin/v10/tasks/tables/AddTableName/steps/createFolder.js +7 -0
  38. package/bin/v10/tasks/tables/AddTableName/steps/decideTemplate.js +3 -0
  39. package/bin/v10/tasks/tables/AddTableName/steps/locateDestination.js +6 -0
  40. package/bin/v10/tasks/tables/AddTableName/steps/locateSource.js +13 -0
  41. package/bin/v10/tasks/tables/AddTableName/steps/resolveFolderName.js +20 -0
  42. package/bin/v10/tasks/tables/AddTableName/steps/updateConfig.js +16 -0
  43. package/bin/v10/tasks/tables/AddTableName/steps/updateEndPointsFile.js +30 -0
  44. package/bin/v10/tasks/tables/AddTableName/steps/updateTableName.js +30 -0
  45. package/bin/v10/tasks/tables/AddTableName/template/Config/schema.json +3 -0
  46. package/bin/v10/tasks/tables/AddTableName/template/end-points.js +7 -0
  47. package/bin/v10/tasks/tables/addTableName.js +56 -0
  48. package/bin/v11/commands/loadCommand.js +7 -0
  49. package/bin/v11/config/actions.json +35 -0
  50. package/bin/v11/config/actionsV1.json +20 -0
  51. package/bin/v11/config/actionsV2.json +27 -0
  52. package/bin/v11/core/createFolder.js +34 -0
  53. package/bin/v11/core/parseInput.js +8 -0
  54. package/bin/v11/core/resolveCommand.js +13 -0
  55. package/bin/v11/core/showUsage.js +39 -0
  56. package/bin/v11/start.js +29 -0
  57. package/bin/v11/tasks/actions/EndPointsJs/AlterJsFile/index.js +31 -0
  58. package/bin/v11/tasks/actions/EndPointsJs/AlterJsFile/insertImport.js +15 -0
  59. package/bin/v11/tasks/actions/EndPointsJs/AlterJsFile/insertUsage.js +15 -0
  60. package/bin/v11/tasks/actions/EndPointsJs/Distinct/index.js +32 -0
  61. package/bin/v11/tasks/actions/EndPointsJs/Distinct/insertImport.js +15 -0
  62. package/bin/v11/tasks/actions/EndPointsJs/Distinct/insertUsage.js +15 -0
  63. package/bin/v11/tasks/actions/EndPointsJs/Insert/index.js +33 -0
  64. package/bin/v11/tasks/actions/EndPointsJs/Insert/insertImport.js +15 -0
  65. package/bin/v11/tasks/actions/EndPointsJs/Insert/insertUsage.js +15 -0
  66. package/bin/v11/tasks/actions/EndPointsJs/ShowAll/index.js +33 -0
  67. package/bin/v11/tasks/actions/EndPointsJs/ShowAll/insertImport.js +15 -0
  68. package/bin/v11/tasks/actions/EndPointsJs/ShowAll/insertUsage.js +15 -0
  69. package/bin/v11/tasks/actions/EndPointsJs/index.js +19 -0
  70. package/bin/v11/tasks/actions/EndPointsJs/showUsage.js +38 -0
  71. package/bin/v11/tasks/actions/appJs.js +6 -0
  72. package/bin/v11/tasks/common/SourceEditor.js +66 -0
  73. package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/common/readFile.js +8 -0
  74. package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/common/writeFile.js +10 -0
  75. package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/index.js +9 -0
  76. package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
  77. package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
  78. package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
  79. package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/index.js +41 -0
  80. package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/buildUseLine.js +11 -0
  81. package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +8 -0
  82. package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
  83. package/bin/v11/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/index.js +42 -0
  84. package/bin/v11/tasks/tables/AddTableName/steps/announce.js +9 -0
  85. package/bin/v11/tasks/tables/AddTableName/steps/createFolder.js +7 -0
  86. package/bin/v11/tasks/tables/AddTableName/steps/decideTemplate.js +3 -0
  87. package/bin/v11/tasks/tables/AddTableName/steps/locateDestination.js +6 -0
  88. package/bin/v11/tasks/tables/AddTableName/steps/locateSource.js +13 -0
  89. package/bin/v11/tasks/tables/AddTableName/steps/resolveFolderName.js +20 -0
  90. package/bin/v11/tasks/tables/AddTableName/steps/updateConfig.js +16 -0
  91. package/bin/v11/tasks/tables/AddTableName/steps/updateEndPointsFile.js +30 -0
  92. package/bin/v11/tasks/tables/AddTableName/steps/updateTableName.js +30 -0
  93. package/bin/v11/tasks/tables/AddTableName/template/Config/schema.json +3 -0
  94. package/bin/v11/tasks/tables/AddTableName/template/end-points.js +7 -0
  95. package/bin/v11/tasks/tables/addTableName.js +56 -0
  96. package/bin/v12/commands/loadCommand.js +7 -0
  97. package/bin/v12/config/actions.json +46 -0
  98. package/bin/v12/config/actionsV1.json +20 -0
  99. package/bin/v12/config/actionsV2.json +27 -0
  100. package/bin/v12/config/actionsV3.json +35 -0
  101. package/bin/v12/config/actionsV4.json +35 -0
  102. package/bin/v12/core/createFolder.js +34 -0
  103. package/bin/v12/core/parseInput.js +8 -0
  104. package/bin/v12/core/resolveCommand.js +13 -0
  105. package/bin/v12/core/showUsage.js +39 -0
  106. package/bin/v12/start.js +21 -0
  107. package/bin/v12/tasks/actions/EndPointsJs/AlterJsFile/index.js +31 -0
  108. package/bin/v12/tasks/actions/EndPointsJs/AlterJsFile/insertImport.js +15 -0
  109. package/bin/v12/tasks/actions/EndPointsJs/AlterJsFile/insertUsage.js +15 -0
  110. package/bin/v12/tasks/actions/EndPointsJs/index.js +19 -0
  111. package/bin/v12/tasks/actions/EndPointsJs/showUsage.js +38 -0
  112. package/bin/v12/tasks/actions/appJs.js +6 -0
  113. package/bin/v12/tasks/common/SourceEditor.js +66 -0
  114. package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/common/readFile.js +8 -0
  115. package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/common/writeFile.js +10 -0
  116. package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/index.js +9 -0
  117. package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
  118. package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
  119. package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
  120. package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateImports/index.js +41 -0
  121. package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/buildUseLine.js +11 -0
  122. package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +8 -0
  123. package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
  124. package/bin/v12/tasks/tables/AddTableName/steps/UpdateRoutesJs/updateUse/index.js +42 -0
  125. package/bin/v12/tasks/tables/AddTableName/steps/announce.js +9 -0
  126. package/bin/v12/tasks/tables/AddTableName/steps/createFolder.js +7 -0
  127. package/bin/v12/tasks/tables/AddTableName/steps/decideTemplate.js +3 -0
  128. package/bin/v12/tasks/tables/AddTableName/steps/locateDestination.js +6 -0
  129. package/bin/v12/tasks/tables/AddTableName/steps/locateSource.js +13 -0
  130. package/bin/v12/tasks/tables/AddTableName/steps/resolveFolderName.js +20 -0
  131. package/bin/v12/tasks/tables/AddTableName/steps/updateConfig.js +16 -0
  132. package/bin/v12/tasks/tables/AddTableName/steps/updateEndPointsFile.js +30 -0
  133. package/bin/v12/tasks/tables/AddTableName/steps/updateTableName.js +30 -0
  134. package/bin/v12/tasks/tables/AddTableName/template/Config/schema.json +3 -0
  135. package/bin/v12/tasks/tables/AddTableName/template/end-points.js +7 -0
  136. package/bin/v12/tasks/tables/addTableName.js +56 -0
  137. package/index.js +5 -0
  138. package/package.json +35 -0
@@ -0,0 +1,20 @@
1
+ import fs from "fs";
2
+
3
+ export default function resolveFolderName({ name }) {
4
+ const defaultFolerName = "KSTable1";
5
+
6
+ // case 1: force new → timestamp
7
+ if (name === null) {
8
+ name = defaultFolerName;
9
+ };
10
+
11
+ // case 2: user provided → strict
12
+ if (fs.existsSync(name)) {
13
+ return {
14
+ KTF: false,
15
+ KReason: `Folder already exists : ${name}`
16
+ };
17
+ };
18
+
19
+ return name;
20
+ };
@@ -0,0 +1,16 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ export function updateConfigFile({ inEndpointFolder, inTableName }) {
5
+ const filePath = path.join(inEndpointFolder, "Config", "schema.json");
6
+
7
+ // Read Synchronously
8
+ const rawData = fs.readFileSync(filePath);
9
+ const data = JSON.parse(rawData);
10
+ data.tableName = `${inTableName}.json`;
11
+
12
+ // // Write Synchronously
13
+ const jsonString = JSON.stringify(data, null, 2);
14
+ fs.writeFileSync(filePath, jsonString);
15
+
16
+ };
@@ -0,0 +1,30 @@
1
+ import fs from 'fs';
2
+
3
+ function updateEndPointsFile({ filePath, inTableName }) {
4
+ try {
5
+ let content = readFile(filePath);
6
+
7
+ content = content.replace("<TABLE_NAME>", inTableName);
8
+
9
+ writeFile(filePath, content);
10
+ } catch (e) {
11
+ handleError(e);
12
+ };
13
+ };
14
+
15
+ // read
16
+ function readFile(filePath) {
17
+ return fs.readFileSync(filePath, "utf-8");
18
+ };
19
+
20
+ // write
21
+ function writeFile(filePath, content) {
22
+ fs.writeFileSync(filePath, content);
23
+ };
24
+
25
+ // error handler
26
+ function handleError(e) {
27
+ console.error("ROUTE USE ERROR:", e.message);
28
+ };
29
+
30
+ export { updateEndPointsFile };
@@ -0,0 +1,30 @@
1
+ import fs from 'fs';
2
+
3
+ function startFunc({ filePath, inTableName }) {
4
+ try {
5
+ let content = readFile(filePath);
6
+
7
+ content = content.replace("<TABLE_NAME>", inTableName);
8
+
9
+ writeFile(filePath, content);
10
+ } catch (e) {
11
+ handleError(e);
12
+ };
13
+ };
14
+
15
+ // read
16
+ function readFile(filePath) {
17
+ return fs.readFileSync(filePath, "utf-8");
18
+ };
19
+
20
+ // write
21
+ function writeFile(filePath, content) {
22
+ fs.writeFileSync(filePath, content);
23
+ };
24
+
25
+ // error handler
26
+ function handleError(e) {
27
+ console.error("ROUTE USE ERROR:", e.message);
28
+ };
29
+
30
+ export default startFunc;
@@ -0,0 +1,3 @@
1
+ {
2
+ "tableName": "<KSTable.json>"
3
+ }
@@ -0,0 +1,7 @@
1
+ import express from 'express';
2
+
3
+ const tableName = "<TABLE_NAME>";
4
+
5
+ const router = express.Router();
6
+
7
+ export { router };
@@ -0,0 +1,56 @@
1
+ import { locateSource } from "./AddTableName/steps/locateSource.js";
2
+ import { locateDestination } from "./AddTableName/steps/locateDestination.js";
3
+ import { createFolder } from "../../core/createFolder.js";
4
+ import UpdateRoutesJs from "./AddTableName/steps/UpdateRoutesJs/index.js";
5
+ import { updateEndPointsFile } from "./AddTableName/steps/updateEndPointsFile.js";
6
+ import { updateConfigFile } from "./AddTableName/steps/updateConfig.js";
7
+
8
+ import { announce } from "./AddTableName/steps/announce.js";
9
+
10
+ import resolveFolderName from "./AddTableName/steps/resolveFolderName.js";
11
+
12
+ export default ({ folderName = "", toPath, isAnnounce = true, checkBeforeCreate = true }) => {
13
+ const localToPath = toPath;
14
+
15
+ const resolvedFolderName = resolveFolderName({
16
+ name: folderName
17
+ });
18
+
19
+ if (resolvedFolderName.KTF === false) {
20
+ console.log(resolvedFolderName.KReason);
21
+
22
+ return folderName;
23
+ };
24
+
25
+ const source = locateSource();
26
+ const destination = locateDestination({
27
+ inResolvedFolderName: resolvedFolderName,
28
+ toPath: localToPath
29
+ });
30
+
31
+ const createFolderResponse = createFolder({
32
+ source, destination,
33
+ isAnnounce, checkBeforeCreate
34
+ });
35
+
36
+ if (createFolderResponse.KTF) {
37
+ UpdateRoutesJs({
38
+ appJsPath: `${localToPath}/routes.js`,
39
+ endpoint: resolvedFolderName
40
+ });
41
+
42
+ updateEndPointsFile({
43
+ filePath: `${destination}/end-points.js`,
44
+ inTableName: resolvedFolderName
45
+ });
46
+
47
+ updateConfigFile({
48
+ inEndpointFolder: destination,
49
+ inTableName: resolvedFolderName
50
+ });
51
+ };
52
+
53
+ if (isAnnounce) announce({ inResolvedFolderName: resolvedFolderName });
54
+
55
+ return resolvedFolderName;
56
+ };
@@ -0,0 +1,7 @@
1
+ // bin/v11/commands/loadCommand.js
2
+
3
+ import endPointsJs from "../tasks/actions/EndPointsJs/index.js"
4
+
5
+ export default async function loadCommand(name) {
6
+ await endPointsJs({ action: name });
7
+ };
@@ -0,0 +1,46 @@
1
+ [
2
+ {
3
+ "cmd": "ShowAll",
4
+ "file": "showAll",
5
+ "exportFile": "ShowAll",
6
+ "group": "GetMethods",
7
+ "description": "Generate ShowAll GET action",
8
+ "endPointsJs": {
9
+ "importLine": "import { getFunc } from './ShowAll/controller.js';",
10
+ "usageLine": "router.get('/ShowAll', (req, res) => getFunc({ res, inTableName : tableName}));"
11
+ }
12
+ },
13
+ {
14
+ "cmd": "Insert",
15
+ "file": "insert",
16
+ "exportFile": "Insert",
17
+ "group": "PostMethods",
18
+ "description": "Generate Insert POST action",
19
+ "endPointsJs": {
20
+ "importLine": "import { postFunc } from './Insert/controller.js';",
21
+ "usageLine": "router.post('/Insert', express.json(), (req, res) => postFunc({ req, res, inTableName : tableName}));"
22
+ }
23
+ },
24
+ {
25
+ "cmd": "Distinct",
26
+ "file": "distinct",
27
+ "exportFile": "Distinct",
28
+ "group": "GetMethods",
29
+ "description": "Generate Distinct GET action",
30
+ "endPointsJs": {
31
+ "importLine": "import distinctFunc from './Distinct/controller.js';",
32
+ "usageLine": "router.get('/Distinct/:columnName', (req, res) => distinctFunc({ req, res, inTableName : tableName}));"
33
+ }
34
+ },
35
+ {
36
+ "cmd": "FilterColumns",
37
+ "file": "filterColumns",
38
+ "exportFile": "FilterColumns",
39
+ "group": "PostMethods",
40
+ "description": "Generate FilterColumns POST action",
41
+ "endPointsJs": {
42
+ "importLine": "import filterColumnsFunc from './FilterColumns/controller.js';",
43
+ "usageLine": "router.post('/FilterColumns', express.json(), (req, res) => filterColumnsFunc({ req, res, inTableName : tableName}));"
44
+ }
45
+ }
46
+ ]
@@ -0,0 +1,20 @@
1
+ [
2
+ {
3
+ "cmd": "showAll",
4
+ "file": "showAll",
5
+ "exportFile": "ShowAll",
6
+ "group": "GetMethods"
7
+ },
8
+ {
9
+ "cmd": "insert",
10
+ "file": "insert",
11
+ "exportFile": "Insert",
12
+ "group": "PostMethods"
13
+ },
14
+ {
15
+ "cmd": "distinct",
16
+ "file": "distinct",
17
+ "exportFile": "Distinct",
18
+ "group": "GetMethods"
19
+ }
20
+ ]
@@ -0,0 +1,27 @@
1
+ [
2
+ {
3
+ "cmd": "ShowAll",
4
+ "file": "showAll",
5
+ "exportFile": "ShowAll",
6
+ "group": "GetMethods",
7
+ "description": "Generate ShowAll GET action",
8
+ "endPointsJs": {
9
+ "importLine": "import { getFunc } from './ShowAll/controller.js';",
10
+ "usageLine": "router.get('/ShowAll', (req, res) => getFunc({ res, inTableName : tableName}));"
11
+ }
12
+ },
13
+ {
14
+ "cmd": "Insert",
15
+ "file": "insert",
16
+ "exportFile": "Insert",
17
+ "group": "PostMethods",
18
+ "description": "Generate Insert POST action"
19
+ },
20
+ {
21
+ "cmd": "Distinct",
22
+ "file": "distinct",
23
+ "exportFile": "Distinct",
24
+ "group": "GetMethods",
25
+ "description": "Generate Distinct GET action"
26
+ }
27
+ ]
@@ -0,0 +1,35 @@
1
+ [
2
+ {
3
+ "cmd": "ShowAll",
4
+ "file": "showAll",
5
+ "exportFile": "ShowAll",
6
+ "group": "GetMethods",
7
+ "description": "Generate ShowAll GET action",
8
+ "endPointsJs": {
9
+ "importLine": "import { getFunc } from './ShowAll/controller.js';",
10
+ "usageLine": "router.get('/ShowAll', (req, res) => getFunc({ res, inTableName : tableName}));"
11
+ }
12
+ },
13
+ {
14
+ "cmd": "Insert",
15
+ "file": "insert",
16
+ "exportFile": "Insert",
17
+ "group": "PostMethods",
18
+ "description": "Generate Insert POST action",
19
+ "endPointsJs": {
20
+ "importLine": "import { postFunc } from './Insert/controller.js';",
21
+ "usageLine": "router.post('/Insert', express.json(), (req, res) => postFunc({ req, res, inTableName : tableName}));"
22
+ }
23
+ },
24
+ {
25
+ "cmd": "Distinct",
26
+ "file": "distinct",
27
+ "exportFile": "Distinct",
28
+ "group": "GetMethods",
29
+ "description": "Generate Distinct GET action",
30
+ "endPointsJs": {
31
+ "importLine": "import { getFunc } from './Distinct/controller.js';",
32
+ "usageLine": "router.get('/Distinct/:columnName', (req, res) => getFunc({ req, res, inTableName : tableName}));"
33
+ }
34
+ }
35
+ ]
@@ -0,0 +1,35 @@
1
+ [
2
+ {
3
+ "cmd": "ShowAll",
4
+ "file": "showAll",
5
+ "exportFile": "ShowAll",
6
+ "group": "GetMethods",
7
+ "description": "Generate ShowAll GET action",
8
+ "endPointsJs": {
9
+ "importLine": "import { getFunc } from './ShowAll/controller.js';",
10
+ "usageLine": "router.get('/ShowAll', (req, res) => getFunc({ res, inTableName : tableName}));"
11
+ }
12
+ },
13
+ {
14
+ "cmd": "Insert",
15
+ "file": "insert",
16
+ "exportFile": "Insert",
17
+ "group": "PostMethods",
18
+ "description": "Generate Insert POST action",
19
+ "endPointsJs": {
20
+ "importLine": "import { postFunc } from './Insert/controller.js';",
21
+ "usageLine": "router.post('/Insert', express.json(), (req, res) => postFunc({ req, res, inTableName : tableName}));"
22
+ }
23
+ },
24
+ {
25
+ "cmd": "Distinct",
26
+ "file": "distinct",
27
+ "exportFile": "Distinct",
28
+ "group": "GetMethods",
29
+ "description": "Generate Distinct GET action",
30
+ "endPointsJs": {
31
+ "importLine": "import distinctFunc from './Distinct/controller.js';",
32
+ "usageLine": "router.get('/Distinct/:columnName', (req, res) => distinctFunc({ req, res, inTableName : tableName}));"
33
+ }
34
+ }
35
+ ]
@@ -0,0 +1,34 @@
1
+ import fs from "fs";
2
+
3
+ export const createFolder = ({ source, destination, checkBeforeCreate = false, isAnnounce = true }) => {
4
+ if (checkBeforeCreate) {
5
+ return createFolderWithCheck({ source, destination, isAnnounce });
6
+ } else {
7
+ return createOnly({ source, destination });
8
+ };
9
+ };
10
+
11
+ const createOnly = ({ source, destination }) => {
12
+ fs.mkdirSync(destination, { recursive: true });
13
+
14
+ fs.cpSync(source, destination, { recursive: true });
15
+
16
+ return {
17
+ KTF: true
18
+ };
19
+ };
20
+
21
+ const createFolderWithCheck = ({ source, destination, isAnnounce }) => {
22
+ if (fs.existsSync(destination)) {
23
+ if (isAnnounce) console.log("Folder already exists :", destination);
24
+
25
+ return {
26
+ KTF: false,
27
+ KReason: "Folder already exists"
28
+ };
29
+ };
30
+
31
+ if (isAnnounce) console.log("Folder created :", destination);
32
+
33
+ return createOnly({ source, destination });
34
+ };
@@ -0,0 +1,8 @@
1
+ export default function parseInput() {
2
+ const [action] = process.argv.slice(2);
3
+
4
+ return {
5
+ action: action || null,
6
+ toPath: process.cwd()
7
+ };
8
+ };
@@ -0,0 +1,13 @@
1
+ // import endPointsJs from "../tasks/actions/EndPointsJs/ShowAll/index.js";
2
+ import appJs from "../tasks/actions/appJs.js";
3
+ import endPointsJs from "../tasks/actions/EndPointsJs/index.js";
4
+
5
+ // resolveCommand.js
6
+ const map = {
7
+ endPointsJs,
8
+ appJs
9
+ };
10
+
11
+ export default function resolveCommand(cmd) {
12
+ return map[cmd] || null;
13
+ };
@@ -0,0 +1,39 @@
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(version) {
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
+ ${c}🚀 KSchema Api Generator v${version}${r}
26
+
27
+ ${y}Usage:${r}
28
+ ${g}npx @keshavsoft/kschema-api-gen${r} <command> [options]
29
+
30
+ ${y}Commands:${r}
31
+ ${g}endPointsJs${r} Checks for end-points.js file in that location
32
+
33
+ ${y}Examples:${r}
34
+ ${gray}npx @keshavsoft/kschema-api-gen endPointsJs ShowAll${r}
35
+
36
+ ${y}Tip:${r}
37
+ ${gray}npm i -g @keshavsoft/kschema-api-gen${r}
38
+ `);
39
+ }
@@ -0,0 +1,21 @@
1
+ import parseInput from "./core/parseInput.js";
2
+ import showUsage from './core/showUsage.js';
3
+
4
+ import resolveCommand from "./tasks/actions/EndPointsJs/index.js";
5
+
6
+ import pkg from '../../package.json' with { type: 'json' };
7
+
8
+ const version = pkg.version;
9
+
10
+ const run = async () => {
11
+ const input = parseInput();
12
+
13
+ if (input.action === "--help" || input.action === "-h" || input.action === "help") return showUsage(version);
14
+
15
+ await resolveCommand({
16
+ action: input.action,
17
+ toPath: input.toPath
18
+ });
19
+ };
20
+
21
+ 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,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,6 @@
1
+ import path from "path";
2
+
3
+ export default ({ action = "", toPath, cmd, isAnnounce = true, checkBeforeCreate = true }) => {
4
+ const localToPath = toPath;
5
+ console.log(" aaaaaaaaa :", cmd, action, toPath);
6
+ };
@@ -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,8 @@
1
+ import fs from "fs";
2
+
3
+ const readFile = (inAppJsPath) => {
4
+ const localPath = inAppJsPath;
5
+ return fs.readFileSync(localPath, "utf-8");
6
+ };
7
+
8
+ export default readFile;