beech-api 3.5.12 → 3.7.0

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 (66) hide show
  1. package/README.md +400 -185
  2. package/index.js +2 -3
  3. package/package.json +9 -6
  4. package/packages/cli/beech +2 -2
  5. package/packages/cli/bin/{beech.js → beech-app.js} +86 -28
  6. package/packages/cli/bin/beech-service.js +40 -212
  7. package/packages/cli/core/auth/Credentials.js +76 -35
  8. package/packages/cli/core/auth/Passport.js +318 -188
  9. package/packages/cli/core/auth/_Request.js +12 -0
  10. package/packages/cli/core/configure/_gitignore +9 -1
  11. package/packages/cli/core/configure/app.config-basic.js +10 -10
  12. package/packages/cli/core/configure/app.config-sequelize.js +12 -12
  13. package/packages/cli/core/configure/beech.config.js +8 -0
  14. package/packages/cli/core/configure/global.config-basic.js +4 -4
  15. package/packages/cli/core/configure/global.config-sequelize.js +4 -4
  16. package/packages/cli/core/configure/passport.config.js +5 -15
  17. package/packages/cli/core/databases/mysql.js +53 -29
  18. package/packages/cli/core/databases/sequelize.js +135 -107
  19. package/packages/cli/core/databases/test.js +168 -0
  20. package/packages/cli/core/file-walk/file-walk.js +31 -14
  21. package/packages/cli/core/generator/_add-on +15 -2
  22. package/packages/cli/core/generator/_endpoints +15 -82
  23. package/packages/cli/core/generator/_endpoints_basic +39 -0
  24. package/packages/cli/core/generator/_help +12 -11
  25. package/packages/cli/core/generator/_help_create +11 -0
  26. package/packages/cli/core/generator/{_service → _help_service} +4 -1
  27. package/packages/cli/core/generator/_models +20 -15
  28. package/packages/cli/core/generator/{_basic-models → _models_basic} +0 -2
  29. package/packages/cli/core/generator/_package +4 -3
  30. package/packages/cli/core/generator/index.js +302 -95
  31. package/packages/cli/core/helpers/math.js +55 -0
  32. package/packages/cli/core/helpers/poolEntity.js +31 -0
  33. package/packages/cli/core/index.js +96 -28
  34. package/packages/cli/core/origin/index.js +2 -0
  35. package/packages/cli/core/origin/whitelist/cors.js +91 -0
  36. package/packages/cli/core/services/http.express.js +338 -203
  37. package/packages/cli/core/test/utils.js +5 -5
  38. package/packages/lib/index.js +4 -0
  39. package/packages/lib/src/endpoint.js +98 -0
  40. package/packages/lib/src/salt.js +3 -0
  41. package/packages/lib/src/schema.js +62 -0
  42. package/packages/lib/src/user.js +196 -0
  43. package/packages/package.json +4 -7
  44. package/packages/cli/core/generator/_create +0 -7
  45. package/packages/lib/beech.js +0 -136
  46. package/packages/lib/salt.js +0 -3
  47. package/packages/src-/Add-on.js +0 -9
  48. package/packages/src-/endpoints/hello-endpoints.js +0 -118
  49. package/packages/src-/endpoints/test2-endpoints.js +0 -75
  50. package/packages/src-/endpoints/testSequalize-endpoints.js +0 -23
  51. package/packages/src-/helpers/Test2.js +0 -11
  52. package/packages/src-/helpers/my/Test.js +0 -11
  53. package/packages/src-/helpers/my/Test2.js +0 -11
  54. package/packages/src-/helpers/my/Test3.js +0 -11
  55. package/packages/src-/helpers/my/Test4.js +0 -11
  56. package/packages/src-/models/Jubu.js +0 -29
  57. package/packages/src-/models/Jubu2.js +0 -20
  58. package/packages/src-/models/Map_master.js +0 -22
  59. package/packages/src-/models/Test.js +0 -29
  60. package/packages/src-/models/Test2.js +0 -29
  61. package/packages/src-/models/User2Sequelize.js +0 -23
  62. package/packages/src-/models/Users-sqlite.js +0 -21
  63. package/packages/src-/models/Users.js +0 -53
  64. package/packages/src-/models/Uuuuuxxx.js +0 -23
  65. package/packages/src-/models/xxx/Uuuuuxxx.js +0 -23
  66. /package/packages/cli/core/generator/{_basic-helpers → _helpers_basic} +0 -0
