nodefony 7.0.0-beta.2 → 7.0.0-beta.21

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 (136) hide show
  1. package/CHANGELOG.md +534 -8028
  2. package/README.md +33 -30
  3. package/autoloader.es6 +46 -48
  4. package/builder.es6 +66 -76
  5. package/cli/builder/bundles/bundle.js +57 -63
  6. package/cli/builder/bundles/controller.js +34 -38
  7. package/cli/builder/bundles/users-bundle/Command/fixtureTask.js +11 -12
  8. package/cli/builder/bundles/users-bundle/Command/usersCommand.js +23 -24
  9. package/cli/builder/bundles/users-bundle/Entity/mongoose/userEntity.js +25 -30
  10. package/cli/builder/bundles/users-bundle/Entity/sequelize/userEntity.js +42 -31
  11. package/cli/builder/bundles/users-bundle/Fixtures/users.js +24 -26
  12. package/cli/builder/bundles/users-bundle/Fixtures/usersFixtures.js +28 -29
  13. package/cli/builder/bundles/users-bundle/Resources/config/config.js +4 -3
  14. package/cli/builder/bundles/users-bundle/Resources/config/routing.js +2 -2
  15. package/cli/builder/bundles/users-bundle/Resources/config/security.js +9 -8
  16. package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.dev.config.js +3 -3
  17. package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.prod.config.js +4 -3
  18. package/cli/builder/bundles/users-bundle/Resources/config/webpack.config.js +74 -75
  19. package/cli/builder/bundles/users-bundle/Resources/scss/awesome/font-awesome.config.js +9 -9
  20. package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/login.js +13 -13
  21. package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/users.js +14 -14
  22. package/cli/builder/bundles/users-bundle/controller/api/graphql/graphqlController.js +13 -15
  23. package/cli/builder/bundles/users-bundle/controller/api/graphql/userResolver.js +29 -29
  24. package/cli/builder/bundles/users-bundle/controller/api/graphql/usertype.js +2 -2
  25. package/cli/builder/bundles/users-bundle/controller/api/openapi/loginApiController.js +34 -36
  26. package/cli/builder/bundles/users-bundle/controller/api/openapi/restUserController.js +32 -36
  27. package/cli/builder/bundles/users-bundle/controller/loginController.js +30 -34
  28. package/cli/builder/bundles/users-bundle/controller/usersController.js +54 -60
  29. package/cli/builder/bundles/users-bundle/package.json +27 -25
  30. package/cli/builder/bundles/users-bundle/pnpm-lock.yaml +4262 -0
  31. package/cli/builder/bundles/users-bundle/readme.md +7 -7
  32. package/cli/builder/bundles/users-bundle/services/usersService.js +97 -102
  33. package/cli/builder/bundles/users-bundle/src/providers/mongoose/userProvider.js +6 -8
  34. package/cli/builder/bundles/users-bundle/src/providers/sequelize/userProvider.js +9 -10
  35. package/cli/builder/bundles/users-bundle/tests/loginTest.js +119 -70
  36. package/cli/builder/bundles/users-bundle/usersBundle.js +2 -3
  37. package/cli/builder/microService/microService.js +139 -141
  38. package/cli/builder/microService/skeletons/package.json +23 -22
  39. package/cli/builder/project/project.js +228 -181
  40. package/cli/builder/project/skeletons/README.md +33 -30
  41. package/cli/builder/project/skeletons/bin/dev-deploy.sh +5 -0
  42. package/cli/builder/project/skeletons/bin/prod-deploy.sh +3 -0
  43. package/cli/builder/project/skeletons/config/config.js.skeleton +1 -0
  44. package/cli/builder/project/skeletons/config/pm2.config.js.skeleton +41 -17
  45. package/cli/builder/project/skeletons/eslintignore.skeleton +15 -0
  46. package/cli/builder/project/skeletons/eslintrc.js.skeleton +97 -0
  47. package/cli/builder/project/skeletons/gitignore.skeleton +1 -0
  48. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.37.entity-user.js +137 -0
  49. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.38.entity-session.js +97 -0
  50. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.39.entity-requests.js +115 -0
  51. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.40.entity-jwts.js +97 -0
  52. package/cli/builder/project/skeletons/migrations/migrations.skeleton.js +0 -2
  53. package/cli/builder/project/skeletons/package.json.twig +70 -0
  54. package/cli/builder/react/reactBuilder.js +59 -65
  55. package/cli/builder/sandbox/sandBoxBuilder.js +132 -134
  56. package/cli/builder/skeletons/app/appKernel.js +120 -2
  57. package/cli/builder/skeletons/config/config.js +1 -1
  58. package/cli/builder/skeletons/config/nodefony/framework-bundle.js +2 -1
  59. package/cli/builder/skeletons/config/nodefony/http-bundle.js +1 -0
  60. package/cli/builder/skeletons/config/nodefony/mongoose-bundle.js +38 -12
  61. package/cli/builder/skeletons/config/nodefony/monitoring-bundle.js +21 -2
  62. package/cli/builder/skeletons/config/nodefony/sequelize-bundle.js +122 -13
  63. package/cli/builder/skeletons/package.json.twig +57 -0
  64. package/cli/builder/skeletons/unittest/testFile.js +44 -45
  65. package/cli/builder/vue/skeletons/vue.config.js +84 -10
  66. package/cli/builder/vue/vueBuilder.js +116 -114
  67. package/cli/generate/generate.es6 +38 -39
  68. package/cli/install/install.js +45 -58
  69. package/cli/sequelize/sequelize.js +50 -39
  70. package/cli/start.js +353 -347
  71. package/cli/tools/pm2.es6 +55 -57
  72. package/cli/tools/tools.es6 +36 -37
  73. package/cli.es6 +280 -228
  74. package/container.es6 +51 -59
  75. package/error.es6 +25 -27
  76. package/fileClass.es6 +53 -55
  77. package/finder/file.es6 +5 -4
  78. package/finder/fileResult.es6 +23 -22
  79. package/finder/finder2.es6 +46 -54
  80. package/finder.es6 +88 -97
  81. package/kernel/annotations/annotations.es6 +44 -46
  82. package/kernel/api/api.es6 +6 -8
  83. package/kernel/api/graphqlApi.es6 +21 -21
  84. package/kernel/api/jsonApi.es6 +40 -45
  85. package/kernel/api/openApi.es6 +9 -11
  86. package/kernel/api/schemas/openApiSchema.js +61 -32
  87. package/kernel/babylon.es6 +31 -38
  88. package/kernel/bundle.es6 +252 -220
  89. package/kernel/cliKernel.es6 +157 -170
  90. package/kernel/command.es6 +17 -20
  91. package/kernel/commands/nodefonyCommand.es6 +111 -58
  92. package/kernel/commands/tasks/bundlesTask.es6 +14 -19
  93. package/kernel/controllers/controller.es6 +167 -180
  94. package/kernel/fixture.es6 +4 -7
  95. package/kernel/injections/injections.es6 +97 -103
  96. package/kernel/kernel.es6 +476 -384
  97. package/kernel/kernelWatcher.es6 +64 -54
  98. package/kernel/orm/entity.es6 +10 -12
  99. package/kernel/orm/orm.es6 +68 -48
  100. package/kernel/reader.es6 +45 -47
  101. package/kernel/security/encoder.es6 +8 -6
  102. package/kernel/security/factories/factory.es6 +34 -37
  103. package/kernel/security/factories/passeportFactory.es6 +13 -14
  104. package/kernel/security/provider.es6 +11 -13
  105. package/kernel/security/providers/chainProvider.es6 +13 -28
  106. package/kernel/security/providers/memoryProvider.es6 +7 -11
  107. package/kernel/security/providers/providerManager.es6 +11 -14
  108. package/kernel/security/providers/userEntityProvider.es6 +7 -8
  109. package/kernel/security/role.es6 +3 -3
  110. package/kernel/security/secureArea.es6 +143 -149
  111. package/kernel/security/tokens/token.es6 +30 -32
  112. package/kernel/security/user.es6 +19 -19
  113. package/kernel/serviceRealTime.es6 +5 -7
  114. package/kernel/services/connectionsService.es6 +20 -22
  115. package/kernel/services/cron/cronService.es6 +14 -16
  116. package/kernel/task.es6 +20 -26
  117. package/kernel/templates.es6 +4 -5
  118. package/kernel/templating/twig.es6 +56 -47
  119. package/kernel/tests/cliTest.js +7 -11
  120. package/kernel/tests/containerTest.js +25 -37
  121. package/kernel/tests/kernelTest.js +9 -16
  122. package/nodefony.es6 +279 -256
  123. package/notificationsCenter.es6 +28 -20
  124. package/package.json +40 -40
  125. package/protocol.es6 +19 -21
  126. package/protocols/bayeux.es6 +35 -38
  127. package/protocols/jsonRpc/jsonrpc.es6 +12 -14
  128. package/result.es6 +11 -12
  129. package/service.es6 +62 -62
  130. package/syslog/pdu.es6 +99 -91
  131. package/syslog/syslog.es6 +101 -102
  132. package/watcher.es6 +21 -20
  133. package/cli/builder/project/skeletons/jshintignore.skeleton +0 -1
  134. package/cli/builder/project/skeletons/jshintrc.skeleton +0 -60
  135. package/cli/builder/project/skeletons/package.json.skeleton +0 -52
  136. package/cli/builder/skeletons/package.json +0 -61
package/kernel/kernel.es6 CHANGED
@@ -1,13 +1,13 @@
1
- 'use strict';
2
- const os = require('os');
1
+ "use strict";
2
+ const os = require("os");
3
3
  const Module = require("module");
4
4
  let myrequire = null;
5
5
  let mypackage = null;
6
6
 
