jcc-express-mvc 1.2.6 → 1.2.7

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 (112) hide show
  1. package/{dist/index.js → index.js} +5 -3
  2. package/lib/Command-Line/NodeArtisanCommand.js +69 -0
  3. package/lib/Command-Line/command.js +111 -0
  4. package/{Command-Line → lib/Command-Line}/files/Controller.js +4 -3
  5. package/{Command-Line → lib/Command-Line}/files/Migration.js +4 -3
  6. package/{Command-Line → lib/Command-Line}/files/Models.js +4 -3
  7. package/{Command-Line → lib/Command-Line}/files/Request.js +4 -3
  8. package/{Command-Line → lib/Command-Line}/files/ResourcesController.js +4 -3
  9. package/lib/Command-Line/utils.js +14 -0
  10. package/package.json +2 -2
  11. package/Command-Line/NodeArtisanCommand.js +0 -93
  12. package/Command-Line/NodeTinker/db/index.js +0 -17
  13. package/Command-Line/NodeTinker/getInput.js +0 -7
  14. package/Command-Line/NodeTinker/index.js +0 -53
  15. package/Command-Line/NodeTinker/repl.js +0 -28
  16. package/Command-Line/command.js +0 -134
  17. package/Command-Line/utils.js +0 -11
  18. package/Database/src/BaseEntity.ts +0 -247
  19. package/Database/src/BaseModel.ts +0 -51
  20. package/Database/src/Builder.ts +0 -498
  21. package/Database/src/Cast/index.ts +0 -126
  22. package/Database/src/Cast/types.ts +0 -24
  23. package/Database/src/Date/index.ts +0 -52
  24. package/Database/src/Model.ts +0 -55
  25. package/Database/src/Query.ts +0 -13
  26. package/Database/src/QueryBuilder.ts +0 -426
  27. package/Database/src/QueryInstance.ts +0 -28
  28. package/Database/src/RelationBuilder.ts +0 -119
  29. package/Database/src/Schema/BaseSchemaEntity/index.ts +0 -32
  30. package/Database/src/Schema/BluePrint/index.ts +0 -287
  31. package/Database/src/Schema/index.ts +0 -15
  32. package/Database/src/Schema/migrationContent.js +0 -19
  33. package/Database/src/db/connection.ts +0 -17
  34. package/Database/src/type.ts +0 -18
  35. package/Database/src/utils/index.ts +0 -122
  36. package/index.ts +0 -36
  37. package/lib/App.ts +0 -46
  38. package/lib/Auth/AuthMiddleware.ts +0 -47
  39. package/lib/Auth/index.ts +0 -110
  40. package/lib/Config/Config.ts +0 -17
  41. package/lib/Error/AppError.ts +0 -11
  42. package/lib/Error/AppErrorHandler.ts +0 -41
  43. package/lib/Error/Constants/error.ts +0 -23
  44. package/lib/Error/Constants/index.ts +0 -5
  45. package/lib/Error/public/pageNotFound.html +0 -28
  46. package/lib/HttpKernel/HttpKernel.ts +0 -12
  47. package/lib/Interface/index.ts +0 -39
  48. package/lib/Middlewares/index.ts +0 -125
  49. package/lib/Middlewares/isLogin.ts +0 -29
  50. package/lib/Passport/config.ts +0 -74
  51. package/lib/Request/FormRequest.ts +0 -58
  52. package/lib/Request/request.ts +0 -44
  53. package/lib/Response/index.ts +0 -52
  54. package/lib/Routes/RouteBuilder.ts +0 -133
  55. package/lib/Routes/Router.ts +0 -145
  56. package/lib/Server/index.ts +0 -40
  57. package/lib/Services/ServiceContainer.ts +0 -34
  58. package/lib/Services/ServiceProvider.ts +0 -58
  59. package/lib/Templating-engine/engineHelper.ts +0 -138
  60. package/lib/Templating-engine/expressions.ts +0 -18
  61. package/lib/Templating-engine/index.ts +0 -242
  62. package/lib/Type/index.ts +0 -28
  63. package/lib/Validation/index.ts +0 -96
  64. package/lib/Validation/rules.ts +0 -107
  65. package/lib/Validation/validate.ts +0 -370
  66. package/lib/util/index.ts +0 -179
  67. /package/{dist/lib → lib}/App.js +0 -0
  68. /package/{dist/lib → lib}/Auth/AuthMiddleware.js +0 -0
  69. /package/{dist/lib → lib}/Auth/index.js +0 -0
  70. /package/{dist/lib → lib}/Config/Config.js +0 -0
  71. /package/{dist → lib}/Database/src/BaseEntity.js +0 -0
  72. /package/{dist → lib}/Database/src/BaseModel.js +0 -0
  73. /package/{dist → lib}/Database/src/Builder.js +0 -0
  74. /package/{dist → lib}/Database/src/Cast/index.js +0 -0
  75. /package/{dist → lib}/Database/src/Cast/types.js +0 -0
  76. /package/{dist → lib}/Database/src/Date/index.js +0 -0
  77. /package/{dist → lib}/Database/src/Model.js +0 -0
  78. /package/{dist → lib}/Database/src/Query.js +0 -0
  79. /package/{dist → lib}/Database/src/QueryBuilder.js +0 -0
  80. /package/{dist → lib}/Database/src/QueryInstance.js +0 -0
  81. /package/{dist → lib}/Database/src/RelationBuilder.js +0 -0
  82. /package/{dist → lib}/Database/src/Schema/BaseSchemaEntity/index.js +0 -0
  83. /package/{dist → lib}/Database/src/Schema/BluePrint/index.js +0 -0
  84. /package/{dist → lib}/Database/src/Schema/index.js +0 -0
  85. /package/{dist → lib}/Database/src/db/connection.js +0 -0
  86. /package/{dist → lib}/Database/src/type.js +0 -0
  87. /package/{dist → lib}/Database/src/utils/index.js +0 -0
  88. /package/{dist/lib → lib}/Error/AppError.js +0 -0
  89. /package/{dist/lib → lib}/Error/AppErrorHandler.js +0 -0
  90. /package/{dist/lib → lib}/Error/Constants/error.js +0 -0
  91. /package/{dist/lib → lib}/Error/Constants/index.js +0 -0
  92. /package/{dist/lib → lib}/HttpKernel/HttpKernel.js +0 -0
  93. /package/{dist/lib → lib}/Interface/index.js +0 -0
  94. /package/{dist/lib → lib}/Middlewares/index.js +0 -0
  95. /package/{dist/lib → lib}/Middlewares/isLogin.js +0 -0
  96. /package/{dist/lib → lib}/Passport/config.js +0 -0
  97. /package/{dist/lib → lib}/Request/FormRequest.js +0 -0
  98. /package/{dist/lib → lib}/Request/request.js +0 -0
  99. /package/{dist/lib → lib}/Response/index.js +0 -0
  100. /package/{dist/lib → lib}/Routes/RouteBuilder.js +0 -0
  101. /package/{dist/lib → lib}/Routes/Router.js +0 -0
  102. /package/{dist/lib → lib}/Server/index.js +0 -0
  103. /package/{dist/lib → lib}/Services/ServiceContainer.js +0 -0
  104. /package/{dist/lib → lib}/Services/ServiceProvider.js +0 -0
  105. /package/{dist/lib → lib}/Templating-engine/engineHelper.js +0 -0
  106. /package/{dist/lib → lib}/Templating-engine/expressions.js +0 -0
  107. /package/{dist/lib → lib}/Templating-engine/index.js +0 -0
  108. /package/{dist/lib → lib}/Type/index.js +0 -0
  109. /package/{dist/lib → lib}/Validation/index.js +0 -0
  110. /package/{dist/lib → lib}/Validation/rules.js +0 -0
  111. /package/{dist/lib → lib}/Validation/validate.js +0 -0
  112. /package/{dist/lib → lib}/util/index.js +0 -0
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Schema = exports.Model = exports.verifyHash = exports.jwtVerify = exports.jwtSign = exports.bcrypt = exports.FormRequest = exports.apiAuth = exports.auth = exports.Auth = exports.config = exports.HttpKernel = exports.server = exports.ApiRoute = exports.Route = void 0;
6
+ exports.artisanCommand = exports.Schema = exports.Model = exports.verifyHash = exports.jwtVerify = exports.jwtSign = exports.bcrypt = exports.FormRequest = exports.apiAuth = exports.auth = exports.Auth = exports.config = exports.HttpKernel = exports.server = exports.ApiRoute = exports.Route = void 0;
7
7
  const Config_1 = __importDefault(require("./lib/Config/Config"));
