jcc-express-mvc 1.3.2 → 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.
@@ -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"}
@@ -11,59 +11,65 @@ const command_1 = __importDefault(require("./command"));
11
11
  @returns {any} -any
12
12
  * */
13
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
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();
22
70
  }
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
71
+ catch (error) {
72
+ console.log("Sorry an error occur, Please try again");
29
73
  }
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
74
  };
69
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"}
@@ -11,8 +11,10 @@ const Models_1 = __importDefault(require("./files/Models"));
11
11
  const ResourcesController_1 = __importDefault(require("./files/ResourcesController"));
12
12
  const Request_1 = __importDefault(require("./files/Request"));
13
13
  const Migration_1 = __importDefault(require("./files/Migration"));
14
+ const colors_1 = __importDefault(require("colors")); // Module for adding color to console output
14
15
  const utils_1 = require("./utils");
15
16
  const rootPath = app_root_path_1.default.path;
17
+ colors_1.default.enable();
16
18
  class Command {
17
19
  // Method to add a web controller
18
20
  addWeb(controllerName, modelName = false) {
@@ -20,7 +22,7 @@ class Command {
20
22
  let webControllerPath = path_1.default.resolve(`${rootPath}/app/Http/Controllers`); // Resolve path to web controllers directory
21
23
  if (fs_1.default.existsSync(`${webControllerPath}/${controllerName}.ts`)) {
22
24
  // Check if controller file already exists
23
- 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
24
26
  }
25
27
  if (modelName && typeof modelName === "string") {
26
28
  // If model name is provided, create a resource controller
@@ -28,10 +30,10 @@ class Command {
28
30
  return console.log(`${controllerName} added successfully`.green); // Log success message
29
31
  }
30
32
  fs_1.default.writeFileSync(`${webControllerPath}/${controllerName}.ts`, (0, Controller_1.default)(controllerName));
31
- return console.log(`${controllerName} added successfully`.green); // Log success message
33
+ return console.log(colors_1.default.green(`${controllerName} added successfully`)); // Log success message
32
34
  }
33
35
  catch (err) {
34
- 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
35
37
  }
36
38
  }
37
39
  // Method to add an API controller
@@ -40,19 +42,19 @@ class Command {
40
42
  let apiPath = path_1.default.resolve(`${rootPath}/app/Http/ApiControllers`); // Resolve path to API controllers directory
41
43
  if (fs_1.default.existsSync(`${apiPath}/${controllerName}.ts`)) {
42
44
  // 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
45
+ return console.log(colors_1.default.yellow(`${controllerName} api controller already exist`)); // Log a warning if API controller already exists
44
46
  }
45
47
  if (modelName && typeof modelName === "string") {
46
48
  // If model name is provided, create a resource controller
47
49
  fs_1.default.writeFileSync(`${apiPath}/${controllerName}.ts`, (0, ResourcesController_1.default)(controllerName, modelName));
48
- return console.log(`${controllerName} added successfully`.green); // Log success message
50
+ return console.log(colors_1.default.green(`${controllerName} added successfully`)); // Log success message
49
51
  }
50
52
  fs_1.default.writeFileSync(`${apiPath}/${controllerName}.ts`, (0, Controller_1.default)(controllerName));
51
- return console.log(`${controllerName} added successfully`.green); // Log success message
53
+ return console.log(colors_1.default.green(`${controllerName} added successfully`)); // Log success message
52
54
  }
53
55
  catch (err) {
54
56
  console.log(err.message);
55
- 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
56
58
  }
57
59
  }
58
60
  // Method to add a model
@@ -61,13 +63,13 @@ class Command {
61
63
  let modelPath = path_1.default.resolve(`${rootPath}/app/Models`); // Resolve path to models directory
62
64
  if (fs_1.default.existsSync(`${modelPath}/${modelName}.ts`)) {
63
65
  // Check if model file already exists
64
- 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
65
67
  }
66
68
  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
69
+ return console.log(colors_1.default.green(`${modelName} model added successfully`)); // Log success message
68
70
  }
69
71
  catch (err) {
70
- 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
71
73
  }
72
74
  }
73
75
  // Method to add a request file
@@ -76,13 +78,15 @@ class Command {
76
78
  let requestPath = path_1.default.resolve(`${rootPath}/app/Http/Requests`); // Resolve path to request files directory
77
79
  if (fs_1.default.existsSync(`${requestPath}/${requestName}.ts`)) {
78
80
  // Check if request file already exists
79
- 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
80
82
  }
81
83
  fs_1.default.writeFileSync(`${requestPath}/${requestName}.ts`, (0, Request_1.default)(requestName));
82
- return console.log(`${requestName} added successfully`.green); // Log success message
84
+ return console.log(colors_1.default.green(`${requestName} added successfully`)); // Log success message
83
85
  }
84
86
  catch (err) {
85
- 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
86
90
  }
87
91
  }
88
92
  // Method to add a request file
@@ -94,18 +98,34 @@ class Command {
94
98
  const fullName = `${(0, utils_1.formatDate)()}_${migrationName}`;
95
99
  if (fs_1.default.existsSync(`${migrationPath}/${fullName}.ts`)) {
96
100
  // Check if request file already exists
97
- 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
98
102
  }
99
103
  fs_1.default.writeFileSync(`${migrationPath}/${fullName}.ts`, (0, Migration_1.default)(tableName));
100
- return console.log(`${fullName} added successfully`.green); // Log success message
104
+ return console.log(colors_1.default.green(`${fullName} added successfully`)); // Log success message
101
105
  }
102
106
  catch (err) {
103
- 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);
104
124
  }
105
125
  }
106
126
  // Method to handle a command not found
107
127
  notFound() {
108
- 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
109
129
  }
110
130
  }
111
131
  exports.default = new Command(); // Export an instance of the Command class
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const inflection = require("inflection");
4
4
  const createMigration = (table) => {
5
5
  return `
6
- import {Schema} from "jcc-express-mvc";
6
+ import {Schema} from "jcc-eloquent";
7
7
  class Migration {
8
8
  up() {
9
9
  return Schema.create("${inflection.pluralize(table)}", (table) => {
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  */
8
8
  const createModel = (name) => {
9
9
  return `
10
- import {Model} from "jcc-express-mvc"
10
+ import {Model} from "jcc-eloquent"
11
11
 
12
12
  export class ${name} extends Model{
13
13
  //
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  * @returns string
7
7
  */
8
8
  const resourceController = (controller, model) => {
9
- return `import {Model}= from "jcc-express-mvc"
9
+ return `import {Model}= from "jcc-eloquent"
10
10
  export class ${controller} extends Model {
11
11
 
12
12
  /**
@@ -10,7 +10,7 @@ class Rules extends validate_1.Validate {
10
10
  switch (validation) {
11
11
  case "required":
12
12
  return this.required(fieldName, fieldValue);
13
- case "min" || "min:":
13
+ case "min":
14
14
  return this.min(fieldName, fieldValue, Number(secondValue));
15
15
  case "max":
16
16
  return this.max(fieldName, fieldValue, Number(secondValue));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jcc-express-mvc",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "express mvc structure",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",