neo.mjs 4.0.61 → 4.0.64
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/buildScripts/createClass.mjs +107 -13
- package/package.json +1 -1
- package/src/DefaultConfig.mjs +4 -1
- package/src/Main.mjs +5 -1
@@ -27,7 +27,7 @@ const
|
|
27
27
|
* folder (parent of cwd, child of sourceRootDirs[n]) will then be used as the
|
28
28
|
* namespace for this created class.
|
29
29
|
* Can be overwritten with the -s option.
|
30
|
-
* @type {
|
30
|
+
* @type {String[]}
|
31
31
|
*/
|
32
32
|
sourceRootDirs = ['apps'];
|
33
33
|
|
@@ -94,7 +94,7 @@ if (programOpts.info) {
|
|
94
94
|
type : 'input',
|
95
95
|
name : 'className',
|
96
96
|
message: 'Please choose the namespace for your class:',
|
97
|
-
default: 'Covid.view.
|
97
|
+
default: 'Covid.view.MyContainer'
|
98
98
|
});
|
99
99
|
}
|
100
100
|
|
@@ -103,7 +103,7 @@ if (programOpts.info) {
|
|
103
103
|
type : 'list',
|
104
104
|
name : 'baseClass',
|
105
105
|
message: 'Please pick the base class, which you want to extend:',
|
106
|
-
choices: ['component.Base', 'container.Base', 'controller.Component', 'core.Base'],
|
106
|
+
choices: ['component.Base', 'container.Base', 'controller.Component', 'core.Base', 'model.Component'],
|
107
107
|
default: 'container.Base'
|
108
108
|
});
|
109
109
|
}
|
@@ -113,7 +113,7 @@ if (programOpts.info) {
|
|
113
113
|
className = programOpts.className || answers.className,
|
114
114
|
isDrop = programOpts.drop,
|
115
115
|
startDate = new Date(),
|
116
|
-
classFolder, file, folderDelta, index, ns, root, rootLowerCase, viewFile;
|
116
|
+
baseType, classFolder, configName, file, folderDelta, index, ns, root, rootLowerCase, viewFile;
|
117
117
|
|
118
118
|
if (className.endsWith('.mjs')) {
|
119
119
|
className = className.slice(0, -4);
|
@@ -201,13 +201,27 @@ if (programOpts.info) {
|
|
201
201
|
fs.writeFileSync(path.join(classFolder, file + '.mjs'), createContent({baseClass, className, file, folderDelta, ns, root}));
|
202
202
|
|
203
203
|
if (baseClass === 'controller.Component') {
|
204
|
-
|
204
|
+
baseType = 'Neo.controller.Component';
|
205
|
+
configName = 'controller';
|
206
|
+
index = file.indexOf('Controller');
|
205
207
|
|
206
208
|
if (index > 0) {
|
207
209
|
viewFile = path.join(classFolder, file.substr(0, index) + '.mjs');
|
208
210
|
|
209
211
|
if (fs.existsSync(viewFile)) {
|
210
|
-
adjustView({file, viewFile});
|
212
|
+
adjustView({baseType, configName, file, viewFile});
|
213
|
+
}
|
214
|
+
}
|
215
|
+
} else if (baseClass === 'model.Component') {
|
216
|
+
baseType = 'Neo.model.Component';
|
217
|
+
configName = 'model';
|
218
|
+
index = file.indexOf('Model');
|
219
|
+
|
220
|
+
if (index > 0) {
|
221
|
+
viewFile = path.join(classFolder, file.substr(0, index) + '.mjs');
|
222
|
+
|
223
|
+
if (fs.existsSync(viewFile)) {
|
224
|
+
adjustView({baseType, configName, file, viewFile});
|
211
225
|
}
|
212
226
|
}
|
213
227
|
}
|
@@ -222,27 +236,57 @@ if (programOpts.info) {
|
|
222
236
|
/**
|
223
237
|
* Adds a comma to the last element of the contentArray
|
224
238
|
* @param {String[]} contentArray
|
239
|
+
* @param {Number} index=contentArray.length - 1
|
225
240
|
* @returns {String[]}
|
226
241
|
*/
|
227
|
-
function addComma(contentArray) {
|
228
|
-
contentArray[
|
242
|
+
function addComma(contentArray, index=contentArray.length - 1) {
|
243
|
+
contentArray[index] += ',';
|
229
244
|
return contentArray;
|
230
245
|
}
|
231
246
|
|
247
|
+
/**
|
248
|
+
* Adds a config to the given index of the contentArray
|
249
|
+
* @param {Object} opts
|
250
|
+
* @param {String} opts.baseType
|
251
|
+
* @param {String} opts.className
|
252
|
+
* @param {String} opts.configName
|
253
|
+
* @param {String[]} opts.contentArray
|
254
|
+
* @param {Boolean} opts.isLastConfig
|
255
|
+
* @param {Number} opts.index
|
256
|
+
* @returns {String[]}
|
257
|
+
*/
|
258
|
+
function addConfig(opts) {
|
259
|
+
const config = [
|
260
|
+
' /**',
|
261
|
+
` * @member {${opts.baseType}} ${opts.configName}=${opts.className}`,
|
262
|
+
' */',
|
263
|
+
` ${opts.configName}: ${opts.className}`
|
264
|
+
];
|
265
|
+
|
266
|
+
!opts.isLastConfig && addComma(config);
|
267
|
+
|
268
|
+
opts.contentArray.splice(opts.index, 0, config.join(os.EOL));
|
269
|
+
return opts.contentArray;
|
270
|
+
}
|
271
|
+
|
232
272
|
/**
|
233
273
|
* Adjusts the views related to controller.Component or model.Component
|
234
274
|
* @param {Object} opts
|
275
|
+
* @param {String} opts.baseType
|
276
|
+
* @param {String} opts.configName
|
235
277
|
* @param {String} opts.file
|
236
278
|
* @param {String} opts.viewFile
|
237
279
|
*/
|
238
280
|
function adjustView(opts) {
|
239
|
-
let
|
281
|
+
let baseType = opts.baseType,
|
282
|
+
configName = opts.configName,
|
283
|
+
file = opts.file,
|
240
284
|
viewFile = opts.viewFile,
|
241
285
|
content = fs.readFileSync(viewFile).toString().split(os.EOL),
|
242
286
|
fromMaxPosition = 0,
|
243
287
|
i = 0,
|
244
288
|
len = content.length,
|
245
|
-
adjustSpaces, codeLine, fromPosition, importLength, importName, j, spaces;
|
289
|
+
adjustSpaces, className, codeLine, fromPosition, importLength, importName, j, nextLine, spaces;
|
246
290
|
|
247
291
|
// find the index where we want to insert our import statement
|
248
292
|
for (; i < len; i++) {
|
@@ -296,10 +340,60 @@ if (programOpts.info) {
|
|
296
340
|
}
|
297
341
|
}
|
298
342
|
|
299
|
-
|
343
|
+
i = 0;
|
344
|
+
len = content.length;
|
345
|
+
|
346
|
+
// find the starting point
|
347
|
+
for (; i < len; i++) {
|
348
|
+
if (content[i].includes('static getConfig')) {
|
349
|
+
break;
|
350
|
+
}
|
351
|
+
}
|
352
|
+
|
353
|
+
for (; i < len; i++) {
|
354
|
+
codeLine = content[i];
|
355
|
+
|
356
|
+
if (codeLine.includes('}}')) {
|
357
|
+
addComma(content, i - 1);
|
358
|
+
addConfig({
|
359
|
+
baseType,
|
360
|
+
className : file,
|
361
|
+
configName,
|
362
|
+
contentArray: content,
|
363
|
+
index : i,
|
364
|
+
isLastConfig: true
|
365
|
+
});
|
366
|
+
break;
|
367
|
+
}
|
300
368
|
|
301
|
-
|
302
|
-
|
369
|
+
if (codeLine.includes('*/')) {
|
370
|
+
nextLine = content[i + 1]
|
371
|
+
className = nextLine.substring(0, nextLine.indexOf(':')).trim();
|
372
|
+
|
373
|
+
if (className === 'className' || className === 'ntype') {
|
374
|
+
continue;
|
375
|
+
}
|
376
|
+
|
377
|
+
if (className > configName) {
|
378
|
+
for (j=i; j > 0; j--) {
|
379
|
+
if (content[j].includes('/**')) {
|
380
|
+
addConfig({
|
381
|
+
baseType,
|
382
|
+
className : file,
|
383
|
+
configName,
|
384
|
+
contentArray: content,
|
385
|
+
index : j,
|
386
|
+
isLastConfig: false
|
387
|
+
});
|
388
|
+
break;
|
389
|
+
}
|
390
|
+
}
|
391
|
+
break;
|
392
|
+
}
|
393
|
+
}
|
394
|
+
}
|
395
|
+
|
396
|
+
fs.writeFileSync(viewFile, content.join(os.EOL));
|
303
397
|
}
|
304
398
|
|
305
399
|
/**
|
package/package.json
CHANGED
package/src/DefaultConfig.mjs
CHANGED
@@ -98,7 +98,10 @@ const DefaultConfig = {
|
|
98
98
|
/**
|
99
99
|
* Add addons for the main thread
|
100
100
|
* Possible values: AmCharts, AnalyticsByGoogle, DragDrop, HighlightJS, LocalStorage, MapboxGL, Markdown, Siesta, Stylesheet, WindowPosition
|
101
|
-
* (src/main/addon)
|
101
|
+
* (src/main/addon) contains all framework related options.
|
102
|
+
* You can also create your own addons within your workspace scope. Make sure to put them inside 'src/main/addon/'
|
103
|
+
* and prefix them with 'WS/' inside your neo-config.json file.
|
104
|
+
* Example: ['DragDrop', 'Stylesheet', 'WS/MyAddon']
|
102
105
|
* @default ['DragDrop','Stylesheet']
|
103
106
|
* @memberOf! module:Neo
|
104
107
|
* @name config.mainThreadAddons
|
package/src/Main.mjs
CHANGED
@@ -215,7 +215,11 @@ class Main extends core.Base {
|
|
215
215
|
}
|
216
216
|
|
217
217
|
mainThreadAddons.forEach(addon => {
|
218
|
-
|
218
|
+
if (addon.startsWith('WS/')) {
|
219
|
+
imports.push(import(`../../../src/main/addon/${addon.substr(3)}.mjs`));
|
220
|
+
} else {
|
221
|
+
imports.push(import(`./main/addon/${addon}.mjs`));
|
222
|
+
}
|
219
223
|
});
|
220
224
|
|
221
225
|
modules = await Promise.all(imports);
|