8
8
  const App_1 = require("./lib/App");
9
9
  const HttpKernel_1 = __importDefault(require("./lib/HttpKernel/HttpKernel"));
@@ -11,8 +11,9 @@ const Auth_1 = __importDefault(require("./lib/Auth"));
11
11
  const AuthMiddleware_1 = require("./lib/Auth/AuthMiddleware");
12
12
  const FormRequest_1 = require("./lib/Request/FormRequest");
13
13
  const util_1 = require("./lib/util");
14
- const Schema_1 = require("./Database/src/Schema");
15
- const Model_1 = require("./Database/src/Model");
14
+ const Schema_1 = require("./lib/Database/src/Schema");
15
+ const Model_1 = require("./lib/Database/src/Model");
16
+ const NodeArtisanCommand_1 = require("./lib/Command-Line/NodeArtisanCommand");
16
17
  exports.Route = App_1.app.webRoutes();
17
18
  exports.ApiRoute = App_1.app.apiRoutes();
18
19
  exports.server = App_1.app.httpServer();
@@ -28,3 +29,4 @@ exports.jwtVerify = util_1.jwtVerify;
28
29
  exports.verifyHash = util_1.verifyHash;
29
30
  exports.Model = Model_1.Model;
30
31
  exports.Schema = Schema_1.Schema;
