jcc-express-mvc 1.3.1 → 1.3.3

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 (49) hide show
  1. package/cli.js +17 -1
  2. package/index.d.ts +1 -1
  3. package/index.d.ts.map +1 -1
  4. package/index.js +26 -20
  5. package/lib/App.js +16 -13
  6. package/lib/Auth/AuthMiddleware.js +6 -3
  7. package/lib/Auth/index.js +10 -5
  8. package/lib/Command-Line/NodeArtisanCommand.d.ts.map +1 -1
  9. package/lib/Command-Line/NodeArtisanCommand.js +67 -54
  10. package/lib/Command-Line/command.d.ts +1 -0
  11. package/lib/Command-Line/command.d.ts.map +1 -1
  12. package/lib/Command-Line/command.js +71 -46
  13. package/lib/Command-Line/files/Controller.js +3 -1
  14. package/lib/Command-Line/files/Migration.js +4 -2
  15. package/lib/Command-Line/files/Models.js +4 -2
  16. package/lib/Command-Line/files/Request.js +3 -1
  17. package/lib/Command-Line/files/ResourcesController.js +4 -2
  18. package/lib/Command-Line/utils.js +5 -1
  19. package/lib/Config/Config.d.ts +2 -2
  20. package/lib/Config/Config.d.ts.map +1 -1
  21. package/lib/Config/Config.js +10 -4
  22. package/lib/Error/AppError.js +5 -1
  23. package/lib/Error/AppErrorHandler.js +11 -7
  24. package/lib/Error/Constants/error.js +45 -42
  25. package/lib/Error/Constants/index.js +6 -3
  26. package/lib/Error/DisplayErrorCode.js +11 -4
  27. package/lib/Error/ErrorHigtlig.js +10 -3
  28. package/lib/HttpKernel/HttpKernel.js +3 -1
  29. package/lib/Interface/index.js +2 -1
  30. package/lib/Middlewares/index.js +30 -23
  31. package/lib/Middlewares/isLogin.js +5 -1
  32. package/lib/Passport/config.js +17 -10
  33. package/lib/Request/FormRequest.js +5 -1
  34. package/lib/Request/request.js +10 -6
  35. package/lib/Response/index.js +5 -1
  36. package/lib/Routes/RouteBuilder.js +14 -10
  37. package/lib/Routes/Router.js +9 -5
  38. package/lib/Server/index.js +15 -8
  39. package/lib/Services/ServiceContainer.js +7 -4
  40. package/lib/Services/ServiceProvider.js +5 -1
  41. package/lib/Templating-engine/engineHelper.js +13 -6
  42. package/lib/Templating-engine/expressions.js +5 -1
  43. package/lib/Templating-engine/index.js +14 -8
  44. package/lib/Type/index.js +2 -1
  45. package/lib/Validation/index.js +11 -7
  46. package/lib/Validation/rules.js +11 -7
  47. package/lib/Validation/validate.js +54 -47
  48. package/lib/util/index.js +59 -37
  49. package/package.json +1 -1
package/cli.js CHANGED
@@ -1 +1,17 @@
1
- export * from "./lib/Command-Line/NodeArtisanCommand";
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./lib/Command-Line/NodeArtisanCommand"), exports);
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import appConfig from "./lib/Config/Config";
1
+ import { config as appConfig } from "./lib/Config/Config";
2
2
  import Kernel from "./lib/HttpKernel/HttpKernel";
3
3
  import Authentication from "./lib/Auth";
