not-node 5.1.10 → 5.1.14
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/bin/not-builder.js +485 -453
- package/package.json +1 -1
- package/src/bootstrap/route.js +11 -3
- package/src/generic/form.listAndCount.js +52 -0
- package/src/generic/index.js +1 -0
package/bin/not-builder.js
CHANGED
|
@@ -9,15 +9,16 @@
|
|
|
9
9
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
|
|
12
13
|
var argv = require('yargs').argv,
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
fs = require('fs'),
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
path = require('path'),
|
|
18
|
+
child_process = require('child_process'),
|
|
19
|
+
deepMerge = require('deepmerge'),
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
lib = require('../src/lib.js');
|
|
21
22
|
|
|
22
23
|
const TEMPLATES_EXT = '.html';
|
|
23
24
|
const SCRIPTS_EXT = '.js';
|
|
@@ -27,15 +28,15 @@ const COMMON_TEMPLATES = 'common';
|
|
|
27
28
|
console.log('NODE VERSION',process.version);
|
|
28
29
|
|
|
29
30
|
let opts = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
'environment': argv.environment || 'production',
|
|
32
|
+
'to': argv.to || false,
|
|
33
|
+
'config': argv.config || './project.manifest.json',
|
|
34
|
+
'rollup': argv.rollup || path.join(process.cwd(),'./node_modules/.bin/rollup'),
|
|
35
|
+
'role': argv.role || null,
|
|
36
|
+
'verbose': argv.verbose || false
|
|
37
|
+
},
|
|
38
|
+
configName = path.join(process.cwd(), opts.config),
|
|
39
|
+
config = {};
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* Returns list of directories in directory
|
|
@@ -43,28 +44,28 @@ let opts = {
|
|
|
43
44
|
* @return {Promise} of array of directories
|
|
44
45
|
*/
|
|
45
46
|
function listDir(dir){
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
47
|
+
return new Promise((resolve, reject)=>{
|
|
48
|
+
fs.stat(dir, (err_stat, info)=>{
|
|
49
|
+
if (err_stat){
|
|
50
|
+
reject(err_stat);
|
|
51
|
+
}else{
|
|
52
|
+
if (info){
|
|
53
|
+
fs.readdir(dir, (err_readdir, files)=>{
|
|
54
|
+
if(err_readdir){
|
|
55
|
+
reject('Error while reading directory file list.');
|
|
56
|
+
}else{
|
|
57
|
+
files = files.filter((item)=>{
|
|
58
|
+
return fs.lstatSync(path.join(dir, item)).isDirectory();
|
|
59
|
+
});
|
|
60
|
+
resolve(files);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}else{
|
|
64
|
+
reject('Not exists!');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
/**
|
|
@@ -73,42 +74,60 @@ function listDir(dir){
|
|
|
73
74
|
* @return {Promise} of array of files
|
|
74
75
|
*/
|
|
75
76
|
function listFiles(dir, ext){
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
77
|
+
//console.info('list files in ',dir,' for ', ext);
|
|
78
|
+
return new Promise((resolve, reject)=>{
|
|
79
|
+
fs.stat(dir, (err_stat, info)=>{
|
|
80
|
+
if (err_stat){
|
|
81
|
+
reject(err_stat);
|
|
82
|
+
}else{
|
|
83
|
+
if (info){
|
|
84
|
+
fs.readdir(dir, (err_readdir, files)=>{
|
|
85
|
+
if(err_readdir){
|
|
86
|
+
reject('Error while reading directory file list.');
|
|
87
|
+
}else{
|
|
88
|
+
//console.log(files);
|
|
89
|
+
files = files.filter((item)=>{
|
|
90
|
+
if(!fs.lstatSync(path.join(dir, item)).isFile()){
|
|
91
|
+
//console.log(item, 'is not a file');
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
if(item.indexOf(ext)===-1){
|
|
95
|
+
//console.log(item, 'wrong ext 1');
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
if((item.length - ext.length) !== item.indexOf(ext)){
|
|
99
|
+
//console.log(item, 'wrong ext 2');
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
});
|
|
104
|
+
resolve(files);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}else{
|
|
108
|
+
reject('Not exists!');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function fileExists(filename){
|
|
116
|
+
try{
|
|
117
|
+
await fs.promises.access(filename, fs.constants.R_OK);
|
|
118
|
+
return true;
|
|
119
|
+
}catch(_){
|
|
120
|
+
//console.error('not exists', filename);
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function indexFilesExistsInDir(dir, exts = ['js']){
|
|
126
|
+
let filenamesList = exts.map(ext => path.join(dir, `index.${ext}`));
|
|
127
|
+
let checks = filenamesList.map(filename => fileExists(filename));
|
|
128
|
+
let results = await Promise.all(checks);
|
|
129
|
+
//console.log(results.some(res => res));
|
|
130
|
+
return results.some(res => res);
|
|
112
131
|
}
|
|
113
132
|
|
|
114
133
|
/**
|
|
@@ -117,17 +136,17 @@ function listFiles(dir, ext){
|
|
|
117
136
|
* @return {array} list of full files paths
|
|
118
137
|
*/
|
|
119
138
|
async function listFilesPaths(dir, ext){
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
139
|
+
let listOfFiles,
|
|
140
|
+
result = [];
|
|
141
|
+
try{
|
|
142
|
+
listOfFiles = await listFiles(dir, ext);
|
|
143
|
+
}catch(e){
|
|
144
|
+
console.error(e);
|
|
145
|
+
}
|
|
146
|
+
listOfFiles.forEach((filename) => {
|
|
147
|
+
result.push(path.join(dir, filename));
|
|
148
|
+
});
|
|
149
|
+
return result;
|
|
131
150
|
}
|
|
132
151
|
|
|
133
152
|
/**
|
|
@@ -137,25 +156,25 @@ async function listFilesPaths(dir, ext){
|
|
|
137
156
|
* @return {array} list of template files
|
|
138
157
|
*/
|
|
139
158
|
async function loadTemplates(dir, role = COMMON_TEMPLATES, templatesExt = TEMPLATES_EXT){
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
let dirsList = await listDir(dir),
|
|
160
|
+
filesList = await listFiles(dir, templatesExt),
|
|
161
|
+
result = [];
|
|
162
|
+
if (dirsList && Array.isArray(dirsList) && dirsList.length > 0){
|
|
163
|
+
if (dirsList.indexOf(role) > -1){
|
|
164
|
+
let pathToModRole = path.join(dir, role),
|
|
165
|
+
files = await listFilesPaths(pathToModRole, templatesExt);
|
|
166
|
+
if(Array.isArray(files)){
|
|
167
|
+
result.push(...files);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if(filesList && Array.isArray(filesList) && filesList.length > 0){
|
|
172
|
+
if (filesList.indexOf(role + templatesExt) > -1){
|
|
173
|
+
result.push(path.join(dir, role + templatesExt));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//console.log('templates in ',dir,role,result);
|
|
177
|
+
return result;
|
|
159
178
|
}
|
|
160
179
|
|
|
161
180
|
/**
|
|
@@ -165,48 +184,48 @@ async function loadTemplates(dir, role = COMMON_TEMPLATES, templatesExt = TEMPLA
|
|
|
165
184
|
* @return {array} list of template files
|
|
166
185
|
*/
|
|
167
186
|
async function loadTemplatesForFront(dir, role, commonDir = COMMON_TEMPLATES, templatesExt = TEMPLATES_EXT){
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
187
|
+
let listDirs,
|
|
188
|
+
roleDir = path.join(dir, role),
|
|
189
|
+
result = [];
|
|
190
|
+
commonDir = path.join(dir, commonDir);
|
|
191
|
+
try{
|
|
192
|
+
listDirs = await listDir(dir);
|
|
193
|
+
}catch(e){
|
|
194
|
+
console.error(e);
|
|
195
|
+
}
|
|
196
|
+
//console.log('listDirs:', listDirs);
|
|
197
|
+
try{
|
|
198
|
+
if(fs.lstatSync(commonDir).isDirectory()){
|
|
199
|
+
//console.log('Directory ', commonDir, ' exists!');
|
|
200
|
+
let files = await listFilesPaths(commonDir, templatesExt);
|
|
201
|
+
//console.log('common files:', files);
|
|
202
|
+
result.push(...files);
|
|
203
|
+
}else{
|
|
204
|
+
//console.log('no such directory', commonDir);
|
|
205
|
+
}
|
|
206
|
+
}catch(e){
|
|
207
|
+
console.error(e);
|
|
208
|
+
}
|
|
209
|
+
if(fs.lstatSync(roleDir).isDirectory()){
|
|
210
|
+
let modsDir;
|
|
211
|
+
try{
|
|
212
|
+
modsDir = await listDir(roleDir);
|
|
213
|
+
}catch(e){
|
|
214
|
+
console.error(e);
|
|
215
|
+
}
|
|
216
|
+
//console.log('!front ',role,roleDir,modsDir);
|
|
217
|
+
if(Array.isArray(modsDir)){
|
|
218
|
+
for(let t = 0; t < modsDir.length; t++){
|
|
219
|
+
let modDir = modsDir[t];
|
|
220
|
+
let files = await listFilesPaths(path.join(roleDir, modDir), templatesExt);
|
|
221
|
+
//console.log('list of files', files);
|
|
222
|
+
result.push(...files);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}else{
|
|
226
|
+
console.error('Directory is not exists: ',roleDir);
|
|
227
|
+
}
|
|
228
|
+
return result;
|
|
210
229
|
}
|
|
211
230
|
|
|
212
231
|
/**
|
|
@@ -218,338 +237,351 @@ async function loadTemplatesForFront(dir, role, commonDir = COMMON_TEMPLATES, te
|
|
|
218
237
|
* @returns {object} result[role][controller]
|
|
219
238
|
*/
|
|
220
239
|
async function loadNPMModule(){
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
240
|
+
let result = {};
|
|
241
|
+
try{
|
|
242
|
+
let {modName, modOptions, roles} = arguments[0];
|
|
243
|
+
let mod = require(modName);
|
|
244
|
+
for(let i = 0; i < roles.length; i++){
|
|
245
|
+
result[roles[i]] = {
|
|
246
|
+
controllers:[],
|
|
247
|
+
templates: [],
|
|
248
|
+
styles: []
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (mod.paths){
|
|
253
|
+
if(mod.paths.controllers){
|
|
254
|
+
let pathToControllers = mod.paths.controllers;
|
|
255
|
+
let dirList = await listDir(pathToControllers);
|
|
256
|
+
if (dirList && Array.isArray(dirList) && dirList.length > 0){
|
|
257
|
+
let common = dirList.indexOf(COMMON_TEMPLATES) > -1;
|
|
258
|
+
roles.forEach((role)=>{
|
|
259
|
+
if (dirList.indexOf(role) > -1){
|
|
260
|
+
result[role].controllers.push(path.join(pathToControllers, role));
|
|
261
|
+
}
|
|
262
|
+
if(common){
|
|
263
|
+
result[role].controllers.push(path.join(pathToControllers, 'common'));
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if(mod.paths.templates){
|
|
269
|
+
let commons;
|
|
270
|
+
try{
|
|
271
|
+
commons = await loadTemplates(mod.paths.templates);
|
|
272
|
+
}catch(e){
|
|
273
|
+
console.error(e);
|
|
274
|
+
commons = [];
|
|
275
|
+
}
|
|
276
|
+
for(let role of roles){
|
|
277
|
+
let list = await loadTemplates(mod.paths.templates, role);
|
|
278
|
+
list.push(...commons);
|
|
279
|
+
result[role].templates.push(...list);
|
|
280
|
+
}
|
|
281
|
+
opts.verbose && console.log('result', result);
|
|
282
|
+
}else{
|
|
283
|
+
opts.verbose && console.info('...no templates');
|
|
284
|
+
}
|
|
285
|
+
if(mod.paths.styles){
|
|
286
|
+
let commons;
|
|
287
|
+
try{
|
|
288
|
+
commons = await loadTemplates(mod.paths.styles, COMMON_TEMPLATES, STYLES_EXT);
|
|
289
|
+
}catch(e){
|
|
290
|
+
console.error(e);
|
|
291
|
+
commons = [];
|
|
292
|
+
}
|
|
293
|
+
for(let role of roles){
|
|
294
|
+
let list = await loadTemplates(mod.paths.styles, role, STYLES_EXT);
|
|
295
|
+
list.push(...commons);
|
|
296
|
+
result[role].styles.push(...list);
|
|
297
|
+
}
|
|
298
|
+
opts.verbose && console.log('result', result);
|
|
299
|
+
}else{
|
|
300
|
+
opts.verbose && console.info('...no styles');
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}catch(e){
|
|
304
|
+
console.error(e);
|
|
305
|
+
}
|
|
306
|
+
opts.verbose && console.log('npm module content ',result);
|
|
307
|
+
return result;
|
|
289
308
|
}
|
|
290
309
|
|
|
291
310
|
async function loadServerModule(){
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
311
|
+
let result = {};
|
|
312
|
+
try{
|
|
313
|
+
let {modName, modOptions, roles, pathToModule} = arguments[0];
|
|
314
|
+
let mod = require(pathToModule);
|
|
315
|
+
for(let i = 0; i < roles.length; i++){
|
|
316
|
+
result[roles[i]] = {
|
|
317
|
+
controllers:[],
|
|
318
|
+
templates: [],
|
|
319
|
+
styles: []
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
if (mod.paths){
|
|
323
|
+
if( mod.paths.controllers){
|
|
324
|
+
let pathToControllers = mod.paths.controllers;
|
|
325
|
+
//console.log(pathToControllers);
|
|
326
|
+
let dirList = await listDir(pathToControllers);
|
|
327
|
+
//console.log(dirList);
|
|
328
|
+
if (dirList && Array.isArray(dirList) && dirList.length > 0){
|
|
329
|
+
for(let i = 0; i < roles.length; i++){
|
|
330
|
+
let role = roles[i];
|
|
331
|
+
if(dirList.indexOf("common") > -1){
|
|
332
|
+
let pathToModRole = path.join(pathToControllers, "common");
|
|
333
|
+
if(await indexFilesExistsInDir(pathToModRole)){
|
|
334
|
+
result[role].controllers.push(pathToModRole);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (dirList.indexOf(role)>-1){
|
|
338
|
+
let pathToModRole = path.join(pathToControllers, role);
|
|
339
|
+
result[role].controllers.push(pathToModRole);
|
|
340
|
+
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
}else{
|
|
346
|
+
opts.verbose && console.info('...no controllers');
|
|
347
|
+
}
|
|
348
|
+
if(mod.paths.templates){
|
|
349
|
+
let commons;
|
|
350
|
+
try{
|
|
351
|
+
commons = await loadTemplates(mod.paths.templates);
|
|
352
|
+
}catch(e){
|
|
353
|
+
console.error(e);
|
|
354
|
+
commons = [];
|
|
355
|
+
}
|
|
356
|
+
//console.log('commons', commons);
|
|
357
|
+
for(let i = 0; i < roles.length; i++){
|
|
358
|
+
try{
|
|
359
|
+
//console.log('loadTemplates', typeof loadTemplates);
|
|
360
|
+
let role = roles[i],
|
|
361
|
+
list = await loadTemplates(mod.paths.templates, role);
|
|
362
|
+
//console.log('list', typeof list, typeof result[role]);
|
|
363
|
+
list.push(...(commons.slice()));
|
|
364
|
+
result[role].templates.push(...list);
|
|
365
|
+
}catch(e){
|
|
366
|
+
console.error(e);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
}
|
|
370
|
+
}else{
|
|
371
|
+
opts.verbose && console.info('...no templates');
|
|
372
|
+
}
|
|
373
|
+
if(mod.paths.styles){
|
|
374
|
+
let commons;
|
|
375
|
+
try{
|
|
376
|
+
commons = await loadTemplates(mod.paths.styles, COMMON_TEMPLATES, STYLES_EXT);
|
|
377
|
+
}catch(e){
|
|
378
|
+
console.error(e);
|
|
379
|
+
commons = [];
|
|
380
|
+
}
|
|
381
|
+
//console.log('commons', commons);
|
|
382
|
+
for(let i = 0; i < roles.length; i++){
|
|
383
|
+
try{
|
|
384
|
+
//console.log('loadTemplates', typeof loadTemplates);
|
|
385
|
+
let role = roles[i],
|
|
386
|
+
list = await loadTemplates(mod.paths.styles, role, STYLES_EXT);
|
|
387
|
+
//console.log('list', typeof list, typeof result[role]);
|
|
388
|
+
list.push(...(commons.slice()));
|
|
389
|
+
result[role].styles.push(...list);
|
|
390
|
+
}catch(e){
|
|
391
|
+
console.error(e);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
}
|
|
395
|
+
}else{
|
|
396
|
+
opts.verbose && console.info('...no styles');
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}catch(e){
|
|
400
|
+
console.error(e);
|
|
401
|
+
}
|
|
402
|
+
return result;
|
|
374
403
|
}
|
|
375
404
|
|
|
376
405
|
function initList(roles, pathTo){
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
406
|
+
let list = {};
|
|
407
|
+
for(let i = 0; i < roles.length; i++){
|
|
408
|
+
list[roles[i]] = {
|
|
409
|
+
templates: [],
|
|
410
|
+
controllers: [],
|
|
411
|
+
styles: []
|
|
412
|
+
};
|
|
413
|
+
if (pathTo){
|
|
414
|
+
list[roles[i]].controllers.push(pathTo);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return list;
|
|
389
418
|
}
|
|
390
419
|
|
|
391
420
|
async function loadFrontModules(){
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
421
|
+
let result = {};
|
|
422
|
+
try{
|
|
423
|
+
let {modsOptions, roles, pathToModules} = arguments[0];
|
|
424
|
+
for(let i = 0; i < roles.length; i++){
|
|
425
|
+
result[roles[i]] = {
|
|
426
|
+
templates: [],
|
|
427
|
+
controllers: [],
|
|
428
|
+
styles: []
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
let modulesDirList = await listDir(pathToModules);
|
|
432
|
+
if (modulesDirList.indexOf('common') > -1){
|
|
433
|
+
result = initList(roles, path.join(pathToModules, 'common'));
|
|
434
|
+
}
|
|
435
|
+
//console.log(modulesDirList);
|
|
436
|
+
for(let i = 0; i < roles.length; i++){
|
|
437
|
+
modulesDirList = await listDir(path.join(pathToModules, roles[i]));
|
|
438
|
+
//console.log(path.join(pathToModules, roles[i]), modulesDirList);
|
|
439
|
+
for(let t = 0; t < modulesDirList.length; t++){
|
|
440
|
+
result[roles[i]].controllers.push(path.join(pathToModules, roles[i], modulesDirList[t]));
|
|
441
|
+
}
|
|
442
|
+
//console.log(result[roles[i]].controllers);
|
|
443
|
+
//console.log('role:', roles[i]);
|
|
444
|
+
result[roles[i]].templates = await loadTemplatesForFront(pathToModules, roles[i]);
|
|
445
|
+
result[roles[i]].styles = await loadTemplatesForFront(pathToModules, roles[i], COMMON_TEMPLATES,STYLES_EXT);
|
|
446
|
+
//console.log('templates in there', result[roles[i]].templates);
|
|
447
|
+
}
|
|
448
|
+
}catch(e){
|
|
449
|
+
console.error('loadFrontModules error', e);
|
|
450
|
+
}
|
|
451
|
+
return result;
|
|
420
452
|
}
|
|
421
453
|
|
|
422
454
|
async function loadServerModulesFromDir(){
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
455
|
+
let list = {};
|
|
456
|
+
try{
|
|
457
|
+
let {modsOptions, roles, pathToModules} = arguments[0];
|
|
458
|
+
let modulesDirList = await listDir(pathToModules);
|
|
459
|
+
for(let i = 0; i < modulesDirList.length; i++){
|
|
460
|
+
let moduleName = modulesDirList[i];
|
|
461
|
+
console.info('Import from', moduleName);
|
|
462
|
+
let modOptions = (modsOptions&&modsOptions.hasOwnProperty[moduleName])?modsOptions[moduleName]:{};
|
|
463
|
+
let pathToModule = path.join(pathToModules, moduleName);
|
|
464
|
+
let partList = await loadServerModule({pathToModule, roles, modName: moduleName, modOptions});
|
|
465
|
+
list = deepMerge(list, partList);
|
|
466
|
+
}
|
|
467
|
+
}catch(e){
|
|
468
|
+
console.error(e);
|
|
469
|
+
}
|
|
470
|
+
return list;
|
|
439
471
|
}
|
|
440
472
|
|
|
441
473
|
|
|
442
474
|
async function build_Server(pathToRoot, roles, targetName, targetManifest){
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
475
|
+
let list = {};
|
|
476
|
+
for(let i = 0; i < roles.length; i++){
|
|
477
|
+
list[roles[i]] = {
|
|
478
|
+
controllers:[],
|
|
479
|
+
templates: [],
|
|
480
|
+
styles: []
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
////searching for app.js template
|
|
484
|
+
////searching modules
|
|
485
|
+
let pathTo = {
|
|
486
|
+
"nodeModules": (targetManifest.modules && targetManifest.modules.serverModulesDir)?path.join(pathToRoot, targetManifest.modules.serverModulesDir):undefined,
|
|
487
|
+
"frontModules": (targetManifest.modules && targetManifest.modules.frontModulesDir)?path.join(pathToRoot, targetManifest.modules.frontModulesDir): undefined
|
|
488
|
+
};
|
|
489
|
+
if (targetManifest.modules){
|
|
490
|
+
/////searching for npm modules
|
|
491
|
+
if (targetManifest.modules.npm){
|
|
492
|
+
let mass = targetManifest.modules.npm;
|
|
493
|
+
console.info('Import from npm modules:');
|
|
494
|
+
for(let t in mass){
|
|
495
|
+
console.info(t, '...');
|
|
496
|
+
let partList = await loadNPMModule({roles, modName: t, modOptions: mass[t]});
|
|
497
|
+
list = deepMerge(list, partList);
|
|
498
|
+
}
|
|
499
|
+
}else{
|
|
500
|
+
console.info('no npm modules in manifest');
|
|
501
|
+
}
|
|
502
|
+
/////searching for server modules
|
|
503
|
+
if (targetManifest.modules.serverModulesDir){
|
|
504
|
+
console.info('Import custom server modules from',targetManifest.modules.serverModulesDir,':');
|
|
505
|
+
let partList = await loadServerModulesFromDir({pathToModules: path.join(pathToRoot,targetManifest.modules.serverModulesDir), roles, modsOptions: targetManifest.modules.server});
|
|
506
|
+
list = deepMerge(list, partList);
|
|
507
|
+
}else{
|
|
508
|
+
console.info('no custom server modules in manifest');
|
|
509
|
+
}
|
|
510
|
+
/////searching for front modules
|
|
511
|
+
if (targetManifest.modules.frontModulesDir){
|
|
512
|
+
console.info('Import custom front modules from', targetManifest.modules.frontModulesDir,':');
|
|
513
|
+
try{
|
|
514
|
+
let mass = targetManifest.modules.front;
|
|
515
|
+
let pathToModules = path.join(pathToRoot, targetManifest.modules.frontModulesDir);
|
|
516
|
+
let partList = await loadFrontModules({pathToModules, roles, modsOptions: mass});
|
|
517
|
+
list = deepMerge(list, partList);
|
|
518
|
+
}catch(e){
|
|
519
|
+
console.error(e);
|
|
520
|
+
}
|
|
521
|
+
}else{
|
|
522
|
+
console.info('no front modules in manifest');
|
|
523
|
+
}
|
|
524
|
+
}else{
|
|
525
|
+
console.info('no modules in manifest');
|
|
526
|
+
}
|
|
527
|
+
opts.verbose && console.log('List:', list);
|
|
528
|
+
////forming index.js and rollup.js
|
|
529
|
+
for(let i = 0; i < roles.length; i++){
|
|
530
|
+
const role = roles[i];
|
|
531
|
+
if((opts.role !== null) && opts.role !== role){
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
try{
|
|
535
|
+
let indexFile = path.join(pathToRoot, targetManifest.src, 'index.' + role + '.js');
|
|
536
|
+
let rollupFile = path.join(pathToRoot, targetManifest.root, 'rollup.' + role + '.js');
|
|
537
|
+
let bundleFile = path.join(pathToRoot, targetManifest.build, role + '.js');
|
|
538
|
+
//let templateFile = path.join(pathToRoot, targetManifest.build, role + '.html');
|
|
539
|
+
await lib.renderScript(path.join(pathToRoot, targetManifest.index), {
|
|
540
|
+
mods:list[role].controllers,
|
|
541
|
+
scss: list[role].styles,
|
|
542
|
+
env: opts.environment,
|
|
543
|
+
role
|
|
544
|
+
}, indexFile);
|
|
545
|
+
await lib.renderScript(path.join(pathToRoot,targetManifest.rollup), {
|
|
546
|
+
appName: targetManifest.name,
|
|
547
|
+
inputPath: indexFile,
|
|
548
|
+
outputPath: bundleFile,
|
|
549
|
+
env: opts.environment,
|
|
550
|
+
role
|
|
551
|
+
}, rollupFile);
|
|
552
|
+
child_process.execFileSync('node', [opts.rollup, '-c', rollupFile], {
|
|
553
|
+
env : {
|
|
554
|
+
NODE_ENV: opts.environment
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
//await lib.joinToFile(templateFile, list[role].templates);
|
|
558
|
+
}catch(e){
|
|
559
|
+
console.error(e);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
////executing rollup
|
|
531
563
|
|
|
532
564
|
}
|
|
533
565
|
|
|
534
566
|
//loading manifest file
|
|
535
567
|
try{
|
|
536
|
-
|
|
537
|
-
|
|
568
|
+
console.log('config path', configName);
|
|
569
|
+
config = lib.getConfReader(configName);
|
|
538
570
|
}catch(e){
|
|
539
|
-
|
|
540
|
-
|
|
571
|
+
console.error(e);
|
|
572
|
+
process.exit(1);
|
|
541
573
|
}
|
|
542
574
|
//searchig for targets
|
|
543
575
|
if (config.get('targets') && Object.keys(config.get('targets')).length > 0){
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
576
|
+
//cycling through targets
|
|
577
|
+
for(let target in config.get('targets')){
|
|
578
|
+
let targetConfig = config.get('targets')[target];
|
|
579
|
+
if (targetConfig && targetConfig.builder){
|
|
580
|
+
//if target type is server
|
|
581
|
+
switch (targetConfig.builder){
|
|
582
|
+
case 'server': build_Server(path.dirname(configName), targetConfig.roles, target, targetConfig);
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
555
587
|
}
|
package/package.json
CHANGED
package/src/bootstrap/route.js
CHANGED
|
@@ -79,12 +79,20 @@ module.exports = ({
|
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
+
const getForm = (actionName) => {
|
|
83
|
+
const form = getApp().getForm(
|
|
84
|
+
[MODULE_NAME, `${MODEL_NAME}.${actionName}`].join("//")
|
|
85
|
+
);
|
|
86
|
+
if (form) {
|
|
87
|
+
return form;
|
|
88
|
+
}
|
|
89
|
+
return getApp().getForm([MODULE_NAME, actionName].join("//"));
|
|
90
|
+
};
|
|
91
|
+
|
|
82
92
|
const beforeDecorator = async (req, res, next) => {
|
|
83
93
|
const actionName = req.notRouteData.actionName;
|
|
84
94
|
const trimmedActionName = actionName.replace("_", "");
|
|
85
|
-
const FormValidator =
|
|
86
|
-
[MODULE_NAME, trimmedActionName].join("//")
|
|
87
|
-
);
|
|
95
|
+
const FormValidator = getForm(trimmedActionName);
|
|
88
96
|
if (FormValidator) {
|
|
89
97
|
const prepared = await FormValidator.run(req, res, next);
|
|
90
98
|
checkAccessRules(trimmedActionName, prepared);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const Form = require("../form/form");
|
|
2
|
+
const { firstLetterToUpper } = require("../common");
|
|
3
|
+
const { getIP } = require("../auth");
|
|
4
|
+
const notFilter = require("not-filter");
|
|
5
|
+
const getApp = require("../getApp");
|
|
6
|
+
|
|
7
|
+
const FIELDS = [
|
|
8
|
+
["query", `not-filter//_filterQuery`],
|
|
9
|
+
["activeUserId", { required: true }, "not-node//objectId"],
|
|
10
|
+
["activeUser", "not-node//requiredObject"],
|
|
11
|
+
["ip", "not-node//ip"],
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
module.exports = ({ MODULE_NAME, MODEL_NAME, actionName }) => {
|
|
15
|
+
const FORM_NAME = `${MODULE_NAME}:${MODEL_NAME}:${firstLetterToUpper(
|
|
16
|
+
actionName
|
|
17
|
+
)}Form`;
|
|
18
|
+
return class extends Form {
|
|
19
|
+
constructor({ app }) {
|
|
20
|
+
super({ FIELDS, FORM_NAME, app });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
extract(req) {
|
|
24
|
+
const thisSchema = getApp().getModelSchema(
|
|
25
|
+
`${MODULE_NAME}//${MODEL_NAME}`
|
|
26
|
+
);
|
|
27
|
+
const { skip, size } = notFilter.pager.process(req), //skip,size
|
|
28
|
+
sorter = notFilter.sorter.process(req, thisSchema),
|
|
29
|
+
search = notFilter.search.process(req, thisSchema);
|
|
30
|
+
let filter = notFilter.filter.process(req, thisSchema);
|
|
31
|
+
|
|
32
|
+
if (!req.user.isRoot() && !req.user.isAdmin()) {
|
|
33
|
+
filter = notFilter.filter.modifyRules(filter, {
|
|
34
|
+
owner: req.user._id,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
query: {
|
|
40
|
+
skip,
|
|
41
|
+
size,
|
|
42
|
+
sorter,
|
|
43
|
+
filter,
|
|
44
|
+
search,
|
|
45
|
+
},
|
|
46
|
+
activeUser: req.user,
|
|
47
|
+
activeUserId: req.user._id,
|
|
48
|
+
ip: getIP(req),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
package/src/generic/index.js
CHANGED