jcc-express-mvc 1.3.2 → 1.3.4

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,GA6FhE,CAAC"}
@@ -11,59 +11,68 @@ 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 (command === "migrate") {
19
+ return command_1.default.runMigration();
20
+ }
21
+ if (commandArg.length === index + 4 &&
22
+ (command === "apiController" || command === "ApiController") &&
23
+ (commandArg[index + 3] === "--resources" ||
24
+ commandArg[index + 3] === "-r")) {
25
+ command_1.default.addModel(commandArg[2]); // Add a model with the provided name
26
+ return command_1.default.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller with resources
27
+ }
28
+ // If the command is for creating a web controller with resources
29
+ if (commandArg.length === 4 &&
30
+ (command === "controller" || command === "Controller") &&
31
+ (commandArg[3] === "--resources" || commandArg[3] === "-r")) {
32
+ command_1.default.addModel(commandArg[2]); // Add a model with the provided name
33
+ return command_1.default.addWeb(commandArg[1], commandArg[2]); // Add a web controller with resources
34
+ }
35
+ // If the command is for creating an admin controller with resources
36
+ // If the command is for creating a web controller
37
+ if (commandArg.length === index + 3 &&
38
+ (command === "controller" || command === "Controller")) {
39
+ return command_1.default.addWeb(commandArg[index + 1], commandArg[index + 2]); // Add a web controller
40
+ }
41
+ // If the command is for creating an API controller
42
+ if (commandArg.length === index + 3 &&
43
+ (command === "apiController" || command === "ApiController")) {
44
+ return command_1.default.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller
45
+ }
46
+ // If the command is for creating a model
47
+ if (commandArg.length === index + 2 &&
48
+ (command === "model" || command === "Model")) {
49
+ return command_1.default.addModel(commandArg[index + 1]); // Add a model
50
+ }
51
+ // If the command is for creating a web controller without specifying a model
52
+ if (commandArg.length === index + 2 &&
53
+ (command === "controller" || command === "Controller")) {
54
+ return command_1.default.addWeb(commandArg[index + 1], false); // Add a web controller without a model
55
+ }
56
+ // If the command is for creating an API controller without specifying a model
57
+ if (commandArg.length === index + 2 &&
58
+ (command === "apiController" || command === "ApiController")) {
59
+ return command_1.default.addApi(commandArg[index + 1], false); // Add an API controller without a model
60
+ }
61
+ // If the command is for creating a request file
62
+ if (commandArg.length === index + 2 &&
63
+ (command === "Request" || command === "request")) {
64
+ return command_1.default.addRequest(commandArg[index + 1]); // Add a request file
65
+ }
66
+ // If the command is for creating a request file
67
+ if (commandArg.length === index + 2 &&
68
+ (command === "Migration" || command === "migration")) {
69
+ return command_1.default.addMigration(commandArg[index + 1]); // Add a request file
70
+ }
71
+ // If the command is not recognized, display "Command not found"
72
+ return command_1.default.notFound();
22
73
  }
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
74
+ catch (error) {
75
+ console.log("Sorry an error occur, Please try again");
29
76
  }
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
77
  };
69
78
  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;IAqBZ,QAAQ,IAAI,GAAG;CAGhB;;AAED,wBAA6B"}
@@ -11,8 +11,11 @@ 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");
16
+ const jcc_eloquent_1 = require("jcc-eloquent");
15
17
  const rootPath = app_root_path_1.default.path;