4
4
  import { AppRequest, AppResponse, AppNext } from "./lib/Interface";
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../framework/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAE5C,OAAO,MAAM,MAAM,6BAA6B,CAAC;AACjD,OAAO,cAAc,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EACL,MAAM,IAAI,SAAS,EACnB,UAAU,IAAI,aAAa,EAC3B,OAAO,IAAI,UAAU,EACrB,SAAS,IAAI,YAAY,EAC1B,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,KAAK,2CAAkB,CAAC;AACrC,eAAO,MAAM,QAAQ,2CAAkB,CAAC;AACxC,eAAO,MAAM,MAAM,KAAmB,CAAC;AACvC,eAAO,MAAM,UAAU,eAAS,CAAC;AACjC,eAAO,MAAM,MAAM,EAAE,OAAO,SAAqB,CAAC;AAClD,eAAO,MAAM,IAAI,EAAE,OAAO,cAA+B,CAAC;AAC1D,eAAO,MAAM,IAAI,oEAAsB,CAAC;AACxC,eAAO,MAAM,OAAO,oEAAyB,CAAC;AAC9C,eAAO,MAAM,WAAW,EAAE,OAAO,cAA+B,CAAC;AACjE,eAAO,MAAM,MAAM,EAAE,OAAO,SAAqB,CAAC;AAClD,eAAO,MAAM,OAAO,EAAE,OAAO,UAAuB,CAAC;AACrD,eAAO,MAAM,SAAS,EAAE,OAAO,YAA2B,CAAC;AAC3D,eAAO,MAAM,UAAU,EAAE,OAAO,aAA6B,CAAC;AAG9D,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC;AACjC,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC;AACnC,MAAM,MAAM,IAAI,GAAG,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../framework/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,MAAM,MAAM,6BAA6B,CAAC;AACjD,OAAO,cAAc,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EACL,MAAM,IAAI,SAAS,EACnB,UAAU,IAAI,aAAa,EAC3B,OAAO,IAAI,UAAU,EACrB,SAAS,IAAI,YAAY,EAC1B,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,KAAK,2CAAkB,CAAC;AACrC,eAAO,MAAM,QAAQ,2CAAkB,CAAC;AACxC,eAAO,MAAM,MAAM,KAAmB,CAAC;AACvC,eAAO,MAAM,UAAU,eAAS,CAAC;AACjC,eAAO,MAAM,MAAM,EAAE,OAAO,SAAqB,CAAC;AAClD,eAAO,MAAM,IAAI,EAAE,OAAO,cAA+B,CAAC;AAC1D,eAAO,MAAM,IAAI,oEAAsB,CAAC;AACxC,eAAO,MAAM,OAAO,oEAAyB,CAAC;AAC9C,eAAO,MAAM,WAAW,EAAE,OAAO,cAA+B,CAAC;AACjE,eAAO,MAAM,MAAM,EAAE,OAAO,SAAqB,CAAC;AAClD,eAAO,MAAM,OAAO,EAAE,OAAO,UAAuB,CAAC;AACrD,eAAO,MAAM,SAAS,EAAE,OAAO,YAA2B,CAAC;AAC3D,eAAO,MAAM,UAAU,EAAE,OAAO,aAA6B,CAAC;AAG9D,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC;AACjC,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC;AACnC,MAAM,MAAM,IAAI,GAAG,OAAO,CAAC"}
package/index.js CHANGED
@@ -1,20 +1,26 @@
1
- import appConfig from "./lib/Config/Config";
2
- import { app } from "./lib/App";
3
- import Kernel from "./lib/HttpKernel/HttpKernel";
4
- import Authentication from "./lib/Auth";
5
- import { authMiddleware } from "./lib/Auth/AuthMiddleware";
6
- import { FormRequest as AppFormRequest } from "./lib/Request/FormRequest";
7
- import { bcrypt as appBcrypt, verifyHash as appVerifyHash, jwtSign as appJwtSign, jwtVerify as appjwtVerify, } from "./lib/util";
8
- export const Route = app.webRoutes();
9
- export const ApiRoute = app.apiRoutes();
10
- export const server = app.httpServer();
11
- export const HttpKernel = Kernel;
12
- export const config = appConfig;
13
- export const Auth = Authentication;
14
- export const auth = authMiddleware.auth;
15
- export const apiAuth = authMiddleware.apiAuth;
16
- export const FormRequest = AppFormRequest;
17
- export const bcrypt = appBcrypt;
18
- export const jwtSign = appJwtSign;
19
- export const jwtVerify = appjwtVerify;
20
- export const verifyHash = appVerifyHash;
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.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
+ const Config_1 = require("./lib/Config/Config");
8
+ const App_1 = require("./lib/App");
9
+ const HttpKernel_1 = __importDefault(require("./lib/HttpKernel/HttpKernel"));
10
+ const Auth_1 = __importDefault(require("./lib/Auth"));
11
+ const AuthMiddleware_1 = require("./lib/Auth/AuthMiddleware");
12
+ const FormRequest_1 = require("./lib/Request/FormRequest");
13
+ const util_1 = require("./lib/util");
14
+ exports.Route = App_1.app.webRoutes();
15
+ exports.ApiRoute = App_1.app.apiRoutes();
16
+ exports.server = App_1.app.httpServer();
17
+ exports.HttpKernel = HttpKernel_1.default;
18
+ exports.config = Config_1.config;
19
+ exports.Auth = Auth_1.default;
20
+ exports.auth = AuthMiddleware_1.authMiddleware.auth;
21
+ exports.apiAuth = AuthMiddleware_1.authMiddleware.apiAuth;
22
+ exports.FormRequest = FormRequest_1.FormRequest;
23
+ exports.bcrypt = util_1.bcrypt;
24
+ exports.jwtSign = util_1.jwtSign;
25
+ exports.jwtVerify = util_1.jwtVerify;
26
+ exports.verifyHash = util_1.verifyHash;
package/lib/App.js CHANGED
@@ -1,40 +1,43 @@
1
- import { Router } from "./Routes/Router";
2
- import config from "./Config/Config";
3
- import { Middleware } from "./Middlewares";
4
- import { HttpSever } from "./Server";
5
- import { loadRoutes } from "./util";
6
- import { PORT } from "./Error/Constants";
7
- class App extends HttpSever {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.app = void 0;
4
+ const Router_1 = require("./Routes/Router");
5
+ const Config_1 = require("./Config/Config");
6
+ const Middlewares_1 = require("./Middlewares");
7
+ const Server_1 = require("./Server");
8
+ const util_1 = require("./util");
9
+ const Constants_1 = require("./Error/Constants");
10
+ class App extends Server_1.HttpSever {
8
11
  // private app = express();
9
12
  constructor() {
10
13
  super();
11
- new Middleware(this.express, this.app);
14
+ new Middlewares_1.Middleware(this.express, this.app);
12
15
  }
13
16
  webRoutes() {
14
- return new Router(this.app, { prefixUrl: "", basePath: "" });
17
+ return new Router_1.Router(this.app, { prefixUrl: "", basePath: "" });
15
18
  }
16
19
  /**
17
20
  * Method to define API routes.
18
21
  * @returns {object} - Instance of Routes class for API routes.
19
22
  */
20
23
  apiRoutes() {
21
- return new Router(this.app, { basePath: "/api", prefixUrl: "" });
24
+ return new Router_1.Router(this.app, { basePath: "/api", prefixUrl: "" });
22
25
  }
23
26
  /**
24
27
  * Method to configure and start the server.
25
28
  * @returns {object} - Object containing server run method and server instance.
26
29
  */
27
30
  httpServer() {
28
- const server = this.server(Number(config.get(PORT, "3000")));
31
+ const server = this.server(Number(Config_1.config.get(Constants_1.PORT, "3000")));
29
32
  const httpErrors = this.httpErrors;
30
33
  const app = this.app;
31
34
  return {
32
35
  listen() {
33
- loadRoutes();
36
+ (0, util_1.loadRoutes)();
34
37
  httpErrors(app);
35
38
  return server;
36
39
  },
37
40
  };
38
41
  }
39
42
  }
40
- export const app = new App();
43
+ exports.app = new App();
@@ -1,4 +1,7 @@
1
- import { jwtVerify } from "../util";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authMiddleware = void 0;
4
+ const util_1 = require("../util");
2
5
  class AuthMiddleware {
3
6
  apiAuth(request, response, next) {
4
7
  let token;
@@ -16,7 +19,7 @@ class AuthMiddleware {
16
19
  return response.json({ message: "Not authorize" }).status(401);
17
20
  }
18
21
  try {
19
- request.id = jwtVerify(token);
22
+ request.id = (0, util_1.jwtVerify)(token);
20
23
  // request.id = jwtVerify(token, process.env.JWT_SECRET);
21
24
  //
22
25
  next();
@@ -37,4 +40,4 @@ class AuthMiddleware {
37
40
  : response.redirect(url ? `/login?redirect=${url}` : "/login");
38
41
  }
39
42
  }
40
- export const authMiddleware = new AuthMiddleware();
43
+ exports.authMiddleware = new AuthMiddleware();
package/lib/Auth/index.js CHANGED
@@ -1,6 +1,11 @@
1
- import passport from "passport"; // Import Passport for authentication
2
- import { getModel } from "../util"; // Import helper functions for database operations and password hashing
3
- const User = getModel("User"); // Get the User model from database
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 passport_1 = __importDefault(require("passport")); // Import Passport for authentication
7
+ const util_1 = require("../util"); // Import helper functions for database operations and password hashing
8
+ const User = (0, util_1.getModel)("User"); // Get the User model from database
4
9
  class Authentication {
5
10
  // Method to authenticate user login
6
11
  static async login(data = {}, password = "") {
@@ -67,7 +72,7 @@ class Authentication {
67
72
  const appRedirect = req.session["appRedirect"]; // Retrieve redirect URL from session
68
73
  const redirectPath = appRedirect ? appRedirect : "/home"; // Determine the redirect path
69
74
  // Use Passport's local authentication strategy
70
- return passport.authenticate("local", {
75
+ return passport_1.default.authenticate("local", {
71
76
  successRedirect: redirectPath, // Redirect on successful authentication
72
77
  failureRedirect: `${redirectBack ? redirectBack : "/login"}`, // Redirect on failed authentication
73
78
  failureFlash: true, // Enable flash messages on failed authentication
@@ -86,4 +91,4 @@ class Authentication {
86
91
  });
87
92
  }
88
93
  }
89
- export default Authentication;
94
+ exports.default = Authentication;
@@ -1 +1 @@
1
- {"version":3,"file":"NodeArtisanCommand.d.ts","sourceRoot":"","sources":["../../../framework/lib/Command-Line/NodeArtisanCommand.ts"],"names":[],"mappings":"AAEA;;;;MAIM;AACN,eAAO,MAAM,kBAAkB,gBAAgB,KAAK,CAAC,GAAG,CAAC,KAAQ,GAmFhE,CAAC"}
1
+ {"version":3,"file":"NodeArtisanCommand.d.ts","sourceRoot":"","sources":["../../../framework/lib/Command-Line/NodeArtisanCommand.ts"],"names":[],"mappings":"AACA;;;;MAIM;AACN,eAAO,MAAM,kBAAkB,gBAAgB,KAAK,CAAC,GAAG,CAAC,KAAQ,GAwFhE,CAAC"}
@@ -1,62 +1,75 @@
1
- import runCommand from "./command";
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"));
2
8
  /**
3
9
  Function to parse command line arguments and execute corresponding commands
4
10
  @param {commandArg} commandArg -string
5
11
  @returns {any} -any
6
12
  * */
7
- export const NodeArtisanCommand = (commandArg = []) => {
8
- let index = commandArg.findIndex((arg, index) => arg.includes(":")); //commandArg[0].split(":")[1] || commandArg[1].split(":")[1]; // Extract the command type from the first argument
9
- let command = commandArg[index].split(":")[1];
10
- // If the command is for creating an API controller with resources
11
- if (commandArg.length === index + 4 &&
12
- (command === "apiController" || command === "ApiController") &&
13
- (commandArg[index + 3] === "--resources" || commandArg[index + 3] === "-r")) {
14
- runCommand.addModel(commandArg[2]); // Add a model with the provided name
15
- return runCommand.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller with resources
16
- }
17
- // If the command is for creating a web controller with resources
18
- if (commandArg.length === 4 &&
19
- (command === "controller" || command === "Controller") &&
20
- (commandArg[3] === "--resources" || commandArg[3] === "-r")) {
21
- runCommand.addModel(commandArg[2]); // Add a model with the provided name
22
- return runCommand.addWeb(commandArg[1], commandArg[2]); // Add a web controller with resources
23
- }
24
- // If the command is for creating an admin controller with resources
25
- // If the command is for creating a web controller
26
- if (commandArg.length === index + 3 &&
27
- (command === "controller" || command === "Controller")) {
28
- return runCommand.addWeb(commandArg[index + 1], commandArg[index + 2]); // Add a web controller
29
- }
30
- // If the command is for creating an API controller
31
- if (commandArg.length === index + 3 &&
32
- (command === "apiController" || command === "ApiController")) {
33
- return runCommand.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller
34
- }
35
- // If the command is for creating a model
36
- if (commandArg.length === index + 2 &&
37
- (command === "model" || command === "Model")) {
38
- return runCommand.addModel(commandArg[index + 1]); // Add a model
39
- }
40
- // If the command is for creating a web controller without specifying a model
41
- if (commandArg.length === index + 2 &&
42
- (command === "controller" || command === "Controller")) {
43
- return runCommand.addWeb(commandArg[index + 1], false); // Add a web controller without a model
44
- }
45
- // If the command is for creating an API controller without specifying a model
46
- if (commandArg.length === index + 2 &&
47
- (command === "apiController" || command === "ApiController")) {
48
- return runCommand.addApi(commandArg[index + 1], false); // Add an API controller without a model
49
- }
50
- // If the command is for creating a request file
51
- if (commandArg.length === index + 2 &&
52
- (command === "Request" || command === "request")) {
53
- return runCommand.addRequest(commandArg[index + 1]); // Add a request file
13
+ const NodeArtisanCommand = (commandArg = []) => {
14
+ try {
15
+ let index = commandArg.findIndex((arg, index) => arg.includes(":")); //commandArg[0].split(":")[1] || commandArg[1].split(":")[1]; // Extract the command type from the first argument
16
+ let command = commandArg[index].split(":")[1];
17
+ // If the command is for creating an API controller with resources
18
+ if (commandArg.length === index + 4 &&
19
+ (command === "apiController" || command === "ApiController") &&
20
+ (commandArg[index + 3] === "--resources" ||
21
+ commandArg[index + 3] === "-r")) {
22
+ command_1.default.addModel(commandArg[2]); // Add a model with the provided name
23
+ return command_1.default.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller with resources
24
+ }
25
+ // If the command is for creating a web controller with resources
26
+ if (commandArg.length === 4 &&
27
+ (command === "controller" || command === "Controller") &&
28
+ (commandArg[3] === "--resources" || commandArg[3] === "-r")) {
29
+ command_1.default.addModel(commandArg[2]); // Add a model with the provided name
30
+ return command_1.default.addWeb(commandArg[1], commandArg[2]); // Add a web controller with resources
31
+ }
32
+ // If the command is for creating an admin controller with resources
33
+ // If the command is for creating a web controller
34
+ if (commandArg.length === index + 3 &&
35
+ (command === "controller" || command === "Controller")) {
36
+ return command_1.default.addWeb(commandArg[index + 1], commandArg[index + 2]); // Add a web controller
37
+ }
38
+ // If the command is for creating an API controller
39
+ if (commandArg.length === index + 3 &&
40
+ (command === "apiController" || command === "ApiController")) {
41
+ return command_1.default.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller
42
+ }
43
+ // If the command is for creating a model
44
+ if (commandArg.length === index + 2 &&
45
+ (command === "model" || command === "Model")) {
46
+ return command_1.default.addModel(commandArg[index + 1]); // Add a model
47
+ }
48
+ // If the command is for creating a web controller without specifying a model
49
+ if (commandArg.length === index + 2 &&
50
+ (command === "controller" || command === "Controller")) {
51
+ return command_1.default.addWeb(commandArg[index + 1], false); // Add a web controller without a model
52
+ }
53
+ // If the command is for creating an API controller without specifying a model
54
+ if (commandArg.length === index + 2 &&
55
+ (command === "apiController" || command === "ApiController")) {
56
+ return command_1.default.addApi(commandArg[index + 1], false); // Add an API controller without a model
57
+ }
58
+ // If the command is for creating a request file
59
+ if (commandArg.length === index + 2 &&
60
+ (command === "Request" || command === "request")) {
61
+ return command_1.default.addRequest(commandArg[index + 1]); // Add a request file
62
+ }
63
+ // If the command is for creating a request file
64
+ if (commandArg.length === index + 2 &&
65
+ (command === "Migration" || command === "migration")) {
66
+ return command_1.default.addMigration(commandArg[index + 1]); // Add a request file
67
+ }
68
+ // If the command is not recognized, display "Command not found"
69
+ return command_1.default.notFound();
54
70
  }
55
- // If the command is for creating a request file
56
- if (commandArg.length === index + 2 &&
57
- (command === "Migration" || command === "migration")) {
58
- return runCommand.addMigration(commandArg[index + 1]); // Add a request file
71
+ catch (error) {
72
+ console.log("Sorry an error occur, Please try again");
59
73
  }
60
- // If the command is not recognized, display "Command not found"
61
- return runCommand.notFound();
62
74
  };
75
+ exports.NodeArtisanCommand = NodeArtisanCommand;
@@ -4,6 +4,7 @@ declare class Command {
4
4
  addModel(modelName: string): any;
5
5
  addRequest(requestName: string): any;
6
6
  addMigration(migrationName: string): any;
7
+ runMigration(): void;
7
8
  notFound(): any;
8
9
  }
9
10
  declare const _default: Command;
@@ -1 +1 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../framework/lib/Command-Line/command.ts"],"names":[],"mappings":"AAaA,cAAM,OAAO;IAEX,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,SAAS,UAAQ,GAAG,GAAG;IA2BtD,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,SAAS,UAAQ,GAAG,GAAG;IA6BtD,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG;IAehC,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,GAAG;IAmBpC,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,GAAG;IAuBxC,QAAQ,IAAI,GAAG;CAGhB;;AAED,wBAA6B"}
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../framework/lib/Command-Line/command.ts"],"names":[],"mappings":"AAcA,cAAM,OAAO;IAGX,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,SAAS,UAAQ,GAAG,GAAG;IA2BtD,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,SAAS,UAAQ,GAAG,GAAG;IA+BtD,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG;IAehC,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,GAAG;IAqBpC,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,GAAG;IAwBxC,YAAY;IAgBZ,QAAQ,IAAI,GAAG;CAGhB;;AAED,wBAA6B"}
@@ -1,106 +1,131 @@
1
- import path from "path";
2
- import fs from "fs";
3
- import appRootPath from "app-root-path";
4
- import createController from "./files/Controller";
5
- import createModel from "./files/Models";
6
- import resourceController from "./files/ResourcesController";
7
- import createRequest from "./files/Request";
8
- import createMigration from "./files/Migration";
9
- import { formatDate } from "./utils";
10
- const rootPath = appRootPath.path;
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 colors_1 = __importDefault(require("colors")); // Module for adding color to console output
15
+ const utils_1 = require("./utils");
16
+ const rootPath = app_root_path_1.default.path;
17
+ colors_1.default.enable();
11
18
  class Command {
12
19
  // Method to add a web controller
13
20
  addWeb(controllerName, modelName = false) {
14
21
  try {
15
- let webControllerPath = path.resolve(`${rootPath}/app/Http/Controllers`); // Resolve path to web controllers directory
16
- if (fs.existsSync(`${webControllerPath}/${controllerName}.ts`)) {
22
+ let webControllerPath = path_1.default.resolve(`${rootPath}/app/Http/Controllers`); // Resolve path to web controllers directory
23
+ if (fs_1.default.existsSync(`${webControllerPath}/${controllerName}.ts`)) {
17
24
  // Check if controller file already exists
18
- return console.log(`${controllerName} already exist`.yellow); // Log a warning if controller already exists
25
+ return console.log(colors_1.default.yellow(`${controllerName} already exist`)); // Log a warning if controller already exists
19
26
  }
20
27
  if (modelName && typeof modelName === "string") {
21
28
  // If model name is provided, create a resource controller
22
- fs.writeFileSync(`${webControllerPath}/${controllerName}.ts`, resourceController(controllerName, modelName));
29
+ fs_1.default.writeFileSync(`${webControllerPath}/${controllerName}.ts`, (0, ResourcesController_1.default)(controllerName, modelName));
23
30
  return console.log(`${controllerName} added successfully`.green); // Log success message
24
31
  }
25
- fs.writeFileSync(`${webControllerPath}/${controllerName}.ts`, createController(controllerName));
26
- return console.log(`${controllerName} added successfully`.green); // Log success message
32
+ fs_1.default.writeFileSync(`${webControllerPath}/${controllerName}.ts`, (0, Controller_1.default)(controllerName));
33
+ return console.log(colors_1.default.green(`${controllerName} added successfully`)); // Log success message
27
34
  }
28
35
  catch (err) {
29
- console.log(`${controllerName} admin controller not added`.red); // Log error if controller addition fails
36
+ console.log(colors_1.default.red(`${controllerName} admin controller not added`)); // Log error if controller addition fails
30
37
  }
31
38
  }
32
39
  // Method to add an API controller
33
40
  addApi(controllerName, modelName = false) {
34
41
  try {
35
- let apiPath = path.resolve(`${rootPath}/app/Http/ApiControllers`); // Resolve path to API controllers directory
36
- if (fs.existsSync(`${apiPath}/${controllerName}.ts`)) {
42
+ let apiPath = path_1.default.resolve(`${rootPath}/app/Http/ApiControllers`); // Resolve path to API controllers directory
43
+ if (fs_1.default.existsSync(`${apiPath}/${controllerName}.ts`)) {
37
44
  // Check if API controller file already exists
38
- return console.log(`${controllerName} api controller already exist`.yellow); // Log a warning if API controller already exists
45
+ return console.log(colors_1.default.yellow(`${controllerName} api controller already exist`)); // Log a warning if API controller already exists
39
46
  }
40
47
  if (modelName && typeof modelName === "string") {
41
48
  // If model name is provided, create a resource controller
42
- fs.writeFileSync(`${apiPath}/${controllerName}.ts`, resourceController(controllerName, modelName));
43
- return console.log(`${controllerName} added successfully`.green); // Log success message
49
+ fs_1.default.writeFileSync(`${apiPath}/${controllerName}.ts`, (0, ResourcesController_1.default)(controllerName, modelName));
50
+ return console.log(colors_1.default.green(`${controllerName} added successfully`)); // Log success message
44
51
  }
45
- fs.writeFileSync(`${apiPath}/${controllerName}.ts`, createController(controllerName));
46
- return console.log(`${controllerName} added successfully`.green); // Log success message
52
+ fs_1.default.writeFileSync(`${apiPath}/${controllerName}.ts`, (0, Controller_1.default)(controllerName));
53
+ return console.log(colors_1.default.green(`${controllerName} added successfully`)); // Log success message
47
54
  }
48
55
  catch (err) {
49
56
  console.log(err.message);
50
- console.log(`${controllerName} api controller not added`.red); // Log error if controller addition fails
57
+ console.log(colors_1.default.red(`${controllerName} api controller not added`)); // Log error if controller addition fails
51
58
  }
52
59
  }
53
60
  // Method to add a model
54
61
  addModel(modelName) {
55
62
  try {
56
- let modelPath = path.resolve(`${rootPath}/app/Models`); // Resolve path to models directory
57
- if (fs.existsSync(`${modelPath}/${modelName}.ts`)) {
63
+ let modelPath = path_1.default.resolve(`${rootPath}/app/Models`); // Resolve path to models directory
64
+ if (fs_1.default.existsSync(`${modelPath}/${modelName}.ts`)) {
58
65
  // Check if model file already exists
59
- return console.log(`${modelName} model already exist`.yellow); // Log a warning if model already exists
66
+ return console.log(colors_1.default.yellow(`${modelName} model already exist`)); // Log a warning if model already exists
60
67
  }
61
- fs.writeFileSync(`${modelPath}/${modelName}.ts`, createModel(modelName)); // Create a model file
62
- return console.log(`${modelName} model added successfully`.green); // Log success message
68
+ fs_1.default.writeFileSync(`${modelPath}/${modelName}.ts`, (0, Models_1.default)(modelName)); // Create a model file
69
+ return console.log(colors_1.default.green(`${modelName} model added successfully`)); // Log success message
63
70
  }
64
71
  catch (err) {
65
- return console.log(`${modelName} model not added`.red); // Log error if model addition fails
72
+ return console.log(colors_1.default.red(`${modelName} model not added`)); // Log error if model addition fails
66
73
  }
67
74
  }
68
75
  // Method to add a request file
69
76
  addRequest(requestName) {
70
77
  try {
71
- let requestPath = path.resolve(`${rootPath}/app/Http/Requests`); // Resolve path to request files directory
72
- if (fs.existsSync(`${requestPath}/${requestName}.ts`)) {
78
+ let requestPath = path_1.default.resolve(`${rootPath}/app/Http/Requests`); // Resolve path to request files directory
79
+ if (fs_1.default.existsSync(`${requestPath}/${requestName}.ts`)) {
73
80
  // Check if request file already exists
74
- return console.log(`${requestName} already exist`.yellow); // Log a warning if request file already exists
81
+ return console.log(colors_1.default.yellow(`${requestName} already exist`)); // Log a warning if request file already exists
75
82
  }
76
- fs.writeFileSync(`${requestPath}/${requestName}.ts`, createRequest(requestName));
77
- return console.log(`${requestName} added successfully`.green); // Log success message
83
+ fs_1.default.writeFileSync(`${requestPath}/${requestName}.ts`, (0, Request_1.default)(requestName));
84
+ return console.log(colors_1.default.green(`${requestName} added successfully`)); // Log success message
78
85
  }
79
86
  catch (err) {
80
- return console.log(`${requestName} request not added`.red, { err }); // Log error if request addition fails
87
+ return console.log(colors_1.default.red(`${requestName} request not added`), {
88
+ err,
89
+ }); // Log error if request addition fails
81
90
  }
82
91
  }
83
92
  // Method to add a request file
84
93
  addMigration(migrationName) {
85
94
  try {
86
95
  const tableName = migrationName.replace(/(create_|_table)/g, "");
87
- let migrationPath = path.resolve(`${rootPath}/database/migrations`);
96
+ let migrationPath = path_1.default.resolve(`${rootPath}/database/migrations`);
88
97
  // Resolve path to request files directory
89
- const fullName = `${formatDate()}_${migrationName}`;
90
- if (fs.existsSync(`${migrationPath}/${fullName}.ts`)) {
98
+ const fullName = `${(0, utils_1.formatDate)()}_${migrationName}`;
99
+ if (fs_1.default.existsSync(`${migrationPath}/${fullName}.ts`)) {
91
100
  // Check if request file already exists
92
- return console.log(`${tableName} already exist`.yellow); // Log a warning if request file already exists
101
+ return console.log(colors_1.default.yellow(`${tableName} already exist`)); // Log a warning if request file already exists
93
102
  }
94
- fs.writeFileSync(`${migrationPath}/${fullName}.ts`, createMigration(tableName));
95
- return console.log(`${fullName} added successfully`.green); // Log success message
103
+ fs_1.default.writeFileSync(`${migrationPath}/${fullName}.ts`, (0, Migration_1.default)(tableName));
104
+ return console.log(colors_1.default.green(`${fullName} added successfully`)); // Log success message
96
105
  }
97
106
  catch (err) {
98
- return console.log(`${migrationName} migration not added`.red, { err }); // Log error if request addition fails
107
+ return console.log(colors_1.default.red(`${migrationName} migration not added`), {
108
+ err,
109
+ }); // Log error if request addition fails
110
+ }
111
+ }
112
+ runMigration() {
113
+ try {
114
+ const migrationPath = `${rootPath}/database/migrations`;
115
+ const files = fs_1.default.readdirSync(migrationPath);
116
+ for (const file of files) {
117
+ const migrationFile = require(`${migrationPath}/${file}.ts`);
118
+ // const sql = migrationFile.up();
119
+ console.log(migrationFile);
120
+ }
121
+ }
122
+ catch (error) {
123
+ console.log(error.message);
99
124
  }
100
125
  }
101
126
  // Method to handle a command not found
102
127
  notFound() {
103
- return console.log(`Command not found`.bgRed); // Log a message indicating the command was not found
128
+ return console.log(colors_1.default.bgRed(`Command not found`)); // Log a message indicating the command was not found
104
129
  }
105
130
  }
106
- export default new Command(); // Export an instance of the Command class
131
+ exports.default = new Command(); // Export an instance of the Command class
@@ -1,3 +1,5 @@
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
@@ -72,4 +74,4 @@ const createController = (name) => {
72
74
  }
73
75
  `;
74
76
  };
75
- export default createController;
77
+ exports.default = createController;
@@ -1,7 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  const inflection = require("inflection");
2
4
  const createMigration = (table) => {
3
5
  return `
4
- import {Schema} from "jcc-express-mvc";
6
+ import {Schema} from "jcc-eloquent";
5
7
  class Migration {
6
8
  up() {
7
9
  return Schema.create("${inflection.pluralize(table)}", (table) => {
@@ -13,4 +15,4 @@ class Migration {
13
15
  }
14
16
  `;
15
17
  };
16
- export default createMigration;
18
+ exports.default = createMigration;
@@ -1,3 +1,5 @@
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
@@ -5,7 +7,7 @@
5
7
  */
6
8
  const createModel = (name) => {
7
9
  return `
8
- import {Model} from "jcc-express-mvc"
10
+ import {Model} from "jcc-eloquent"
9
11
 
10
12
  export class ${name} extends Model{
11
13
  //
@@ -16,4 +18,4 @@ const createModel = (name) => {
16
18
 
17
19
  `;
18
20
  };
19
- export default createModel;
21
+ exports.default = createModel;
@@ -1,3 +1,5 @@
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
@@ -28,4 +30,4 @@ const createRequest = (fileName) => {
28
30
 
29
31
  `;
30
32
  };
31
- export default 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 `import {Model}= from "jcc-express-mvc"
9
+ return `import {Model}= from "jcc-eloquent"
8
10
  export class ${controller} extends Model {
9
11
 
10
12
  /**
@@ -72,4 +74,4 @@ const resourceController = (controller, model) => {
72
74
  }
73
75
  `;
74
76
  };
75
- export default resourceController;
77
+ exports.default = resourceController;