7
- const makeRequireFunction = function makeRequireFunction(mod) {
7
+ const makeRequireFunction = function makeRequireFunction (mod) {
8
8
  const myModule = mod.constructor;
9
9
 
10
- function myRequire(path) {
10
+ function myRequire (path) {
11
11
  try {
12
12
  exports.requireDepth += 1;
13
13
  return mod.require(path);
@@ -16,35 +16,35 @@ const makeRequireFunction = function makeRequireFunction(mod) {
16
16
  }
17
17
  }
18
18
 
19
- function resolve(request, options) {
20
- if (typeof request !== 'string') {
21
- throw new new Error(`resolve arg must be a string ERR_INVALID_ARG_TYPE : ${request}`);
19
+ function resolve (request, options) {
20
+ if (typeof request !== "string") {
21
+ throw new new Error(`resolve arg must be a string ERR_INVALID_ARG_TYPE : ${request}`)();
22
22
  }
23
23
  return myModule._resolveFilename(request, mod, false, options);
24
24
  }
25
25
  myRequire.resolve = resolve;
26
26
 
27
- function paths(request) {
28
- if (typeof request !== 'string') {
29
- throw new new Error(`paths arg must be a string ERR_INVALID_ARG_TYPE : ${request}`);
27
+ function paths (request) {
28
+ if (typeof request !== "string") {
29
+ throw new new Error(`paths arg must be a string ERR_INVALID_ARG_TYPE : ${request}`)();
30
30
  }
31
31
  return myModule._resolveLookupPaths(request, mod, true);
32
32
  }
33
33
  resolve.paths = paths;
34
- myRequire.main = module; //process.mainModule;
34
+ myRequire.main = module; // process.mainModule;
35
35
  // Enable support to add extra extension types.
36
36
  myRequire.extensions = myModule._extensions;
37
37
  myRequire.cache = myModule._cache;
38
38
  return myRequire;
39
39
  };
40
- const createRequireFromPath = function createRequireFromPath(filename) {
40
+ const createRequireFromPath = function createRequireFromPath (filename) {
41
41
  const m = new Module(filename, module);
42
42
  m.filename = filename;
43
43
  m.paths = Module._nodeModulePaths(path.dirname(filename));
44
44
  return makeRequireFunction(m);
45
45
  };
46
46
  try {
47
- let filemame = path.resolve(process.cwd(), "package.json");
47
+ const filemame = path.resolve(process.cwd(), "package.json");
48
48
  myrequire = createRequireFromPath(filemame);
49
49
  mypackage = myrequire(filemame);
50
50
  } catch (e) {}
@@ -54,7 +54,7 @@ const regBundle = /^(\w+)[Bb]undle.js$/;
54
54
  const regClassBundle = /^(\w+)[Bb]undle$/;
55
55
  const regPackageFile = /^\s*file:(.*)/;
56
56
 
57
- /*const promiseBundleReady = function () {
57
+ /* const promiseBundleReady = function () {
58
58
  let myresolve = null;
59
59
  let myPromise = new Promise((resolve) => {
60
60
  myresolve = resolve;
@@ -93,7 +93,8 @@ const defaultOptions = {
93
93
  }
94
94
  };
95
95
 
96
- const colorLogEvent = clc.cyan.bgBlue(`EVENT KERNEL`);
96
+ const colorLogEvent = clc.cyan.bgBlue("EVENT KERNEL");
97
+
97
98
  /**
98
99
  * KERKEL class
99
100
  * The class is a **`KERNEL NODEFONY`** .
@@ -107,18 +108,20 @@ const colorLogEvent = clc.cyan.bgBlue(`EVENT KERNEL`);
107
108
  *
108
109
  */
109
110
  class Kernel extends nodefony.Service {
110
-
111
- constructor(environment, cli, options) {
111
+ constructor (environment, cli, options) {
112
112
  super("KERNEL", cli.container, cli.notificationsCenter, nodefony.extend({}, defaultOptions, options));
113
113
  this.cli = cli;
114
114
  this.type = cli.type;
115
115
  this.package = mypackage;
116
- this.debug = (!!cli.commander.opts().debug) || false;
116
+ this.debug = Boolean(cli.commander.opts().debug) || false;
117
+ this.appEnvironment = {
118
+ environment: process.env.NODE_ENV
119
+ };
117
120
  this.setEnv(environment);
118
121
  // Manage Kernel Container
119
122
  this.set("kernel", this);
120
123
  this.set("cli", this.cli);
121
- //Autoloader
124
+ // Autoloader
122
125
  this.autoLoader = nodefony.autoloader;
123
126
  this.autoLoader.setKernel(this);
124
127
  this.set("autoLoader", this.autoLoader);
@@ -128,7 +131,7 @@ class Kernel extends nodefony.Service {
128
131
  this.isElectron = nodefony.isElectron;
129
132
  this.uptime = new Date().getTime();
130
133
  this.numberCpu = os.cpus().length;
131
- //boolean
134
+ // boolean
132
135
  this.console = this.isConsole();
133
136
  this.booted = false;
134
137
  this.ready = false;
@@ -150,7 +153,7 @@ class Kernel extends nodefony.Service {
150
153
  this.path = this.rootDir;
151
154
  this.bundlesPath = path.resolve(this.rootDir, "src", "bundles");
152
155
  this.appPath = nodefony.appPath; // path.resolve(this.rootDir, "app");
153
- this.configPath = nodefony.kernelConfigPath; //path.resolve(this.rootDir, "config", "config.yml");
156
+ this.configPath = nodefony.kernelConfigPath; // path.resolve(this.rootDir, "config", "config.yml");
154
157
  this.generateConfigPath = path.resolve(this.rootDir, "config", "generatedConfig.yml");
155
158
  this.publicPath = path.resolve(this.rootDir, "web");
156
159
  this.nodefonyPath = this.autoLoader.dirname;
@@ -173,20 +176,20 @@ class Kernel extends nodefony.Service {
173
176
  this.git = this.cli.setGitPath(this.rootDir);
174
177
  this.once("onPostReady", () => {
175
178
  if (process.getuid && process.getuid() === 0) {
176
- //this.drop_root();
179
+ // this.drop_root();
177
180
  }
178
- //this.clean();
181
+ // this.clean();
179
182
  this.postReady = true;
180
183
  switch (this.environment) {
181
- case 'production':
182
- case 'prod':
183
- case 'preprod':
184
- case 'preproduction':
185
- this.clean();
186
- break;
187
- default:
188
- this.clean();
189
- myrequire = null;
184
+ case "production":
185
+ case "prod":
186
+ case "preprod":
187
+ case "preproduction":
188
+ this.clean();
189
+ break;
190
+ default:
191
+ this.clean();
192
+ myrequire = null;
190
193
  }
191
194
  });
192
195
  } catch (e) {
@@ -195,7 +198,7 @@ class Kernel extends nodefony.Service {
195
198
  }
196
199
  }
197
200
 
198
- clean() {
201
+ clean () {
199
202
  require.cache = null;
200
203
  delete require.cache;
201
204
  myrequire.cache = null;
@@ -203,23 +206,23 @@ class Kernel extends nodefony.Service {
203
206
  myrequire = null;
204
207
  }
205
208
 
206
- drop_root() {
209
+ drop_root () {
207
210
  try {
208
- process.setgid('nobody');
209
- process.setuid('nobody');
211
+ process.setgid("nobody");
212
+ process.setuid("nobody");
210
213
  } catch (e) {
211
214
  console.error(e);
212
- console.log('Refusing to keep the process alive as root.');
215
+ console.log("Refusing to keep the process alive as root.");
213
216
  nodefony.cli.quit(1);
214
217
  }
215
218
  }
216
219
 
217
- getLocalExternalIP() {
220
+ getLocalExternalIP () {
218
221
  return [].concat(...Object.values(os.networkInterfaces()))
219
222
  .find((details) => !details.internal);
220
223
  }
221
224
 
222
- getNetworkInterfaces() {
225
+ getNetworkInterfaces () {
223
226
  const nets = os.networkInterfaces();
224
227
  const devices = Object.create(null); // or just '{}', an empty object
225
228
  for (const name of Object.keys(nets)) {
@@ -235,7 +238,7 @@ class Kernel extends nodefony.Service {
235
238
  return devices;
236
239
  }
237
240
 
238
- start() {
241
+ start () {
239
242
  if (!this.started) {
240
243
  return this.cli.showAsciify(this.projectName)
241
244
  .then(async () => {
@@ -244,28 +247,27 @@ class Kernel extends nodefony.Service {
244
247
  try {
245
248
  // config
246
249
  this.readKernelConfig();
250
+ this.setNodeEnv(this.environment);
247
251
  // Clusters
248
252
  this.initCluster();
249
253
  // Manage Template engine
250
254
  this.initTemplate();
251
255
  } catch (e) {
252
- console.error(e);
253
256
  throw e;
254
257
  }
255
258
  this.started = true;
256
259
  return await this.boot()
257
- .catch(e => {
260
+ .catch((e) => {
258
261
  throw e;
259
262
  });
260
263
  })
261
- .catch((e) => {
262
- //this.log(e, "ERROR");
264
+ .catch(async (e) => {
263
265
  throw e;
264
266
  });
265
267
  }
266
268
  }
267
269
 
268
- loadCommand() {
270
+ loadCommand () {
269
271
  try {
270
272
  return this.cli.loadCommand()
271
273
  .then((commands) => {
@@ -277,30 +279,29 @@ class Kernel extends nodefony.Service {
277
279
  } catch (e) {
278
280
  this.log(e, "ERROR");
279
281
  this.terminate(e.code || 1);
280
- return;
281
282
  }
282
283
  }
283
284
 
284
- displayCommand(commands) {
285
- let table = this.cli.displayTable([], {
285
+ displayCommand (commands) {
286
+ const table = this.cli.displayTable([], {
286
287
  head: [
287
288
  "BUNDLES",
288
289
  "COMMAND NAME"
289
290
  ]
290
291
  });
291
- for (let bundle in commands) {
292
- let cmd = commands[bundle];
293
- for (let command in cmd) {
294
- let tab = [];
292
+ for (const bundle in commands) {
293
+ const cmd = commands[bundle];
294
+ for (const command in cmd) {
295
+ const tab = [];
295
296
  tab.push(bundle);
296
297
  tab.push(command);
297
298
  table.push(tab);
298
299
  }
299
300
  }
300
- this.log("\n" + table.toString(), "DEBUG");
301
+ this.log(`\n${table.toString()}`, "DEBUG");
301
302
  }
302
303
 
303
- async matchCommand() {
304
+ async matchCommand () {
304
305
  try {
305
306
  return await this.cli.matchCommand();
306
307
  } catch (e) {
@@ -308,26 +309,26 @@ class Kernel extends nodefony.Service {
308
309
  }
309
310
  }
310
311
 
311
- setCli() {
312
+ setCli () {
312
313
  if (this.typeCluster === "worker") {
313
314
  this.cli.setPid();
314
315
  }
315
316
  this.cli.setProcessTitle(this.projectName);
316
317
  this.cli.setCommandVersion(this.isCore ? this.version : nodefony.projectVersion);
317
- //this.cli.syslog.removeAllListeners();
318
+ // this.cli.syslog.removeAllListeners();
318
319
  this.cli.syslog.reset();
319
320
  }
320
321
 
321
- isBundleCore(name) {
322
+ isBundleCore (name) {
322
323
  if (name in bundlesCore) {
323
324
  return true;
324
325
  }
325
- for (let bundle in bundlesCore) {
326
+ for (const bundle in bundlesCore) {
326
327
  if (bundlesCore[bundle] === name) {
327
328
  return true;
328
329
  }
329
330
  }
330
- let res = regBundleName.exec(name);
331
+ const res = regBundleName.exec(name);
331
332
  if (res) {
332
333
  if (res[2]) {
333
334
  return this.isBundleCore(res[2].toLowerCase());
@@ -336,11 +337,10 @@ class Kernel extends nodefony.Service {
336
337
  return false;
337
338
  }
338
339
 
339
-
340
- getRegisteredBundles(name = null) {
341
- if( name){
340
+ getRegisteredBundles (name = null) {
341
+ if (name) {
342
342
  const bundle = this.getBundle(name);
343
- if( bundle){
343
+ if (bundle) {
344
344
  return {
345
345
  name: bundle.name,
346
346
  packageName: bundle.package.name,
@@ -352,11 +352,11 @@ class Kernel extends nodefony.Service {
352
352
  }
353
353
  return null;
354
354
  }
355
- let tab = [];
355
+ const tab = [];
356
356
  const bundles = this.getBundles();
357
357
  for (const mybundle in bundles) {
358
358
  const bundle = bundles[mybundle];
359
- let ob = {
359
+ const ob = {
360
360
  name: bundle.name,
361
361
  packageName: bundle.package.name,
362
362
  package: bundle.package,
@@ -369,7 +369,7 @@ class Kernel extends nodefony.Service {
369
369
  return tab;
370
370
  }
371
371
 
372
- async getUnregistredBundle(nameBundle) {
372
+ async getUnregistredBundle (nameBundle) {
373
373
  const finder = new nodefony.Finder2({
374
374
  recurse: false,
375
375
  depth: 1
@@ -394,7 +394,7 @@ class Kernel extends nodefony.Service {
394
394
  }
395
395
  return null;
396
396
  })
397
- .catch(e => {
397
+ .catch((e) => {
398
398
  this.log(e, "ERROR");
399
399
  });
400
400
  if (result.length) {
@@ -406,7 +406,7 @@ class Kernel extends nodefony.Service {
406
406
  .in(localNodefony)
407
407
  .then((result) => {
408
408
  if (result[0].children.length) {
409
- //console.log(result[0].children)
409
+ // console.log(result[0].children)
410
410
  return result[0].children
411
411
  .map((bundle) => {
412
412
  const name = this.regBundleName.exec(bundle.name);
@@ -423,31 +423,36 @@ class Kernel extends nodefony.Service {
423
423
  }
424
424
  return null;
425
425
  })
426
- .catch(e => {
426
+ .catch((e) => {
427
427
  this.log(e, "ERROR");
428
428
  });
429
- if (result.length) {
429
+ if (result && result.length) {
430
430
  return result[0];
431
431
  }
432
432
  return null;
433
433
  }
434
434
 
435
- loadBundleUnregister(name, bundle) {
436
- const mypackage = path.resolve(bundle.path, "package.json");
437
- const pack = require(mypackage);
438
- return {
439
- name: name, //pack.name.replace("@nodefony/", "").replace("-bundle", "").replace("Bundle", ""),
440
- packageName: pack.name,
441
- package: pack,
442
- path: bundle.path,
443
- version: pack.version,
444
- registred: false
445
- };
435
+ loadBundleUnregister (name, bundle) {
436
+ try {
437
+ const mypackage = path.resolve(bundle.path, "package.json");
438
+ const pack = require(mypackage);
439
+ return {
440
+ name, // pack.name.replace("@nodefony/", "").replace("-bundle", "").replace("Bundle", ""),
441
+ packageName: pack.name,
442
+ package: pack,
443
+ path: bundle.path,
444
+ version: pack.version,
445
+ registred: false
446
+ };
447
+ } catch (e) {
448
+ this.log(e, "WARNING");
449
+ return false;
450
+ }
446
451
  }
447
452
 
448
- async getUnregistredBundles() {
453
+ async getUnregistredBundles () {
449
454
  let tab = [];
450
- //unregistered
455
+ // unregistered
451
456
  const finder = new nodefony.Finder2({
452
457
  recurse: false,
453
458
  depth: 1
@@ -459,7 +464,7 @@ class Kernel extends nodefony.Service {
459
464
  return result[0].children
460
465
  .map((bundle) => {
461
466
  const name = this.regBundleName.exec(bundle.name);
462
- if (!(name[1] in this.bundles)) {
467
+ if (name && !(name[1] in this.bundles)) {
463
468
  return this.loadBundleUnregister(name[1], bundle);
464
469
  }
465
470
  return false;
@@ -471,17 +476,22 @@ class Kernel extends nodefony.Service {
471
476
  });
472
477
  }
473
478
  })
474
- .catch(e => {
479
+ .catch((e) => {
475
480
  this.log(e, "ERROR");
476
481
  });
477
482
  tab = tab.concat(result);
478
483
 
479
- const localNodefony = path.resolve(this.nodefonyPath, "bundles");
484
+ let localNodefony = null;
485
+ if (this.isCore) {
486
+ localNodefony = path.resolve(this.nodefonyPath, "bundles");
487
+ } else {
488
+ localNodefony = path.resolve(this.path, "node_modules", "@nodefony");
489
+ }
480
490
  result = await finder
481
491
  .in(localNodefony)
482
492
  .then((result) => {
483
493
  if (result[0].children.length) {
484
- //console.log(result[0].children)
494
+ // console.log(result[0].children)
485
495
  return result[0].children
486
496
  .map((bundle) => {
487
497
  const name = this.regBundleName.exec(bundle.name);
@@ -498,40 +508,62 @@ class Kernel extends nodefony.Service {
498
508
  });
499
509
  }
500
510
  })
501
- .catch(e => {
511
+ .catch((e) => {
502
512
  this.log(e, "ERROR");
503
513
  });
504
- tab = tab.concat(result);
514
+ if (result) {
515
+ tab = tab.concat(result);
516
+ }
505
517
  return tab;
506
518
  }
507
519
 
508
- setEnv(environment) {
520
+ setEnv (environment) {
509
521
  if (environment in defaultEnvEnable) {
510
522
  switch (environment) {
511
- case "dev":
512
- case "development":
513
- this.environment = "dev";
514
- process.env.NODE_ENV = "development";
515
- process.env.BABEL_ENV = 'development';
516
- break;
517
- default:
518
- this.environment = "prod";
519
- process.env.NODE_ENV = "production";
520
- process.env.BABEL_ENV = 'production';
523
+ case "dev":
524
+ case "development":
525
+ this.environment = "dev";
526
+ if (!this.appEnvironment.environment) {
527
+ this.appEnvironment.environment = "development";
528
+ }
529
+ break;
530
+ default:
531
+ this.environment = "prod";
532
+ if (!this.appEnvironment.environment) {
533
+ this.appEnvironment.environment = "production";
534
+ }
535
+ }
536
+ }
537
+ }
538
+
539
+ setNodeEnv (environment) {
540
+ if (environment in defaultEnvEnable) {
541
+ switch (environment) {
542
+ case "dev":
543
+ case "development":
544
+ process.env.NODE_ENV = "development";
545
+ process.env.BABEL_ENV = "development";
546
+ break;
547
+ default:
548
+ process.env.NODE_ENV = "production";
549
+ process.env.BABEL_ENV = "production";
521
550
  }
522
551
  }
523
552
  process.env.NODE_DEBUG = this.debug;
524
553
  }
525
554
 
526
- logEnv() {
527
- let txt = this.cli.clc.blue(" \x1b KERNEL " + this.type);
528
- txt += " Cluster : " + this.cli.clc.magenta(this.typeCluster);
529
- txt += " Environment : " + this.cli.clc.magenta(this.environment);
530
- txt += " Debug :" + this.cli.clc.magenta(this.debug) + "\n";
555
+ logEnv () {
556
+ let txt = ` \x1b ${this.cli.clc.blue(this.type)} `;
557
+ txt += ` ${this.cli.clc.magenta("Cluster")} : ${this.typeCluster} `;
558
+ txt += ` ${this.cli.clc.magenta("Nodefony Environment")} : ${this.environment} `;
559
+ if (this.appEnvironment) {
560
+ txt += ` ${this.cli.clc.magenta("App Environment")} : ${this.appEnvironment.environment} `;
561
+ }
562
+ txt += ` ${this.cli.clc.magenta("Debug")} : ${this.debug}\n`;
531
563
  return txt;
532
564
  }
533
565
 
534
- readKernelConfig() {
566
+ readKernelConfig () {
535
567
  try {
536
568
  if (path.basename(this.configPath) === "config.js") {
537
569
  this.settings = this.autoLoader.load(this.configPath, true);
@@ -543,19 +575,19 @@ class Kernel extends nodefony.Service {
543
575
  this.settings.environment = this.environment;
544
576
  this.settings.debug = this.debug;
545
577
  this.setParameters("kernel", this.settings);
546
- this.httpPort = nodefony.kernelConfig.system.httpPort || null;
547
- this.httpsPort = nodefony.kernelConfig.system.httpsPort || null;
548
- this.domain = nodefony.kernelConfig.system.domain || null;
549
- this.hostname = nodefony.kernelConfig.system.domain || null;
550
- this.hostHttp = this.hostname + ":" + this.httpPort;
551
- this.hostHttps = this.hostname + ":" + this.httpsPort;
552
- this.domainAlias = nodefony.kernelConfig.system.domainAlias;
553
- this.domainCheck = nodefony.kernelConfig.system.domainCheck;
578
+ this.httpPort = this.settings.system.httpPort || null;
579
+ this.httpsPort = this.settings.system.httpsPort || null;
580
+ this.domain = this.settings.system.domain || null;
581
+ this.hostname = this.settings.system.domain || null;
582
+ this.hostHttp = `${this.hostname}:${this.httpPort}`;
583
+ this.hostHttps = `${this.hostname}:${this.httpsPort}`;
584
+ this.domainAlias = this.settings.system.domainAlias;
585
+ this.domainCheck = this.settings.system.domainCheck;
554
586
  this.initializeLog();
555
587
  if (!this.settings.system.bundles) {
556
588
  this.settings.system.bundles = {};
557
589
  }
558
- let gconf = this.readGeneratedConfig();
590
+ const gconf = this.readGeneratedConfig();
559
591
  if (gconf) {
560
592
  if (gconf.system && gconf.system.bundles) {
561
593
  this.settings = nodefony.extend(true, gconf, this.settings);
@@ -567,22 +599,21 @@ class Kernel extends nodefony.Service {
567
599
  }
568
600
  }
569
601
 
570
- checkPath(myPath) {
602
+ checkPath (myPath) {
571
603
  if (!myPath) {
572
604
  return null;
573
605
  }
574
- let abs = path.isAbsolute(myPath);
606
+ const abs = path.isAbsolute(myPath);
575
607
  if (abs) {
576
608
  return myPath;
577
- } else {
578
- return path.resolve(this.rootDir, myPath);
579
609
  }
610
+ return path.resolve(this.rootDir, myPath);
580
611
  }
581
612
 
582
- getConfigBunbles() {
583
- let config = [];
613
+ getConfigBunbles () {
614
+ const config = [];
584
615
  if (this.settings && this.settings.system && this.settings.system.bundles) {
585
- for (let bundle in this.settings.system.bundles) {
616
+ for (const bundle in this.settings.system.bundles) {
586
617
  let res = null;
587
618
  try {
588
619
  res = this.searchPackage(bundle, this.settings.system.bundles[bundle]);
@@ -596,9 +627,9 @@ class Kernel extends nodefony.Service {
596
627
  return config;
597
628
  }
598
629
 
599
- checkBundlesExist(yml, nameConfig, pathConfig, remove) {
630
+ checkBundlesExist (yml, nameConfig, pathConfig, remove) {
600
631
  if (yml && yml.system && yml.system.bundles) {
601
- for (let bundle in yml.system.bundles) {
632
+ for (const bundle in yml.system.bundles) {
602
633
  let exist = null;
603
634
  try {
604
635
  exist = this.searchPackage(bundle, yml.system.bundles[bundle]);
@@ -610,27 +641,27 @@ class Kernel extends nodefony.Service {
610
641
  if (remove) {
611
642
  try {
612
643
  fs.writeFileSync(pathConfig, yaml.dump(yml), {
613
- encoding: 'utf8'
644
+ encoding: "utf8"
614
645
  });
615
- this.log(nameConfig + " : " + bundle + " Bundle don't exist in file : " + pathConfig, "WARNING");
616
- this.log("Update Config : " + pathConfig);
646
+ this.log(`${nameConfig} : ${bundle} Bundle don't exist in file : ${pathConfig}`, "WARNING");
647
+ this.log(`Update Config : ${pathConfig}`);
617
648
  } catch (e) {
618
649
  this.log(e, "ERROR");
619
650
  }
620
651
  } else {
621
- let error = new Error(nameConfig + " : " + bundle + " Bundle don't exist in file : " + pathConfig);
652
+ const error = new Error(`${nameConfig} : ${bundle} Bundle don't exist in file : ${pathConfig}`);
622
653
  this.log(error, "ERROR");
623
- this.log("Config file : " + pathConfig);
654
+ this.log(`Config file : ${pathConfig}`);
624
655
  this.log(yml.system.bundles);
625
656
  }
626
657
  try {
627
- let link = path.resolve(this.publicPath, bundle);
628
- let stat = fs.lstatSync(link);
658
+ const link = path.resolve(this.publicPath, bundle);
659
+ const stat = fs.lstatSync(link);
629
660
  if (stat) {
630
661
  exist = fs.existsSync(fs.readlinkSync(link));
631
662
  if (!exist) {
632
663
  fs.unlinkSync(link);
633
- this.log("REMOVE LINK : " + link);
664
+ this.log(`REMOVE LINK : ${link}`);
634
665
  }
635
666
  }
636
667
  } catch (e) {}
@@ -639,13 +670,13 @@ class Kernel extends nodefony.Service {
639
670
  }
640
671
  }
641
672
 
642
- readGeneratedConfig() {
673
+ readGeneratedConfig () {
643
674
  let exist = null;
644
675
  try {
645
676
  exist = fs.existsSync(this.generateConfigPath);
646
677
  if (exist) {
647
678
  try {
648
- let yml = yaml.load(fs.readFileSync(this.generateConfigPath, 'utf8'));
679
+ const yml = yaml.load(fs.readFileSync(this.generateConfigPath, "utf8"));
649
680
  this.checkBundlesExist(yml, "Generated Config", this.generateConfigPath, true);
650
681
  return yml;
651
682
  } catch (e) {
@@ -659,7 +690,7 @@ class Kernel extends nodefony.Service {
659
690
  }
660
691
  }
661
692
 
662
- searchPackage(name, mypath) {
693
+ searchPackage (name, mypath) {
663
694
  let res = null;
664
695
  let error = null;
665
696
  if (mypath && mypath !== "*") {
@@ -673,30 +704,28 @@ class Kernel extends nodefony.Service {
673
704
  if (myrequire) {
674
705
  try {
675
706
  res = myrequire.resolve(`${name}`);
676
- let version = myrequire(path.resolve(path.dirname(res), "package.json")).version;
707
+ const {version} = myrequire(path.resolve(path.dirname(res), "package.json"));
677
708
  if (version === mypath) {
678
709
  if (this.type === "SERVER") {
679
710
  this.log(`Find NPM Bundle Package : ${name}@${mypath} in : ${res}`, "DEBUG");
680
711
  }
681
712
  return `${name}`;
682
- } else {
683
- throw new Error(`Can not found NPM Bundle Package : ${name}@${mypath}`);
684
713
  }
714
+ throw new Error(`Can not found NPM Bundle Package : ${name}@${mypath}`);
685
715
  } catch (e) {
686
716
  error = e;
687
717
  }
688
718
  }
689
719
  try {
690
720
  res = require.resolve(`${name}`);
691
- let version = myrequire(path.resolve(path.dirname(res), "package.json")).version;
721
+ const {version} = myrequire(path.resolve(path.dirname(res), "package.json"));
692
722
  if (version === mypath) {
693
723
  if (this.type === "SERVER") {
694
724
  this.log(`Find NPM Bundle Package : ${name}@${mypath} in : ${res}`, "DEBUG");
695
725
  }
696
726
  return `${name}`;
697
- } else {
698
- throw new Error(`Can not found NPM Bundle Package : ${name}@${mypath}`);
699
727
  }
728
+ throw new Error(`Can not found NPM Bundle Package : ${name}@${mypath}`);
700
729
  } catch (e) {
701
730
  if (error) {
702
731
  throw error;
@@ -721,10 +750,10 @@ class Kernel extends nodefony.Service {
721
750
  require.resolve(res);
722
751
  } catch (e) {
723
752
  // no main in package.json
724
- let bundleName = this.getBundleName(name);
753
+ const bundleName = this.getBundleName(name);
725
754
  if (bundleName) {
726
755
  try {
727
- require.resolve(path.resolve(res, bundleName + "Bundle.js"));
756
+ require.resolve(path.resolve(res, `${bundleName}Bundle.js`));
728
757
  } catch (e) {
729
758
  this.log(e, "ERROR");
730
759
  throw new Error(`${name} is not a Bundle Package`);
@@ -800,7 +829,7 @@ class Kernel extends nodefony.Service {
800
829
  } catch (e) {}
801
830
  try {
802
831
  res = null;
803
- res = path.resolve(this.nodefonyPath, '..', '..', "src", "bundles", name);
832
+ res = path.resolve(this.nodefonyPath, "..", "..", "src", "bundles", name);
804
833
  require.resolve(res);
805
834
  if (this.type === "SERVER") {
806
835
  this.log(`Find Core Local Bundle Package : ${name} in : ${res}`, "DEBUG");
@@ -809,7 +838,7 @@ class Kernel extends nodefony.Service {
809
838
  } catch (e) {}
810
839
  try {
811
840
  res = null;
812
- const globalPath = path.resolve(process.execPath, '..', '..', 'lib', 'node_modules', "nodefony", "bundle");
841
+ const globalPath = path.resolve(process.execPath, "..", "..", "lib", "node_modules", "nodefony", "bundle");
813
842
  res = path.resolve(globalPath, `@nodefony/${name}`);
814
843
  require.resolve(res);
815
844
  if (this.type === "SERVER") {
@@ -819,7 +848,7 @@ class Kernel extends nodefony.Service {
819
848
  } catch (e) {}
820
849
  try {
821
850
  res = null;
822
- const globalPath = path.resolve(process.execPath, '..', '..', 'lib', 'node_modules', "nodefony", 'node_modules');
851
+ const globalPath = path.resolve(process.execPath, "..", "..", "lib", "node_modules", "nodefony", "node_modules");
823
852
  res = path.resolve(globalPath, `@nodefony/${name}`);
824
853
  require.resolve(res);
825
854
  if (this.type === "SERVER") {
@@ -837,12 +866,12 @@ class Kernel extends nodefony.Service {
837
866
  /**
838
867
  * @method boot
839
868
  */
840
- async boot() {
869
+ async boot () {
841
870
  /*
842
871
  * BUNDLES
843
872
  */
844
873
  this.configBundle = this.getConfigBunbles();
845
- let bundles = [];
874
+ const bundles = [];
846
875
  let res = null;
847
876
  try {
848
877
  res = this.searchPackage("http-bundle");
@@ -853,23 +882,24 @@ class Kernel extends nodefony.Service {
853
882
  res = this.searchPackage("security-bundle");
854
883
  bundles.push(res);
855
884
  }
856
- /*if (this.settings.system.documentation) {
885
+
886
+ /* if (this.settings.system.documentation) {
857
887
  res = this.searchPackage("documentation-bundle");
858
888
  bundles.push(res);
859
889
  }*/
860
890
  switch (this.settings.orm) {
861
- case "sequelize":
862
- res = this.searchPackage("sequelize-bundle");
863
- bundles.push(res);
864
- break;
865
- case "mongoose":
866
- res = this.searchPackage("mongoose-bundle");
867
- bundles.push(res);
868
- break;
869
- default:
870
- let error = new Error("nodefony can't load ORM : " + this.settings.orm);
871
- this.log(error, "ERROR");
872
- throw error;
891
+ case "sequelize":
892
+ res = this.searchPackage("sequelize-bundle");
893
+ bundles.push(res);
894
+ break;
895
+ case "mongoose":
896
+ res = this.searchPackage("mongoose-bundle");
897
+ bundles.push(res);
898
+ break;
899
+ default:
900
+ const error = new Error(`nodefony can't load ORM : ${this.settings.orm}`);
901
+ this.log(error, "ERROR");
902
+ throw error;
873
903
  }
874
904
  if (this.settings.system.realtime) {
875
905
  res = this.searchPackage("realtime-bundle");
@@ -913,36 +943,34 @@ class Kernel extends nodefony.Service {
913
943
  }
914
944
 
915
945
  switch (this.isInstall()) {
916
- case "install":
917
- return await this.install(bundles)
918
- .catch(e => {
919
- throw e;
920
- });
921
- case "rebuild":
922
- return await this.rebuild(bundles)
923
- .catch(e => {
924
- throw e;
925
- });
926
- default:
927
- return await this.preRegister(bundles)
928
- .then(() => {
929
- return this;
930
- })
931
- .catch(e => {
932
- throw e;
933
- });
946
+ case "install":
947
+ return await this.install(bundles)
948
+ .catch((e) => {
949
+ throw e;
950
+ });
951
+ case "rebuild":
952
+ return await this.rebuild(bundles)
953
+ .catch((e) => {
954
+ throw e;
955
+ });
956
+ default:
957
+ return await this.preRegister(bundles)
958
+ .then(() => this)
959
+ .catch((e) => {
960
+ throw e;
961
+ });
934
962
  }
935
963
  }
936
964
 
937
- async install(coreBundles = []) {
938
- let bundles = coreBundles.concat(this.configBundle, [this.appPath]);
965
+ async install (coreBundles = []) {
966
+ const bundles = coreBundles.concat(this.configBundle, [this.appPath]);
939
967
  try {
940
968
  for (let i = 0; i < bundles.length; i++) {
941
969
  let bundleFile = null;
942
970
  try {
943
971
  bundleFile = new nodefony.fileClass(path.resolve(bundles[i], "package.json"));
944
972
  } catch (e) {
945
- let Path = this.isNodeModule(bundles[i]);
973
+ const Path = this.isNodeModule(bundles[i]);
946
974
  if (Path) {
947
975
  bundleFile = new nodefony.fileClass(Path);
948
976
  } else {
@@ -953,14 +981,14 @@ class Kernel extends nodefony.Service {
953
981
  if (this.isCore) {
954
982
  await this.cli.installPackage(bundleFile, "development");
955
983
  } else {
956
- let dir = path.basename(bundleFile.dirName);
984
+ const dir = path.basename(bundleFile.dirName);
957
985
  if (!this.isBundleCore(dir)) {
958
986
  await this.cli.installPackage(bundleFile, "development");
959
987
  }
960
988
  }
961
989
  }
962
990
  return await this.preRegister(coreBundles)
963
- .catch(e => {
991
+ .catch((e) => {
964
992
  throw e;
965
993
  });
966
994
  } catch (e) {
@@ -969,15 +997,15 @@ class Kernel extends nodefony.Service {
969
997
  }
970
998
  }
971
999
 
972
- async rebuild(coreBundles) {
973
- let bundles = coreBundles.concat(this.configBundle, [this.appPath]);
1000
+ async rebuild (coreBundles) {
1001
+ const bundles = coreBundles.concat(this.configBundle, [this.appPath]);
974
1002
  try {
975
1003
  for (let i = 0; i < bundles.length; i++) {
976
1004
  let bundleFile = null;
977
1005
  try {
978
1006
  bundleFile = new nodefony.fileClass(path.resolve(bundles[i], "package.json"));
979
1007
  } catch (e) {
980
- let Path = this.isNodeModule(bundles[i]);
1008
+ const Path = this.isNodeModule(bundles[i]);
981
1009
  if (Path) {
982
1010
  bundleFile = new nodefony.fileClass(Path);
983
1011
  } else {
@@ -985,10 +1013,10 @@ class Kernel extends nodefony.Service {
985
1013
  continue;
986
1014
  }
987
1015
  }
988
- await this.cli.rebuildPackage(bundleFile, "development");
1016
+ await this.cli.rebuildPackage(bundleFile, "production");
989
1017
  }
990
1018
  return await this.preRegister(coreBundles)
991
- .catch(e => {
1019
+ .catch((e) => {
992
1020
  throw e;
993
1021
  });
994
1022
  } catch (e) {
@@ -997,38 +1025,48 @@ class Kernel extends nodefony.Service {
997
1025
  }
998
1026
  }
999
1027
 
1000
- async preRegister(bundles) {
1028
+ async preRegister (bundles) {
1001
1029
  try {
1002
- //this.fire("onPreRegister", this);
1003
- await this.emitAsync("onPreRegister", this);
1030
+ // this.fire("onPreRegister", this);
1031
+ await this.emitAsync("onPreRegister", this)
1032
+ .catch((e) => {
1033
+ throw e;
1034
+ });
1004
1035
  this.preRegistered = true;
1036
+ return await this.registerBundles(bundles)
1037
+ .then(async (res) => {
1038
+ this.preboot = true;
1039
+ // this.fire("onPreBoot", this);
1040
+ await this.emitAsync("onPreBoot", this);
1041
+ this.log(res, "DEBUG", "REGISTER BUNDLES");
1042
+ return await this.registerBundles(this.configBundle)
1043
+ .then(async (res) => {
1044
+ if (res.length) {
1045
+ this.log(res, "DEBUG", "REGISTER BUNDLES");
1046
+ }
1047
+ // this.fire("onRegister", this);
1048
+ await this.emitAsync("onRegister", this);
1049
+ return await this.initializeBundles()
1050
+ .catch((e) => {
1051
+ throw e;
1052
+ });
1053
+ })
1054
+ .catch((e) => {
1055
+ throw e;
1056
+ });
1057
+ })
1058
+ .catch((e) => {
1059
+ throw e;
1060
+ });
1005
1061
  } catch (e) {
1006
- this.log(e);
1007
- }
1008
- return await this.registerBundles(bundles)
1009
- .then(async (res) => {
1010
- this.preboot = true;
1011
- //this.fire("onPreBoot", this);
1012
- await this.emitAsync("onPreBoot", this);
1013
- this.log(res, "DEBUG", "REGISTER BUNDLES");
1014
- return await this.registerBundles(this.configBundle)
1015
- .then(async (res) => {
1016
- if (res.length) {
1017
- this.log(res, "DEBUG", "REGISTER BUNDLES");
1018
- }
1019
- //this.fire("onRegister", this);
1020
- await this.emitAsync("onRegister", this);
1021
- return await this.initializeBundles();
1022
- });
1023
- })
1024
- .catch(e => {
1025
- throw e;
1026
- });
1062
+ this.log(e, "ERROR");
1063
+ throw e;
1064
+ }
1027
1065
  }
1028
1066
 
1029
- async onReady() {
1067
+ async onReady () {
1030
1068
  return new Promise((resolve, reject) => {
1031
- //process.nextTick(() => {
1069
+ // process.nextTick(() => {
1032
1070
  try {
1033
1071
  if (this.type === "SERVER") {
1034
1072
  this.initServers();
@@ -1048,15 +1086,15 @@ class Kernel extends nodefony.Service {
1048
1086
  return reject(e);
1049
1087
  }
1050
1088
  });
1051
- //});
1089
+ // });
1052
1090
  }
1053
1091
 
1054
1092
  /**
1055
1093
  * initialisation all bundles
1056
1094
  * @method initializeBundles
1057
1095
  */
1058
- async initializeBundles() {
1059
- let tab = [];
1096
+ async initializeBundles () {
1097
+ const tab = [];
1060
1098
  try {
1061
1099
  this.app = await this.initApplication();
1062
1100
  await this.emitAsync("onPostRegister", this);
@@ -1071,20 +1109,21 @@ class Kernel extends nodefony.Service {
1071
1109
  this.log(e, "WARNING", "EVENTS onBoot");
1072
1110
  throw e;
1073
1111
  }
1074
- for (let name in this.bundles) {
1075
- this.log("\x1b[36m INITIALIZE Bundle : " + name.toUpperCase() + "\x1b[0m", "DEBUG");
1112
+ for (const name in this.bundles) {
1113
+ this.log(`\x1b[36m INITIALIZE Bundle : ${name.toUpperCase()}\x1b[0m`, "DEBUG");
1076
1114
  try {
1077
1115
  tab.push(await this.bundles[name].initialize());
1078
1116
  } catch (e) {
1079
- this.log(e, "ERROR");
1080
- continue;
1117
+ // this.log(e, "ERROR");
1118
+ throw e;
1119
+ // continue;
1081
1120
  }
1082
1121
  }
1083
1122
 
1084
1123
  // BOOT
1085
1124
  tab.length = 0;
1086
1125
  try {
1087
- //this.fire("onBoot", this, tab);
1126
+ // this.fire("onBoot", this, tab);
1088
1127
  await this.emitAsync("onBoot", this, tab);
1089
1128
  } catch (e) {
1090
1129
  this.log(e, "WARNING", "EVENTS onBoot");
@@ -1092,13 +1131,13 @@ class Kernel extends nodefony.Service {
1092
1131
  }
1093
1132
  this.booted = true;
1094
1133
 
1095
- for (let name in this.bundles) {
1096
- this.log("\x1b[36m BOOT Bundle : " + name.toUpperCase() + "\x1b[0m", "DEBUG");
1134
+ for (const name in this.bundles) {
1135
+ this.log(`\x1b[36m BOOT Bundle : ${name.toUpperCase()}\x1b[0m`, "DEBUG");
1097
1136
  try {
1098
1137
  tab.push(await this.bundles[name].boot());
1099
1138
  } catch (e) {
1100
1139
  this.log(e, "ERROR");
1101
- //continue;
1140
+ // continue;
1102
1141
  throw e;
1103
1142
  }
1104
1143
  }
@@ -1106,7 +1145,8 @@ class Kernel extends nodefony.Service {
1106
1145
  await this.loadCommand();
1107
1146
  } else {
1108
1147
  await this.cli.assetInstall();
1109
- /*if (!fs.existsSync(this.cacheLink)) {
1148
+
1149
+ /* if (!fs.existsSync(this.cacheLink)) {
1110
1150
  try {
1111
1151
  fs.mkdirSync(this.cacheLink);
1112
1152
  this.cli.assetInstall();
@@ -1116,18 +1156,18 @@ class Kernel extends nodefony.Service {
1116
1156
  }*/
1117
1157
  }
1118
1158
 
1119
- /*let bundles = [];
1159
+ /* let bundles = [];
1120
1160
  for await (let boot of this.promisesBundleReady) {
1121
1161
  this.log(`End Waiting Bundle Ready ${boot.name}`, "DEBUG");
1122
1162
  bundles.push(boot);
1123
1163
  }*/
1124
- //await this.emitAsync("onReady", this, tab);
1164
+ // await this.emitAsync("onReady", this, tab);
1125
1165
  try {
1126
- //this.fire("onReady", this, bundles);
1166
+ // this.fire("onReady", this, bundles);
1127
1167
  await this.emitAsync("onReady", this, tab);
1128
1168
  } catch (e) {
1129
1169
  this.log(e, "WARNING", "EVENTS onReady");
1130
- throw e
1170
+ throw e;
1131
1171
  }
1132
1172
  this.ready = true;
1133
1173
 
@@ -1142,7 +1182,7 @@ class Kernel extends nodefony.Service {
1142
1182
  return command;
1143
1183
  })
1144
1184
  .catch((error) => {
1145
- //this.log(error, "ERROR", `COMMAND`);
1185
+ // this.log(error, "ERROR", `COMMAND`);
1146
1186
  throw error;
1147
1187
  });
1148
1188
  }
@@ -1156,15 +1196,19 @@ class Kernel extends nodefony.Service {
1156
1196
  });
1157
1197
  }
1158
1198
 
1159
- getOrm() {
1199
+ getOrm () {
1160
1200
  return this.settings.orm;
1161
1201
  }
1162
1202
 
1163
- getORM() {
1203
+ getOrmStrategy () {
1204
+ return this.getORM().settings.strategy;
1205
+ }
1206
+
1207
+ getORM () {
1164
1208
  return this.get(this.getOrm());
1165
1209
  }
1166
1210
 
1167
- initServers() {
1211
+ initServers () {
1168
1212
  // create HTTP server
1169
1213
  let http = null;
1170
1214
  let http2 = null;
@@ -1194,11 +1238,11 @@ class Kernel extends nodefony.Service {
1194
1238
  * CLUSTERS
1195
1239
  *
1196
1240
  */
1197
- clusterIsMaster() {
1241
+ clusterIsMaster () {
1198
1242
  return cluster.isMaster;
1199
1243
  }
1200
1244
 
1201
- initCluster() {
1245
+ initCluster () {
1202
1246
  this.processId = process.pid;
1203
1247
  this.process = process;
1204
1248
  if (this.console && this.cli && this.cli.commander && this.cli.commander.opts().json) {
@@ -1212,7 +1256,7 @@ class Kernel extends nodefony.Service {
1212
1256
  this.workerId = cluster.worker.id;
1213
1257
  this.worker = cluster.worker;
1214
1258
  this.fire("onCluster", "WORKER", this, process);
1215
- //process.on("message", this.listen(this, "onMessage"));
1259
+ // process.on("message", this.listen(this, "onMessage"));
1216
1260
  process.on("message", (msg) => {
1217
1261
  this.fire("onMessage", msg);
1218
1262
  });
@@ -1222,24 +1266,24 @@ class Kernel extends nodefony.Service {
1222
1266
  }
1223
1267
  }
1224
1268
 
1225
- fire() {
1269
+ fire () {
1226
1270
  this.log(`${colorLogEvent} ${arguments[0]}`, "DEBUG");
1227
1271
  return super.fire.apply(this, arguments);
1228
1272
  }
1229
1273
 
1230
- emit() {
1274
+ emit () {
1231
1275
  this.log(`${colorLogEvent} ${arguments[0]}`, "DEBUG");
1232
1276
  return super.fire.apply(this, arguments);
1233
1277
  }
1234
1278
 
1235
- emitAsync() {
1279
+ emitAsync () {
1236
1280
  this.log(`${colorLogEvent} ${arguments[0]}`, "DEBUG");
1237
1281
  return super.emitAsync.apply(this, arguments);
1238
1282
  }
1239
1283
 
1240
- sendMessage(message) {
1284
+ sendMessage (message) {
1241
1285
  return process.send({
1242
- type: 'process:msg',
1286
+ type: "process:msg",
1243
1287
  data: message
1244
1288
  });
1245
1289
  }
@@ -1247,7 +1291,7 @@ class Kernel extends nodefony.Service {
1247
1291
  /**
1248
1292
  * @method initializeLog
1249
1293
  */
1250
- initializeLog() {
1294
+ initializeLog () {
1251
1295
  if (this.type === "CONSOLE") {
1252
1296
  return this.cli.initSyslog(this.environment, this.debug);
1253
1297
  }
@@ -1263,15 +1307,15 @@ class Kernel extends nodefony.Service {
1263
1307
  /**
1264
1308
  * @method getTemplate
1265
1309
  */
1266
- getTemplate(name) {
1310
+ getTemplate (name) {
1267
1311
  return nodefony.templates[name];
1268
1312
  }
1269
1313
 
1270
1314
  /**
1271
1315
  * @method initTemplate
1272
1316
  */
1273
- initTemplate() {
1274
- let classTemplate = this.getTemplate(this.settings.templating);
1317
+ initTemplate () {
1318
+ const classTemplate = this.getTemplate(this.settings.templating);
1275
1319
  this.templating = new classTemplate(this.container, this.settings[this.settings.templating]);
1276
1320
  this.set("templating", this.templating);
1277
1321
  }
@@ -1279,7 +1323,7 @@ class Kernel extends nodefony.Service {
1279
1323
  /**
1280
1324
  * @method log
1281
1325
  */
1282
- log(pci, severity, msgid, msg) {
1326
+ log (pci, severity, msgid, msg) {
1283
1327
  if (!msgid) {
1284
1328
  msgid = this.cli.clc.magenta("KERNEL");
1285
1329
  }
@@ -1291,16 +1335,16 @@ class Kernel extends nodefony.Service {
1291
1335
  * @method getBundle
1292
1336
  * @param {String} name
1293
1337
  */
1294
- getBundle(name) {
1338
+ getBundle (name) {
1295
1339
  this.regBundleName.test(name);
1296
- let res = regBundleName.exec(name);
1340
+ const res = regBundleName.exec(name);
1297
1341
  if (res) {
1298
1342
  name = res[1];
1299
1343
  }
1300
1344
  if (name === "App" || name === "app") {
1301
1345
  return this.bundles.app;
1302
1346
  }
1303
- for (let ns in this.bundles) {
1347
+ for (const ns in this.bundles) {
1304
1348
  if (ns === name) {
1305
1349
  return this.bundles[ns];
1306
1350
  }
@@ -1313,7 +1357,7 @@ class Kernel extends nodefony.Service {
1313
1357
  * @method getBundles
1314
1358
  * @param {String} name
1315
1359
  */
1316
- getBundles(name) {
1360
+ getBundles (name) {
1317
1361
  if (name) {
1318
1362
  return this.getBundle(name);
1319
1363
  }
@@ -1325,77 +1369,77 @@ class Kernel extends nodefony.Service {
1325
1369
  * @method getBundleName
1326
1370
  * @param {String} str
1327
1371
  */
1328
- getBundleName(str) {
1372
+ getBundleName (str) {
1329
1373
  if (str === "app") {
1330
1374
  return str;
1331
1375
  }
1332
1376
  let ret = null;
1333
1377
  switch (typeof str) {
1334
- case "string":
1335
- ret = regBundleName.exec(str);
1336
- if (ret) {
1337
- return ret[1] || ret[2];
1338
- }
1339
- throw new Error("Bundle Bad Name :" + str);
1340
- case "function":
1341
- ret = regClassBundle.exec(str.name);
1342
- if (ret) {
1343
- return ret[1];
1344
- }
1345
- throw new Error("Bundle Bad Name :" + str.name);
1346
- default:
1347
- throw new Error("Bundle Bad Name :" + str);
1378
+ case "string":
1379
+ ret = regBundleName.exec(str);
1380
+ if (ret) {
1381
+ return ret[1] || ret[2];
1382
+ }
1383
+ throw new Error(`Bundle Bad Name :${str}`);
1384
+ case "function":
1385
+ ret = regClassBundle.exec(str.name);
1386
+ if (ret) {
1387
+ return ret[1];
1388
+ }
1389
+ throw new Error(`Bundle Bad Name :${str.name}`);
1390
+ default:
1391
+ throw new Error(`Bundle Bad Name :${str}`);
1348
1392
  }
1349
1393
  }
1350
1394
 
1351
- getBundleClass(Class, Path) {
1395
+ getBundleClass (Class, Path) {
1352
1396
  try {
1353
1397
  switch (true) {
1354
- case (Class instanceof nodefony.fileClass):
1355
- return this.getBundleClass(require(Class.path), require.resolve(Class.path));
1356
- case (typeof Class === "function"):
1357
- if (Class.toString().indexOf("class") >= 0) {
1358
- Class.prototype.path = path.dirname(Path);
1359
- Class.prototype.autoLoader = this.autoLoader;
1360
- return {
1361
- class: Class,
1362
- name: this.getBundleName(Class)
1363
- };
1364
- } else {
1365
- throw new Error(`getBundleClass Bad Bundle Class : ${Class.toString()} Path : ${Path}`);
1366
- }
1367
- break;
1368
- case (typeof Class === "string"):
1369
- return this.getBundleClass(require(Class), require.resolve(Class));
1370
- default:
1371
- throw new Error(`getBundleClass Bad Bundle Class : ${typeof Class} Path : ${Path}`);
1398
+ case Class instanceof nodefony.fileClass:
1399
+ return this.getBundleClass(require(Class.path), require.resolve(Class.path));
1400
+ case typeof Class === "function":
1401
+ if (Class.toString().indexOf("class") >= 0) {
1402
+ Class.prototype.path = path.dirname(Path);
1403
+ Class.prototype.autoLoader = this.autoLoader;
1404
+ return {
1405
+ class: Class,
1406
+ name: this.getBundleName(Class)
1407
+ };
1408
+ }
1409
+ throw new Error(`getBundleClass Bad Bundle Class : ${Class.toString()} Path : ${Path}`);
1410
+
1411
+ break;
1412
+ case typeof Class === "string":
1413
+ return this.getBundleClass(require(Class), require.resolve(Class));
1414
+ default:
1415
+ throw new Error(`getBundleClass Bad Bundle Class : ${typeof Class} Path : ${Path}`);
1372
1416
  }
1373
1417
  } catch (e) {
1374
1418
  throw e;
1375
1419
  }
1376
1420
  }
1377
1421
 
1378
- loadBundle(file, loader) {
1422
+ loadBundle (file, loader) {
1379
1423
  try {
1380
- let bundle = this.getBundleClass(file);
1424
+ const bundle = this.getBundleClass(file);
1381
1425
  try {
1382
1426
  this.log(`${bundle.name} : ${file.path}`, "DEBUG", "LOADER BUNDLE");
1383
1427
  this.bundles[bundle.name] = new bundle.class(bundle.name, this, this.container);
1384
1428
  this.bundles[bundle.name].loader = loader;
1385
- //console.log(bundle.name, this.notificationsCenter._events)
1429
+ // console.log(bundle.name, this.notificationsCenter._events)
1386
1430
  } catch (e) {
1387
1431
  throw e;
1388
1432
  }
1389
- //this.bundles[bundle.name].once("onReady", promiseBundleReady.call(this));
1433
+ // this.bundles[bundle.name].once("onReady", promiseBundleReady.call(this));
1390
1434
  return this.bundles[bundle.name];
1391
1435
  } catch (e) {
1392
1436
  throw e;
1393
1437
  }
1394
1438
  }
1395
1439
 
1396
- isPathExist(Path) {
1440
+ isPathExist (Path) {
1397
1441
  try {
1398
- let mypath = path.resolve(Path);
1442
+ const mypath = path.resolve(Path);
1399
1443
  if (fs.existsSync(mypath)) {
1400
1444
  return mypath;
1401
1445
  }
@@ -1404,11 +1448,11 @@ class Kernel extends nodefony.Service {
1404
1448
  }
1405
1449
  }
1406
1450
 
1407
- isConsole() {
1451
+ isConsole () {
1408
1452
  return this.type === "CONSOLE";
1409
1453
  }
1410
1454
 
1411
- isInstall() {
1455
+ isInstall () {
1412
1456
  if (this.cli.command === "nodefony" &&
1413
1457
  this.cli.task === "bundles" &&
1414
1458
  this.cli.action === "install") {
@@ -1436,29 +1480,29 @@ class Kernel extends nodefony.Service {
1436
1480
  return false;
1437
1481
  }
1438
1482
 
1439
- async isBundleDirectory(dir) {
1440
- let directory = this.isPathExist(dir);
1483
+ async isBundleDirectory (dir) {
1484
+ const directory = this.isPathExist(dir);
1441
1485
  if (directory) {
1442
- let finder = new nodefony.Finder2({
1486
+ const finder = new nodefony.Finder2({
1443
1487
  followSymLink: true,
1444
1488
  excludeDir: nodefony.Bundle.excludeDir(),
1445
1489
  exclude: nodefony.Bundle.exclude(),
1446
1490
  recurse: false,
1447
1491
  match: this.regBundle
1448
1492
  });
1449
- let result = await finder.in(directory);
1493
+ const result = await finder.in(directory);
1450
1494
  return result.getFiles();
1451
1495
  }
1452
1496
  return false;
1453
1497
  }
1454
1498
 
1455
- isNodeModule(module) {
1456
- //console.log(module)
1499
+ isNodeModule (module) {
1500
+ // console.log(module)
1457
1501
  let error = null;
1458
1502
  try {
1459
1503
  return require.resolve(module);
1460
1504
  } catch (e) {
1461
- //this.log(e, "ERROR");
1505
+ // this.log(e, "ERROR");
1462
1506
  error = e;
1463
1507
  }
1464
1508
  try {
@@ -1474,29 +1518,31 @@ class Kernel extends nodefony.Service {
1474
1518
  * @method
1475
1519
  * @param {array} bundles
1476
1520
  */
1477
- registerBundles(bundles) {
1521
+ registerBundles (bundles) {
1478
1522
  return new Promise(async (resolve, reject) => {
1479
1523
  switch (nodefony.typeOf(bundles)) {
1480
- case "array":
1524
+ case "array":
1525
+ try {
1481
1526
  for (let i = 0; i < bundles.length; i++) {
1482
1527
  let Path = await this.isBundleDirectory(bundles[i]);
1483
1528
  if (Path && Path.length) {
1484
1529
  try {
1485
- let bundle = this.loadBundle(Path[0], "filesystem");
1530
+ const bundle = this.loadBundle(Path[0], "filesystem");
1486
1531
  await bundle.find();
1487
1532
  } catch (e) {
1488
1533
  this.log(e, "ERROR");
1534
+ throw e;
1489
1535
  }
1490
1536
  } else {
1491
1537
  try {
1492
1538
  Path = this.isNodeModule(bundles[i]);
1493
1539
  if (Path) {
1494
- let bundle = this.loadBundle(Path, "package");
1540
+ const bundle = this.loadBundle(Path, "package");
1495
1541
  await bundle.find();
1496
1542
  } else {
1497
1543
  this.log("GLOBAL CONFIG REGISTER : ", "INFO");
1498
1544
  this.log(this.configBundle, "INFO");
1499
- let gene = this.readGeneratedConfig();
1545
+ const gene = this.readGeneratedConfig();
1500
1546
  if (gene) {
1501
1547
  this.log("GENERATED CONFIG REGISTER file ./config/GeneratedConfig.yml : ", "INFO");
1502
1548
  this.log(gene, "INFO");
@@ -1504,12 +1550,16 @@ class Kernel extends nodefony.Service {
1504
1550
  }
1505
1551
  } catch (e) {
1506
1552
  this.log(e, "ERROR");
1553
+ throw e;
1507
1554
  }
1508
1555
  }
1509
1556
  }
1510
1557
  return resolve(bundles);
1511
- default:
1512
- return reject(new Error("registerBundles argument bundles must be an array "));
1558
+ } catch (e) {
1559
+ return reject(e);
1560
+ }
1561
+ default:
1562
+ return reject(new Error("registerBundles argument bundles must be an array "));
1513
1563
  }
1514
1564
  });
1515
1565
  }
@@ -1518,9 +1568,9 @@ class Kernel extends nodefony.Service {
1518
1568
  * initialisation application bundle
1519
1569
  * @method initApplication
1520
1570
  */
1521
- async initApplication() {
1522
- let app = class appBundle extends nodefony.Bundle {
1523
- constructor(name, myKernel, myContainer) {
1571
+ async initApplication () {
1572
+ const app = class appBundle extends nodefony.Bundle {
1573
+ constructor (name, myKernel, myContainer) {
1524
1574
  super(name, myKernel, myContainer);
1525
1575
  }
1526
1576
  };
@@ -1531,11 +1581,11 @@ class Kernel extends nodefony.Service {
1531
1581
  await this.bundles.app.find();
1532
1582
  // OVERRIDE VIEWS BUNDLE in APP DIRECTORY
1533
1583
  this.once("onBoot", async () => {
1534
- for (let bundle in this.bundles) {
1584
+ for (const bundle in this.bundles) {
1535
1585
  if (bundle === "app") {
1536
1586
  continue;
1537
1587
  }
1538
- let result = this.bundles.app.resourcesFiles.find(bundle + "-bundle");
1588
+ const result = this.bundles.app.resourcesFiles.find(`${bundle}-bundle`);
1539
1589
  if (result.length) {
1540
1590
  try {
1541
1591
  this.bundles[bundle].registerI18n(null, result);
@@ -1548,93 +1598,135 @@ class Kernel extends nodefony.Service {
1548
1598
  return this.bundles.app;
1549
1599
  }
1550
1600
 
1601
+ // CONFIG
1602
+ readConfigFile (bundle, Path, callback) {
1603
+ try {
1604
+ this.log(`${bundle} CONFIG LOAD FILE :${Path}`, "DEBUG", "KERNEL READER");
1605
+ return this.reader.readConfig(Path, this.name, callback);
1606
+ } catch (e) {
1607
+ this.log(e, "ERROR", `BUNDLE ${bundle} CONFIG :${Path}`);
1608
+ throw e;
1609
+ }
1610
+ }
1611
+
1612
+ readRoutingFile (bundle, Path) {
1613
+ // ROUTING
1614
+ try {
1615
+ this.log(`${bundle} ROUTER LOAD FILE :${Path}`, "DEBUG", "KERNEL READER");
1616
+ const router = this.get("router");
1617
+ if (router) {
1618
+ return router.reader(Path, this.name);
1619
+ }
1620
+ this.log(`${bundle} Router service not ready to LOAD FILE :${Path}`, "WARNING", "KERNEL READER");
1621
+ } catch (e) {
1622
+ this.log(e, "ERROR", `BUNDLE ${this.name.toUpperCase()} CONFIG ROUTING :${Path}`);
1623
+ throw e;
1624
+ }
1625
+ }
1626
+
1627
+ readServicesFile (bundle, Path, callback) {
1628
+ try {
1629
+ this.log(`${bundle} LOAD FILE :${Path}`, "DEBUG", "KERNEL READER");
1630
+ return this.get("injection").reader(Path, this.name);
1631
+ } catch (e) {
1632
+ this.log(e, "ERROR", `BUNDLE ${this.name.toUpperCase()} CONFIG SERVICE :${Path}`);
1633
+ throw e;
1634
+ }
1635
+ }
1636
+
1637
+ readSecurityFile (bundle, Path, callback) {
1638
+ try {
1639
+ const firewall = this.get("security");
1640
+ if (firewall) {
1641
+ this.log(`${bundle} SECURITY LOAD FILE :${Path}`, "DEBUG", "KERNEL READER");
1642
+ return firewall.reader(Path, this.name);
1643
+ }
1644
+ this.log(`${bundle} SECURITY LOAD FILE :${Path} BUT SERVICE NOT READY`, "WARNING");
1645
+ } catch (e) {
1646
+ this.log(e, "ERROR", `BUNDLE ${this.name.toUpperCase()} CONFIG SECURITY :${Path}`);
1647
+ throw e;
1648
+ }
1649
+ }
1650
+
1651
+ findConfigFile (ele, callback) {
1652
+ const name = this.name.toUpperCase();
1653
+ switch (true) {
1654
+ case (/^config\..*$/).test(ele.name):
1655
+ try {
1656
+ return this.kernel.readConfigFile.call(this, name, ele.path, callback);
1657
+ } catch (e) {
1658
+ throw e;
1659
+ }
1660
+ case (/^routing\..*$/).test(ele.name):
1661
+ try {
1662
+ return this.kernel.readRoutingFile.call(this, name, ele.path, callback);
1663
+ } catch (e) {
1664
+ throw e;
1665
+ }
1666
+ case (/^services\..*$/).test(ele.name):
1667
+ try {
1668
+ return this.kernel.readServicesFile.call(this, name, ele.path, callback);
1669
+ } catch (e) {
1670
+ throw e;
1671
+ }
1672
+ case (/^security\..*$/).test(ele.name):
1673
+ try {
1674
+ return this.kernel.readSecurityFile.call(this, name, ele.path, callback);
1675
+ } catch (e) {
1676
+ throw e;
1677
+ }
1678
+ }
1679
+ }
1680
+
1551
1681
  /**
1552
1682
  *
1553
1683
  * @method readConfig
1554
1684
  */
1555
- readConfig(error, result, callback) {
1556
- let name = this.name.toUpperCase();
1685
+ readConfig (error, result, callback) {
1557
1686
  if (error) {
1558
- this.log(error, "ERROR");
1687
+ throw error;
1559
1688
  } else {
1689
+ if (!result) {
1690
+ throw new Error("readConfig no result found");
1691
+ }
1560
1692
  result.forEach((ele) => {
1561
- switch (true) {
1562
- case /^config\..*$/.test(ele.name):
1563
- try {
1564
- this.log(name + " CONFIG LOAD FILE :" + ele.path, "DEBUG", "KERNEL READER");
1565
- this.reader.readConfig(ele.path, this.name, callback);
1566
- } catch (e) {
1567
- this.log(e, "ERROR", "BUNDLE " + name + " CONFIG :" + ele.path);
1568
- }
1569
- break;
1570
- case /^routing\..*$/.test(ele.name):
1571
- // ROUTING
1572
- try {
1573
- this.log(name + " ROUTER LOAD FILE :" + ele.path, "DEBUG", "KERNEL READER");
1574
- let router = this.get("router");
1575
- if (router) {
1576
- router.reader(ele.path, this.name);
1577
- } else {
1578
- this.log(name + " Router service not ready to LOAD FILE :" + ele.path, "WARNING", "KERNEL READER");
1579
- }
1580
- } catch (e) {
1581
- this.log(e, "ERROR", "BUNDLE " + this.name.toUpperCase() + " CONFIG ROUTING :" + ele.path);
1582
- }
1583
- break;
1584
- case /^services\..*$/.test(ele.name):
1585
- try {
1586
- this.log(name + " LOAD FILE :" + ele.path, "DEBUG", "KERNEL READER");
1587
- this.get("injection").reader(ele.path, this.name);
1588
- } catch (e) {
1589
- this.log(e, "ERROR", "BUNDLE " + this.name.toUpperCase() + " CONFIG SERVICE :" + ele.path);
1590
- }
1591
- break;
1592
- case /^security\..*$/.test(ele.name):
1593
- try {
1594
- let firewall = this.get("security");
1595
- if (firewall) {
1596
- this.log(name + " SECURITY LOAD FILE :" + ele.path, "DEBUG", "KERNEL READER");
1597
- firewall.reader(ele.path, this.name);
1598
- } else {
1599
- this.log(name + " SECURITY LOAD FILE :" + ele.path + " BUT SERVICE NOT READY", "WARNING");
1600
- }
1601
- } catch (e) {
1602
- this.log(e, "ERROR", "BUNDLE " + this.name.toUpperCase() + " CONFIG SECURITY :" + ele.path);
1603
- }
1604
- break;
1693
+ try {
1694
+ this.kernel.findConfigFile.call(this, ele, callback);
1695
+ } catch (e) {
1696
+ throw e;
1605
1697
  }
1606
1698
  });
1607
1699
  }
1608
1700
  }
1609
1701
 
1610
- memoryUsage(message) {
1611
- //let memory = process.memoryUsage() ;
1612
- let memory = this.stats().memory;
1613
- for (let ele in memory) {
1702
+ memoryUsage (message) {
1703
+ // let memory = process.memoryUsage() ;
1704
+ const {memory} = this.stats();
1705
+ for (const ele in memory) {
1614
1706
  switch (ele) {
1615
- case "rss":
1616
- this.log((message || ele) + " ( Resident Set Size ) PID ( " + this.processId + " ) : " + nodefony.cli.niceBytes(memory[ele]), "DEBUG", "MEMORY " + ele);
1617
- break;
1618
- case "heapTotal":
1619
- this.log((message || ele) + " ( Total Size of the Heap ) PID ( " + this.processId + " ) : " + nodefony.cli.niceBytes(memory[ele]), "DEBUG", "MEMORY " + ele);
1620
- break;
1621
- case "heapUsed":
1622
- this.log((message || ele) + " ( Heap actually Used ) PID ( " + this.processId + " ) : " + nodefony.cli.niceBytes(memory[ele]), "DEBUG", "MEMORY " + ele);
1623
- break;
1624
- case "external":
1625
- this.log((message || ele) + " PID ( " + this.processId + " ) : " + nodefony.cli.niceBytes(memory[ele]), "DEBUG", "MEMORY " + ele);
1626
- break;
1707
+ case "rss":
1708
+ this.log(`${message || ele} ( Resident Set Size ) PID ( ${this.processId} ) : ${nodefony.cli.niceBytes(memory[ele])}`, "DEBUG", `MEMORY ${ele}`);
1709
+ break;
1710
+ case "heapTotal":
1711
+ this.log(`${message || ele} ( Total Size of the Heap ) PID ( ${this.processId} ) : ${nodefony.cli.niceBytes(memory[ele])}`, "DEBUG", `MEMORY ${ele}`);
1712
+ break;
1713
+ case "heapUsed":
1714
+ this.log(`${message || ele} ( Heap actually Used ) PID ( ${this.processId} ) : ${nodefony.cli.niceBytes(memory[ele])}`, "DEBUG", `MEMORY ${ele}`);
1715
+ break;
1716
+ case "external":
1717
+ this.log(`${message || ele} PID ( ${this.processId} ) : ${nodefony.cli.niceBytes(memory[ele])}`, "DEBUG", `MEMORY ${ele}`);
1718
+ break;
1627
1719
  }
1628
1720
  }
1629
1721
  }
1630
1722
 
1631
- stats() {
1632
- let stat = {
1723
+ stats () {
1724
+ const stat = {
1633
1725
  memory: {}
1634
- //cpu:process.cpuUsage()
1726
+ // cpu:process.cpuUsage()
1635
1727
  };
1636
- let memory = process.memoryUsage();
1637
- for (let ele in memory) {
1728
+ const memory = process.memoryUsage();
1729
+ for (const ele in memory) {
1638
1730
  stat.memory[ele] = memory[ele];
1639
1731
  }
1640
1732
  return stat;
@@ -1644,12 +1736,12 @@ class Kernel extends nodefony.Service {
1644
1736
  *
1645
1737
  * @method terminate
1646
1738
  */
1647
- async terminate(code) {
1739
+ async terminate (code) {
1648
1740
  if (code === undefined) {
1649
1741
  code = 0;
1650
1742
  }
1651
1743
  if (this.debug) {
1652
- console.trace(code);
1744
+ console.trace(`terminate : ${code}`);
1653
1745
  }
1654
1746
  try {
1655
1747
  if (fs.existsSync(this.cacheLink)) {
@@ -1665,7 +1757,7 @@ class Kernel extends nodefony.Service {
1665
1757
  code = 1;
1666
1758
  }
1667
1759
  process.nextTick(() => {
1668
- this.log("NODEFONY Kernel Life Cycle Terminate CODE : " + code, "INFO");
1760
+ this.log(`NODEFONY Kernel Life Cycle Terminate CODE : ${code}`, "INFO");
1669
1761
  try {
1670
1762
  nodefony.cli.quit(code);
1671
1763
  } catch (e) {