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
|
@@ -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/v10/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
|
+
};
|
|
@@ -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,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,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,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,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,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
|
+
}
|