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/cli.es6 CHANGED
@@ -1,28 +1,46 @@
1
- const Table = require('cli-table3');
2
- const asciify = require('asciify');
3
- let inquirer = null
4
- const inquirerImport = async()=>{
5
- inquirer = await import('inquirer')
6
- .then((esmFS) => {
7
- return esmFS.default
8
- })
9
- }
1
+ /* eslint-disable max-lines-per-function */
2
+ // const Table = require('cli-table3');
3
+ const asciify = require("asciify");
4
+ let inquirer = null;
5
+ const inquirerImport = async () => {
6
+ inquirer = await import("inquirer")
7
+ .then((esmFS) => esmFS.default)
8
+ .catch((e) => {
9
+ throw e;
10
+ });
11
+ };
12
+
13
+ let Table = null;
14
+ const cliTableImport = async () => {
15
+ Table = await import("cli-table3")
16
+ .then((esmFS) => esmFS.default)
17
+ .catch((e) => {
18
+ throw e;
19
+ });
20
+ };
21
+
22
+ const nodeEmojiImport = async () => await import("node-emoji")
23
+ .then((esmFS) => esmFS)
24
+ .catch((e) => {
25
+ throw e;
26
+ });
27
+
10
28
  const {
11
29
  program,
12
30
  command
13
- } = require('commander');
14
- const spawn = require('child_process').spawn;
15
- const spawnSync = require('child_process').spawnSync;
31
+ } = require("commander");
32
+ const {spawn} = require("child_process");
33
+ const {spawnSync} = require("child_process");
16
34
  const moment = require("moment");
17
- const semver = require('semver');
35
+ const semver = require("semver");
18
36
 
19
- //const red = clc.red.bold;
20
- //const cyan = clc.cyan.bold;
37
+ // const red = clc.red.bold;
38
+ // const cyan = clc.cyan.bold;
21
39
  const blue = clc.blueBright.bold;
22
- const green = clc.green;
23
- //const yellow = clc.yellow.bold;
40
+ const {green} = clc;
41
+ // const yellow = clc.yellow.bold;
24
42
  const magenta = clc.magenta.bold;
25
- const reset = clc.reset; // '\x1b[0m';
43
+ const {reset} = clc; // '\x1b[0m';
26
44
 
27
45
  let processName = null;