package/index.js CHANGED
@@ -1,3 +1,2 @@
1
- module.exports = {
2
- User: require('./packages/lib/beech')
3
- }
1
+ const { Base, Schema, Store, Update } = require("./packages/lib/index");
2
+ module.exports = { Base, Schema, Store, Update };
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "beech-api",
3
- "version": "3.5.12",
3
+ "version": "3.7.0",
4
4
  "description": "Command line interface for rapid Beech API development",
5
5
  "keywords": [
6
6
  "api",
7
+ "node-api",
7
8
  "api-framework",
8
9
  "beech-api",
9
10
  "cli",
@@ -17,7 +18,7 @@
17
18
  },
18
19
  "authors": "bombkiml",
19
20
  "bin": {
20
- "beech-app": "./packages/cli/bin/beech.js",
21
+ "beech-app": "./packages/cli/bin/beech-app.js",
21
22
  "beech-service": "./packages/cli/bin/beech-service.js",
22
23
  "beech": "./packages/cli/core/generator/index.js"
23
24
  },
@@ -32,10 +33,12 @@
32
33
  "dependencies": {
33
34
  "app-root-path": "^3.0.0",
34
35
  "axios": "^0.26.1",
36
+ "child-process-promise": "^2.2.1",
35
37
  "cli-clear": "^1.0.4",
36
38
  "cookie-parser": "1.4.3",
37
39
  "cors": "^2.8.1",
38
- "express": "4.16.3",
40
+ "cryptr": "^6.3.0",
41
+ "express": "4.19.2",
39
42
  "express-session": "^1.17.1",
40
43
  "express-validator": "2.21.0",
41
44
  "fs": "0.0.1-security",
@@ -43,11 +46,12 @@
43
46
  "jsonwebtoken": "^8.5.1",
44
47
  "log-update": "^4.0.0",
45
48
  "md5": "^2.3.0",
49
+ "method-override": "^3.0.0",
46
50
  "mkdirp": "^2.1.6",
47
51
  "module-alias": "^2.2.2",
48
52
  "mysql": "^2.18.1",
49
53
  "mysql2": "^2.3.3",
50
- "node-cmd": "^3.0.0",
54
+ "node-emoji": "^1.11.0",
51
55
  "node-notifier": "^10.0.1",
52
56
  "passport": "^0.6.0",
53
57
  "passport-facebook": "^3.0.0",
@@ -61,8 +65,7 @@
61
65
  },
62
66
  "devDependencies": {
63
67
  "jest": "^28.1.3",
64
- "node-dev": "^8.0.0",
65
- "nodemon": "^3.0.1",
68
+ "nodemon": "^3.1.0",
66
69
  "sequelize-cli": "^5.5.1"
67
70
  },
