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/container.es6
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const shortId = require(
|
|
1
|
+
const shortId = require("shortid");
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
const ISDefined = function (ele) {
|
|
@@ -23,12 +23,10 @@ const parseParameterString = function (str, value) {
|
|
|
23
23
|
ns = Array.prototype.shift.call(str);
|
|
24
24
|
if (!this[ns]) {
|
|
25
25
|
this[ns] = value;
|
|
26
|
+
} else if (ISDefined(value)) {
|
|
27
|
+
this[ns] = value;
|
|
26
28
|
} else {
|
|
27
|
-
|
|
28
|
-
this[ns] = value;
|
|
29
|
-
} else {
|
|
30
|
-
return this[ns];
|
|
31
|
-
}
|
|
29
|
+
return this[ns];
|
|
32
30
|
}
|
|
33
31
|
return value;
|
|
34
32
|
default:
|
|
@@ -40,7 +38,7 @@ const parseParameterString = function (str, value) {
|
|
|
40
38
|
}
|
|
41
39
|
break;
|
|
42
40
|
default:
|
|
43
|
-
return this; //nodefony.extend(true, this, this.prototype);
|
|
41
|
+
return this; // nodefony.extend(true, this, this.prototype);
|
|
44
42
|
}
|
|
45
43
|
};
|
|
46
44
|
|
|
@@ -50,28 +48,27 @@ const parseParameterString = function (str, value) {
|
|
|
50
48
|
*
|
|
51
49
|
*/
|
|
52
50
|
class Container {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.
|
|
56
|
-
this.protoParameters = function protoParameters() {};
|
|
51
|
+
constructor (services, parameters) {
|
|
52
|
+
this.protoService = function protoService () {};
|
|
53
|
+
this.protoParameters = function protoParameters () {};
|
|
57
54
|
this.id = generateId();
|
|
58
55
|
this.scope = {};
|
|
59
56
|
this.services = new this.protoService();
|
|
60
57
|
if (services && typeof services === "object") {
|
|
61
|
-
for (
|
|
58
|
+
for (const service in services) {
|
|
62
59
|
this.set(service, services[service]);
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
62
|
this.parameters = new this.protoParameters();
|
|
66
63
|
if (parameters && typeof parameters === "object") {
|
|
67
|
-
for (
|
|
64
|
+
for (const parameter in parameters) {
|
|
68
65
|
this.setParameters(parameter, parameters[parameter]);
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
68
|
}
|
|
72
69
|
|
|
73
|
-
log(pci, severity, msgid, msg) {
|
|
74
|
-
|
|
70
|
+
log (pci, severity, msgid, msg) {
|
|
71
|
+
const syslog = this.get("syslog");
|
|
75
72
|
if (!syslog) {
|
|
76
73
|
console.log(pci);
|
|
77
74
|
return;
|
|
@@ -82,29 +79,29 @@ class Container {
|
|
|
82
79
|
return syslog.log(pci, severity, msgid, msg);
|
|
83
80
|
}
|
|
84
81
|
|
|
85
|
-
set(name, object) {
|
|
82
|
+
set (name, object) {
|
|
86
83
|
if (name) {
|
|
87
84
|
return this.protoService.prototype[name] = object;
|
|
88
85
|
}
|
|
89
86
|
throw new Error("Container bad argument name");
|
|
90
87
|
}
|
|
91
88
|
|
|
92
|
-
get(name) {
|
|
89
|
+
get (name) {
|
|
93
90
|
if (name in this.services) {
|
|
94
91
|
return this.services[name];
|
|
95
92
|
}
|
|
96
93
|
return null;
|
|
97
94
|
}
|
|
98
95
|
|
|
99
|
-
remove(name) {
|
|
96
|
+
remove (name) {
|
|
100
97
|
if (this.get(name)) {
|
|
101
98
|
delete this.services[name];
|
|
102
99
|
if (this.protoService.prototype[name]) {
|
|
103
100
|
delete this.protoService.prototype[name];
|
|
104
101
|
}
|
|
105
|
-
for (
|
|
106
|
-
|
|
107
|
-
for (
|
|
102
|
+
for (const scope in this.scope) {
|
|
103
|
+
const subScopes = this.scope[scope];
|
|
104
|
+
for (const subScope in subScopes) {
|
|
108
105
|
subScopes[subScope].remove(name);
|
|
109
106
|
}
|
|
110
107
|
}
|
|
@@ -113,78 +110,77 @@ class Container {
|
|
|
113
110
|
return false;
|
|
114
111
|
}
|
|
115
112
|
|
|
116
|
-
has(name) {
|
|
113
|
+
has (name) {
|
|
117
114
|
return this.services[name];
|
|
118
115
|
}
|
|
119
116
|
|
|
120
|
-
addScope(name) {
|
|
117
|
+
addScope (name) {
|
|
121
118
|
if (!this.scope[name]) {
|
|
122
119
|
return this.scope[name] = {};
|
|
123
120
|
}
|
|
124
121
|
return this.scope[name];
|
|
125
122
|
}
|
|
126
123
|
|
|
127
|
-
enterScope(name) {
|
|
128
|
-
|
|
124
|
+
enterScope (name) {
|
|
125
|
+
const sc = new Scope(name, this);
|
|
129
126
|
this.scope[name][sc.id] = sc;
|
|
130
127
|
return sc;
|
|
131
128
|
}
|
|
132
129
|
|
|
133
|
-
enterScopeExtended(name) {
|
|
134
|
-
|
|
130
|
+
enterScopeExtended (name) {
|
|
131
|
+
const sc = new ExtendedScope(name, this);
|
|
135
132
|
this.scope[name][sc.id] = sc;
|
|
136
133
|
return sc;
|
|
137
134
|
}
|
|
138
135
|
|
|
139
|
-
leaveScope(scope) {
|
|
136
|
+
leaveScope (scope) {
|
|
140
137
|
if (this.scope[scope.name]) {
|
|
141
138
|
let sc = this.scope[scope.name][scope.id];
|
|
142
139
|
if (sc) {
|
|
143
140
|
sc.clean();
|
|
144
|
-
//console.log("pass leaveScope "+ scope.id)
|
|
141
|
+
// console.log("pass leaveScope "+ scope.id)
|
|
145
142
|
delete this.scope[scope.name][scope.id];
|
|
146
143
|
sc = null;
|
|
147
144
|
}
|
|
148
|
-
//console.log(this.scope)
|
|
145
|
+
// console.log(this.scope)
|
|
149
146
|
}
|
|
150
147
|
}
|
|
151
148
|
|
|
152
|
-
removeScope(name) {
|
|
149
|
+
removeScope (name) {
|
|
153
150
|
if (this.scope[name]) {
|
|
154
|
-
for (
|
|
151
|
+
for (const scope in this.scope[name]) {
|
|
155
152
|
this.leaveScope(this.scope[name][scope]);
|
|
156
153
|
}
|
|
157
154
|
delete this.scope[name];
|
|
158
155
|
}
|
|
159
156
|
}
|
|
160
157
|
|
|
161
|
-
setParameters(name, str) {
|
|
158
|
+
setParameters (name, str) {
|
|
162
159
|
if (typeof name !== "string") {
|
|
163
160
|
this.log(new Error("setParameters : container parameter name must be a string"));
|
|
164
161
|
return false;
|
|
165
162
|
}
|
|
166
163
|
if (str === undefined) {
|
|
167
|
-
this.log(new Error(
|
|
164
|
+
this.log(new Error(`setParameters : ${name} container parameter value must be define`));
|
|
168
165
|
return false;
|
|
169
166
|
}
|
|
170
167
|
if (parseParameterString.call(this.protoParameters.prototype, name, str) === str) {
|
|
171
168
|
return str;
|
|
172
|
-
} else {
|
|
173
|
-
this.log(new Error("container parameter " + name + " parse error"));
|
|
174
|
-
return false;
|
|
175
169
|
}
|
|
170
|
+
this.log(new Error(`container parameter ${name} parse error`));
|
|
171
|
+
return false;
|
|
176
172
|
}
|
|
177
173
|
|
|
178
|
-
getParameters(name) {
|
|
179
|
-
/*if (typeof name !== "string") {
|
|
174
|
+
getParameters (name) {
|
|
175
|
+
/* if (typeof name !== "string") {
|
|
180
176
|
this.log(new Error("container parameter name must be a string"));
|
|
181
177
|
return false;
|
|
182
178
|
}*/
|
|
183
|
-
//return parseParameterString.call(this.protoParameters.prototype, name, null);
|
|
179
|
+
// return parseParameterString.call(this.protoParameters.prototype, name, null);
|
|
184
180
|
return parseParameterString.call(this.parameters, name, null);
|
|
185
181
|
}
|
|
186
182
|
|
|
187
|
-
clean() {
|
|
183
|
+
clean () {
|
|
188
184
|
this.services = null;
|
|
189
185
|
delete this.services;
|
|
190
186
|
this.parameters = null;
|
|
@@ -199,34 +195,32 @@ class Container {
|
|
|
199
195
|
*/
|
|
200
196
|
|
|
201
197
|
class Scope extends Container {
|
|
202
|
-
|
|
203
|
-
constructor(name, parent) {
|
|
198
|
+
constructor (name, parent) {
|
|
204
199
|
super();
|
|
205
200
|
this.name = name;
|
|
206
201
|
this.parent = parent;
|
|
207
202
|
this.services = new parent.protoService();
|
|
208
203
|
this.parameters = new parent.protoParameters();
|
|
209
204
|
this.scope = parent.scope;
|
|
210
|
-
//this.id = generateId();
|
|
205
|
+
// this.id = generateId();
|
|
211
206
|
}
|
|
212
207
|
|
|
213
|
-
set(name, obj) {
|
|
208
|
+
set (name, obj) {
|
|
214
209
|
this.services[name] = obj;
|
|
215
210
|
return super.set(name, obj);
|
|
216
211
|
}
|
|
217
212
|
|
|
218
|
-
clean() {
|
|
213
|
+
clean () {
|
|
219
214
|
this.parent = null;
|
|
220
215
|
return super.clean();
|
|
221
216
|
}
|
|
222
217
|
|
|
223
|
-
setParameters(name, str) {
|
|
218
|
+
setParameters (name, str) {
|
|
224
219
|
if (parseParameterString.call(this.parameters, name, str) === str) {
|
|
225
220
|
return super.setParameters(name, str);
|
|
226
|
-
} else {
|
|
227
|
-
this.log(new Error("container parameter " + name + " parse error"));
|
|
228
|
-
return false;
|
|
229
221
|
}
|
|
222
|
+
this.log(new Error(`container parameter ${name} parse error`));
|
|
223
|
+
return false;
|
|
230
224
|
}
|
|
231
225
|
}
|
|
232
226
|
|
|
@@ -236,15 +230,14 @@ class Scope extends Container {
|
|
|
236
230
|
*
|
|
237
231
|
*/
|
|
238
232
|
class ExtendedScope extends Container {
|
|
239
|
-
|
|
240
|
-
constructor(name, parent) {
|
|
233
|
+
constructor (name, parent) {
|
|
241
234
|
super();
|
|
242
235
|
this.name = name;
|
|
243
236
|
this.parent = parent;
|
|
244
237
|
this.services = new parent.protoService();
|
|
245
238
|
this.parameters = new parent.protoParameters();
|
|
246
239
|
this.scope = parent.scope;
|
|
247
|
-
//this.id = generateId();
|
|
240
|
+
// this.id = generateId();
|
|
248
241
|
|
|
249
242
|
this.protoService = function () {};
|
|
250
243
|
this.protoService.prototype = nodefony.extend({}, this.parent.protoService.prototype);
|
|
@@ -253,7 +246,7 @@ class ExtendedScope extends Container {
|
|
|
253
246
|
this.protoParameters.prototype = nodefony.extend({}, this.parent.protoParameters.prototype);
|
|
254
247
|
}
|
|
255
248
|
|
|
256
|
-
clean() {
|
|
249
|
+
clean () {
|
|
257
250
|
this.services = null;
|
|
258
251
|
delete this.services;
|
|
259
252
|
this.parameters = null;
|
|
@@ -262,18 +255,17 @@ class ExtendedScope extends Container {
|
|
|
262
255
|
this.protoParameters = null;
|
|
263
256
|
}
|
|
264
257
|
|
|
265
|
-
set(name, obj) {
|
|
258
|
+
set (name, obj) {
|
|
266
259
|
this.services[name] = obj;
|
|
267
260
|
return super.set(name, obj);
|
|
268
261
|
}
|
|
269
262
|
|
|
270
|
-
setParameters(name, str) {
|
|
263
|
+
setParameters (name, str) {
|
|
271
264
|
if (parseParameterString.call(this.parameters, name, str) === str) {
|
|
272
265
|
return super.setParameters(name, str);
|
|
273
|
-
} else {
|
|
274
|
-
this.log(new Error("container parameter " + name + " parse error"));
|
|
275
|
-
return false;
|
|
276
266
|
}
|
|
267
|
+
this.log(new Error(`container parameter ${name} parse error`));
|
|
268
|
+
return false;
|
|
277
269
|
}
|
|
278
270
|
}
|
|
279
271
|
|
package/error.es6
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const assert = require("assert");
|
|
2
|
-
const STATUS_CODES = require("http")
|
|
2
|
+
const {STATUS_CODES} = require("http");
|
|
3
3
|
const json = {
|
|
4
4
|
configurable: true,
|
|
5
5
|
writable: true,
|
|
6
|
-
value
|
|
7
|
-
|
|
6
|
+
value () {
|
|
7
|
+
const alt = {};
|
|
8
8
|
const storeKey = function (key) {
|
|
9
9
|
alt[key] = this[key];
|
|
10
10
|
};
|
|
@@ -12,22 +12,22 @@ const json = {
|
|
|
12
12
|
return alt;
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
-
Object.defineProperty(Error.prototype,
|
|
15
|
+
Object.defineProperty(Error.prototype, "toJSON", json);
|
|
16
16
|
|
|
17
17
|
const exclude = {
|
|
18
|
-
context:true,
|
|
19
|
-
resolver:true,
|
|
20
|
-
container:true,
|
|
21
|
-
secure:true
|
|
18
|
+
context: true,
|
|
19
|
+
resolver: true,
|
|
20
|
+
container: true,
|
|
21
|
+
secure: true
|
|
22
22
|
};
|
|
23
23
|
const jsonNodefony = {
|
|
24
24
|
configurable: true,
|
|
25
25
|
writable: true,
|
|
26
|
-
value
|
|
27
|
-
|
|
26
|
+
value () {
|
|
27
|
+
const alt = {};
|
|
28
28
|
const storeKey = function (key) {
|
|
29
|
-
if (key in exclude){
|
|
30
|
-
return
|
|
29
|
+
if (key in exclude) {
|
|
30
|
+
return;
|
|
31
31
|
}
|
|
32
32
|
alt[key] = this[key];
|
|
33
33
|
};
|
|
@@ -54,8 +54,7 @@ const isMongooseError = function (error) {
|
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
class nodefonyError extends Error {
|
|
57
|
-
|
|
58
|
-
constructor(message, code) {
|
|
57
|
+
constructor (message, code) {
|
|
59
58
|
super(message);
|
|
60
59
|
this.name = this.constructor.name;
|
|
61
60
|
this.code = null;
|
|
@@ -68,11 +67,11 @@ class nodefonyError extends Error {
|
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
toJSON(){
|
|
70
|
+
toJSON () {
|
|
72
71
|
|
|
73
72
|
}
|
|
74
73
|
|
|
75
|
-
static isError(error) {
|
|
74
|
+
static isError (error) {
|
|
76
75
|
switch (true) {
|
|
77
76
|
case error instanceof ReferenceError:
|
|
78
77
|
return "ReferenceError";
|
|
@@ -102,7 +101,7 @@ class nodefonyError extends Error {
|
|
|
102
101
|
return false;
|
|
103
102
|
}
|
|
104
103
|
|
|
105
|
-
getType(error) {
|
|
104
|
+
getType (error) {
|
|
106
105
|
const errorType = nodefony.Error.isError(error);
|
|
107
106
|
if (errorType) {
|
|
108
107
|
switch (errorType) {
|
|
@@ -170,8 +169,8 @@ class nodefonyError extends Error {
|
|
|
170
169
|
return "Error";
|
|
171
170
|
}
|
|
172
171
|
|
|
173
|
-
toString() {
|
|
174
|
-
let err =
|
|
172
|
+
toString () {
|
|
173
|
+
let err = "";
|
|
175
174
|
switch (this.errorType) {
|
|
176
175
|
case "Error":
|
|
177
176
|
if (kernel && kernel.environment === "prod") {
|
|
@@ -237,7 +236,7 @@ class nodefonyError extends Error {
|
|
|
237
236
|
return err;
|
|
238
237
|
}
|
|
239
238
|
|
|
240
|
-
parseMessage(message) {
|
|
239
|
+
parseMessage (message) {
|
|
241
240
|
this.errorType = this.getType(message);
|
|
242
241
|
switch (nodefony.typeOf(message)) {
|
|
243
242
|
case "Error":
|
|
@@ -263,8 +262,8 @@ class nodefonyError extends Error {
|
|
|
263
262
|
if (message.message) {
|
|
264
263
|
this.message = message.message;
|
|
265
264
|
} else {
|
|
266
|
-
//this.message = JSON.stringify(message);
|
|
267
|
-
this.message = util.inspect(message,{depth:0});
|
|
265
|
+
// this.message = JSON.stringify(message);
|
|
266
|
+
this.message = util.inspect(message, {depth: 0});
|
|
268
267
|
}
|
|
269
268
|
} catch (e) {
|
|
270
269
|
this.error = e;
|
|
@@ -275,21 +274,20 @@ class nodefonyError extends Error {
|
|
|
275
274
|
}
|
|
276
275
|
}
|
|
277
276
|
|
|
278
|
-
getDefaultMessage() {
|
|
277
|
+
getDefaultMessage () {
|
|
279
278
|
if (!this.message && this.code) {
|
|
280
|
-
|
|
279
|
+
const str = this.code.toString();
|
|
281
280
|
if (str in STATUS_CODES) {
|
|
282
281
|
this.message = STATUS_CODES[str];
|
|
283
282
|
}
|
|
284
283
|
}
|
|
285
284
|
}
|
|
286
285
|
|
|
287
|
-
logger() {
|
|
286
|
+
logger () {
|
|
288
287
|
return console.log(this.toString());
|
|
289
288
|
}
|
|
290
|
-
|
|
291
289
|
}
|
|
292
290
|
|
|
293
|
-
Object.defineProperty(nodefonyError.prototype,
|
|
291
|
+
Object.defineProperty(nodefonyError.prototype, "toJSON", jsonNodefony);
|
|
294
292
|
|
|
295
293
|
module.exports = nodefonyError;
|
package/fileClass.es6
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
const mime = require(
|
|
2
|
-
const crypto = require(
|
|
1
|
+
const mime = require("mime");
|
|
2
|
+
const crypto = require("crypto");
|
|
3
3
|
const checkPath = function (myPath) {
|
|
4
4
|
if (!myPath) {
|
|
5
5
|
return null;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
const abs = path.isAbsolute(myPath);
|
|
8
8
|
if (abs) {
|
|
9
9
|
return myPath;
|
|
10
|
-
} else {
|
|
11
|
-
return path.resolve(process.cwd(), myPath);
|
|
12
10
|
}
|
|
11
|
+
return path.resolve(process.cwd(), myPath);
|
|
13
12
|
};
|
|
14
13
|
const regHidden = /^\./;
|
|
15
14
|
const defautWriteOption = {
|
|
16
|
-
flags:
|
|
17
|
-
defaultEncoding:
|
|
18
|
-
//mode: 0o666
|
|
15
|
+
flags: "w",
|
|
16
|
+
defaultEncoding: "utf8"
|
|
17
|
+
// mode: 0o666
|
|
19
18
|
};
|
|
20
19
|
|
|
21
20
|
/*
|
|
@@ -25,7 +24,7 @@ const defautWriteOption = {
|
|
|
25
24
|
*
|
|
26
25
|
*/
|
|
27
26
|
class File {
|
|
28
|
-
constructor(Path) {
|
|
27
|
+
constructor (Path) {
|
|
29
28
|
if (Path) {
|
|
30
29
|
Path = checkPath(Path);
|
|
31
30
|
this.stats = fs.lstatSync(Path);
|
|
@@ -42,22 +41,22 @@ class File {
|
|
|
42
41
|
this.shortName = this.parse.name;
|
|
43
42
|
if (this.type === "File") {
|
|
44
43
|
this.mimeType = this.getMimeType(this.name);
|
|
45
|
-
this.encoding = "UTF-8"; //this.getCharset();
|
|
44
|
+
this.encoding = "UTF-8"; // this.getCharset();
|
|
46
45
|
this.extention = this.getExtension(this.mimeType);
|
|
47
46
|
}
|
|
48
47
|
this.dirName = this.parse.dir;
|
|
49
48
|
this.match = null;
|
|
50
49
|
} else {
|
|
51
|
-
throw new Error(
|
|
50
|
+
throw new Error(`error fileClass Path : ${Path}`);
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
toString() {
|
|
54
|
+
toString () {
|
|
56
55
|
return JSON.stringify(this.toJson(), null, "\n");
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
toJson() {
|
|
60
|
-
|
|
58
|
+
toJson () {
|
|
59
|
+
const obj = {
|
|
61
60
|
path: this.path,
|
|
62
61
|
name: this.name,
|
|
63
62
|
ext: this.ext,
|
|
@@ -75,7 +74,7 @@ class File {
|
|
|
75
74
|
return obj;
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
checkType() {
|
|
77
|
+
checkType () {
|
|
79
78
|
if (this.stats.isDirectory()) {
|
|
80
79
|
return "Directory";
|
|
81
80
|
}
|
|
@@ -97,41 +96,41 @@ class File {
|
|
|
97
96
|
if (this.stats.isSocket()) {
|
|
98
97
|
return "Socket";
|
|
99
98
|
}
|
|
100
|
-
return;
|
|
101
99
|
}
|
|
102
100
|
|
|
103
|
-
getType() {
|
|
101
|
+
getType () {
|
|
104
102
|
return this.checkType();
|
|
105
103
|
}
|
|
106
104
|
|
|
107
|
-
checkSum(type) {
|
|
105
|
+
checkSum (type) {
|
|
108
106
|
if (!type) {
|
|
109
|
-
type =
|
|
107
|
+
type = "md5";
|
|
110
108
|
}
|
|
111
|
-
return crypto.createHash(type).update(this.content())
|
|
109
|
+
return crypto.createHash(type).update(this.content())
|
|
110
|
+
.digest("hex");
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
getMimeType(name) {
|
|
113
|
+
getMimeType (name) {
|
|
115
114
|
return mime.getType(name || this.name);
|
|
116
115
|
}
|
|
117
116
|
|
|
118
|
-
getExtension(mimeType) {
|
|
117
|
+
getExtension (mimeType) {
|
|
119
118
|
return mime.getExtension(mimeType || this.mimeType);
|
|
120
119
|
}
|
|
121
120
|
|
|
122
|
-
getExtention(mimeType) {
|
|
121
|
+
getExtention (mimeType) {
|
|
123
122
|
return mime.getExtension(mimeType || this.mimeType);
|
|
124
123
|
}
|
|
125
124
|
|
|
126
|
-
/*getCharset (mimeType){
|
|
125
|
+
/* getCharset (mimeType){
|
|
127
126
|
//return mime.charsets.lookup(mimeType || this.mimeType );
|
|
128
127
|
}*/
|
|
129
128
|
|
|
130
|
-
getRealpath(Path, options) {
|
|
129
|
+
getRealpath (Path, options) {
|
|
131
130
|
return fs.realpathSync(Path, options);
|
|
132
131
|
}
|
|
133
132
|
|
|
134
|
-
matchName(ele) {
|
|
133
|
+
matchName (ele) {
|
|
135
134
|
if (ele instanceof RegExp) {
|
|
136
135
|
this.match = ele.exec(this.name);
|
|
137
136
|
return this.match;
|
|
@@ -142,49 +141,49 @@ class File {
|
|
|
142
141
|
return false;
|
|
143
142
|
}
|
|
144
143
|
|
|
145
|
-
matchType(type) {
|
|
144
|
+
matchType (type) {
|
|
146
145
|
return type === this.type;
|
|
147
146
|
}
|
|
148
147
|
|
|
149
|
-
isFile() {
|
|
148
|
+
isFile () {
|
|
150
149
|
return this.type === "File";
|
|
151
150
|
}
|
|
152
151
|
|
|
153
|
-
isDirectory() {
|
|
152
|
+
isDirectory () {
|
|
154
153
|
return this.type === "Directory";
|
|
155
154
|
}
|
|
156
155
|
|
|
157
|
-
isSymbolicLink() {
|
|
156
|
+
isSymbolicLink () {
|
|
158
157
|
return this.type === "symbolicLink";
|
|
159
158
|
}
|
|
160
159
|
|
|
161
|
-
dirname() {
|
|
160
|
+
dirname () {
|
|
162
161
|
return path.dirname(this.path);
|
|
163
162
|
}
|
|
164
163
|
|
|
165
|
-
isHidden() {
|
|
164
|
+
isHidden () {
|
|
166
165
|
return regHidden.test(this.name);
|
|
167
166
|
}
|
|
168
167
|
|
|
169
|
-
content(encoding) {
|
|
170
|
-
|
|
168
|
+
content (encoding) {
|
|
169
|
+
const encode = encoding ? encoding : this.encoding ? this.encoding : "utf8";
|
|
171
170
|
return fs.readFileSync(this.path, encode);
|
|
172
171
|
}
|
|
173
172
|
|
|
174
|
-
read(encoding) {
|
|
175
|
-
|
|
173
|
+
read (encoding) {
|
|
174
|
+
const encode = encoding ? encoding : this.encoding ? this.encoding : "utf8";
|
|
176
175
|
if (this.type === "symbolicLink") {
|
|
177
|
-
|
|
176
|
+
const Path = fs.readlinkSync(this.path, encode);
|
|
178
177
|
return fs.readFileSync(Path, encode);
|
|
179
178
|
}
|
|
180
179
|
return fs.readFileSync(this.path, encode);
|
|
181
180
|
}
|
|
182
181
|
|
|
183
|
-
readAsync(encoding) {
|
|
184
|
-
|
|
182
|
+
readAsync (encoding) {
|
|
183
|
+
const encode = encoding ? encoding : this.encoding ? this.encoding : "utf8";
|
|
185
184
|
if (this.type === "symbolicLink") {
|
|
186
185
|
return new Promise((resolve, reject) => {
|
|
187
|
-
|
|
186
|
+
const Path = fs.readlinkSync(this.path, encode);
|
|
188
187
|
return fs.readFileSync(Path, encode, (error, data) => {
|
|
189
188
|
if (error) {
|
|
190
189
|
return reject(error);
|
|
@@ -193,25 +192,24 @@ class File {
|
|
|
193
192
|
});
|
|
194
193
|
});
|
|
195
194
|
}
|
|
196
|
-
return new Promise((resolve, reject) => {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
});
|
|
203
|
-
});
|
|
195
|
+
return new Promise((resolve, reject) => fs.readFile(this.path, encode, (error, data) => {
|
|
196
|
+
if (error) {
|
|
197
|
+
return reject(error);
|
|
198
|
+
}
|
|
199
|
+
return resolve(data);
|
|
200
|
+
}));
|
|
204
201
|
}
|
|
205
202
|
|
|
206
|
-
readByLine(callback, encoding) {
|
|
203
|
+
readByLine (callback, encoding) {
|
|
207
204
|
return new Promise((resolve, reject) => {
|
|
208
205
|
let res = null;
|
|
209
206
|
try {
|
|
210
207
|
res = this.content(encoding);
|
|
211
208
|
let nb = 0;
|
|
212
|
-
res.toString().split(
|
|
213
|
-
|
|
214
|
-
|
|
209
|
+
res.toString().split("\n")
|
|
210
|
+
.forEach((line) => {
|
|
211
|
+
callback(line, ++nb);
|
|
212
|
+
});
|
|
215
213
|
} catch (e) {
|
|
216
214
|
return reject(e);
|
|
217
215
|
}
|
|
@@ -219,11 +217,11 @@ class File {
|
|
|
219
217
|
});
|
|
220
218
|
}
|
|
221
219
|
|
|
222
|
-
write(data, options) {
|
|
220
|
+
write (data, options) {
|
|
223
221
|
return fs.writeFileSync(this.path, data, nodefony.extend({}, defautWriteOption, options));
|
|
224
222
|
}
|
|
225
223
|
|
|
226
|
-
move(target) {
|
|
224
|
+
move (target) {
|
|
227
225
|
try {
|
|
228
226
|
fs.renameSync(this.path, target);
|
|
229
227
|
return new File(target);
|
|
@@ -232,7 +230,7 @@ class File {
|
|
|
232
230
|
}
|
|
233
231
|
}
|
|
234
232
|
|
|
235
|
-
unlink() {
|
|
233
|
+
unlink () {
|
|
236
234
|
try {
|
|
237
235
|
fs.unlinkSync(this.path);
|
|
238
236
|
} catch (e) {
|
package/finder/file.es6
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
class File extends nodefony.fileClass {
|
|
2
|
-
constructor(path, parent = null) {
|
|
2
|
+
constructor (path, parent = null) {
|
|
3
3
|
super(path);
|
|
4
4
|
this.parent = parent;
|
|
5
5
|
this.children = new nodefony.FileResult();
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
get length () {
|
|
8
9
|
return this.children.length;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
toJson() {
|
|
12
|
-
|
|
12
|
+
toJson () {
|
|
13
|
+
const obj = {
|
|
13
14
|
path: this.path,
|
|
14
15
|
name: this.name,
|
|
15
16
|
ext: this.ext,
|