@keshavsoft/kschema-api-gen-actions 1.16.3 → 1.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +1 -1
- package/bin/v17/commands/loadCommand.js +11 -0
- package/bin/v17/config/actions.json +46 -0
- package/bin/v17/config/actionsV1.json +20 -0
- package/bin/v17/config/actionsV2.json +23 -0
- package/bin/v17/config/actionsV3.json +35 -0
- package/bin/v17/core/createFolder.js +34 -0
- package/bin/v17/core/parseInput.js +8 -0
- package/bin/v17/core/resolveCommand.js +11 -0
- package/bin/v17/core/showUsage.js +49 -0
- package/bin/v17/start.js +22 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/UpdateRoutesJs/updateImports/index.js +45 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/UpdateRoutesJs/updateUse/buildUseLine.js +9 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +8 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/UpdateRoutesJs/updateUse/index.js +46 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/announce.js +9 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/createFolder.js +7 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/createHttpFile.js +12 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/decideTemplate.js +3 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/locateDestination.js +7 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/locateSource.js +13 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/resolveFolderName.js +20 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/updateAppJs.js +7 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/updateEndPointsFile.js +30 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/steps/updateEndPointsJs.js +16 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/template/controller.js +26 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/template/errors.js +11 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V1/template/service.js +12 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/UpdateRoutesJs/updateImports/index.js +45 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/UpdateRoutesJs/updateUse/buildUseLine.js +9 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +8 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/UpdateRoutesJs/updateUse/index.js +46 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/announce.js +9 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/createFolder.js +7 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/createHttpFile.js +12 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/decideTemplate.js +3 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/locateDestination.js +7 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/locateSource.js +13 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/resolveFolderName.js +20 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/updateAppJs.js +7 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/updateEndPointsFile.js +30 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/steps/updateEndPointsJs.js +16 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/template/controller.js +26 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/template/errors.js +11 -0
- package/bin/v17/tasks/actions/GetMethods/Distinct/V2/template/service.js +12 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateImports/index.js +45 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateUse/buildUseLine.js +9 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +8 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateUse/index.js +46 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/announce.js +9 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/createFolder.js +7 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/createHttpFile.js +12 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/decideTemplate.js +3 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/locateDestination.js +7 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/locateSource.js +13 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/resolveFolderName.js +20 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/updateAppJs.js +7 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/updateEndPointsFile.js +30 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/steps/updateEndPointsJs.js +16 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/template/controller.js +21 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/template/errors.js +11 -0
- package/bin/v17/tasks/actions/GetMethods/ShowAll/template/service.js +9 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/UpdateRoutesJs/updateImports/index.js +47 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/UpdateRoutesJs/updateUse/buildUseLine.js +5 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +9 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/UpdateRoutesJs/updateUse/index.js +56 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/announce.js +9 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/createFolder.js +7 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/createHttpFile.js +12 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/decideTemplate.js +3 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/locateDestination.js +7 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/locateSource.js +13 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/resolveFolderName.js +20 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/updateAppJs.js +7 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/updateEndPointsFile.js +30 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/steps/updateEndPointsJs.js +16 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/template/controller.js +27 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/template/errors.js +11 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/template/middleware.js +19 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/template/rest.http +4 -0
- package/bin/v17/tasks/actions/PostMethods/FilterColumns/template/service.js +9 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateImports/index.js +47 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateUse/buildUseLine.js +5 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +9 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateUse/index.js +56 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/announce.js +9 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/createFolder.js +7 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/createHttpFile.js +12 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/decideTemplate.js +3 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/locateDestination.js +7 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/locateSource.js +13 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/resolveFolderName.js +20 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/updateAppJs.js +7 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/updateEndPointsFile.js +30 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/steps/updateEndPointsJs.js +16 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/template/controller.js +24 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/template/errors.js +11 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/template/middleware.js +19 -0
- package/bin/v17/tasks/actions/PostMethods/Insert/template/service.js +11 -0
- package/bin/v17/tasks/actions/distinct.js +55 -0
- package/bin/v17/tasks/actions/filterColumns.js +56 -0
- package/bin/v17/tasks/actions/insert.js +59 -0
- package/bin/v17/tasks/actions/showAll.js +53 -0
- package/bin/v17/tasks/core/createFolder.js +34 -0
- package/bin/v17/tasks/core/parseInput.js +12 -0
- package/bin/v17/tasks/core/resolveCommand.js +24 -0
- package/bin/v17/tasks/core/showUsage.js +43 -0
- package/package.json +1 -1
|
@@ -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,12 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
const createHttpFile = ({ inTargetPath, toPath }) => {
|
|
5
|
+
const relative = inTargetPath.replace(toPath, "").replace(/\\/g, "/");
|
|
6
|
+
|
|
7
|
+
const content = `GET http://localhost:3000${relative}`;
|
|
8
|
+
|
|
9
|
+
fs.writeFileSync(path.join(inTargetPath, "rest.http"), content);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default createHttpFile;
|
|
@@ -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, inDefaultFolderName = "Insert" }) {
|
|
4
|
+
const defaultFolderName = inDefaultFolderName;
|
|
5
|
+
|
|
6
|
+
// case 1: force new → timestamp
|
|
7
|
+
if (name === null) {
|
|
8
|
+
name = defaultFolderName;
|
|
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,7 @@
|
|
|
1
|
+
import updateImports from "./UpdateRoutesJs/updateImports/index.js";
|
|
2
|
+
import updateAppUse from "./UpdateRoutesJs/updateUse/index.js";
|
|
3
|
+
|
|
4
|
+
export default ({ appJsPath, endpoint }) => {
|
|
5
|
+
updateImports({ appJsPath, endpoint });
|
|
6
|
+
updateAppUse({ appJsPath, endpoint });
|
|
7
|
+
};
|
|
@@ -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,16 @@
|
|
|
1
|
+
import updateImports from "./UpdateRoutesJs/updateImports/index.js";
|
|
2
|
+
import updateAppUse from "./UpdateRoutesJs/updateUse/index.js";
|
|
3
|
+
|
|
4
|
+
const funcName = "getFunc";
|
|
5
|
+
|
|
6
|
+
export default ({ appJsPath, endpoint }) => {
|
|
7
|
+
updateImports({
|
|
8
|
+
appJsPath, endpoint,
|
|
9
|
+
inFuncName: funcName
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
updateAppUse({
|
|
13
|
+
appJsPath, endpoint,
|
|
14
|
+
inFuncName: funcName
|
|
15
|
+
});
|
|
16
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { startFunc as Service } from "./service.js";
|
|
2
|
+
import { ConflictError, StorageError } from "./errors.js";
|
|
3
|
+
|
|
4
|
+
const postFunc = async ({ req, res, inTableName }) => {
|
|
5
|
+
try {
|
|
6
|
+
const inRequestBody = req.body;
|
|
7
|
+
|
|
8
|
+
const fromService = await Service({ inRequestBody, inTableName });
|
|
9
|
+
|
|
10
|
+
res.type("application/json").send(fromService);
|
|
11
|
+
} catch (err) {
|
|
12
|
+
|
|
13
|
+
if (err instanceof ConflictError)
|
|
14
|
+
return res.status(409).send(err.message);
|
|
15
|
+
|
|
16
|
+
if (err instanceof StorageError)
|
|
17
|
+
return res.status(500).send("Failed to persist data");
|
|
18
|
+
|
|
19
|
+
console.error(err);
|
|
20
|
+
res.status(500).send("Unexpected error");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { postFunc };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class AppError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = this.constructor.name;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class ConflictError extends AppError { }
|
|
9
|
+
class StorageError extends AppError { }
|
|
10
|
+
|
|
11
|
+
export { AppError, ConflictError, StorageError };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const StartFunc = (req, res, next) => {
|
|
2
|
+
const LocalBody = req.body;
|
|
3
|
+
|
|
4
|
+
if (!LocalBody || Object.keys(LocalBody).length === 0) {
|
|
5
|
+
return res.status(400).send("Request body should not be empty.");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (Array.isArray(LocalBody)) {
|
|
9
|
+
return res.status(400).send("Remove The Array From The Body.");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (typeof LocalBody === 'object' && Object.keys(LocalBody).length === 0) {
|
|
13
|
+
return res.status(400).send("Request body should not be an empty object.");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
next();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { StartFunc };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { kschema } from "@keshavsoft/kschema";
|
|
2
|
+
|
|
3
|
+
const startFunc = async ({ inRequestBody, inTableName }) => {
|
|
4
|
+
const tableName = inTableName;
|
|
5
|
+
|
|
6
|
+
const insertedPk = await kschema.table(tableName).mutate.insertGenPk(inRequestBody);
|
|
7
|
+
|
|
8
|
+
return await insertedPk;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { startFunc };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import endPointsJs from "@keshavsoft/kschema-api-check";
|
|
3
|
+
|
|
4
|
+
import { locateSource } from "./GetMethods/Distinct/V2/steps/locateSource.js";
|
|
5
|
+
import { locateDestination } from "./GetMethods/Distinct/V2/steps/locateDestination.js";
|
|
6
|
+
import { createFolder } from "../core/createFolder.js";
|
|
7
|
+
|
|
8
|
+
import createHttpFile from "./GetMethods/Distinct/V2/steps/createHttpFile.js";
|
|
9
|
+
|
|
10
|
+
import { announce } from "./GetMethods/Distinct/V2/steps/announce.js";
|
|
11
|
+
|
|
12
|
+
import resolveFolderName from "./GetMethods/Distinct/V2/steps/resolveFolderName.js";
|
|
13
|
+
|
|
14
|
+
const startFunc = async ({ cmd = "", toPath, isAnnounce = true, checkBeforeCreate = true }) => {
|
|
15
|
+
const localToPath = toPath;
|
|
16
|
+
|
|
17
|
+
const resolvedFolderName = resolveFolderName({
|
|
18
|
+
name: cmd
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (resolvedFolderName.KTF === false) {
|
|
22
|
+
console.log(resolvedFolderName.KReason);
|
|
23
|
+
|
|
24
|
+
return;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const source = locateSource();
|
|
28
|
+
const destination = locateDestination({
|
|
29
|
+
inResolvedFolderName: resolvedFolderName,
|
|
30
|
+
toPath: localToPath
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const createFolderResponse = createFolder({
|
|
34
|
+
source, destination,
|
|
35
|
+
isAnnounce, checkBeforeCreate
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (createFolderResponse.KTF) {
|
|
39
|
+
await endPointsJs({
|
|
40
|
+
toPath: localToPath,
|
|
41
|
+
action: resolvedFolderName
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
createHttpFile({
|
|
45
|
+
inTargetPath: path.join(localToPath, resolvedFolderName),
|
|
46
|
+
toPath: process.cwd()
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (isAnnounce) announce({ inResolvedFolderName: resolvedFolderName });
|
|
51
|
+
|
|
52
|
+
return resolveFolderName;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default startFunc
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import apiCheck from "@keshavsoft/kschema-api-check";
|
|
3
|
+
|
|
4
|
+
import { locateSource } from "./PostMethods/FilterColumns/steps/locateSource.js";
|
|
5
|
+
import { locateDestination } from "./PostMethods/FilterColumns/steps/locateDestination.js";
|
|
6
|
+
import { createFolder } from "../../core/createFolder.js";
|
|
7
|
+
|
|
8
|
+
import updateEndPointsJs from "./PostMethods/FilterColumns/steps/updateEndPointsJs.js";
|
|
9
|
+
import createHttpFile from "./PostMethods/FilterColumns/steps/createHttpFile.js";
|
|
10
|
+
|
|
11
|
+
import { announce } from "./PostMethods/FilterColumns/steps/announce.js";
|
|
12
|
+
|
|
13
|
+
import resolveFolderName from "./PostMethods/FilterColumns/steps/resolveFolderName.js";
|
|
14
|
+
|
|
15
|
+
const startFunc = async ({ cmd = "", toPath, isAnnounce = true, checkBeforeCreate = true }) => {
|
|
16
|
+
const localToPath = toPath;
|
|
17
|
+
|
|
18
|
+
const resolvedFolderName = resolveFolderName({
|
|
19
|
+
name: cmd
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (resolvedFolderName.KTF === false) {
|
|
23
|
+
console.log(resolvedFolderName.KReason);
|
|
24
|
+
|
|
25
|
+
return;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const source = locateSource();
|
|
29
|
+
const destination = locateDestination({
|
|
30
|
+
inResolvedFolderName: resolvedFolderName,
|
|
31
|
+
toPath: localToPath
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const createFolderResponse = createFolder({
|
|
35
|
+
source, destination,
|
|
36
|
+
isAnnounce, checkBeforeCreate
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (createFolderResponse.KTF) {
|
|
40
|
+
await apiCheck({
|
|
41
|
+
toPath: localToPath,
|
|
42
|
+
action: resolvedFolderName
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
createHttpFile({
|
|
46
|
+
inTargetPath: path.join(localToPath, resolvedFolderName),
|
|
47
|
+
toPath: process.cwd()
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
if (isAnnounce) announce({ inResolvedFolderName: resolvedFolderName });
|
|
52
|
+
|
|
53
|
+
return resolvedFolderName;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default startFunc;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { endPointsJs } from "@keshavsoft/kschema-api-check";
|
|
3
|
+
|
|
4
|
+
import { locateSource } from "./PostMethods/Insert/steps/locateSource.js";
|
|
5
|
+
import { locateDestination } from "./PostMethods/Insert/steps/locateDestination.js";
|
|
6
|
+
import { createFolder } from "../../core/createFolder.js";
|
|
7
|
+
|
|
8
|
+
import updateEndPointsJs from "./PostMethods/Insert/steps/updateEndPointsJs.js";
|
|
9
|
+
import createHttpFile from "./PostMethods/Insert/steps/createHttpFile.js";
|
|
10
|
+
|
|
11
|
+
import { announce } from "./PostMethods/Insert/steps/announce.js";
|
|
12
|
+
|
|
13
|
+
import resolveFolderName from "./PostMethods/Insert/steps/resolveFolderName.js";
|
|
14
|
+
|
|
15
|
+
export default ({ cmd = "", toPath, isAnnounce = true, checkBeforeCreate = true }) => {
|
|
16
|
+
const localToPath = toPath;
|
|
17
|
+
|
|
18
|
+
const resolvedFolderName = resolveFolderName({
|
|
19
|
+
name: cmd
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (resolvedFolderName.KTF === false) {
|
|
23
|
+
console.log(resolvedFolderName.KReason);
|
|
24
|
+
|
|
25
|
+
return;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const source = locateSource();
|
|
29
|
+
const destination = locateDestination({
|
|
30
|
+
inResolvedFolderName: resolvedFolderName,
|
|
31
|
+
toPath: localToPath
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const createFolderResponse = createFolder({
|
|
35
|
+
source, destination,
|
|
36
|
+
isAnnounce, checkBeforeCreate
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (createFolderResponse.KTF) {
|
|
40
|
+
endPointsJs({
|
|
41
|
+
toPath: localToPath,
|
|
42
|
+
action: resolvedFolderName
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// updateEndPointsJs({
|
|
46
|
+
// appJsPath: `${localToPath}/end-points.js`,
|
|
47
|
+
// endpoint: resolvedFolderName
|
|
48
|
+
// });
|
|
49
|
+
|
|
50
|
+
createHttpFile({
|
|
51
|
+
inTargetPath: path.join(localToPath, resolvedFolderName),
|
|
52
|
+
toPath: process.cwd()
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
if (isAnnounce) announce({ inResolvedFolderName: resolvedFolderName });
|
|
57
|
+
|
|
58
|
+
return resolvedFolderName;
|
|
59
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import endPointsJs from "@keshavsoft/kschema-api-check";
|
|
3
|
+
|
|
4
|
+
import { locateSource } from "./GetMethods/ShowAll/steps/locateSource.js";
|
|
5
|
+
import { locateDestination } from "./GetMethods/ShowAll/steps/locateDestination.js";
|
|
6
|
+
import { createFolder } from "../core/createFolder.js";
|
|
7
|
+
|
|
8
|
+
import createHttpFile from "./GetMethods/ShowAll/steps/createHttpFile.js";
|
|
9
|
+
|
|
10
|
+
import { announce } from "./GetMethods/ShowAll/steps/announce.js";
|
|
11
|
+
|
|
12
|
+
import resolveFolderName from "./GetMethods/ShowAll/steps/resolveFolderName.js";
|
|
13
|
+
|
|
14
|
+
export default async ({ cmd = "", toPath, isAnnounce = true, checkBeforeCreate = true }) => {
|
|
15
|
+
const localToPath = toPath;
|
|
16
|
+
|
|
17
|
+
const resolvedFolderName = resolveFolderName({
|
|
18
|
+
name: cmd
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (resolvedFolderName.KTF === false) {
|
|
22
|
+
console.log(resolvedFolderName.KReason);
|
|
23
|
+
|
|
24
|
+
return;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const source = locateSource();
|
|
28
|
+
const destination = locateDestination({
|
|
29
|
+
inResolvedFolderName: resolvedFolderName,
|
|
30
|
+
toPath: localToPath
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const createFolderResponse = createFolder({
|
|
34
|
+
source, destination,
|
|
35
|
+
isAnnounce, checkBeforeCreate
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (createFolderResponse.KTF) {
|
|
39
|
+
await endPointsJs({
|
|
40
|
+
toPath: localToPath,
|
|
41
|
+
action: resolvedFolderName
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
createHttpFile({
|
|
45
|
+
inTargetPath: path.join(localToPath, resolvedFolderName),
|
|
46
|
+
toPath: process.cwd()
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (isAnnounce) announce({ inResolvedFolderName: resolvedFolderName });
|
|
51
|
+
|
|
52
|
+
return resolveFolderName;
|
|
53
|
+
};
|
|
@@ -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,24 @@
|
|
|
1
|
+
import StartEndPoint from "../commands/startEndPoint.js";
|
|
2
|
+
import AddSubRoute from "../commands/addSubRoute.js";
|
|
3
|
+
import AddTableName from "../tasks/tables/addTableName.js";
|
|
4
|
+
// import ShowAll from "../commands/showAll.js";
|
|
5
|
+
import Insert from "../tasks/actions/insert.js";
|
|
6
|
+
import ShowAll from "../tasks/actions/showAll.js";
|
|
7
|
+
|
|
8
|
+
import CreateApi from "../Orchestration/CreateApi/createApi.js";
|
|
9
|
+
import InsertApi from "../Orchestration/InsertApi/insertApi.js";
|
|
10
|
+
|
|
11
|
+
// resolveCommand.js
|
|
12
|
+
const map = {
|
|
13
|
+
StartEndPoint,
|
|
14
|
+
AddSubRoute,
|
|
15
|
+
AddTableName,
|
|
16
|
+
ShowAll,
|
|
17
|
+
CreateApi,
|
|
18
|
+
InsertApi,
|
|
19
|
+
Insert
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default function resolveCommand(cmd) {
|
|
23
|
+
return map[cmd] || null;
|
|
24
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
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}StartEndPoint${r} Initialize a new folder and files
|
|
32
|
+
${g}CreateApi${r} Creates new end point and hooks to app.js
|
|
33
|
+
${g}InsertApi${r} Creates new InsertApi end point and hooks to app.js
|
|
34
|
+
|
|
35
|
+
${y}Examples:${r}
|
|
36
|
+
${gray}npx @keshavsoft/kschema-api-gen StartEndPoint${r}
|
|
37
|
+
${gray}npx @keshavsoft/kschema-api-gen CreateApi Api/V1/journals/ShowAll${r}
|
|
38
|
+
${gray}npx @keshavsoft/kschema-api-gen InsertApi Api/V1/journals/Insert${r}
|
|
39
|
+
|
|
40
|
+
${y}Tip:${r}
|
|
41
|
+
${gray}npm i -g @keshavsoft/kschema-api-gen${r}
|
|
42
|
+
`);
|
|
43
|
+
}
|