68
71
  "jest": {
@@ -4,8 +4,8 @@
4
4
  * The beech api (cli) package generator and server (bash for developer and production build)
5
5
  *
6
6
  * @author bombkiml
7
- * @version 3.6
8
- * @built Aug 14, 2023 at 00:09:19
7
+ * @version 3.7
8
+ * @built Apr 19, 2024 at 16:20:09
9
9
  *
10
10
  */
11
11
  (process.argv[2]) ? require('./core/generator/index') : require('./core/index')
@@ -41,6 +41,8 @@ class Beech {
41
41
  let pasteGloablConfigFile = this.argument + '/global.config.js';
42
42
  let tmpGitignoreFile = __dirname + '/../core/configure/_gitignore';
43
43
  let pasteGitignoreFile = this.argument + '/.gitignore';
44
+ let tmpBeechConfigFile = __dirname + '/../core/configure/beech.config.js';
45
+ let pasteBeechConfigFile = this.argument + '/beech.config.js';
44
46
  // start log clear screen
45
47
  clear();
46
48
  logUpdate("Beech CLI v" + require(__dirname + "/../../../package.json").version);
@@ -63,22 +65,27 @@ class Beech {
63
65
  message: "Check the features needed for your project:",
64
66
  choices: [ "Add-Ons", "Basic Helper", "Passport / JWT / Official Strategy Google, Facebook" ],
65
67
  } ]).then(resFreat => {
66
- // init project
67
- this.makeFolder(this.argument)
68
- .then(this.copy.bind(this, tmpPackageFile, pastePackageFile))
69
- .then(this.contentReplace.bind(this, pastePackageFile, { 'application': this.argument }))
70
- .then(this.copy.bind(this, tmpConfigFile, pasteConfigFile))
71
- .then(this.copy.bind(this, tmpJestFile, pasteJestFile))
72
- .then(this.copy.bind(this, tmpJsConfigFile, pasteJsConfigFile))
73
- .then(this.copy.bind(this, tmpDotSequelizercFile, pasteDotSequelizercFile))
74
- .then(this.copy.bind(this, tmpGloablConfigFile, pasteGloablConfigFile))
75
- .then(this.copy.bind(this, tmpGitignoreFile, pasteGitignoreFile))
76
- .then(this.generateKeyConfigFile.bind(this, this.argument))
77
- .then(this.installPackage.bind(this, this.argument, resFreat.freature))
78
- .then(console.log("\n Processing  The Application `" + this.argument + "` is creating...\n"))
79
- .catch((err) => {
80
- throw err;
81
- });
68
+ logUpdate(": Initialize...");
69
+ setTimeout(() => {
70
+ // init project
71
+ this.makeFolder(this.argument)
72
+ .then(this.copy.bind(this, tmpPackageFile, pastePackageFile))
73
+ //.then(this.contentReplace.bind(this, pastePackageFile, { 'application': this.argument }))
74
+ .then(this.copy.bind(this, tmpConfigFile, pasteConfigFile))
75
+ .then(this.copy.bind(this, tmpJestFile, pasteJestFile))
76
+ .then(this.copy.bind(this, tmpJsConfigFile, pasteJsConfigFile))
77
+ .then(this.copy.bind(this, tmpDotSequelizercFile, pasteDotSequelizercFile))
78
+ .then(this.copy.bind(this, tmpGloablConfigFile, pasteGloablConfigFile))
79
+ .then(this.copy.bind(this, tmpGitignoreFile, pasteGitignoreFile))
80
+ .then(this.copy.bind(this, tmpBeechConfigFile, pasteBeechConfigFile))
81
+ .then(this.contentReplace.bind(this, pastePackageFile, { 'application': this.argument }))
82
+ .then(this.generateKeyConfigFile.bind(this, this.argument))
83
+ .then(this.installPackage.bind(this, this.argument, resFreat.freature))
84
+ .then(console.log("\n Processing   The Application `" + this.argument + "` is creating...\n"))
85
+ .catch((err) => {
86
+ throw err;
87
+ });
88
+ }, 2000);
82
89
  });
83
90
  });
84
91
  } else {
@@ -87,11 +94,62 @@ class Beech {
87
94
  } else {
88
95
  resolve("\n Warning  Please specify your project name.");
89
96
  }
97
+ } else if (this.option == "update") {
98
+ // upgrade the beech-api package
99
+ let isGlobalYarn = "yarn add beech-api";
100
+ let isGlobalNpm = "npm update beech-api";
101
+ let processUpdate = null;
102
+ let lineStdout = "";
103
+ if (this.argument == '-g' || this.argument == '--global') {
104
+ isGlobalNpm = "npm update beech-api -g";
105
+ isGlobalYarn = "yarn global add beech-api";
106
+ }
107
+ // prompt select
108
+ inquirer.prompt([ {
109
+ type: "list",
110
+ name: "package",
111
+ message: "Please pick a package control:",
112
+ choices: [ "NPM", "Yarn" ],
113
+ } ]).then(selectedPackage => {
114
+ logUpdate(": Initialize...");
115
+ // delay for update package
116
+ setTimeout(() => {
117
+ if(selectedPackage.package == "NPM") {
118
+ processUpdate = this.cmd.get(isGlobalNpm, (err) => {
119
+ if (err) { throw err }
120
+ });
121
+ // npm install line shoutout
122
+ processUpdate.stdout.on('data', (npmData) => {
123
+ lineStdout += npmData;
124
+ if (lineStdout[ lineStdout.length - 1 ] == '\n') {
125
+ logUpdate('\n' + lineStdout);
126
+ }
127
+ });
128
+ } else if(selectedPackage.package == "Yarn") {
129
+ processUpdate = this.cmd.get(isGlobalYarn, (err) => {
130
+ if (err) { throw err }
131
+ });
132
+ // yarn install line shoutout
133
+ processUpdate.stdout.on('data', (yarnData) => {
134
+ lineStdout += yarnData;
135
+ if (lineStdout[ lineStdout.length - 1 ] == '\n') {
136
+ logUpdate('\n' + lineStdout);
137
+ }
138
+ });
139
+ } else {
140
+ logUpdate("\n Faltal  Catch update package. Try again...");
141
+ return;
142
+ }
143
+ }, 1000);
144
+ });
90
145
  } else {
91
- resolve("\n Faltal  commnad it's not available.");
146
+ // help for see avaliable command
147
+ this.help()
148
+ .then(help => resolve(help))
149
+ .catch(err => reject(err));
92
150
  }