28
46
  if (process.argv && process.argv[1]) {
@@ -33,13 +51,13 @@ if (process.argv && process.argv[1]) {
33
51
 
34
52
  const defaultTableCli = {
35
53
  style: {
36
- head: ['cyan'],
37
- border: ['grey']
54
+ head: ["cyan"],
55
+ border: ["grey"]
38
56
  }
39
57
  };
40
58
 
41
59
  const defaultOptions = {
42
- processName: processName,
60
+ processName,
43
61
  autostart: true,
44
62
  asciify: true,
45
63
  clear: true,
@@ -56,8 +74,8 @@ const defaultOptions = {
56
74
  };
57
75
 
58
76
  class CLI extends nodefony.Service {
59
-
60
- constructor(name, container, notificationsCenter, options) {
77
+ // eslint-disable-next-line complexity
78
+ constructor (name, container, notificationsCenter, options) {
61
79
  switch (arguments.length) {
62
80
  case 0:
63
81
  options = nodefony.extend({}, defaultOptions);
@@ -71,34 +89,32 @@ class CLI extends nodefony.Service {
71
89
  super(options.processName, null, null, options);
72
90
  } else {
73
91
  options = nodefony.extend({}, defaultOptions);
74
- name = name || options.processName;
92
+ name ||= options.processName;
75
93
  super(name, null, null, options);
76
94
  }
77
95
  break;
78
96
  case 2:
79
97
  if (container instanceof nodefony.Container) {
80
98
  options = nodefony.extend({}, defaultOptions);
81
- name = name || options.processName;
99
+ name ||= options.processName;
82
100
  super(name, container, null, options);
101
+ } else if (typeof container === "object" && container !== null) {
102
+ options = nodefony.extend({}, defaultOptions, container);
103
+ name ||= options.processName;
104
+ super(name, null, null, options);
83
105
  } else {
84
- if (typeof container === "object" && container !== null) {
85
- options = nodefony.extend({}, defaultOptions, container);
86
- name = name || options.processName;
87
- super(name, null, null, options);
88
- } else {
89
- options = nodefony.extend({}, defaultOptions);
90
- name = name || options.processName;
91
- super(name, container, null, options);
92
- }
106
+ options = nodefony.extend({}, defaultOptions);
107
+ name ||= options.processName;
108
+ super(name, container, null, options);
93
109
  }
94
110
  break;
95
111
  default:
96
112
  options = nodefony.extend({}, defaultOptions, options);
97
- name = name || options.processName;
113
+ name ||= options.processName;
98
114
  super(name, container, notificationsCenter, options);
99
115
  }
100
116
  this.environment = process.env.NODE_ENV || "production";
101
- process.env.NODE_ENV = this.environment;
117
+ // process.env.NODE_ENV = this.environment;
102
118
  this.unhandledRejections = new Map();
103
119
 
104
120
  this.setProcessTitle();
@@ -112,36 +128,50 @@ class CLI extends nodefony.Service {
112
128
  if (this.options.autoLogger) {
113
129
  this.initSyslog();
114
130
  }
115
- this.initUi()
116
- this.prependOnceListener("onStart",async () => {
131
+ this.initUi();
132
+ this.prependOnceListener("onStart", async () => {
117
133
  await inquirerImport()
118
- this.initPrompt()
119
- })
134
+ .catch((e) => {
135
+ this.log(e, "WARNING");
136
+ });
137
+ await cliTableImport()
138
+ .catch((e) => {
139
+ this.log(e, "WARNING");
140
+ // Table = require("cli-table3")
141
+ });
142
+ this.emoji = await nodeEmojiImport()
143
+ .catch((e) => {
144
+ this.log(e, "WARNING");
145
+ });
146
+ this.initPrompt();
147
+ });
148
+ this.commander = null;
120
149
  this.initCommander();
121
150
 
122
151
  if (this.options.warning) {
123
- process.on('warning', (warning) => {
152
+ process.on("warning", (warning) => {
124
153
  this.log(warning, "WARNING");
125
154
  this.fire("onNodeWarning", warning, this);
126
155
  });
127
156
  } else {
128
157
  process.env.NODE_NO_WARNINGS = 1;
129
158
  }
159
+
130
160
  /**
131
161
  * @signals
132
162
  */
133
163
  if (this.options.signals) {
134
- process.on('SIGINT', () => {
164
+ process.on("SIGINT", () => {
135
165
  this.blankLine();
136
166
  this.wrapperLog = console.log;
137
167
  this.log("SIGINT", "CRITIC");
138
- //this.clear();
168
+ // this.clear();
139
169
  this.fire("onSignal", "SIGINT", this);
140
170
  process.nextTick(() => {
141
171
  this.terminate();
142
172
  });
143
173
  });
144
- process.on('SIGTERM', () => {
174
+ process.on("SIGTERM", () => {
145
175
  this.blankLine();
146
176
  this.wrapperLog = console.log;
147
177
  this.log("SIGTERM", "CRITIC");
@@ -150,7 +180,7 @@ class CLI extends nodefony.Service {
150
180
  this.terminate();
151
181
  });
152
182
  });
153
- process.on('SIGHUP', () => {
183
+ process.on("SIGHUP", () => {
154
184
  this.blankLine();
155
185
  this.wrapperLog = console.log;
156
186
  this.log("SIGHUP", "CRITIC");
@@ -159,73 +189,75 @@ class CLI extends nodefony.Service {
159
189
  this.terminate();
160
190
  });
161
191
  });
162
- process.on('SIGQUIT', () => {
192
+ process.on("SIGQUIT", () => {
163
193
  this.blankLine();
164
194
  this.wrapperLog = console.log;
165
195
  this.log("SIGQUIT", "CRITIC");
166
- //this.clear();
196
+ // this.clear();
167
197
  this.fire("onSignal", "SIGQUIT", this);
168
198
  process.nextTick(() => {
169
199
  this.terminate();
170
200
  });
171
201
  });
172
- process.on('uncaughtException', (err) => {
173
- this.log(err, "CRITIC", 'uncaughtException');
202
+ process.on("uncaughtException", (err) => {
203
+ this.log(err, "CRITIC", "uncaughtException");
174
204
  });
175
205
  }
206
+
176
207
  /**
177
208
  * @promiseRejection
178
209
  */
179
210
  if (this.options.promiseRejection) {
180
211
  this.listenRejection();
181
212
  }
213
+
182
214
  /**
183
215
  * ASCIIFY
184
216
  */
185
217
  if (name && this.options.asciify) {
186
218
  this.showAsciify(name)
187
- .then(() => {
219
+ .then(async () => {
188
220
  if (this.options.autostart) {
189
221
  try {
190
- this.fireAsync("onStart", this);
222
+ await this.fireAsync("onStart", this);
191
223
  } catch (e) {
192
- throw e;
224
+ this.log(e, "ERROR");
193
225
  }
194
226
  }
195
227
  });
196
- } else {
197
- if (this.options.autostart) {
198
- try {
199
- this.fireAsync("onStart", this);
200
- } catch (e) {
201
- this.log(e, "ERROR");
202
- }
228
+ } else if (this.options.autostart) {
229
+ try {
230
+ async () => {
231
+ try {
232
+ await this.fireAsync("onStart", this);
233
+ } catch (e) {
234
+ this.log(e, "ERROR");
235
+ }
236
+ };
237
+ } catch (e) {
238
+ this.log(e, "ERROR");
203
239
  }
204
240
  }
205
241
  }
206
242
 
207
- start() {
243
+ start () {
208
244
  return new Promise(async (resolve, reject) => {
209
245
  try {
210
246
  if (this.options.autostart) {
211
247
  if (this.options.asciify) {
212
- this.once("onStart", () => {
213
- return resolve(this);
214
- });
248
+ this.once("onStart", () => resolve(this));
215
249
  } else {
216
250
  await this.fireAsync("onStart", this);
217
251
  return resolve(this);
218
252
  }
219
- } else {
220
- if (this.options.asciify) {
221
- this.once("onAsciify", async () => {
222
- await this.fireAsync("onStart", this);
223
- return resolve(this);
224
- });
225
- } else {
253
+ } else if (this.options.asciify) {
254
+ this.once("onAsciify", async () => {
226
255
  await this.fireAsync("onStart", this);
227
256
  return resolve(this);
228
- }
257
+ });
258
+ } else {
259
+ await this.fireAsync("onStart", this);
260
+ return resolve(this);
229
261
  }
230
262
  } catch (e) {
231
263
  return reject(e);
@@ -233,47 +265,47 @@ class CLI extends nodefony.Service {
233
265
  });
234
266
  }
235
267
 
236
- idle() {
237
- let resolve = null
238
- let reject = null
268
+ idle () {
269
+ let resolve = null;
270
+ let reject = null;
239
271
  const promise = new Promise((res, rej) => {
240
- resolve = res
241
- reject = rej
242
- })
243
- return function () {
272
+ resolve = res;
273
+ reject = rej;
274
+ });
275
+ return (function () {
244
276
  return {
245
277
  resolve,
246
278
  promise,
247
279
  reject
248
- }
249
- }()
250
- //return this.idleId = setInterval(() => {}, 0);
280
+ };
281
+ }());
282
+ // return this.idleId = setInterval(() => {}, 0);
251
283
  }
252
284
 
253
- checkVersion(version = null) {
285
+ checkVersion (version = null) {
254
286
  if (!version) {
255
287
  version = this.version;
256
288
  }
257
- let res = semver.valid(version);
289
+ const res = semver.valid(version);
258
290
  if (res) {
259
291
  return res;
260
292
  }
261
- throw new Error("Not valid version : " + version + " check http://semver.org ");
293
+ throw new Error(`Not valid version : ${version} check http://semver.org `);
262
294
  }
263
295
 
264
- async showAsciify(name = null) {
296
+ async showAsciify (name = null) {
265
297
  if (!name) {
266
298
  name = this.name;
267
299
  }
268
300
  return await this.asciify(` ${name}`, {
269
- font: this.options.font || "standard"
270
- })
301
+ font: this.options.font || "standard"
302
+ })
271
303
  .then((data) => {
272
304
  this.fire("onAsciify", data);
273
305
  if (this.options.clear) {
274
306
  this.clear();
275
307
  }
276
- let color = this.options.color || blue;
308
+ const color = this.options.color || blue;
277
309
  console.log(color(data));
278
310
  return data;
279
311
  })
@@ -283,8 +315,8 @@ class CLI extends nodefony.Service {
283
315
  });
284
316
  }
285
317
 
286
- showBanner() {
287
- let version = this.commander ? this.commander.version() : (this.options.version || "1.0.0");
318
+ showBanner () {
319
+ const version = this.commander ? this.commander.version() : this.options.version || "1.0.0";
288
320
  let banner = null;
289
321
  if (this.options.version) {
290
322
  banner = ` Version : ${blue(version)} Platform : ${green(process.platform)} Process : ${green(process.title)} Pid : ${process.pid}`;
@@ -294,23 +326,23 @@ class CLI extends nodefony.Service {
294
326
  return banner;
295
327
  }
296
328
 
297
- listenRejection() {
298
- process.on('rejectionHandled', (promise) => {
299
- this.log("PROMISE REJECTION EVENT ", "CRITIC", 'rejectionHandled');
329
+ listenRejection () {
330
+ process.on("rejectionHandled", (promise) => {
331
+ this.log("PROMISE REJECTION EVENT ", "CRITIC", "rejectionHandled");
300
332
  this.unhandledRejections.delete(promise);
301
333
  });
302
- process.on('unhandledRejection', (reason, promise) => {
303
- this.log("WARNING !!! PROMISE CHAIN BREAKING : " + reason, "WARNING", 'unhandledRejection');
334
+ process.on("unhandledRejection", (reason, promise) => {
335
+ this.log(`WARNING !!! PROMISE CHAIN BREAKING : ${reason}`, "WARNING", "unhandledRejection");
304
336
  console.trace(promise);
305
337
  this.unhandledRejections.set(promise, reason);
306
338
  });
307
339
  }
308
340
 
309
- setPid() {
341
+ setPid () {
310
342
  this.pid = process.pid;
311
343
  }
312
344
 
313
- setProcessTitle(name) {
345
+ setProcessTitle (name) {
314
346
  if (name) {
315
347
  process.title = name.replace(new RegExp("\\s", "gi"), "").toLowerCase();
316
348
  } else {
@@ -319,26 +351,28 @@ class CLI extends nodefony.Service {
319
351
  return process.title;
320
352
  }
321
353
 
322
- logEnv() {
323
- return blue(" \x1b " + this.name) + " NODE_ENV : " + magenta(this.environment);
354
+ logEnv () {
355
+ return `${blue(` \x1b ${this.name}`)} Nodefony Environment : ${magenta(this.environment)}`;
324
356
  }
325
357
 
326
- initCommander() {
358
+ initCommander () {
327
359
  if (this.options.commander) {
328
360
  this.commander = program;
329
361
  if (this.options.version) {
330
362
  this.setCommandVersion(this.options.version);
331
363
  }
332
- /*this.on("onStart", () => {
364
+ return program;
365
+
366
+ /* this.on("onStart", () => {
333
367
  //this.commander.parse(process.argv);
334
368
  });*/
335
369
  }
370
+ return null;
336
371
  }
337
372
 
338
- initUi() {
373
+ initUi () {
339
374
  this.clc = clc;
340
375
  this.clui = require("clui");
341
- this.emoji = require("node-emoji");
342
376
  this.spinner = null;
343
377
  this.blankLine = function () {
344
378
  const myLine = new this.clui.Line().fill();
@@ -351,27 +385,27 @@ class CLI extends nodefony.Service {
351
385
  }
352
386
  }
353
387
 
354
- initPrompt() {
388
+ initPrompt () {
355
389
  this.inquirer = inquirer;
356
390
  if (this.options.prompt === "rxjs") {
357
391
  this.prompt = new Rx.Subject();
358
- let prompt = inquirer.createPromptModule();
392
+ const prompt = inquirer.createPromptModule();
359
393
  prompt(this.prompt);
360
394
  } else {
361
395
  this.prompt = inquirer.createPromptModule();
362
396
  }
363
397
  }
364
398
 
365
- getFonts() {
399
+ getFonts () {
366
400
  asciify.getFonts((err, fonts) => {
367
401
  fonts.forEach(this.log);
368
402
  });
369
403
  }
370
404
 
371
- async asciify(txt, options, callback) {
405
+ async asciify (txt, options, callback) {
372
406
  return new Promise((resolve, reject) => {
373
407
  asciify(txt, nodefony.extend({
374
- font: 'standard'
408
+ font: "standard"
375
409
  }, options), (error, data) => {
376
410
  if (callback && typeof callback === "function") {
377
411
  return callback(error, data);
@@ -384,15 +418,15 @@ class CLI extends nodefony.Service {
384
418
  });
385
419
  }
386
420
 
387
- async parseCommand(argv) {
421
+ async parseCommand (argv) {
388
422
  const parser = await this.commander.parse(argv || process.argv);
389
- let debug = this.commander.opts().debug;
423
+ const {debug} = this.commander.opts();
390
424
  if (debug) {
391
425
  this.debug = debug;
392
426
  } else {
393
427
  this.debug = false;
394
428
  }
395
- let interactive = this.commander.opts().interactive;
429
+ const {interactive} = this.commander.opts();
396
430
  if (interactive) {
397
431
  this.interactive = interactive;
398
432
  } else {
@@ -401,29 +435,32 @@ class CLI extends nodefony.Service {
401
435
  return Promise.resolve(parser);
402
436
  }
403
437
 
404
- setOption(option, description, callback) {
438
+ setOption (option, description, callback) {
405
439
  return this.commander.option(option, description, callback);
406
440
  }
407
- setCommandVersion(version) {
441
+
442
+ setCommandVersion (version) {
408
443
  if (this.commander && typeof this.commander.version === "function") {
409
- return this.commander.version(version, '-v, --version', 'Nodefony Current Version');
444
+ return this.commander.version(version, "-v, --version", "Nodefony Current Version");
410
445
  }
411
446
  }
412
- setCommand(command, description, options) {
447
+
448
+ setCommand (command, description, options) {
413
449
  return this.commander.command(command, description, options);
414
450
  }
415
- showHelp(quit, callback) {
451
+
452
+ showHelp (quit, callback) {
416
453
  if (quit) {
417
454
  return this.commander.help(callback);
418
455
  }
419
456
  return this.commander.outputHelp(callback);
420
457
  }
421
458
 
422
- createProgress(size) {
459
+ createProgress (size) {
423
460
  return new this.clui.Progress(size);
424
461
  }
425
462
 
426
- createSparkline(values, suffix) {
463
+ createSparkline (values, suffix) {
427
464
  if (values) {
428
465
  try {
429
466
  return this.clui.Sparkline(values, suffix || "");
@@ -434,18 +471,18 @@ class CLI extends nodefony.Service {
434
471
  }
435
472
  }
436
473
 
437
- getSeparator(sep) {
474
+ getSeparator (sep) {
438
475
  if (sep) {
439
476
  return new inquirer.Separator(sep);
440
477
  }
441
478
  return new inquirer.Separator("--------");
442
479
  }
443
480
 
444
- getSpinner(message, design) {
481
+ getSpinner (message, design) {
445
482
  return new this.clui.Spinner(message, design || null);
446
483
  }
447
484
 
448
- startSpinner(message, design) {
485
+ startSpinner (message, design) {
449
486
  try {
450
487
  this.spinner = this.getSpinner(message, design);
451
488
  this.wrapperLog = this.spinner.message;
@@ -456,7 +493,8 @@ class CLI extends nodefony.Service {
456
493
  throw e;
457
494
  }
458
495
  }
459
- stopSpinner( /*message, options*/ ) {
496
+
497
+ stopSpinner (/* message, options*/) {
460
498
  if (this.spinner) {
461
499
  this.spinner.stop();
462
500
  this.wrapperLog = console.log;
@@ -468,7 +506,7 @@ class CLI extends nodefony.Service {
468
506
  return false;
469
507
  }
470
508
 
471
- displayTable(datas, options = defaultTableCli, syslog = null) {
509
+ displayTable (datas, options = defaultTableCli, syslog = null) {
472
510
  if (!datas || !datas.length) {
473
511
  return new Table(nodefony.extend({}, defaultTableCli, options));
474
512
  }
@@ -491,77 +529,81 @@ class CLI extends nodefony.Service {
491
529
  return table;
492
530
  }
493
531
 
494
- static niceBytes(x) {
495
- let units = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
532
+ static niceBytes (x) {
533
+ let units = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
496
534
  n = parseInt(x, 10) || 0,
497
535
  l = 0;
498
536
  while (n >= 1024) {
499
- n = n / 1024;
537
+ n /= 1024;
500
538
  l++;
501
539
  }
502
- return (n.toFixed(n >= 10 || l < 1 ? 0 : 1) + ' ' + units[l]);
540
+ return `${n.toFixed(n >= 10 || l < 1 ? 0 : 1)} ${units[l]}`;
503
541
  }
504
542
 
505
- static niceUptime(date, suffix) {
543
+ static niceUptime (date, suffix) {
506
544
  return moment(date).fromNow(suffix || false);
507
545
  }
508
546
 
509
- static niceDate(date, format) {
547
+ static niceDate (date, format) {
510
548
  return moment(date).format(format);
511
549
  }
512
550
 
513
- getEmoji(name) {
551
+ getEmoji (name) {
514
552
  if (name) {
515
553
  return this.emoji.get(name);
516
554
  }
517
555
  return this.emoji.random().emoji;
518
556
  }
519
557
 
520
- clear() {
558
+ clear () {
521
559
  this.clui.Clear();
522
560
  }
523
561
 
524
- reset() {
562
+ reset () {
525
563
  process.stdout.write(reset);
526
564
  }
527
565
 
528
- resize() {
529
- process.stdout.on('resize', () => {
566
+ resize () {
567
+ process.stdout.on("resize", () => {
530
568
  this.columns = process.stdout.columns;
531
569
  this.rows = process.stdout.rows;
532
570
  this.fire("onResize", this.columns, this.rows, this);
533
571
  });
534
572
  }
535
573
 
536
- rm() {
574
+ rm () {
537
575
  try {
538
576
  return shell.rm.apply(shell, arguments);
539
577
  } catch (e) {
540
578
  throw e;
541
579
  }
542
580
  }
543
- cp() {
581
+
582
+ cp () {
544
583
  try {
545
584
  return shell.cp.apply(shell, arguments);
546
585
  } catch (e) {
547
586
  throw e;
548
587
  }
549
588
  }
550
- cd() {
589
+
590
+ cd () {
551
591
  try {
552
592
  return shell.cd.apply(shell, arguments);
553
593
  } catch (e) {
554
594
  throw e;
555
595
  }
556
596
  }
557
- ln() {
597
+
598
+ ln () {
558
599
  try {
559
600
  return shell.ln.apply(shell, arguments);
560
601
  } catch (e) {
561
602
  throw e;
562
603
  }
563
604
  }
564
- mkdir() {
605
+
606
+ mkdir () {
565
607
  try {
566
608
  return shell.mkdir.apply(shell, arguments);
567
609
  } catch (e) {
@@ -569,14 +611,15 @@ class CLI extends nodefony.Service {
569
611
  }
570
612
  }
571
613
 
572
- chmod() {
614
+ chmod () {
573
615
  try {
574
616
  return shell.chmod.apply(shell, arguments);
575
617
  } catch (e) {
576
618
  throw e;
577
619
  }
578
620
  }
579
- ls() {
621
+
622
+ ls () {
580
623
  try {
581
624
  return shell.ls.apply(shell, arguments);
582
625
  } catch (e) {
@@ -584,27 +627,27 @@ class CLI extends nodefony.Service {
584
627
  }
585
628
  }
586
629
 
587
- createDirectory(myPath, mode, callback, force) {
630
+ createDirectory (myPath, mode, callback, force) {
588
631
  let file = null;
589
632
  if (!callback) {
590
633
  return new Promise((resolve, reject) => {
591
- try {
592
- fs.mkdirSync(myPath, mode);
593
- file = new nodefony.fileClass(myPath);
594
- return resolve(file);
595
- } catch (e) {
596
- switch (e.code) {
597
- case "EEXIST":
598
- if (force) {
599
- file = new nodefony.fileClass(myPath);
600
- return resolve(file);
601
- }
602
- break;
634
+ try {
635
+ fs.mkdirSync(myPath, mode);
636
+ file = new nodefony.fileClass(myPath);
637
+ return resolve(file);
638
+ } catch (e) {
639
+ switch (e.code) {
640
+ case "EEXIST":
641
+ if (force) {
642
+ file = new nodefony.fileClass(myPath);
643
+ return resolve(file);
603
644
  }
604
- return reject(e);
645
+ break;
605
646
  }
606
- })
607
- .catch(e => {
647
+ return reject(e);
648
+ }
649
+ })
650
+ .catch((e) => {
608
651
  throw e;
609
652
  });
610
653
  }
@@ -627,14 +670,14 @@ class CLI extends nodefony.Service {
627
670
  }
628
671
  }
629
672
 
630
- existsSync(myPath) {
673
+ existsSync (myPath) {
631
674
  if (!myPath) {
632
675
  throw new Error("existsSync no path found");
633
676
  }
634
677
  return fs.existsSync(myPath);
635
678
  }
636
679
 
637
- exists(myPath, mode, callback) {
680
+ exists (myPath, mode, callback) {
638
681
  if (!myPath) {
639
682
  throw new Error("exists no path found");
640
683
  }
@@ -647,7 +690,7 @@ class CLI extends nodefony.Service {
647
690
  return fs.existsSync(myPath);
648
691
  }
649
692
 
650
- terminate(code, quiet) {
693
+ terminate (code, quiet) {
651
694
  if (quiet) {
652
695
  return code;
653
696
  }
@@ -657,19 +700,19 @@ class CLI extends nodefony.Service {
657
700
  process.exit(code);
658
701
  }
659
702
 
660
- static quit(code) {
703
+ static quit (code) {
661
704
  if (code === 0) {
662
705
  process.exitCode = code;
663
706
  }
664
707
  process.exit(code);
665
708
  }
666
709
 
667
- startTimer(name) {
710
+ startTimer (name) {
668
711
  if (name in this.timers) {
669
- throw new Error("Timer : " + name + " already exist !! stopTimer to clear");
712
+ throw new Error(`Timer : ${name} already exist !! stopTimer to clear`);
670
713
  }
671
714
  try {
672
- this.log("BEGIN TIMER : " + name, "INFO");
715
+ this.log(`BEGIN TIMER : ${name}`, "INFO");
673
716
  this.timers[name] = name;
674
717
  return console.time(name);
675
718
  } catch (e) {
@@ -680,19 +723,19 @@ class CLI extends nodefony.Service {
680
723
  }
681
724
  }
682
725
 
683
- stopTimer(name) {
726
+ stopTimer (name) {
684
727
  if (!name) {
685
- for (let timer in this.timers) {
728
+ for (const timer in this.timers) {
686
729
  this.stopTimer(this.timers[timer]);
687
730
  }
688
731
  }
689
732
  try {
690
733
  if (name in this.timers) {
691
- this.log("END TIMER : " + name, "INFO");
734
+ this.log(`END TIMER : ${name}`, "INFO");
692
735
  delete this.timers[name];
693
736
  return console.timeEnd(name);
694
737
  }
695
- throw new Error("Timer : " + name + " not exist !! startTimer before");
738
+ throw new Error(`Timer : ${name} not exist !! startTimer before`);
696
739
  } catch (e) {
697
740
  if (name in this.timers) {
698
741
  delete this.timers[name];
@@ -701,57 +744,58 @@ class CLI extends nodefony.Service {
701
744
  }
702
745
  }
703
746
 
704
- async npm(argv = [], cwd = path.resolve("."), env = "dev") {
705
- switch (env) {
706
- case "dev":
707
- case "development":
708
- process.env.NODE_ENV = "development";
709
- break;
710
- case "prod":
711
- case "production":
712
- process.env.NODE_ENV = "production";
713
- break;
714
- default:
715
- process.env.NODE_ENV = this.environment;
716
- }
717
- return new Promise((resolve, reject) => {
718
- let cmd = null;
719
- try {
720
- this.debug = this.commander.opts().debug || false;
721
- this.log(`Command : npm ${argv.join(' ')} in cwd : ${cwd}`);
722
- //const exe = path.resolve(nodefony.path, "node_modules", ".bin", "npm");
723
- let exe = null;
724
- if (process.platform === "win32") {
725
- exe = 'npm.cmd';
726
- } else {
727
- exe = 'npm';
728
- }
729
- cmd = this.spawn(exe, argv, {
730
- cwd: cwd,
731
- env: process.env,
732
- stdio: "inherit",
733
- NODE_ENV: process.env.NODE_ENV
734
- }, (code) => {
735
- if (code === 0) {
736
- return resolve(code);
737
- }
738
- return resolve(new Error(`Command : npm ${argv.join(' ')} cwd : ${cwd} Error Code : ${code}`));
739
- });
740
- } catch (e) {
741
- this.log(e, "ERROR");
742
- return reject(e);
747
+ getCommandManager (manager) {
748
+ if (process.platform === "win32") {
749
+ switch (manager) {
750
+ case "npm":
751
+ return "npm.cmd";
752
+ case "yarn":
753
+ return "yarn.cmd";
754
+ case "pnpm":
755
+ return "pnpm.cmd";
756
+ default:
757
+ throw new Error(`bad manager : ${manager}`);
743
758
  }
744
- });
759
+ } else {
760
+ switch (manager) {
761
+ case "npm":
762
+ return "npm";
763
+ case "yarn":
764
+ return "yarn";
765
+ case "pnpm":
766
+ return "pnpm";
767
+ default:
768
+ throw new Error(`bad manager : ${manager}`);
769
+ }
770
+ }
745
771
  }
746
772
 
747
- async yarn(argv = [], cwd = path.resolve("."), env = "dev") {
773
+ runPackageManager (argv = [], cwd = path.resolve("."), env, manager) {
774
+ const currentenv = process.env.NODE_ENV;
748
775
  switch (env) {
749
776
  case "dev":
750
777
  case "development":
778
+ switch (manager) {
779
+ case "npm":
780
+ case "yarn":
781
+ case "pnpm":
782
+ break;
783
+ }
751
784
  process.env.NODE_ENV = "development";
752
785
  break;
753
786
  case "prod":
754
787
  case "production":
788
+ switch (manager) {
789
+ case "npm":
790
+ argv.push("--omit=dev");
791
+ break;
792
+ case "yarn":
793
+ argv.push("--production");
794
+ break;
795
+ case "pnpm":
796
+ argv.push("--prod");
797
+ break;
798
+ }
755
799
  process.env.NODE_ENV = "production";
756
800
  break;
757
801
  default:
@@ -760,34 +804,42 @@ class CLI extends nodefony.Service {
760
804
  return new Promise((resolve, reject) => {
761
805
  let cmd = null;
762
806
  try {
763
- this.log(`Command : yarn ${argv.join(' ')} in cwd : ${cwd}`);
764
- this.debug = this.commander.opts().debug || false;
765
- //const exe = path.resolve(nodefony.path, "node_modules", ".bin", "npm");
766
- let exe = null;
767
- if (process.platform === "win32") {
768
- exe = 'yarn.cmd';
769
- } else {
770
- exe = 'yarn';
771
- }
807
+ this.debug = this.commander ? this.commander.opts().debug || false : false;
808
+ this.log(`Command : ${manager} ${argv.join(" ")} in cwd : ${cwd}`);
809
+ const exe = this.getCommandManager(manager);
772
810
  cmd = this.spawn(exe, argv, {
773
- cwd: cwd,
811
+ cwd,
774
812
  env: process.env,
775
813
  stdio: "inherit",
776
814
  NODE_ENV: process.env.NODE_ENV
777
815
  }, (code) => {
816
+ process.env.NODE_ENV = currentenv;
778
817
  if (code === 0) {
779
818
  return resolve(code);
780
819
  }
781
- return resolve(new Error(`Command : yarn ${argv.join(' ')} cwd : ${cwd} Error Code : ${code}`));
820
+ return resolve(new Error(`Command : ${manager} ${argv.join(" ")} cwd : ${cwd} Error Code : ${code}`));
782
821
  });
783
822
  } catch (e) {
823
+ process.env.NODE_ENV = currentenv;
784
824
  this.log(e, "ERROR");
785
825
  return reject(e);
786
826
  }
787
827
  });
788
828
  }
789
829
 
790
- spawn(command, args, options = {}, close = null) {
830
+ async npm (argv = [], cwd = path.resolve("."), env = "dev") {
831
+ return this.runPackageManager(argv, cwd, env, "npm");
832
+ }
833
+
834
+ async yarn (argv = [], cwd = path.resolve("."), env = "dev") {
835
+ return this.runPackageManager(argv, cwd, env, "yarn");
836
+ }
837
+
838
+ async pnpm (argv = [], cwd = path.resolve("."), env = "dev") {
839
+ return this.runPackageManager(argv, cwd, env, "pnpm");
840
+ }
841
+
842
+ spawn (command, args, options = {}, close = null) {
791
843
  return new Promise((resolve, reject) => {
792
844
  let cmd = null;
793
845
  try {
@@ -798,8 +850,8 @@ class CLI extends nodefony.Service {
798
850
  this.log(`Spawn : ${command} ${args.join(" ")}`, "INFO");
799
851
  cmd = spawn(command, args, options || {});
800
852
  if (cmd.stdout) {
801
- cmd.stdout.on('data', (data) => {
802
- let str = data.toString();
853
+ cmd.stdout.on("data", (data) => {
854
+ const str = data.toString();
803
855
  if (str) {
804
856
  if (this.debug) {
805
857
  this.log(`${command} :\n`, "INFO", "STDOUT");
@@ -809,8 +861,8 @@ class CLI extends nodefony.Service {
809
861
  });
810
862
  }
811
863
  if (cmd.stderr) {
812
- cmd.stderr.on('data', (data) => {
813
- let str = data.toString();
864
+ cmd.stderr.on("data", (data) => {
865
+ const str = data.toString();
814
866
  if (str) {
815
867
  if (this.debug) {
816
868
  this.log(`${command} :\n`, "INFO", "STDERR");
@@ -819,7 +871,7 @@ class CLI extends nodefony.Service {
819
871
  }
820
872
  });
821
873
  }
822
- cmd.on('close', (code) => {
874
+ cmd.on("close", (code) => {
823
875
  if (this.debug) {
824
876
  this.log(`Child Process exited with code ${code}`, "DEBUG");
825
877
  }
@@ -831,7 +883,7 @@ class CLI extends nodefony.Service {
831
883
  }
832
884
  return resolve(code);
833
885
  });
834
- cmd.on('error', (err) => {
886
+ cmd.on("error", (err) => {
835
887
  this.log(err, "ERROR");
836
888
  return reject(err);
837
889
  });
@@ -845,7 +897,7 @@ class CLI extends nodefony.Service {
845
897
  });
846
898
  }
847
899
 
848
- spawnSync(command, args, options) {
900
+ spawnSync (command, args, options) {
849
901
  let cmd = null;
850
902
  try {
851
903
  cmd = spawnSync(command, args, options);