32
+ exports.artisanCommand = NodeArtisanCommand_1.NodeArtisanCommand;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NodeArtisanCommand = void 0;
7
+ const command_1 = __importDefault(require("./command"));
8
+ /**
9
+ Function to parse command line arguments and execute corresponding commands
10
+ @param {commandArg} commandArg -string
11
+ @returns {any} -any
12
+ * */
13
+ const NodeArtisanCommand = (commandArg = []) => {
14
+ let index = commandArg.findIndex((arg, index) => arg.includes(":")); //commandArg[0].split(":")[1] || commandArg[1].split(":")[1]; // Extract the command type from the first argument
15
+ let command = commandArg[index].split(":")[1];
16
+ // If the command is for creating an API controller with resources
17
+ if (commandArg.length === index + 4 &&
18
+ (command === "apiController" || command === "ApiController") &&
19
+ (commandArg[index + 3] === "--resources" || commandArg[index + 3] === "-r")) {
20
+ command_1.default.addModel(commandArg[2]); // Add a model with the provided name
21
+ return command_1.default.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller with resources
22
+ }
23
+ // If the command is for creating a web controller with resources
24
+ if (commandArg.length === 4 &&
25
+ (command === "controller" || command === "Controller") &&
26
+ (commandArg[3] === "--resources" || commandArg[3] === "-r")) {
27
+ command_1.default.addModel(commandArg[2]); // Add a model with the provided name
28
+ return command_1.default.addWeb(commandArg[1], commandArg[2]); // Add a web controller with resources
29
+ }
30
+ // If the command is for creating an admin controller with resources
31
+ // If the command is for creating a web controller
32
+ if (commandArg.length === index + 3 &&
33
+ (command === "controller" || command === "Controller")) {
34
+ return command_1.default.addWeb(commandArg[index + 1], commandArg[index + 2]); // Add a web controller
35
+ }
36
+ // If the command is for creating an API controller
37
+ if (commandArg.length === index + 3 &&
38
+ (command === "apiController" || command === "ApiController")) {
39
+ return command_1.default.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller
40
+ }
41
+ // If the command is for creating a model
42
+ if (commandArg.length === index + 2 &&
43
+ (command === "model" || command === "Model")) {
44
+ return command_1.default.addModel(commandArg[index + 1]); // Add a model
45
+ }
46
+ // If the command is for creating a web controller without specifying a model
47
+ if (commandArg.length === index + 2 &&
48
+ (command === "controller" || command === "Controller")) {
49
+ return command_1.default.addWeb(commandArg[index + 1], false); // Add a web controller without a model
50
+ }
51
+ // If the command is for creating an API controller without specifying a model
52
+ if (commandArg.length === index + 2 &&
53
+ (command === "apiController" || command === "ApiController")) {
54
+ return command_1.default.addApi(commandArg[index + 1], false); // Add an API controller without a model
55
+ }
56
+ // If the command is for creating a request file
57
+ if (commandArg.length === index + 2 &&
58
+ (command === "Request" || command === "request")) {
59
+ return command_1.default.addRequest(commandArg[index + 1]); // Add a request file
60
+ }
61
+ // If the command is for creating a request file
62
+ if (commandArg.length === index + 2 &&
63
+ (command === "Migration" || command === "migration")) {
64
+ return command_1.default.addMigration(commandArg[index + 1]); // Add a request file
65
+ }
66
+ // If the command is not recognized, display "Command not found"
67
+ return command_1.default.notFound();
68
+ };
69
+ exports.NodeArtisanCommand = NodeArtisanCommand;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const app_root_path_1 = __importDefault(require("app-root-path"));
9
+ const Controller_1 = __importDefault(require("./files/Controller"));
10
+ const Models_1 = __importDefault(require("./files/Models"));
11
+ const ResourcesController_1 = __importDefault(require("./files/ResourcesController"));
12
+ const Request_1 = __importDefault(require("./files/Request"));
13
+ const Migration_1 = __importDefault(require("./files/Migration"));
14
+ const utils_1 = require("./utils");
15
+ const rootPath = app_root_path_1.default.path;
16
+ class Command {
17
+ // Method to add a web controller
18
+ addWeb(controllerName, modelName = false) {
19
+ try {
20
+ let webControllerPath = path_1.default.resolve(`${rootPath}/app/Http/Controllers`); // Resolve path to web controllers directory
21
+ if (fs_1.default.existsSync(`${webControllerPath}/${controllerName}.ts`)) {
22
+ // Check if controller file already exists
23
+ return console.log(`${controllerName} already exist`.yellow); // Log a warning if controller already exists
24
+ }
25
+ if (modelName && typeof modelName === "string") {
26
+ // If model name is provided, create a resource controller
27
+ fs_1.default.writeFileSync(`${webControllerPath}/${controllerName}.ts`, (0, ResourcesController_1.default)(controllerName, modelName));
28
+ return console.log(`${controllerName} added successfully`.green); // Log success message
29
+ }
30
+ fs_1.default.writeFileSync(`${webControllerPath}/${controllerName}.ts`, (0, Controller_1.default)(controllerName));
31
+ return console.log(`${controllerName} added successfully`.green); // Log success message
32
+ }
33
+ catch (err) {
34
+ console.log(`${controllerName} admin controller not added`.red); // Log error if controller addition fails
35
+ }
36
+ }
37
+ // Method to add an API controller
38
+ addApi(controllerName, modelName = false) {
39
+ try {
40
+ let apiPath = path_1.default.resolve(`${rootPath}/app/Http/ApiControllers`); // Resolve path to API controllers directory
41
+ if (fs_1.default.existsSync(`${apiPath}/${controllerName}.ts`)) {
42
+ // Check if API controller file already exists
43
+ return console.log(`${controllerName} api controller already exist`.yellow); // Log a warning if API controller already exists
44
+ }
45
+ if (modelName && typeof modelName === "string") {
46
+ // If model name is provided, create a resource controller
47
+ fs_1.default.writeFileSync(`${apiPath}/${controllerName}.ts`, (0, ResourcesController_1.default)(controllerName, modelName));
48
+ return console.log(`${controllerName} added successfully`.green); // Log success message
49
+ }
50
+ fs_1.default.writeFileSync(`${apiPath}/${controllerName}.ts`, (0, Controller_1.default)(controllerName));
51
+ return console.log(`${controllerName} added successfully`.green); // Log success message
52
+ }
53
+ catch (err) {
54
+ console.log(err.message);
55
+ console.log(`${controllerName} api controller not added`.red); // Log error if controller addition fails
56
+ }
57
+ }
58
+ // Method to add a model
59
+ addModel(modelName) {
60
+ try {
61
+ let modelPath = path_1.default.resolve(`${rootPath}/app/Models`); // Resolve path to models directory
62
+ if (fs_1.default.existsSync(`${modelPath}/${modelName}.ts`)) {
63
+ // Check if model file already exists
64
+ return console.log(`${modelName} model already exist`.yellow); // Log a warning if model already exists
65
+ }
66
+ fs_1.default.writeFileSync(`${modelPath}/${modelName}.ts`, (0, Models_1.default)(modelName)); // Create a model file
67
+ return console.log(`${modelName} model added successfully`.green); // Log success message
68
+ }
69
+ catch (err) {
70
+ return console.log(`${modelName} model not added`.red); // Log error if model addition fails
71
+ }
72
+ }
73
+ // Method to add a request file
74
+ addRequest(requestName) {
75
+ try {
76
+ let requestPath = path_1.default.resolve(`${rootPath}/app/Http/Requests`); // Resolve path to request files directory
77
+ if (fs_1.default.existsSync(`${requestPath}/${requestName}.ts`)) {
78
+ // Check if request file already exists
79
+ return console.log(`${requestName} already exist`.yellow); // Log a warning if request file already exists
80
+ }
81
+ fs_1.default.writeFileSync(`${requestPath}/${requestName}.ts`, (0, Request_1.default)(requestName));
82
+ return console.log(`${requestName} added successfully`.green); // Log success message
83
+ }
84
+ catch (err) {
85
+ return console.log(`${requestName} request not added`.red, { err }); // Log error if request addition fails
86
+ }
87
+ }
88
+ // Method to add a request file
89
+ addMigration(migrationName) {
90
+ try {
91
+ const tableName = migrationName.replace(/(create_|_table)/g, "");
92
+ let migrationPath = path_1.default.resolve(`${rootPath}/database/migrations`);
93
+ // Resolve path to request files directory
94
+ const fullName = `${(0, utils_1.formatDate)()}_${migrationName}`;
95
+ if (fs_1.default.existsSync(`${migrationPath}/${fullName}.ts`)) {
96
+ // Check if request file already exists
97
+ return console.log(`${tableName} already exist`.yellow); // Log a warning if request file already exists
98
+ }
99
+ fs_1.default.writeFileSync(`${migrationPath}/${fullName}.ts`, (0, Migration_1.default)(tableName));
100
+ return console.log(`${fullName} added successfully`.green); // Log success message
101
+ }
102
+ catch (err) {
103
+ return console.log(`${migrationName} migration not added`.red, { err }); // Log error if request addition fails
104
+ }
105
+ }
106
+ // Method to handle a command not found
107
+ notFound() {
108
+ return console.log(`Command not found`.bgRed); // Log a message indicating the command was not found
109
+ }
110
+ }
111
+ exports.default = new Command(); // Export an instance of the Command class
@@ -1,10 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  /**
2
4
  * Function to create a controller file
3
5
  * @param name string
4
6
  * @returns string
5
7
  */