93
151
  } catch (error) {
94
- reject(error);
152
+ throw error;
95
153
  }
96
154
  });
97
155
  }
@@ -138,13 +196,13 @@ class Beech {
138
196
  return new Promise((resolve, reject) => {
139
197
  try {
140
198
  let helperPath = argument + '/src/helpers/';
141
- let tmpBasicHelperFile = __dirname + '/../core/generator/_basic-helpers';
199
+ let tmpBasicHelperFile = __dirname + '/../core/generator/_helpers_basic';
142
200
  let pasteBasicHelperFile = helperPath + '/Basic.js';
143
201
  let freatureLength = freatureArr.length;
144
202
  if (freatureLength) {
145
203
  freatureArr.map((f, key) => {
146
204
  if (f.split(' ')[ 0 ] == "Add-Ons") {
147
- (process.env.NODE_ENV == "development") ? this.cmd.get('cd ' + argument + ' && node cli/bin/beech.js add-on init') : this.cmd.get('cd ' + argument + ' && beech add-on init');
205
+ (process.env.NODE_ENV == "development") ? this.cmd.get('cd ' + argument + ' && node cli/bin/beech-app.js add-on init') : this.cmd.get('cd ' + argument + ' && beech add-on init');
148
206
  console.log("[" + (key + 1) + "/" + freatureLength + "] Installing Add-Ons");
149
207
  }
150
208
  if (f.split(' ')[ 0 ] == "Basic") {
@@ -152,7 +210,7 @@ class Beech {
152
210
  console.log("[" + (key + 1) + "/" + freatureLength + "] Installing Basic helper");
153
211
  }
154
212
  if (f.split(' ')[ 0 ] == "Passport") {
155
- (process.env.NODE_ENV == "development") ? this.cmd.get('cd ' + argument + ' && node cli/bin/beech.js passport init') : this.cmd.get('cd ' + argument + ' && beech passport init');
213
+ (process.env.NODE_ENV == "development") ? this.cmd.get('cd ' + argument + ' && node cli/bin/beech-app.js passport init') : this.cmd.get('cd ' + argument + ' && beech passport init');
156
214
  console.log("[" + (key + 1) + "/" + freatureLength + "] Installing Passport JWT, Official strategy Google, Facebook");
157
215
  }
158
216
  if (freatureArr.length == (key + 1)) {
@@ -246,7 +304,7 @@ class Beech {
246
304
  return new Promise((resolve, reject) => {
247
305
  try {
248
306
  let md5 = require("md5");
249
- let secret = require(__dirname + "/../../lib/salt").salt;
307
+ let secret = require(__dirname + "/../../lib/src/salt").salt;
250
308
  let result = '';
251
309
  let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
252
310
  let charactersLength = characters.length;
@@ -272,17 +330,17 @@ class Beech {
272
330
  let buf2str = buffer.toString();
273
331
  let buf2json = JSON.parse(JSON.stringify(buf2str));
274
332
  let buf2eval = eval(buf2json);
275
- let oldSecret = buf2eval.main_config.app_secret;
276
- // generate new key secret
277
- this.appKeyGenerator(8).then(newAppSecret => {
333
+ let oldKey = buf2eval.main_config.app_key;
334
+ // generate new key
335
+ this.appKeyGenerator(8).then(newAppKey => {
278
336
  // content replace
279
- let text = data.replace(new RegExp(oldSecret, 'g'), newAppSecret);
337
+ let text = data.replace(new RegExp(oldKey, 'g'), newAppKey);
280
338
  // writing the file
281
339
  this.fs.writeFile(pjName + "/app.config.js", text, 'utf8', (err) => {
282
340
  if (err) {
283
341
  throw err;
284
342
  } else {
285
- resolve("\n Passed  App secret it's new generated.");
343
+ resolve("\n Passed  App key it's new generated.");
286
344
  }
287
345
  });
288
346
  });
@@ -297,7 +355,7 @@ class Beech {
297
355
  help() {
298
356
  return new Promise((resolve, reject) => {
299
357
  try {
300
- this.fs.readFile(__dirname + "/../core/generator/_create", "utf8", (err, data) => {
358
+ this.fs.readFile(__dirname + "/../core/generator/_help_create", "utf8", (err, data) => {
301
359
  if (err) {
302
360
  reject(err);
303
361
  } else {
@@ -2,11 +2,8 @@
2
2
  const logUpdate = require("log-update");
3
3
  const notifier = require("node-notifier");
4
4
  const path = require("path");
5
- const clear = require("cli-clear");
6
5
  const express = require("express");
7
6
  const _app_ = express();
8
- const Sequelize = require('sequelize');
9
- let testSql = {};
10
7
 
11
8
  class Beech {
12
9
  constructor() {
@@ -29,21 +26,18 @@ class Beech {
29
26
  }
30
27
  // check project config file exists ?
31
28
  if (this.fs.existsSync(this.configFile)) {
32
- const testServ = _app_.listen(this._config_.main_config.app_port, () => {
33
- //console.log("Test Started.");
34
- testServ.close();
29
+ let testServ = require("http").createServer(_app_);
30
+ testServ.listen(this._config_.main_config.app_port, async () => {
31
+ await testServ.close();
35
32
  // Start real service.
36
- this.getStart(turnNoti, (err, res) => {
37
- if (err) {
38
- reject("\n Faltal  start service catch.");
39
- return;
40
- }
41
- // show info
42
- console.clear();
43
- //console.log(res);
44
- });
45
-
46
- });
33
+ await this.serviceDevStart(this.argument);
34
+ // check turn on nofi
35
+ if (turnNoti) {
36
+ this.notiCompile();
37
+ }
38
+ }).on('error', (err) => {
39
+ console.log("\n Faltal ", err);
40
+ })
47
41
  } else {
48
42
  resolve("\n Faltal  The app.conifg.js file is not found.");
49
43
  }
@@ -52,8 +46,13 @@ class Beech {
52
46
  this.help()
53
47
  .then(help => resolve(help))
54
48
  .catch(err => reject(err));
49
+ } else if (this.option == "build") {
50
+ resolve("\n Notic.  The commnad it's not supported, Please wait for next version.");
55
51
  } else {
56
- resolve("\n Faltal  commnad it's not available.");
52
+ // help for see avaliable command
53
+ this.help()
54
+ .then(help => resolve(help))
55
+ .catch(err => reject(err));
57
56
  }
58
57
  } catch (error) {
59
58
  reject(error);
@@ -61,181 +60,27 @@ class Beech {
61
60
  });
62
61
  }
63
62
 
64
- filterDbIsTrue(dbConfig, cb) {
65
- try {
66
- let dbIsTrue = [];
67
- dbConfig.filter((e, k) => {
68
- if (e.is_connect) {
69
- dbIsTrue.push(e);
70
- }
71
- if (dbConfig.length == k + 1) {
72
- cb(null, dbIsTrue);
73
- }
74
- });
75
- } catch (error) {
76
- cb(error, null);
77
- }
78
- }
79
-
80
- initSequelize(val, cb) {
81
- try {
82
- const sq = new Sequelize({
83
- dialect: val.dialect || "mysql",
84
- host: val.host,
85
- username: val.username,
86
- password: val.password,
87
- database: val.database,
88
- port: val.port,
89
- storage: val.storage || ":memory:",
90
- protocol: val.protocol || null,
91
- logging: val.logging || false,
92
- dialectOptions: {
93
- socketPath: ((val.dialectOptions) ? ((val.dialectOptions.socketPath) ? val.dialectOptions.socketPath : "") : ""), //Applications/MAMP/tmp/mysql/mysql.sock
94
- supportBigNumbers: ((val.dialectOptions) ? ((val.dialectOptions.supportBigNumbers) ? val.dialectOptions.supportBigNumbers : false) : false),
95
- bigNumberStrings: ((val.dialectOptions) ? ((val.dialectOptions.bigNumberStrings) ? val.dialectOptions.bigNumberStrings : false) : false),
96
- options: ((val.dialectOptions) ? ((val.dialectOptions.options) ? ({ encrypt: false, ...val.dialectOptions.options }) : { encrypt: false }) : { encrypt: false }),
97
- },
98
- omitNull: val.omitNull || false,
99
- native: val.native || false,
100
- define: {
101
- underscored: ((val.define) ? ((val.define.underscored) ? val.define.underscored : false) : false),
102
- freezeTableName: ((val.define) ? ((val.define.freezeTableName === false) ? val.define.freezeTableName : true) : true),
103
- charset: ((val.define) ? ((val.define.charset) ? val.define.charset : "utf8") : "utf8"),
104
- dialectOptions: {
105
- collate: ((val.define) ? ((val.define.dialectOptions) ? ((val.define.dialectOptions.timestamps) ? val.define.dialectOptions.timestamps : "utf8_general_ci") : "utf8_general_ci") : "utf8_general_ci"),
106
- },
107
- timestamps: ((val.define) ? ((val.define.timestamps) ? val.define.timestamps : false) : false),
108
- },
109
- sync: {
110
- force: ((val.sync) ? ((val.sync.force) ? val.sync.force : false) : false),
111
- },
112
- pool: {
113
- max: ((val.pool) ? ((val.pool.max) ? val.pool.max : 5) : 5),
114
- idle: ((val.pool) ? ((val.pool.idle) ? val.pool.idle : 30000) : 30000),
115
- acquire: ((val.pool) ? ((val.pool.acquire) ? val.pool.acquire : 60000) : 60000),
116
- },
117
- isolationLevel: val.isolationLevel || "Transaction.ISOLATION_LEVELS.REPEATABLE_READ",
118
- query: {
119
- raw: ((val.query) ? ((val.query.raw) ? val.query.raw : true) : true),
120
- nest: ((val.query) ? ((val.query.nest) ? val.query.nest : true) : true),
121
- }
122
- });
123
- cb(false, sq);
124
- } catch (error) {
125
- cb(error, null);
126
- }
127
- }
128
-
129
- testConnectInProcess = (database_config, dbConnTotal, cb) => {
130
- try {
131
- let val = database_config.shift();
132
- if (val) {
133
- this.initSequelize(val, async (err, sq) => {
134
- if (err) {
135
- console.error(" Failed  Can't to create a Sequelize instance:", val.name, "\n", err);
136
- cb(err, null, null);
137
- }
138
- // Test connection
139
- await sq.authenticate()
140
- .then(() => {
141
- // Database some is true perfectly.
142
- if (database_config.length == 0) {
143
- if (sq) {
144
- testSql[ val.name ] = sq;
145
- //console.log("DB true, Perfectly.", val.name);
146
- cb(null, true, testSql);
147
- }
148
- } else {
149
- testSql[ val.name ] = sq;
150
- this.testConnectInProcess(database_config, dbConnTotal, cb);
151
- }
152
- })
153
- .catch(err => {
154
- console.error(" Failed  Unable to connect to the database:", val.name, "\n", err);
155
- cb(err, null, null);
156
- });
157
- });
158
- } else if (!dbConnTotal) {
159
- // All Database is falsly perfectly.
160
- //console.log("DB all false, Perfectly.");
161
- cb(null, true, testSql);
63
+ serviceDevStart(argument) {
64
+ logUpdate("Compiling...");
65
+ let promise = null;
66
+ // check Dev. run service
67
+ const spawnData = new Promise((resolve) => {
68
+ if(argument == "-D" || argument == "--dev") {
69
+ promise = this.spawn('npx', ['nodemon', '-q', './cli/beech']); // For Dev.
70
+ } else {
71
+ promise = this.spawn('npx', ['nodemon', '-q', './node_modules/beech-api/packages/cli/beech']); // For Prd.
162
72
  }
163
- } catch (error) {
164
- cb(error, null, null);
165
- }
166
- }
167
-
168
- getStart(turnNoti, cb) {
169
- try {
170
- clear();
171
- logUpdate("Compiling...");
172
- // filter for check dabatase only true
173
- this.filterDbIsTrue(this._config_.database_config, (err, dbConnectIsTrueOnly) => {
174
- if (err) {
175
- logUpdate("Config file crash.", err);
176
- return;
177
- }
178
- // leave data to disconnect database
179
- let leaveDataForDisconnect = dbConnectIsTrueOnly.slice(0);
180
- // check db connect truthy length ?
181
- if (dbConnectIsTrueOnly.length > 0) {
182
- // Test connect process
183
- this.testConnectInProcess(dbConnectIsTrueOnly, dbConnectIsTrueOnly.length, (err, result, dbs) => {
184
- if (err) {
185
- logUpdate(" Failed  Database connect failed.", err);
186
- return;
187
- }
188
- if (result) {
189
- // Disconnect database
190
- this.disConnectTestDB(leaveDataForDisconnect, dbs, (err, disResult) => {
191
- if (err) {
192
- logUpdate(" Failed  Testing Database connect failed.", err);
193
- return;
194
- }
195
- if (disResult) {
196
- // Start service
197
- this.serviceDevStart();
198
- // check turn on nofi
199
- if (turnNoti) {
200
- this.notiCompile();
201
- }
202
- } else {
203
- cb(err, null);
204
- }
205
- });
206
- }
207
- });
208
- } else {
209
- this.serviceDevStart();
210
- }
73
+ resolve(promise.childProcess);
74
+ });
75
+ Promise.all([spawnData]).then((childProcess) => {
76
+ childProcess[0].stdout.on('data', (data) => {
77
+ console.log(data.toString().slice(0, -1));
211
78
  });
212
- } catch (error) {
213
- cb(error, null);
214
- }
215
- }
216
-
217
- serviceDevStart() {
218
- let firstCount = 0;
219
- const command = this.cmd.get(`npx nodemon -q ./node_modules/beech-api/packages/cli/beech`);
220
- command.stdout.on('data', (data) => {
221
- firstCount++;
222
- let leaveData = data.slice(0);
223
- if (firstCount == 1) {
224
- clear();
225
- }
226
- // shout out
227
- if (data.trim().slice(-1) == ":") {
228
- console.log("\n", leaveData.trim());
229
- } else {
230
- let serviceShoutOut = leaveData.trim().split('- ');
231
- if (serviceShoutOut.length > 2) {
232
- console.log(" -", serviceShoutOut[ 1 ].trim());
233
- console.log(" -", serviceShoutOut[ 2 ].trim());
234
- } else {
235
- console.log(" ", leaveData.trim());
79
+ childProcess[0].stderr.on('data', (data) => {
80
+ if(data.toString().slice(0, 8) != "Ignoring" && data.toString().match(/\[SEQUELIZE0006\]/g) != "[SEQUELIZE0006]") {
81
+ console.log(data.toString());
236
82
  }
237
- }
238
-
83
+ });
239
84
  });
240
85
  }
241
86
 
@@ -251,27 +96,10 @@ class Beech {
251
96
  });
252
97
  }
253
98
 
254
- disConnectTestDB(dbConfigTruthy, dbs, cb) {
255
- try {
256
- dbConfigTruthy.map((e, k) => {
257
- // Closing database
258
- if (dbs[ e.name ].close()) {
259
- if (dbConfigTruthy.length == k + 1) {
260
- cb(null, dbConfigTruthy);
261
- }
262
- } else {
263
- cb(`Close database failed, ${e.name}`, null);
264
- }
265
- });
266
- } catch (error) {
267
- cb(error, null);
268
- }
269
- }
270
-
271
99
  help() {
272
100
  return new Promise((resolve, reject) => {
273
101
  try {
274
- this.fs.readFile(__dirname + "/../core/generator/_service", "utf8", (err, data) => {
102
+ this.fs.readFile(__dirname + "/../core/generator/_help_service", "utf8", (err, data) => {
275
103
  if (err) {
276
104
  reject(err);
277
105
  } else {
@@ -288,10 +116,10 @@ class Beech {
288
116
  return new Promise((resolve, reject) => {
289
117
  try {
290
118
  this.fs = require("fs");
291
- this.cmd = require('node-cmd');
119
+ this.spawn = require('child-process-promise').spawn;
292
120
  this.argv = argv;
293
- this.option = argv[ 2 ];
294
- this.argument = argv[ 3 ];
121
+ this.option = argv[ 2 ]; // serve|build
122
+ this.argument = argv[ 3 ]; // --silent -S | --dev -D
295
123
  this.configFile = path.resolve("./app.config.js");
296
124
  this._config_ = require(this.configFile);
297
125
  resolve(this);
@@ -302,4 +130,4 @@ class Beech {
302
130
  }
303
131
  }
304
132
 
305
- new Beech();
133
+ new Beech();