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.
- package/CHANGELOG.md +534 -8028
- package/README.md +33 -30
- package/autoloader.es6 +46 -48
- package/builder.es6 +66 -76
- package/cli/builder/bundles/bundle.js +57 -63
- package/cli/builder/bundles/controller.js +34 -38
- package/cli/builder/bundles/users-bundle/Command/fixtureTask.js +11 -12
- package/cli/builder/bundles/users-bundle/Command/usersCommand.js +23 -24
- package/cli/builder/bundles/users-bundle/Entity/mongoose/userEntity.js +25 -30
- package/cli/builder/bundles/users-bundle/Entity/sequelize/userEntity.js +42 -31
- package/cli/builder/bundles/users-bundle/Fixtures/users.js +24 -26
- package/cli/builder/bundles/users-bundle/Fixtures/usersFixtures.js +28 -29
- package/cli/builder/bundles/users-bundle/Resources/config/config.js +4 -3
- package/cli/builder/bundles/users-bundle/Resources/config/routing.js +2 -2
- package/cli/builder/bundles/users-bundle/Resources/config/security.js +9 -8
- package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.dev.config.js +3 -3
- package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.prod.config.js +4 -3
- package/cli/builder/bundles/users-bundle/Resources/config/webpack.config.js +74 -75
- package/cli/builder/bundles/users-bundle/Resources/scss/awesome/font-awesome.config.js +9 -9
- package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/login.js +13 -13
- package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/users.js +14 -14
- package/cli/builder/bundles/users-bundle/controller/api/graphql/graphqlController.js +13 -15
- package/cli/builder/bundles/users-bundle/controller/api/graphql/userResolver.js +29 -29
- package/cli/builder/bundles/users-bundle/controller/api/graphql/usertype.js +2 -2
- package/cli/builder/bundles/users-bundle/controller/api/openapi/loginApiController.js +34 -36
- package/cli/builder/bundles/users-bundle/controller/api/openapi/restUserController.js +32 -36
- package/cli/builder/bundles/users-bundle/controller/loginController.js +30 -34
- package/cli/builder/bundles/users-bundle/controller/usersController.js +54 -60
- package/cli/builder/bundles/users-bundle/package.json +27 -25
- package/cli/builder/bundles/users-bundle/pnpm-lock.yaml +4262 -0
- package/cli/builder/bundles/users-bundle/readme.md +7 -7
- package/cli/builder/bundles/users-bundle/services/usersService.js +97 -102
- package/cli/builder/bundles/users-bundle/src/providers/mongoose/userProvider.js +6 -8
- package/cli/builder/bundles/users-bundle/src/providers/sequelize/userProvider.js +9 -10
- package/cli/builder/bundles/users-bundle/tests/loginTest.js +119 -70
- package/cli/builder/bundles/users-bundle/usersBundle.js +2 -3
- package/cli/builder/microService/microService.js +139 -141
- package/cli/builder/microService/skeletons/package.json +23 -22
- package/cli/builder/project/project.js +228 -181
- package/cli/builder/project/skeletons/README.md +33 -30
- package/cli/builder/project/skeletons/bin/dev-deploy.sh +5 -0
- package/cli/builder/project/skeletons/bin/prod-deploy.sh +3 -0
- package/cli/builder/project/skeletons/config/config.js.skeleton +1 -0
- package/cli/builder/project/skeletons/config/pm2.config.js.skeleton +41 -17
- package/cli/builder/project/skeletons/eslintignore.skeleton +15 -0
- package/cli/builder/project/skeletons/eslintrc.js.skeleton +97 -0
- package/cli/builder/project/skeletons/gitignore.skeleton +1 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.37.entity-user.js +137 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.38.entity-session.js +97 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.39.entity-requests.js +115 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.40.entity-jwts.js +97 -0
- package/cli/builder/project/skeletons/migrations/migrations.skeleton.js +0 -2
- package/cli/builder/project/skeletons/package.json.twig +70 -0
- package/cli/builder/react/reactBuilder.js +59 -65
- package/cli/builder/sandbox/sandBoxBuilder.js +132 -134
- package/cli/builder/skeletons/app/appKernel.js +120 -2
- package/cli/builder/skeletons/config/config.js +1 -1
- package/cli/builder/skeletons/config/nodefony/framework-bundle.js +2 -1
- package/cli/builder/skeletons/config/nodefony/http-bundle.js +1 -0
- package/cli/builder/skeletons/config/nodefony/mongoose-bundle.js +38 -12
- package/cli/builder/skeletons/config/nodefony/monitoring-bundle.js +21 -2
- package/cli/builder/skeletons/config/nodefony/sequelize-bundle.js +122 -13
- package/cli/builder/skeletons/package.json.twig +57 -0
- package/cli/builder/skeletons/unittest/testFile.js +44 -45
- package/cli/builder/vue/skeletons/vue.config.js +84 -10
- package/cli/builder/vue/vueBuilder.js +116 -114
- package/cli/generate/generate.es6 +38 -39
- package/cli/install/install.js +45 -58
- package/cli/sequelize/sequelize.js +50 -39
- package/cli/start.js +353 -347
- package/cli/tools/pm2.es6 +55 -57
- package/cli/tools/tools.es6 +36 -37
- package/cli.es6 +280 -228
- package/container.es6 +51 -59
- package/error.es6 +25 -27
- package/fileClass.es6 +53 -55
- package/finder/file.es6 +5 -4
- package/finder/fileResult.es6 +23 -22
- package/finder/finder2.es6 +46 -54
- package/finder.es6 +88 -97
- package/kernel/annotations/annotations.es6 +44 -46
- package/kernel/api/api.es6 +6 -8
- package/kernel/api/graphqlApi.es6 +21 -21
- package/kernel/api/jsonApi.es6 +40 -45
- package/kernel/api/openApi.es6 +9 -11
- package/kernel/api/schemas/openApiSchema.js +61 -32
- package/kernel/babylon.es6 +31 -38
- package/kernel/bundle.es6 +252 -220
- package/kernel/cliKernel.es6 +157 -170
- package/kernel/command.es6 +17 -20
- package/kernel/commands/nodefonyCommand.es6 +111 -58
- package/kernel/commands/tasks/bundlesTask.es6 +14 -19
- package/kernel/controllers/controller.es6 +167 -180
- package/kernel/fixture.es6 +4 -7
- package/kernel/injections/injections.es6 +97 -103
- package/kernel/kernel.es6 +476 -384
- package/kernel/kernelWatcher.es6 +64 -54
- package/kernel/orm/entity.es6 +10 -12
- package/kernel/orm/orm.es6 +68 -48
- package/kernel/reader.es6 +45 -47
- package/kernel/security/encoder.es6 +8 -6
- package/kernel/security/factories/factory.es6 +34 -37
- package/kernel/security/factories/passeportFactory.es6 +13 -14
- package/kernel/security/provider.es6 +11 -13
- package/kernel/security/providers/chainProvider.es6 +13 -28
- package/kernel/security/providers/memoryProvider.es6 +7 -11
- package/kernel/security/providers/providerManager.es6 +11 -14
- package/kernel/security/providers/userEntityProvider.es6 +7 -8
- package/kernel/security/role.es6 +3 -3
- package/kernel/security/secureArea.es6 +143 -149
- package/kernel/security/tokens/token.es6 +30 -32
- package/kernel/security/user.es6 +19 -19
- package/kernel/serviceRealTime.es6 +5 -7
- package/kernel/services/connectionsService.es6 +20 -22
- package/kernel/services/cron/cronService.es6 +14 -16
- package/kernel/task.es6 +20 -26
- package/kernel/templates.es6 +4 -5
- package/kernel/templating/twig.es6 +56 -47
- package/kernel/tests/cliTest.js +7 -11
- package/kernel/tests/containerTest.js +25 -37
- package/kernel/tests/kernelTest.js +9 -16
- package/nodefony.es6 +279 -256
- package/notificationsCenter.es6 +28 -20
- package/package.json +40 -40
- package/protocol.es6 +19 -21
- package/protocols/bayeux.es6 +35 -38
- package/protocols/jsonRpc/jsonrpc.es6 +12 -14
- package/result.es6 +11 -12
- package/service.es6 +62 -62
- package/syslog/pdu.es6 +99 -91
- package/syslog/syslog.es6 +101 -102
- package/watcher.es6 +21 -20
- package/cli/builder/project/skeletons/jshintignore.skeleton +0 -1
- package/cli/builder/project/skeletons/jshintrc.skeleton +0 -60
- package/cli/builder/project/skeletons/package.json.skeleton +0 -52
- package/cli/builder/skeletons/package.json +0 -61
package/nodefony.es6
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
const execSync = require(
|
|
1
|
+
const {execSync} = require("child_process");
|
|
2
2
|
const uuid = require("uuid");
|
|
3
3
|
|
|
4
|
+
const myobj = {};
|
|
5
|
+
const hasOwn = myobj.hasOwnProperty;
|
|
6
|
+
const fnToString = hasOwn.toString;
|
|
7
|
+
const ObjectFunctionString = fnToString.call(Object);
|
|
8
|
+
const getProto = Object.getPrototypeOf;
|
|
9
|
+
|
|
4
10
|
/**
|
|
5
11
|
* The class is a **`Nodefony Nodefony `** .
|
|
6
12
|
* @class Nodefony
|
|
@@ -8,12 +14,9 @@ const uuid = require("uuid");
|
|
|
8
14
|
* @module Nodefony
|
|
9
15
|
*
|
|
10
16
|
*/
|
|
11
|
-
const myObj = {};
|
|
12
|
-
|
|
13
17
|
class Nodefony {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//this.require = require;
|
|
18
|
+
constructor (context) {
|
|
19
|
+
// this.require = require;
|
|
17
20
|
this.path = path.resolve(__dirname);
|
|
18
21
|
this.io = {};
|
|
19
22
|
this.context = context;
|
|
@@ -52,7 +55,7 @@ class Nodefony {
|
|
|
52
55
|
this.appConfig = null;
|
|
53
56
|
this.projectName = "nodefony";
|
|
54
57
|
this.appKernel = null;
|
|
55
|
-
this.isRegExp = require(
|
|
58
|
+
this.isRegExp = require("lodash.isregexp");
|
|
56
59
|
this.isCore = false;
|
|
57
60
|
this.isElectron = this.isElectronContext();
|
|
58
61
|
this.yarn = this.checkYarn();
|
|
@@ -61,7 +64,7 @@ class Nodefony {
|
|
|
61
64
|
this.checkTrunk();
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
checkTrunk(cwd = path.resolve(".")) {
|
|
67
|
+
checkTrunk (cwd = path.resolve(".")) {
|
|
65
68
|
this.isTrunk = this.isNodefonyTrunk(cwd);
|
|
66
69
|
if (this.isTrunk) {
|
|
67
70
|
this.builded = this.isBuilded(cwd);
|
|
@@ -74,7 +77,7 @@ class Nodefony {
|
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
isBuilded(cwd = path.resolve(".")) {
|
|
80
|
+
isBuilded (cwd = path.resolve(".")) {
|
|
78
81
|
try {
|
|
79
82
|
fs.lstatSync(path.resolve(cwd, "node_modules"));
|
|
80
83
|
return true;
|
|
@@ -83,15 +86,16 @@ class Nodefony {
|
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
generateId(...args) {
|
|
89
|
+
generateId (...args) {
|
|
87
90
|
return uuid.v4(...args);
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
setConfig(cwd = path.resolve(".")) {
|
|
93
|
+
setConfig (cwd = path.resolve(".")) {
|
|
91
94
|
try {
|
|
92
95
|
this.projectPackage = require(path.resolve(cwd, "package.json"));
|
|
93
96
|
this.projectVersion = this.projectPackage.version;
|
|
94
97
|
this.projectName = this.projectPackage.name;
|
|
98
|
+
this.context.kernel = {};
|
|
95
99
|
this.kernelConfig = this.loadConfig(this.kernelConfigPath);
|
|
96
100
|
this.appConfig = this.loadConfig(this.appConfigPath, console.warn);
|
|
97
101
|
this.packageManager = this.kernelConfig.packageManager || "npm";
|
|
@@ -99,21 +103,21 @@ class Nodefony {
|
|
|
99
103
|
if (!this.Error) {
|
|
100
104
|
this.Error = require(path.resolve(__dirname, "error.es6"));
|
|
101
105
|
}
|
|
102
|
-
|
|
106
|
+
const error = new this.Error(e);
|
|
103
107
|
throw error;
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
110
|
|
|
107
|
-
setPm2Config() {
|
|
111
|
+
setPm2Config () {
|
|
108
112
|
if (this.builded) {
|
|
109
113
|
this.pm2Config = require(this.pm2ConfigPath);
|
|
110
114
|
}
|
|
111
115
|
return this.pm2Config;
|
|
112
116
|
}
|
|
113
117
|
|
|
114
|
-
loadConfig(file, log) {
|
|
118
|
+
loadConfig (file, log) {
|
|
115
119
|
try {
|
|
116
|
-
|
|
120
|
+
const ext = path.extname(file);
|
|
117
121
|
switch (ext) {
|
|
118
122
|
case ".js":
|
|
119
123
|
return require(file);
|
|
@@ -122,24 +126,24 @@ class Nodefony {
|
|
|
122
126
|
}
|
|
123
127
|
} catch (e) {
|
|
124
128
|
if (log) {
|
|
125
|
-
//log(e);
|
|
129
|
+
// log(e);
|
|
126
130
|
return {};
|
|
127
131
|
}
|
|
128
132
|
throw e;
|
|
129
133
|
}
|
|
130
134
|
}
|
|
131
135
|
|
|
132
|
-
readFileSync(file) {
|
|
136
|
+
readFileSync (file) {
|
|
133
137
|
try {
|
|
134
138
|
return fs.readFileSync(file, {
|
|
135
|
-
encoding:
|
|
139
|
+
encoding: "utf8"
|
|
136
140
|
});
|
|
137
141
|
} catch (e) {
|
|
138
142
|
throw e;
|
|
139
143
|
}
|
|
140
144
|
}
|
|
141
145
|
|
|
142
|
-
isCoreTrunk() {
|
|
146
|
+
isCoreTrunk () {
|
|
143
147
|
if (this.isTrunk) {
|
|
144
148
|
if (this.projectPackage.name === "nodefony-core") {
|
|
145
149
|
return true;
|
|
@@ -154,19 +158,19 @@ class Nodefony {
|
|
|
154
158
|
return false;
|
|
155
159
|
}
|
|
156
160
|
|
|
157
|
-
isFunction(it) {
|
|
158
|
-
return Object.prototype.toString.call(it) ===
|
|
161
|
+
isFunction (it) {
|
|
162
|
+
return Object.prototype.toString.call(it) === "[object Function]";
|
|
159
163
|
}
|
|
160
164
|
|
|
161
|
-
isArray(it) {
|
|
162
|
-
return Object.prototype.toString.call(it) ===
|
|
165
|
+
isArray (it) {
|
|
166
|
+
return Object.prototype.toString.call(it) === "[object Array]";
|
|
163
167
|
}
|
|
164
168
|
|
|
165
|
-
isError(it) {
|
|
169
|
+
isError (it) {
|
|
166
170
|
return nodefony.Error.isError(it);
|
|
167
171
|
}
|
|
168
172
|
|
|
169
|
-
isContainer(container) {
|
|
173
|
+
isContainer (container) {
|
|
170
174
|
if (container) {
|
|
171
175
|
if (container instanceof nodefony.Container) {
|
|
172
176
|
return true;
|
|
@@ -179,35 +183,39 @@ class Nodefony {
|
|
|
179
183
|
return false;
|
|
180
184
|
}
|
|
181
185
|
|
|
182
|
-
isPromise(obj) {
|
|
186
|
+
isPromise (obj) {
|
|
183
187
|
switch (true) {
|
|
184
188
|
case obj instanceof Promise:
|
|
185
189
|
case obj instanceof BlueBird:
|
|
186
190
|
return true;
|
|
187
191
|
default:
|
|
188
|
-
return
|
|
192
|
+
return Boolean(obj) && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
189
193
|
}
|
|
190
194
|
}
|
|
191
195
|
|
|
192
|
-
isUndefined(value) {
|
|
196
|
+
isUndefined (value) {
|
|
193
197
|
return value === undefined;
|
|
194
198
|
}
|
|
195
199
|
|
|
196
|
-
|
|
200
|
+
isEmptyObject (obj) {
|
|
201
|
+
let name;
|
|
202
|
+
for (name in obj) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
isPlainObject (obj) {
|
|
197
209
|
let proto, Ctor;
|
|
198
|
-
|
|
199
|
-
// Use toString instead of jQuery.type to catch host objects
|
|
200
|
-
if (!obj || myObj.toString.call(obj) !== "[object Object]") {
|
|
210
|
+
if (!obj || toString.call(obj) !== "[object Object]") {
|
|
201
211
|
return false;
|
|
202
212
|
}
|
|
203
|
-
proto =
|
|
204
|
-
// Objects with no prototype (e.g., `Object.create( null )`) are plain
|
|
213
|
+
proto = getProto(obj);
|
|
205
214
|
if (!proto) {
|
|
206
215
|
return true;
|
|
207
216
|
}
|
|
208
|
-
|
|
209
|
-
Ctor
|
|
210
|
-
return typeof Ctor === "function" && myObj.hasOwnProperty.toString.call(Ctor) === myObj.hasOwnProperty.toString.call(Object);
|
|
217
|
+
Ctor = hasOwn.call(proto, "constructor") && proto.constructor;
|
|
218
|
+
return typeof Ctor === "function" && fnToString.call(Ctor) === ObjectFunctionString;
|
|
211
219
|
}
|
|
212
220
|
|
|
213
221
|
/**
|
|
@@ -215,10 +223,9 @@ class Nodefony {
|
|
|
215
223
|
* @param value
|
|
216
224
|
* @return {String} type of value
|
|
217
225
|
*/
|
|
218
|
-
typeOf(value) {
|
|
219
|
-
|
|
220
|
-
if (t ===
|
|
221
|
-
|
|
226
|
+
typeOf (value) {
|
|
227
|
+
const t = typeof value;
|
|
228
|
+
if (t === "object") {
|
|
222
229
|
if (value === null) {
|
|
223
230
|
return null;
|
|
224
231
|
}
|
|
@@ -229,7 +236,7 @@ class Nodefony {
|
|
|
229
236
|
return "array";
|
|
230
237
|
}
|
|
231
238
|
if (this.isFunction(value)) {
|
|
232
|
-
return
|
|
239
|
+
return "function";
|
|
233
240
|
}
|
|
234
241
|
if (value instanceof Date) {
|
|
235
242
|
return "date";
|
|
@@ -246,19 +253,17 @@ class Nodefony {
|
|
|
246
253
|
if (this.isError(value)) {
|
|
247
254
|
return "Error";
|
|
248
255
|
}
|
|
249
|
-
} else {
|
|
250
|
-
|
|
251
|
-
return 'object';
|
|
252
|
-
}
|
|
256
|
+
} else if (t === "function" && typeof value.call === "undefined") {
|
|
257
|
+
return "object";
|
|
253
258
|
}
|
|
254
259
|
return t;
|
|
255
260
|
}
|
|
256
261
|
|
|
257
|
-
extend() {
|
|
262
|
+
extend () {
|
|
258
263
|
let options, name, src, copy, copyIsArray, clone,
|
|
259
264
|
target = arguments[0] || {},
|
|
260
265
|
i = 1,
|
|
261
|
-
length = arguments
|
|
266
|
+
{length} = arguments,
|
|
262
267
|
deep = false;
|
|
263
268
|
|
|
264
269
|
// Handle a deep copy situation
|
|
@@ -269,35 +274,38 @@ class Nodefony {
|
|
|
269
274
|
i++;
|
|
270
275
|
}
|
|
271
276
|
// Handle case when target is a string or something (possible in deep copy)
|
|
272
|
-
if (typeof target !== "object" &&
|
|
277
|
+
if (typeof target !== "object" && typeof target !== "function") {
|
|
273
278
|
target = {};
|
|
274
279
|
}
|
|
275
|
-
// Extend
|
|
280
|
+
// Extend Nodefony itself if only one argument is passed
|
|
276
281
|
if (i === length) {
|
|
277
282
|
target = this;
|
|
278
283
|
i--;
|
|
279
284
|
}
|
|
280
285
|
for (; i < length; i++) {
|
|
281
286
|
// Only deal with non-null/undefined values
|
|
282
|
-
if ((options = arguments[i])
|
|
287
|
+
if ((options = arguments[i]) != null) {
|
|
283
288
|
// Extend the base object
|
|
284
289
|
for (name in options) {
|
|
285
|
-
src = target[name];
|
|
286
290
|
copy = options[name];
|
|
291
|
+
// Prevent Object.prototype pollution
|
|
287
292
|
// Prevent never-ending loop
|
|
288
|
-
if (target === copy) {
|
|
293
|
+
if (name === "__proto__" || target === copy) {
|
|
289
294
|
continue;
|
|
290
295
|
}
|
|
291
296
|
// Recurse if we're merging plain objects or arrays
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
clone =
|
|
297
|
+
if (deep && copy && (this.isPlainObject(copy) ||
|
|
298
|
+
(copyIsArray = Array.isArray(copy)))) {
|
|
299
|
+
src = target[name];
|
|
300
|
+
// Ensure proper type for the source value
|
|
301
|
+
if (copyIsArray && !Array.isArray(src)) {
|
|
302
|
+
clone = [];
|
|
303
|
+
} else if (!copyIsArray && !this.isPlainObject(src)) {
|
|
304
|
+
clone = {};
|
|
298
305
|
} else {
|
|
299
|
-
clone = src
|
|
306
|
+
clone = src;
|
|
300
307
|
}
|
|
308
|
+
copyIsArray = false;
|
|
301
309
|
// Never move original objects, clone them
|
|
302
310
|
target[name] = this.extend(deep, clone, copy);
|
|
303
311
|
// Don't bring in undefined values
|
|
@@ -318,13 +326,12 @@ class Nodefony {
|
|
|
318
326
|
* @param {Function} closure
|
|
319
327
|
*
|
|
320
328
|
*/
|
|
321
|
-
register(name, closure) {
|
|
329
|
+
register (name, closure) {
|
|
322
330
|
if (typeof closure === "function") {
|
|
323
331
|
// exec closure
|
|
324
332
|
return this[name] = closure(this, name);
|
|
325
|
-
} else {
|
|
326
|
-
return this[name] = closure;
|
|
327
333
|
}
|
|
334
|
+
return this[name] = closure;
|
|
328
335
|
}
|
|
329
336
|
|
|
330
337
|
/**
|
|
@@ -334,11 +341,11 @@ class Nodefony {
|
|
|
334
341
|
* @param {Function} closure
|
|
335
342
|
*
|
|
336
343
|
*/
|
|
337
|
-
registerBundle(name, closure) {
|
|
344
|
+
registerBundle (name, closure) {
|
|
338
345
|
if (typeof closure === "function") {
|
|
339
346
|
return this.bundles[name] = closure();
|
|
340
347
|
}
|
|
341
|
-
throw new Error(
|
|
348
|
+
throw new Error(`Register bundle : ${name} error bundle bad format`);
|
|
342
349
|
}
|
|
343
350
|
|
|
344
351
|
/**
|
|
@@ -348,11 +355,11 @@ class Nodefony {
|
|
|
348
355
|
* @param {Function} closure
|
|
349
356
|
*
|
|
350
357
|
*/
|
|
351
|
-
registerFixture(name, closure) {
|
|
358
|
+
registerFixture (name, closure) {
|
|
352
359
|
if (typeof closure === "function") {
|
|
353
360
|
return closure();
|
|
354
361
|
}
|
|
355
|
-
throw new Error(
|
|
362
|
+
throw new Error(`Register fixtures : ${name} error fixtures bad format`);
|
|
356
363
|
}
|
|
357
364
|
|
|
358
365
|
/**
|
|
@@ -362,37 +369,39 @@ class Nodefony {
|
|
|
362
369
|
* @param {Function} closure
|
|
363
370
|
*
|
|
364
371
|
*/
|
|
365
|
-
registerCommand(name, closure) {
|
|
372
|
+
registerCommand (name, closure) {
|
|
366
373
|
if (typeof closure === "function") {
|
|
367
374
|
return closure();
|
|
368
375
|
}
|
|
369
|
-
throw new Error(
|
|
376
|
+
throw new Error(`Register commands : ${name} error commands bad format`);
|
|
370
377
|
}
|
|
371
378
|
|
|
372
|
-
registerFactory(name, closure) {
|
|
379
|
+
registerFactory (name, closure) {
|
|
373
380
|
if (typeof closure === "function") {
|
|
374
381
|
return nodefony.security.factories[name] = closure();
|
|
375
382
|
}
|
|
376
|
-
throw new Error(
|
|
383
|
+
throw new Error(`Register Factory : ${name} Error Factory bad format`);
|
|
377
384
|
}
|
|
378
|
-
|
|
385
|
+
|
|
386
|
+
registerToken (name, closure) {
|
|
379
387
|
if (typeof closure === "function") {
|
|
380
388
|
return nodefony.security.tokens[name] = closure();
|
|
381
389
|
}
|
|
382
|
-
throw new Error(
|
|
390
|
+
throw new Error(`Register Token : ${name} Error Token bad format`);
|
|
383
391
|
}
|
|
384
|
-
|
|
392
|
+
|
|
393
|
+
registerProvider (name, closure) {
|
|
385
394
|
if (typeof closure === "function") {
|
|
386
395
|
return nodefony.security.providers[name] = closure();
|
|
387
396
|
}
|
|
388
|
-
throw new Error(
|
|
397
|
+
throw new Error(`Register Provider : ${name} Error Provider bad format`);
|
|
389
398
|
}
|
|
390
399
|
|
|
391
|
-
getVersion() {
|
|
400
|
+
getVersion () {
|
|
392
401
|
return require(path.resolve(__dirname, "package.json")).version;
|
|
393
402
|
}
|
|
394
403
|
|
|
395
|
-
isNodefonyTrunk(cwd = path.resolve(".")) {
|
|
404
|
+
isNodefonyTrunk (cwd = path.resolve(".")) {
|
|
396
405
|
try {
|
|
397
406
|
try {
|
|
398
407
|
this.kernelConfigPath = path.resolve(cwd, "config", "config.js");
|
|
@@ -422,22 +431,36 @@ class Nodefony {
|
|
|
422
431
|
}
|
|
423
432
|
}
|
|
424
433
|
|
|
425
|
-
loadAppKernel(cwd = path.resolve(".")) {
|
|
434
|
+
loadAppKernel (cwd = path.resolve("."), detectError = false) {
|
|
426
435
|
try {
|
|
427
|
-
|
|
436
|
+
const detectpath = path.resolve(cwd, "app", "appKernel.js");
|
|
437
|
+
try {
|
|
438
|
+
fs.lstatSync(detectpath);
|
|
439
|
+
} catch (e) {
|
|
440
|
+
if (detectError) {
|
|
441
|
+
console.error(e);
|
|
442
|
+
throw e;
|
|
443
|
+
}
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
return this.appKernel = require(detectpath);
|
|
428
447
|
} catch (e) {
|
|
448
|
+
if (e.message === "Class extends value undefined is not a constructor or null") {
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
console.trace(e);
|
|
429
452
|
return null;
|
|
430
453
|
}
|
|
431
454
|
}
|
|
432
455
|
|
|
433
|
-
isElectronContext() {
|
|
456
|
+
isElectronContext () {
|
|
434
457
|
if (this.versions.electron) {
|
|
435
|
-
return require(
|
|
458
|
+
return require("electron");
|
|
436
459
|
}
|
|
437
460
|
return false;
|
|
438
461
|
}
|
|
439
462
|
|
|
440
|
-
checkYarn() {
|
|
463
|
+
checkYarn () {
|
|
441
464
|
try {
|
|
442
465
|
return require("yarn");
|
|
443
466
|
} catch (e) {
|
|
@@ -445,7 +468,7 @@ class Nodefony {
|
|
|
445
468
|
}
|
|
446
469
|
}
|
|
447
470
|
|
|
448
|
-
checkNpm() {
|
|
471
|
+
checkNpm () {
|
|
449
472
|
try {
|
|
450
473
|
return require("npm");
|
|
451
474
|
} catch (e) {
|
|
@@ -453,7 +476,7 @@ class Nodefony {
|
|
|
453
476
|
}
|
|
454
477
|
}
|
|
455
478
|
|
|
456
|
-
checkYarnVersion() {
|
|
479
|
+
checkYarnVersion () {
|
|
457
480
|
let res = null;
|
|
458
481
|
try {
|
|
459
482
|
res = execSync("yarn -v", {
|
|
@@ -468,7 +491,7 @@ class Nodefony {
|
|
|
468
491
|
}
|
|
469
492
|
}
|
|
470
493
|
|
|
471
|
-
checkNpmVersion() {
|
|
494
|
+
checkNpmVersion () {
|
|
472
495
|
let res = null;
|
|
473
496
|
try {
|
|
474
497
|
res = execSync("npm -v", {
|
|
@@ -483,31 +506,32 @@ class Nodefony {
|
|
|
483
506
|
}
|
|
484
507
|
}
|
|
485
508
|
|
|
486
|
-
manageCache(cli) {
|
|
509
|
+
manageCache (cli) {
|
|
487
510
|
if (this.isTrunk) {
|
|
488
|
-
|
|
511
|
+
const cacheLink = path.resolve("tmp", "assestLink");
|
|
489
512
|
if (fs.existsSync(cacheLink)) {
|
|
490
513
|
if (cli && cli.logger && cli.debug) {
|
|
491
|
-
cli.logger(
|
|
514
|
+
cli.logger(`DELETE TMP LINK :${cacheLink}`, "DEBUG");
|
|
492
515
|
}
|
|
493
516
|
shell.rm("-Rf", this.cacheLink);
|
|
494
517
|
}
|
|
495
|
-
|
|
518
|
+
const cacheWebpack = path.resolve("tmp", "webpack");
|
|
496
519
|
if (fs.existsSync(cacheWebpack)) {
|
|
497
520
|
if (cli && cli.logger && cli.debug) {
|
|
498
|
-
cli.logger(
|
|
521
|
+
cli.logger(`DELETE TMP :${cacheWebpack}`, "DEBUG");
|
|
499
522
|
}
|
|
500
523
|
shell.rm("-Rf", cacheWebpack);
|
|
501
524
|
}
|
|
502
525
|
}
|
|
503
526
|
}
|
|
504
527
|
|
|
505
|
-
showHelp(cli) {
|
|
528
|
+
showHelp (cli) {
|
|
506
529
|
// Servers
|
|
507
530
|
cli.setTitleHelp(`${cli.clc.cyan("Servers")}`);
|
|
508
531
|
cli.setHelp("", "dev", "Run Nodefony Development Server");
|
|
509
|
-
cli.setHelp("", "preprod", "Run Nodefony Preprod Server ( Usefull to check Clusters Node )");
|
|
532
|
+
cli.setHelp("", "preprod", "Run Nodefony Preprod Server ( Usefull to check Clusters Node use os.cpus().length )");
|
|
510
533
|
cli.setHelp("", "prod", "Run Nodefony Production Server ( PM2 mode )");
|
|
534
|
+
cli.setHelp("", "start", "Run Nodefony Production Server before transpile for prodution ( dump + PM2 mode ) ");
|
|
511
535
|
cli.setTitleHelp(cli.clc.cyan("PM2 Process Manager 2"));
|
|
512
536
|
cli.setHelp("", "stop [name]", "Stop Production Project");
|
|
513
537
|
cli.setHelp("", "reload [name]", "Reload Production Project");
|
|
@@ -524,16 +548,16 @@ class Nodefony {
|
|
|
524
548
|
// nodefony
|
|
525
549
|
cli.setTitleHelp(cli.clc.cyan("nodefony"));
|
|
526
550
|
cli.setHelp("", "create [-i] name [path]", "Create New Nodefony Project");
|
|
527
|
-
cli.setHelp("", "build", "Build Nodefony Framework");
|
|
528
|
-
cli.setHelp("", "
|
|
529
|
-
cli.setHelp("", "
|
|
530
|
-
cli.setHelp("", "certificates",
|
|
531
|
-
//cli.setHelp("", "dependencies", "List Project dependencies");
|
|
551
|
+
cli.setHelp("", "build [sync|migrate]", "Build Nodefony Framework ,transpile, certificats, skeleton , install (default orm migrate)");
|
|
552
|
+
cli.setHelp("", "install [sync|migrate]", "Install Nodefony Project transpile, sync or migrate Orm (default orm migrate)");
|
|
553
|
+
cli.setHelp("", "rebuild", "Rebuild Nodefony Framework in production (Usefull when node version change )");
|
|
554
|
+
cli.setHelp("", "certificates", "Generate HTTPS Certificates 'Change default openssl configuration in config/openssl'");
|
|
555
|
+
// cli.setHelp("", "dependencies", "List Project dependencies");
|
|
532
556
|
cli.setHelp("", "outdated", "List Project dependencies outdated");
|
|
533
557
|
cli.setHelp("", "version", "Get Project Version");
|
|
534
558
|
}
|
|
535
559
|
|
|
536
|
-
async start(cmd, args, cli, options = {}) {
|
|
560
|
+
async start (cmd, args, cli, options = {}) {
|
|
537
561
|
if (cmd !== "preprod" && cluster.isWorker) {
|
|
538
562
|
cmd = "production";
|
|
539
563
|
}
|
|
@@ -548,7 +572,11 @@ class Nodefony {
|
|
|
548
572
|
process.env.MODE_START = "NODEFONY_DEV";
|
|
549
573
|
cli.setType("SERVER");
|
|
550
574
|
const kernel = new nodefony.appKernel(environment, cli, options);
|
|
551
|
-
return await kernel.start()
|
|
575
|
+
return await kernel.start()
|
|
576
|
+
.catch((e) => {
|
|
577
|
+
cli.log(e, "ERROR");
|
|
578
|
+
throw e;
|
|
579
|
+
});
|
|
552
580
|
case "preprod":
|
|
553
581
|
case "preproduction":
|
|
554
582
|
cli.keepAlive = true;
|
|
@@ -556,26 +584,67 @@ class Nodefony {
|
|
|
556
584
|
environment = "prod";
|
|
557
585
|
process.env.MODE_START = "NODEFONY";
|
|
558
586
|
cli.setType("SERVER");
|
|
559
|
-
return this.preProd(environment, cli, options)
|
|
587
|
+
return this.preProd(environment, cli, options)
|
|
588
|
+
.catch((e) => {
|
|
589
|
+
cli.log(e, "ERROR");
|
|
590
|
+
throw e;
|
|
591
|
+
});
|
|
560
592
|
case "production":
|
|
561
593
|
case "prod":
|
|
562
594
|
case "start":
|
|
563
595
|
case "pm2":
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
596
|
+
try {
|
|
597
|
+
cli.keepAlive = true;
|
|
598
|
+
environment = "prod";
|
|
599
|
+
if (process.env.MODE_START && process.env.MODE_START === "PM2") {
|
|
600
|
+
cli.setType("SERVER");
|
|
601
|
+
const kernel = new nodefony.appKernel(environment, cli, options);
|
|
602
|
+
return await kernel.start()
|
|
603
|
+
.catch(async (e) => {
|
|
604
|
+
cli.log(e, "ERROR");
|
|
605
|
+
cli.log("terminate code 1");
|
|
606
|
+
await cli.terminate(1);
|
|
607
|
+
throw e;
|
|
608
|
+
});
|
|
609
|
+
} else {
|
|
610
|
+
const options = cli.commander.opts();
|
|
611
|
+
if (options.dump && !(cmd === "prod" || cmd === "production" || cmd === "pm2")) {
|
|
612
|
+
await cli.setCommand("webpack:dump");
|
|
613
|
+
}
|
|
614
|
+
cli.setType("SERVER");
|
|
615
|
+
this.manageCache(cli);
|
|
616
|
+
process.env.MODE_START = "PM2_START";
|
|
617
|
+
return await this.pm2Start(cli, options)
|
|
618
|
+
.then((deamon) => {
|
|
619
|
+
if (deamon) {
|
|
620
|
+
cli.logger(`DAEMONIZE Process
|
|
621
|
+
--no-daemon if don't want DAEMONIZE (Usefull for docker)`);
|
|
622
|
+
return pm2.disconnect(() => {
|
|
623
|
+
cli.log("pm2.disconnect");
|
|
624
|
+
cli.log("terminate code 0");
|
|
625
|
+
return cli.terminate(0);
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
cli.log("NO DAEMONIZE");
|
|
629
|
+
})
|
|
630
|
+
.catch((e) => {
|
|
631
|
+
cli.log(e, "ERROR");
|
|
632
|
+
console.trace(e);
|
|
633
|
+
return pm2.disconnect(() => {
|
|
634
|
+
cli.log("pm2.disconnect");
|
|
635
|
+
cli.log("terminate code 1");
|
|
636
|
+
return cli.terminate(1);
|
|
637
|
+
|
|
638
|
+
/* pm2.killDaemon(() => {
|
|
639
|
+
cli.logger(`pm2 killDaemon `, "ERROR");
|
|
640
|
+
cli.log(`terminate code 1`)
|
|
641
|
+
})*/
|
|
642
|
+
});
|
|
643
|
+
});
|
|
574
644
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
return this.pm2Start(cli, options);
|
|
645
|
+
} catch (e) {
|
|
646
|
+
// console.error(e)
|
|
647
|
+
throw e;
|
|
579
648
|
}
|
|
580
649
|
break;
|
|
581
650
|
case "stop":
|
|
@@ -583,14 +652,16 @@ class Nodefony {
|
|
|
583
652
|
if (args.length) {
|
|
584
653
|
name = args[0];
|
|
585
654
|
}
|
|
586
|
-
pm2.stop(name, (error, proc) => {
|
|
655
|
+
return pm2.stop(name, (error, proc) => {
|
|
587
656
|
if (error) {
|
|
588
657
|
cli.logger(error, "ERROR");
|
|
589
658
|
cli.terminate(-1);
|
|
590
659
|
}
|
|
591
660
|
cli.logger(`PM2 Stop Project ${name}`);
|
|
592
661
|
this.tablePm2(cli, proc);
|
|
593
|
-
|
|
662
|
+
return pm2.disconnect(() => {
|
|
663
|
+
cli.terminate(0);
|
|
664
|
+
});
|
|
594
665
|
});
|
|
595
666
|
break;
|
|
596
667
|
case "reload":
|
|
@@ -598,14 +669,14 @@ class Nodefony {
|
|
|
598
669
|
if (args.length) {
|
|
599
670
|
name = args[0];
|
|
600
671
|
}
|
|
601
|
-
pm2.reload(name, (error, proc) => {
|
|
672
|
+
return pm2.reload(name, (error, proc) => {
|
|
602
673
|
if (error) {
|
|
603
674
|
cli.logger(error, "ERROR");
|
|
604
675
|
return cli.terminate(-1);
|
|
605
676
|
}
|
|
606
677
|
cli.logger(`PM2 reload Project ${name}`);
|
|
607
678
|
this.tablePm2(cli, proc);
|
|
608
|
-
return cli.terminate(0);
|
|
679
|
+
return pm2.disconnect(() => cli.terminate(0));
|
|
609
680
|
});
|
|
610
681
|
break;
|
|
611
682
|
case "restart":
|
|
@@ -613,14 +684,14 @@ class Nodefony {
|
|
|
613
684
|
if (args.length) {
|
|
614
685
|
name = args[0];
|
|
615
686
|
}
|
|
616
|
-
pm2.restart(name, (error, proc) => {
|
|
687
|
+
return pm2.restart(name, (error, proc) => {
|
|
617
688
|
if (error) {
|
|
618
689
|
cli.logger(error, "ERROR");
|
|
619
690
|
return cli.terminate(-1);
|
|
620
691
|
}
|
|
621
692
|
cli.logger(`PM2 restart Project ${name}`);
|
|
622
693
|
this.tablePm2(cli, proc);
|
|
623
|
-
return cli.terminate(0);
|
|
694
|
+
return pm2.disconnect(() => cli.terminate(0));
|
|
624
695
|
});
|
|
625
696
|
break;
|
|
626
697
|
case "delete":
|
|
@@ -628,32 +699,33 @@ class Nodefony {
|
|
|
628
699
|
if (args.length) {
|
|
629
700
|
name = args[0];
|
|
630
701
|
}
|
|
631
|
-
pm2.delete(name, (error, proc) => {
|
|
702
|
+
return pm2.delete(name, (error, proc) => {
|
|
632
703
|
if (error) {
|
|
633
704
|
cli.logger(error, "ERROR");
|
|
634
705
|
return cli.terminate(-1);
|
|
635
706
|
}
|
|
636
707
|
cli.logger(`PM2 delete Project ${name}`);
|
|
637
708
|
this.tablePm2(cli, proc);
|
|
638
|
-
return cli.terminate(0);
|
|
709
|
+
return pm2.disconnect(() => cli.terminate(0));
|
|
639
710
|
});
|
|
640
711
|
break;
|
|
641
712
|
case "kill":
|
|
642
713
|
cli.keepAlive = true;
|
|
643
714
|
return new Promise(async (resolve, reject) => {
|
|
644
|
-
const util = require(
|
|
645
|
-
const exec = util.promisify(require(
|
|
646
|
-
let ret = null
|
|
715
|
+
const util = require("node:util");
|
|
716
|
+
const exec = util.promisify(require("node:child_process").exec);
|
|
717
|
+
let ret = null;
|
|
647
718
|
try {
|
|
648
719
|
const {
|
|
649
720
|
stdout,
|
|
650
721
|
stderr
|
|
651
|
-
} = await exec(
|
|
722
|
+
} = await exec("npx pm2 kill");
|
|
652
723
|
if (stderr) {
|
|
653
724
|
cli.log(`Kill PM2 MANAGER ${stderr}`, "WARNING");
|
|
654
725
|
} else {
|
|
655
726
|
cli.log(`Kill PM2 MANAGER success ${stdout}`);
|
|
656
|
-
ret = 0
|
|
727
|
+
ret = 0;
|
|
728
|
+
return resolve(process.exit(ret));
|
|
657
729
|
}
|
|
658
730
|
} catch (e) {
|
|
659
731
|
cli.log(`Kill PM2 MANAGER ${e}`, "ERROR");
|
|
@@ -662,12 +734,12 @@ class Nodefony {
|
|
|
662
734
|
const {
|
|
663
735
|
stdout,
|
|
664
736
|
stderr
|
|
665
|
-
} = await exec(
|
|
737
|
+
} = await exec("pkill pm2");
|
|
666
738
|
if (stderr) {
|
|
667
739
|
cli.log(`pkill pm2 ${stderr}`, "WARNING");
|
|
668
740
|
} else {
|
|
669
741
|
cli.log(`pkill pm2 success ${stdout}`);
|
|
670
|
-
ret = 0
|
|
742
|
+
ret = 0;
|
|
671
743
|
}
|
|
672
744
|
} catch (e) {
|
|
673
745
|
cli.log(`pkill pm2 ${e}`, "WARNING");
|
|
@@ -676,12 +748,12 @@ class Nodefony {
|
|
|
676
748
|
const {
|
|
677
749
|
stdout,
|
|
678
750
|
stderr
|
|
679
|
-
} = await exec(
|
|
751
|
+
} = await exec("killall pm2");
|
|
680
752
|
if (stderr) {
|
|
681
753
|
cli.log(`killall pm2 ${stderr}`, "WARNING");
|
|
682
754
|
} else {
|
|
683
755
|
cli.log(`killall pm2 success ${stdout}`);
|
|
684
|
-
ret = 0
|
|
756
|
+
ret = 0;
|
|
685
757
|
}
|
|
686
758
|
} catch (e) {
|
|
687
759
|
cli.log(`killall pm2 ${e}`, "WARNING");
|
|
@@ -690,73 +762,17 @@ class Nodefony {
|
|
|
690
762
|
return resolve(process.exit(ret));
|
|
691
763
|
}
|
|
692
764
|
return resolve(process.exit(-1));
|
|
693
|
-
|
|
694
|
-
/*let res = await pm2.killDaemon((err, proc) => {
|
|
695
|
-
console.log("passsssss")
|
|
696
|
-
if (err) {
|
|
697
|
-
cli.logger(err, "ERROR");
|
|
698
|
-
pm2.disconnect()
|
|
699
|
-
process.nextTick(() => {
|
|
700
|
-
return reject(cli.terminate(-1));
|
|
701
|
-
})
|
|
702
|
-
}
|
|
703
|
-
})*/
|
|
704
|
-
/*res = pm2.disconnect(() => {
|
|
705
|
-
cli.logger(`Kill PM2 MANAGER success `);
|
|
706
|
-
process.nextTick(() => {
|
|
707
|
-
return resolve(process.exit(0));
|
|
708
|
-
})
|
|
709
|
-
console.log("pass")
|
|
710
|
-
})*/
|
|
711
|
-
/*return pm2.killDaemon((error, proc) => {
|
|
712
|
-
console.log("passss killDaemon")
|
|
713
|
-
if (error) {
|
|
714
|
-
cli.logger(error, "ERROR");
|
|
715
|
-
pm2.disconnect()
|
|
716
|
-
process.nextTick(() => {
|
|
717
|
-
return reject(cli.terminate(-1));
|
|
718
|
-
})
|
|
719
|
-
}
|
|
720
|
-
cli.logger(`Kill PM2 MANAGER success : ${proc.success}`);
|
|
721
|
-
pm2.disconnect()
|
|
722
|
-
process.nextTick(() => {
|
|
723
|
-
return resolve(process.exit(0));
|
|
724
|
-
})*/
|
|
725
|
-
/*return pm2.list((error, processDescriptionList) => {
|
|
726
|
-
if (error) {
|
|
727
|
-
cli.logger(error, "ERROR");
|
|
728
|
-
pm2.disconnect()
|
|
729
|
-
process.nextTick(() => {
|
|
730
|
-
return reject(process.exit(-1));
|
|
731
|
-
})
|
|
732
|
-
}
|
|
733
|
-
this.tablePm2(cli, processDescriptionList);
|
|
734
|
-
pm2.disconnect()
|
|
735
|
-
process.nextTick(() => {
|
|
736
|
-
return resolve(process.exit(0));
|
|
737
|
-
})
|
|
738
|
-
});*/
|
|
739
|
-
//});
|
|
740
|
-
//} catch (e) {
|
|
741
|
-
// pm2.disconnect()
|
|
742
|
-
// cli.log(e)
|
|
743
|
-
// return reject(cli.terminate(-1));
|
|
744
|
-
//}
|
|
745
|
-
})
|
|
765
|
+
});
|
|
746
766
|
case "status":
|
|
747
767
|
case "list":
|
|
748
768
|
cli.keepAlive = true;
|
|
749
|
-
pm2.list((error, processDescriptionList) => {
|
|
769
|
+
return pm2.list((error, processDescriptionList) => {
|
|
750
770
|
if (error) {
|
|
751
771
|
cli.logger(error, "ERROR");
|
|
752
772
|
return cli.terminate(-1);
|
|
753
773
|
}
|
|
754
774
|
this.tablePm2(cli, processDescriptionList);
|
|
755
|
-
pm2.disconnect(() =>
|
|
756
|
-
process.nextTick(() => {
|
|
757
|
-
return process.exit(0);
|
|
758
|
-
})
|
|
759
|
-
})
|
|
775
|
+
return pm2.disconnect(() => pm2.disconnect(() => cli.terminate(0)));
|
|
760
776
|
});
|
|
761
777
|
break;
|
|
762
778
|
case "log":
|
|
@@ -781,14 +797,14 @@ class Nodefony {
|
|
|
781
797
|
break;
|
|
782
798
|
case "clean-log":
|
|
783
799
|
cli.keepAlive = true;
|
|
784
|
-
pm2.flush((error, result) => {
|
|
800
|
+
return pm2.flush((error, result) => {
|
|
785
801
|
if (error) {
|
|
786
802
|
cli.logger(error, "ERROR");
|
|
787
803
|
return cli.terminate(-1);
|
|
788
804
|
}
|
|
789
805
|
cli.logger(`clean log ${nodefony.projectName}`);
|
|
790
806
|
this.tablePm2(cli, result);
|
|
791
|
-
return
|
|
807
|
+
return pm2.disconnect(() => cli.terminate(0));
|
|
792
808
|
});
|
|
793
809
|
break;
|
|
794
810
|
case "pm2-logrotate":
|
|
@@ -801,19 +817,20 @@ class Nodefony {
|
|
|
801
817
|
env: process.env,
|
|
802
818
|
stdio: "inherit"
|
|
803
819
|
}).then((code) => {
|
|
804
|
-
cli.log(
|
|
820
|
+
cli.log("[PM2] Init System found To setup the Startup Script, copy/paste the previous command :)");
|
|
805
821
|
return code;
|
|
806
|
-
})
|
|
807
|
-
|
|
808
|
-
|
|
822
|
+
})
|
|
823
|
+
.catch((e) => {
|
|
824
|
+
cli.log(e, "ERROR");
|
|
825
|
+
});
|
|
809
826
|
case "pm2-unstartup":
|
|
810
827
|
return cli.npm(["run", "pm2", "unstartup"]);
|
|
811
828
|
case "outdated":
|
|
812
829
|
return cli.setCommand("nodefony:outdated");
|
|
813
830
|
case "test":
|
|
814
831
|
return cli.setCommand("unitest:launch:all");
|
|
815
|
-
//case "dependencies":
|
|
816
|
-
//return cli.setCommand("nodefony:bundles:dependencies");
|
|
832
|
+
// case "dependencies":
|
|
833
|
+
// return cli.setCommand("nodefony:bundles:dependencies");
|
|
817
834
|
default:
|
|
818
835
|
if (cli.kernel) {
|
|
819
836
|
return await cli.kernel.matchCommand()
|
|
@@ -827,7 +844,7 @@ class Nodefony {
|
|
|
827
844
|
})
|
|
828
845
|
.catch((error) => {
|
|
829
846
|
throw error;
|
|
830
|
-
//this.logger(error, "ERROR", `COMMAND`);
|
|
847
|
+
// this.logger(error, "ERROR", `COMMAND`);
|
|
831
848
|
});
|
|
832
849
|
}
|
|
833
850
|
if (this.appKernel) {
|
|
@@ -835,24 +852,29 @@ class Nodefony {
|
|
|
835
852
|
cli.setType("CONSOLE");
|
|
836
853
|
process.env.MODE_START = "NODEFONY_CONSOLE";
|
|
837
854
|
this.manageCache(cli);
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
.
|
|
841
|
-
|
|
842
|
-
|
|
855
|
+
try {
|
|
856
|
+
const kernel = new this.appKernel(environment, cli, options);
|
|
857
|
+
return await kernel.start()
|
|
858
|
+
.catch((e) => {
|
|
859
|
+
throw e;
|
|
860
|
+
});
|
|
861
|
+
} catch (e) {
|
|
862
|
+
console.error(e);
|
|
863
|
+
throw e;
|
|
864
|
+
}
|
|
843
865
|
}
|
|
844
|
-
if (cli.commander.hasOwnProperty(
|
|
866
|
+
if (cli.commander.hasOwnProperty("help")) {
|
|
845
867
|
cli.clear();
|
|
846
868
|
cli.showHelp();
|
|
847
869
|
return Promise.resolve();
|
|
848
870
|
}
|
|
849
|
-
|
|
871
|
+
const error = new Error("No nodefony trunk detected !");
|
|
850
872
|
throw error;
|
|
851
873
|
}
|
|
852
874
|
}
|
|
853
875
|
|
|
854
|
-
tablePm2(cli, apps) {
|
|
855
|
-
//console.log(apps)
|
|
876
|
+
tablePm2 (cli, apps) {
|
|
877
|
+
// console.log(apps)
|
|
856
878
|
let table = null;
|
|
857
879
|
table = cli.displayTable([], {
|
|
858
880
|
head: [
|
|
@@ -867,16 +889,16 @@ class Nodefony {
|
|
|
867
889
|
cli.clc.blue("memory"),
|
|
868
890
|
cli.clc.blue("user"),
|
|
869
891
|
cli.clc.blue("watching")
|
|
870
|
-
]
|
|
871
|
-
//colWidths: [30, 15, 20, 15]
|
|
892
|
+
]
|
|
893
|
+
// colWidths: [30, 15, 20, 15]
|
|
872
894
|
});
|
|
873
895
|
apps.forEach((ele) => {
|
|
874
|
-
//console.log(ele.pm2_env)
|
|
875
|
-
//console.log(ele)
|
|
896
|
+
// console.log(ele.pm2_env)
|
|
897
|
+
// console.log(ele)
|
|
876
898
|
let cpu = "-";
|
|
877
899
|
let memory = "-";
|
|
878
900
|
if (ele.monit) {
|
|
879
|
-
cpu = ele.monit.cpu
|
|
901
|
+
cpu = `${ele.monit.cpu}%`;
|
|
880
902
|
memory = nodefony.cli.niceBytes(ele.monit.memory);
|
|
881
903
|
}
|
|
882
904
|
let exec_mode = "-";
|
|
@@ -933,50 +955,53 @@ class Nodefony {
|
|
|
933
955
|
/*
|
|
934
956
|
* PM2
|
|
935
957
|
*/
|
|
936
|
-
pm2Start(cli, options) {
|
|
958
|
+
pm2Start (cli, options) {
|
|
937
959
|
return new Promise((resolve, reject) => {
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
this.pm2Config
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
this.pm2Config.apps[0].name
|
|
960
|
+
try {
|
|
961
|
+
this.setPm2Config();
|
|
962
|
+
if (!this.pm2Config) {
|
|
963
|
+
this.pm2Config = this.kernelConfig.system.PM2;
|
|
964
|
+
this.pm2Config.apps[0].script = process.argv[1] || "nodefony";
|
|
965
|
+
this.pm2Config.apps[0].args = "pm2";
|
|
966
|
+
this.pm2Config.apps[0].env = {
|
|
967
|
+
NODE_ENV: "production",
|
|
968
|
+
MODE_START: "PM2"
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
if (!this.pm2Config.apps[0].name) {
|
|
972
|
+
this.pm2Config.apps[0].name = this.projectPackage.name || this.projectName;
|
|
973
|
+
}
|
|
974
|
+
this.pm2Config.apps[0].vizion = false;
|
|
975
|
+
} catch (e) {
|
|
976
|
+
return reject(e);
|
|
950
977
|
}
|
|
951
|
-
this.pm2Config.apps[0].vizion = false;
|
|
952
978
|
pm2.connect((err) => {
|
|
953
979
|
if (err) {
|
|
954
980
|
cli.logger(err, "ERROR");
|
|
955
|
-
|
|
956
|
-
return;
|
|
981
|
+
return reject(err);
|
|
957
982
|
}
|
|
958
983
|
console.log(util.inspect(this.pm2Config, {
|
|
959
984
|
depth: 10
|
|
960
985
|
}));
|
|
961
|
-
pm2.start(this.pm2Config, (err
|
|
986
|
+
pm2.start(this.pm2Config, (err /* , apps*/) => {
|
|
962
987
|
if (err) {
|
|
963
988
|
cli.logger(err.stack || err, "ERROR");
|
|
964
|
-
reject(err);
|
|
965
|
-
cli.terminate(1);
|
|
989
|
+
return reject(err);
|
|
966
990
|
}
|
|
967
|
-
|
|
991
|
+
cli.logger("PM2 started");
|
|
992
|
+
process.nextTick(async () => {
|
|
968
993
|
try {
|
|
969
994
|
pm2.list((err, processDescriptionList) => {
|
|
995
|
+
cli.logger("LIST PROCESS PM2");
|
|
970
996
|
if (err) {
|
|
971
|
-
|
|
997
|
+
cli.logger(err, "WARNING");
|
|
972
998
|
}
|
|
973
999
|
this.tablePm2(cli, processDescriptionList);
|
|
974
|
-
cli.logger(`SAVING process`);
|
|
975
|
-
//process.env.PWD = process.cwd();
|
|
976
1000
|
pm2.dump((err, result) => {
|
|
977
1001
|
if (err) {
|
|
978
|
-
cli.logger(err, "
|
|
1002
|
+
cli.logger(err, "WARNING");
|
|
979
1003
|
}
|
|
1004
|
+
cli.logger("PM2 SAVING process");
|
|
980
1005
|
if (result.success) {
|
|
981
1006
|
cli.logger(`${process.platform} PM2 process saved `);
|
|
982
1007
|
}
|
|
@@ -1008,17 +1033,11 @@ Examples with pm2 native tools :
|
|
|
1008
1033
|
$ npx pm2 monit
|
|
1009
1034
|
$ npx pm2 --lines 1000 logs
|
|
1010
1035
|
`);
|
|
1011
|
-
|
|
1012
|
-
if (options.daemon) {
|
|
1013
|
-
cli.terminate(0);
|
|
1014
|
-
}
|
|
1036
|
+
return resolve(options.daemon);
|
|
1015
1037
|
});
|
|
1016
1038
|
});
|
|
1017
1039
|
} catch (e) {
|
|
1018
|
-
|
|
1019
|
-
reject(e);
|
|
1020
|
-
resolve(pm2.disconnect());
|
|
1021
|
-
cli.terminate(1);
|
|
1040
|
+
return reject(e);
|
|
1022
1041
|
}
|
|
1023
1042
|
});
|
|
1024
1043
|
});
|
|
@@ -1026,26 +1045,26 @@ $ npx pm2 --lines 1000 logs
|
|
|
1026
1045
|
});
|
|
1027
1046
|
}
|
|
1028
1047
|
|
|
1029
|
-
async preProd(environment, cli, options) {
|
|
1030
|
-
const instances = require(
|
|
1048
|
+
async preProd (environment, cli, options) {
|
|
1049
|
+
const instances = require("os").cpus().length;
|
|
1031
1050
|
if (cluster.isMaster) {
|
|
1032
1051
|
for (let i = 0; i < instances; i++) {
|
|
1033
1052
|
cluster.fork();
|
|
1034
1053
|
}
|
|
1035
|
-
cluster.on(
|
|
1036
|
-
console.error(
|
|
1054
|
+
cluster.on("disconnect", (/* worker*/) => {
|
|
1055
|
+
console.error("disconnect!");
|
|
1037
1056
|
});
|
|
1038
|
-
cluster.on(
|
|
1039
|
-
|
|
1040
|
-
worker.on(
|
|
1057
|
+
cluster.on("fork", (worker) => {
|
|
1058
|
+
const wid = worker.id;
|
|
1059
|
+
worker.on("message", (msg) => {
|
|
1041
1060
|
if (msg && msg.worker === wid) {
|
|
1042
1061
|
return;
|
|
1043
1062
|
}
|
|
1044
|
-
Object.keys(cluster.workers).forEach(
|
|
1063
|
+
Object.keys(cluster.workers).forEach((id) => {
|
|
1045
1064
|
if (id !== wid) {
|
|
1046
|
-
//console.log("CLUSTER SEND FROM "+ wid + " to " + id)
|
|
1065
|
+
// console.log("CLUSTER SEND FROM "+ wid + " to " + id)
|
|
1047
1066
|
cluster.workers[id].send(nodefony.extend(msg, {
|
|
1048
|
-
worker: wid
|
|
1067
|
+
worker: wid
|
|
1049
1068
|
}));
|
|
1050
1069
|
}
|
|
1051
1070
|
});
|
|
@@ -1053,7 +1072,11 @@ $ npx pm2 --lines 1000 logs
|
|
|
1053
1072
|
});
|
|
1054
1073
|
} else {
|
|
1055
1074
|
const kernel = new nodefony.appKernel(environment, cli, options);
|
|
1056
|
-
return await kernel.start()
|
|
1075
|
+
return await kernel.start()
|
|
1076
|
+
.catch((e) => {
|
|
1077
|
+
cli.log(e, "ERROR");
|
|
1078
|
+
throw e;
|
|
1079
|
+
});
|
|
1057
1080
|
}
|
|
1058
1081
|
}
|
|
1059
1082
|
}
|