18
+ colors_1.default.enable();
16
19
  class Command {
17
20
  // Method to add a web controller
18
21
  addWeb(controllerName, modelName = false) {
@@ -20,7 +23,7 @@ class Command {
20
23
  let webControllerPath = path_1.default.resolve(`${rootPath}/app/Http/Controllers`); // Resolve path to web controllers directory
21
24
  if (fs_1.default.existsSync(`${webControllerPath}/${controllerName}.ts`)) {
22
25
  // Check if controller file already exists
23
- return console.log(`${controllerName} already exist`.yellow); // Log a warning if controller already exists
26
+ return console.log(colors_1.default.yellow(`${controllerName} already exist`)); // Log a warning if controller already exists
24
27
  }
25
28
  if (modelName && typeof modelName === "string") {
26
29
  // If model name is provided, create a resource controller
@@ -28,10 +31,10 @@ class Command {
28
31
  return console.log(`${controllerName} added successfully`.green); // Log success message
29
32
  }
30
33
  fs_1.default.writeFileSync(`${webControllerPath}/${controllerName}.ts`, (0, Controller_1.default)(controllerName));
31
- return console.log(`${controllerName} added successfully`.green); // Log success message
34
+ return console.log(colors_1.default.green(`${controllerName} added successfully`)); // Log success message
32
35
  }
33
36
  catch (err) {
34
- console.log(`${controllerName} admin controller not added`.red); // Log error if controller addition fails
37
+ console.log(colors_1.default.red(`${controllerName} admin controller not added`)); // Log error if controller addition fails
35
38
  }
36
39
  }
37
40
  // Method to add an API controller
@@ -40,19 +43,19 @@ class Command {
40
43
  let apiPath = path_1.default.resolve(`${rootPath}/app/Http/ApiControllers`); // Resolve path to API controllers directory
41
44
  if (fs_1.default.existsSync(`${apiPath}/${controllerName}.ts`)) {
42
45
  // 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
46
+ return console.log(colors_1.default.yellow(`${controllerName} api controller already exist`)); // Log a warning if API controller already exists
44
47
  }
45
48
  if (modelName && typeof modelName === "string") {
46
49
  // If model name is provided, create a resource controller
47
50
  fs_1.default.writeFileSync(`${apiPath}/${controllerName}.ts`, (0, ResourcesController_1.default)(controllerName, modelName));
48
- return console.log(`${controllerName} added successfully`.green); // Log success message
51
+ return console.log(colors_1.default.green(`${controllerName} added successfully`)); // Log success message
49
52
  }
50
53
  fs_1.default.writeFileSync(`${apiPath}/${controllerName}.ts`, (0, Controller_1.default)(controllerName));
51
- return console.log(`${controllerName} added successfully`.green); // Log success message
54
+ return console.log(colors_1.default.green(`${controllerName} added successfully`)); // Log success message
52
55
  }
53
56
  catch (err) {
54
57
  console.log(err.message);
55
- console.log(`${controllerName} api controller not added`.red); // Log error if controller addition fails
58
+ console.log(colors_1.default.red(`${controllerName} api controller not added`)); // Log error if controller addition fails
56
59
  }
57
60
  }
58
61
  // Method to add a model
@@ -61,13 +64,13 @@ class Command {
61
64
  let modelPath = path_1.default.resolve(`${rootPath}/app/Models`); // Resolve path to models directory
62
65
  if (fs_1.default.existsSync(`${modelPath}/${modelName}.ts`)) {
63
66
  // Check if model file already exists
64
- return console.log(`${modelName} model already exist`.yellow); // Log a warning if model already exists
67
+ return console.log(colors_1.default.yellow(`${modelName} model already exist`)); // Log a warning if model already exists
65
68
  }
66
69
  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
70
+ return console.log(colors_1.default.green(`${modelName} model added successfully`)); // Log success message
68
71
  }
69
72
  catch (err) {
70
- return console.log(`${modelName} model not added`.red); // Log error if model addition fails
73
+ return console.log(colors_1.default.red(`${modelName} model not added`)); // Log error if model addition fails
71
74
  }
72
75
  }
73
76
  // Method to add a request file
@@ -76,13 +79,15 @@ class Command {
76
79
  let requestPath = path_1.default.resolve(`${rootPath}/app/Http/Requests`); // Resolve path to request files directory
77
80
  if (fs_1.default.existsSync(`${requestPath}/${requestName}.ts`)) {
78
81
  // Check if request file already exists
79
- return console.log(`${requestName} already exist`.yellow); // Log a warning if request file already exists
82
+ return console.log(colors_1.default.yellow(`${requestName} already exist`)); // Log a warning if request file already exists
80
83
  }
81
84
  fs_1.default.writeFileSync(`${requestPath}/${requestName}.ts`, (0, Request_1.default)(requestName));
82
- return console.log(`${requestName} added successfully`.green); // Log success message
85
+ return console.log(colors_1.default.green(`${requestName} added successfully`)); // Log success message
83
86
  }
