neo.mjs 4.0.63 → 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.
@@ -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.HeaderContainerController'
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
- index = file.indexOf('Controller');
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,35 +236,51 @@ 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[contentArray.length - 1] += ',';
242
+ function addComma(contentArray, index=contentArray.length - 1) {
243
+ contentArray[index] += ',';
229
244
  return contentArray;
230
245
  }
231
246
 
232
- function addConfig(contentArray, index, className, isLastConfig) {
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) {
233
259
  const config = [
234
260
  ' /**',
235
- ` * @member {Neo.controller.Component} controller=${className}`,
261
+ ` * @member {${opts.baseType}} ${opts.configName}=${opts.className}`,
236
262
  ' */',
237
- ` controller: ${className}`
263
+ ` ${opts.configName}: ${opts.className}`
238
264
  ];
239
265
 
240
- !isLastConfig && addComma(config);
266
+ !opts.isLastConfig && addComma(config);
241
267
 
242
- contentArray.splice(index, 0, config.join(os.EOL));
243
- return contentArray;
268
+ opts.contentArray.splice(opts.index, 0, config.join(os.EOL));
269
+ return opts.contentArray;
244
270
  }
245
271
 
246
272
  /**
247
273
  * Adjusts the views related to controller.Component or model.Component
248
274
  * @param {Object} opts
275
+ * @param {String} opts.baseType
276
+ * @param {String} opts.configName
249
277
  * @param {String} opts.file
250
278
  * @param {String} opts.viewFile
251
279
  */
252
280
  function adjustView(opts) {
253
- let file = opts.file,
281
+ let baseType = opts.baseType,
282
+ configName = opts.configName,
283
+ file = opts.file,
254
284
  viewFile = opts.viewFile,
255
285
  content = fs.readFileSync(viewFile).toString().split(os.EOL),
256
286
  fromMaxPosition = 0,
@@ -324,7 +354,15 @@ if (programOpts.info) {
324
354
  codeLine = content[i];
325
355
 
326
356
  if (codeLine.includes('}}')) {
327
- addConfig(content, i, file, true);
357
+ addComma(content, i - 1);
358
+ addConfig({
359
+ baseType,
360
+ className : file,
361
+ configName,
362
+ contentArray: content,
363
+ index : i,
364
+ isLastConfig: true
365
+ });
328
366
  break;
329
367
  }
330
368
 
@@ -336,10 +374,17 @@ if (programOpts.info) {
336
374
  continue;
337
375
  }
338
376
 
339
- if (className > 'controller') {
377
+ if (className > configName) {
340
378
  for (j=i; j > 0; j--) {
341
379
  if (content[j].includes('/**')) {
342
- addConfig(content, j, file, false);
380
+ addConfig({
381
+ baseType,
382
+ className : file,
383
+ configName,
384
+ contentArray: content,
385
+ index : j,
386
+ isLastConfig: false
387
+ });
343
388
  break;
344
389
  }
345
390
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo.mjs",
3
- "version": "4.0.63",
3
+ "version": "4.0.64",
4
4
  "description": "The webworkers driven UI framework",
5
5
  "type": "module",
6
6
  "repository": {