6
8
  const createController = (name) => {
7
- return `
9
+ return `
8
10
  import {Request, Response,Next} from "jcc-express-mvc"
9
11
 
10
12
 
@@ -72,5 +74,4 @@ const createController = (name) => {
72
74
  }
73
75
  `;
74
76
  };
75
-
76
- module.exports = createController;
77
+ exports.default = createController;
@@ -1,6 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  const inflection = require("inflection");
2
4
  const createMigration = (table) => {
3
- return `
5
+ return `
4
6
  import {Schema} from "";
5
7
  class Migration {
6
8
  up() {
@@ -13,5 +15,4 @@ class Migration {
13
15
  }
14
16
  `;
15
17
  };
16
-
17
- module.exports = createMigration;
18
+ exports.default = createMigration;
@@ -1,10 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  /**
2
4
  * Function to create a model file
3
5
  * @param name - string
4
6
  * @returns string
5
7
  */
6
8
  const createModel = (name) => {
7
- return `
9
+ return `
8
10
  import {Model} from "jcc-express-mvc"
9
11
 
10
12
  export class ${name} extends Model{
@@ -16,5 +18,4 @@ const createModel = (name) => {
16
18
 
17
19
  `;
18
20
  };
19
-
20
- module.exports = createModel;
21
+ exports.default = createModel;
@@ -1,10 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  /**
2
4
  * Function to create a request file
3
5
  * @param name - string
4
6
  * @returns string
5
7
  */
6
8
  const createRequest = (fileName) => {
7
- return `
9
+ return `
8
10
  import { getModel, FormRequest,Request } = from "jcc-express-mvc";
9
11
 
10
12
  export class ${fileName} extends FormRequest {
@@ -28,5 +30,4 @@ const createRequest = (fileName) => {
28
30
 
29
31
  `;
30
32
  };
31
-
32
- module.exports = createRequest;
33
+ exports.default = createRequest;
@@ -1,10 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  /**
2
4
  * Function to create a resources file
3
5
  * @param name - string
4
6
  * @returns string
5
7
  */
6
8
  const resourceController = (controller, model) => {
7
- return `const {getModel }= require("jcc-express-mvc")
9
+ return `const {getModel }= require("jcc-express-mvc")
8
10
  const ${model} = getModel('${model}')
9
11
  export class ${controller} {
10
12
 
@@ -73,5 +75,4 @@ const resourceController = (controller, model) => {
73
75
  }
74
76
  `;
75
77
  };
76
-
77
- module.exports = resourceController;
78
+ exports.default = resourceController;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatDate = void 0;
4
+ const formatDate = () => {
5
+ const date = new Date();
6
+ const year = date.getFullYear();
7
+ const month = String(date.getMonth() + 1).padStart(2, "0");
8
+ const day = String(date.getDate()).padStart(2, "0");
9
+ const hours = String(date.getHours()).padStart(2, "0");
10
+ const minutes = String(date.getMinutes()).padStart(2, "0");
11
+ const seconds = String(date.getSeconds()).padStart(2, "0");
12
+ return `${year}_${month}_${day}_${hours}_${minutes}_${seconds}`;
13
+ };
14
+ exports.formatDate = formatDate;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "jcc-express-mvc",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "description": "express mvc structure",
5
- "main": "dist/index.js",
5
+ "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
8
8
  "build": "tsc"
@@ -1,93 +0,0 @@
1
- const runCommand = require("./command");
2
-
3
- /**
4
- Function to parse command line arguments and execute corresponding commands
5
- @param {commandArg} commandArg -string
6
- @returns {any} -any
7
- * */
8
- const NodeArtisanCommand = (commandArg = []) => {
9
- let index = commandArg.findIndex((arg, index) => arg.includes(":")); //commandArg[0].split(":")[1] || commandArg[1].split(":")[1]; // Extract the command type from the first argument
10
- let command = commandArg[index].split(":")[1];
11
- // If the command is for creating an API controller with resources
12
- if (
13
- commandArg.length === index + 4 &&
14
- (command === "apiController" || command === "ApiController") &&
15
- (commandArg[index + 3] === "--resources" || commandArg[index + 3] === "-r")
16
- ) {
17
- runCommand.addModel(commandArg[2]); // Add a model with the provided name
18
- return runCommand.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller with resources
19
- }
20
-
21
- // If the command is for creating a web controller with resources
22
- if (
23
- commandArg.length === 4 &&
24
- (command === "controller" || command === "Controller") &&
25
- (commandArg[3] === "--resources" || commandArg[3] === "-r")
26
- ) {
27
- runCommand.addModel(commandArg[2]); // Add a model with the provided name
28
- return runCommand.addWeb(commandArg[1], commandArg[2]); // Add a web controller with resources
29
- }
30
-
31
- // If the command is for creating an admin controller with resources
32
-
33
- // If the command is for creating a web controller
34
- if (
35
- commandArg.length === index + 3 &&
36
- (command === "controller" || command === "Controller")
37
- ) {
38
- return runCommand.addWeb(commandArg[index + 1], commandArg[index + 2]); // Add a web controller
39
- }
40
-
41
- // If the command is for creating an API controller
42
- if (
43
- commandArg.length === index + 3 &&
44
- (command === "apiController" || command === "ApiController")
45
- ) {
46
- return runCommand.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller
47
- }
48
-
49
- // If the command is for creating a model
50
- if (
51
- commandArg.length === index + 2 &&
52
- (command === "model" || command === "Model")
53
- ) {
54
- return runCommand.addModel(commandArg[index + 1]); // Add a model
55
- }
56
-
57
- // If the command is for creating a web controller without specifying a model
58
- if (
59
- commandArg.length === index + 2 &&
60
- (command === "controller" || command === "Controller")
61
- ) {
62
- return runCommand.addWeb(commandArg[index + 1], false); // Add a web controller without a model
63
- }
64
-
65
- // If the command is for creating an API controller without specifying a model
66
- if (
67
- commandArg.length === index + 2 &&
68
- (command === "apiController" || command === "ApiController")
69
- ) {
70
- return runCommand.addApi(commandArg[index + 1], false); // Add an API controller without a model
71
- }
72
-
73
- // If the command is for creating a request file
74
- if (
75
- commandArg.length === index + 2 &&
76
- (command === "Request" || command === "request")
77
- ) {
78
- return runCommand.addRequest(commandArg[index + 1]); // Add a request file
79
- }
80
-
81
- // If the command is for creating a request file
82
- if (
83
- commandArg.length === index + 2 &&
84
- (command === "Migration" || command === "migration")
85
- ) {
86
- return runCommand.addMigration(commandArg[index + 1]); // Add a request file
87
- }
88
-
89
- // If the command is not recognized, display "Command not found"
90
- return runCommand.notFound();
91
- };
92
-
93
- module.exports = NodeArtisanCommand;
@@ -1,17 +0,0 @@
1
- const mysql = require("mysql2/promise.js");
2
- class Database {
3
- async connect() {
4
- return await mysql.createConnection({
5
- host: process.env.DB_HOST || "",
6
- user: process.env.DB_USERNAME,
7
- password: process.env.DB_PASSWORD,
8
- database: process.env.DB_DATABASE,
9
- port: Number(process.env.DB_PORT) || 0,
10
- });
11
- }
12
-
13
- async runQuery(sqlQuery) {
14
- const [results] = await (await this.connect()).query(sqlQuery);
15
- return results;
16
- }
17
- }
@@ -1,7 +0,0 @@
1
- const TinkerNode = require("./");
2
-
3
- const getInput = async (input) => {
4
- const cli = new TinkerNode();
5
- return cli.extractCommand(input);
6
- };
7
- module.exports = getInput;
@@ -1,53 +0,0 @@
1
- const appRootPath = require("app-root-path").path;
2
-
3
- class TinkerNode {
4
- #allowedMethodsRegex = /[^\s{}()\[\]\(\)0-9a-zA-Z',_.:@]/g;
5
-
6
- getModel(file) {
7
- return require(`${appRootPath}/app/Models/${file}`);
8
- }
9
-
10
- sanitizedInput(input) {
11
- return input.replace(this.#allowedMethodsRegex, "");
12
- }
13
-
14
- validatedInput(input) {
15
- const sanitizedInputData = this.sanitizedInput(input);
16
- if (sanitizedInputData !== input) {
17
- // Input contains disallowed characters, reject it
18
- throw new Error("Input contains disallowed characters.");
19
- }
20
-
21
- const data = input.split(".");
22
- if (data.length <= 1) {
23
- throw new Error("Invalid Mongoose query:", input);
24
- }
25
- const model = data[0];
26
- data.splice(0, 1);
27
- return { model, methods: data.join(".") };
28
- }
29
-
30
- async extractCommand(input) {
31
- try {
32
- const { model, methods } = this.validatedInput(input);
33
-
34
- return console.log(this.getModel(`${model}.ts`));
35
-
36
- const queryFunction = new Function(
37
- "model",
38
- "getModel",
39
- `
40
- const modelName = getModel(model)
41
- return modelName.${methods}
42
- `,
43
- );
44
-
45
- this.connect();
46
- return queryFunction(model, this.getModel);
47
- } catch (error) {
48
- return console.error("Error " + error?.message);
49
- }
50
- }
51
- }
52
-
53
- module.exports = TinkerNode;
@@ -1,28 +0,0 @@
1
- const { REPL } = require("repl-cli");
2
- const getInput = require("./getInput");
3
- const repl = new REPL();
4
-
5
- const replPrompt = () => {
6
- repl.use({
7
- async evaluate(input) {
8
- switch (input) {
9
- case "exit()":
10
- return process.exit(-1);
11
-
12
- case "exit":
13
- return process.exit(-1);
14
- case "quit()":
15
- return process.exit(-1);
16
- case "quit":
17
- return process.exit(-1);
18
- default:
19
- const result = await getInput(input);
20
- console.log(result);
21
- break;
22
- }
23
- },
24
- });
25
- repl.start();
26
- };
27
-
28
- module.exports = replPrompt;