84
87
  catch (err) {
85
- return console.log(`${requestName} request not added`.red, { err }); // Log error if request addition fails
88
+ return console.log(colors_1.default.red(`${requestName} request not added`), {
89
+ err,
90
+ }); // Log error if request addition fails
86
91
  }
87
92
  }
88
93
  // Method to add a request file
@@ -92,20 +97,41 @@ class Command {
92
97
  let migrationPath = path_1.default.resolve(`${rootPath}/database/migrations`);
93
98
  // Resolve path to request files directory
94
99
  const fullName = `${(0, utils_1.formatDate)()}_${migrationName}`;
95
- if (fs_1.default.existsSync(`${migrationPath}/${fullName}.ts`)) {
100
+ if (fs_1.default.existsSync(`${migrationPath}/${fullName}.js`)) {
96
101
  // Check if request file already exists
97
- return console.log(`${tableName} already exist`.yellow); // Log a warning if request file already exists
102
+ return console.log(colors_1.default.yellow(`${tableName} already exist`)); // Log a warning if request file already exists
98
103
  }
99
- fs_1.default.writeFileSync(`${migrationPath}/${fullName}.ts`, (0, Migration_1.default)(tableName));
100
- return console.log(`${fullName} added successfully`.green); // Log success message
104
+ fs_1.default.writeFileSync(`${migrationPath}/${fullName}.js`, (0, Migration_1.default)(tableName));
105
+ return console.log(colors_1.default.green(`${fullName} added successfully`)); // Log success message
101
106
  }
102
107
  catch (err) {
103
- return console.log(`${migrationName} migration not added`.red, { err }); // Log error if request addition fails
108
+ return console.log(colors_1.default.red(`${migrationName} migration not added`), {
109
+ err,
110
+ }); // Log error if request addition fails
111
+ }
112
+ }
113
+ runMigration() {
114
+ try {
115
+ const migrationPath = `${rootPath}/database/migrations`;
116
+ const files = fs_1.default.readdirSync(migrationPath);
117
+ for (const file of files) {
118
+ const migrationFile = require(`${migrationPath}/${file}.ts`);
119
+ const sql = migrationFile.up();
120
+ jcc_eloquent_1.DB.runQuery(sql)
121
+ .then((res) => {
122
+ console.log(res);
123
+ process.exit();
124
+ })
125
+ .catch((err) => console.log(err));
126
+ }
127
+ }
128
+ catch (error) {
129
+ console.log(error.message);
104
130
  }
105
131
  }
106
132
  // Method to handle a command not found
107
133
  notFound() {
108
- return console.log(`Command not found`.bgRed); // Log a message indicating the command was not found
134
+ return console.log(colors_1.default.bgRed(`Command not found`)); // Log a message indicating the command was not found
109
135
  }
110
136
  }
111
137
  exports.default = new Command(); // Export an instance of the Command class
@@ -1 +1 @@
1
- {"version":3,"file":"Migration.d.ts","sourceRoot":"","sources":["../../../../framework/lib/Command-Line/files/Migration.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,eAAe,UAAW,MAAM,KAAG,MAaxC,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"Migration.d.ts","sourceRoot":"","sources":["../../../../framework/lib/Command-Line/files/Migration.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,eAAe,UAAW,MAAM,KAAG,MAexC,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -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) => {
@@ -13,6 +13,8 @@ class Migration {
13
13
  });
14
14
  }
15
15
  }
16
+
17
+ module.exports = new Migration()
16
18
  `;
17
19
  };
18
20
  exports.default = createMigration;
@@ -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.4",
4
4
  "description": "express mvc structure",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",