neo.mjs 4.0.64 → 4.0.65

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/README.md CHANGED
@@ -236,12 +236,12 @@ More infos: <a href="./BACKERS.md">Sponsors & Backers</a>
236
236
  </br></br>
237
237
  <h2 id="jobs">14. Jobs</h2>
238
238
  Accenture is hiring multiple neo.mjs developers for the new Cloud Technology Studio in Kaiserslauern (Germany):</br>
239
- <a href="https://www.accenture.com/de-de/careers/jobdetails?id=R00057924_de">Senior neo.mjs Frontend Developer /Architect (all genders)</a></br></br>
240
-
239
+ </br>
241
240
  These full-time roles are based on German contracts, so they require living in (or relocating to) Germany.
241
+ Ping us on LinkedIn or Slack for details.
242
242
 
243
243
  </br></br>
244
- Logo contributed by <a href="https://www.linkedin.com/in/dinkheller/">Torsten Dinkheller</a>.
244
+ Logo contributed by <a href="https://www.linkedin.com/in/torsten-dinkheller-614516231/">Torsten Dinkheller</a>.
245
245
 
246
246
  </br></br>
247
247
  Build with :heart: in Germany.
@@ -14,7 +14,7 @@ const
14
14
  cwd = process.cwd(),
15
15
  requireJson = path => JSON.parse(fs.readFileSync((path))),
16
16
  packageJson = requireJson(path.join(__dirname, 'package.json')),
17
- insideNeo = packageJson.name === 'neo.mjs',
17
+ insideNeo = process.env.npm_package_name === 'neo.mjs',
18
18
  program = new Command(),
19
19
  programName = `${packageJson.name} create-class`,
20
20
  questions = [],
@@ -103,8 +103,17 @@ 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', 'model.Component'],
107
- default: 'container.Base'
106
+ default: 'container.Base',
107
+
108
+ choices: [
109
+ 'component.Base',
110
+ 'container.Base',
111
+ 'controller.Component',
112
+ 'core.Base',
113
+ 'data.Model',
114
+ 'data.Store',
115
+ 'model.Component'
116
+ ]
108
117
  });
109
118
  }
110
119
 
@@ -113,7 +122,7 @@ if (programOpts.info) {
113
122
  className = programOpts.className || answers.className,
114
123
  isDrop = programOpts.drop,
115
124
  startDate = new Date(),
116
- baseType, classFolder, configName, file, folderDelta, index, ns, root, rootLowerCase, viewFile;
125
+ baseFileName, baseType, classFolder, configName, file, folderDelta, importName, importPath, index, ns, root, rootLowerCase, viewFile;
117
126
 
118
127
  if (className.endsWith('.mjs')) {
119
128
  className = className.slice(0, -4);
@@ -184,8 +193,8 @@ if (programOpts.info) {
184
193
  }
185
194
 
186
195
  if (isDrop !== true) {
187
- if (fs.existsSync(path.resolve(__dirname, 'apps', rootLowerCase))) {
188
- classFolder = path.resolve(__dirname, 'apps', rootLowerCase, ns.join('/'));
196
+ if (fs.existsSync(path.resolve(cwd, 'apps', rootLowerCase))) {
197
+ classFolder = path.resolve(cwd, 'apps', rootLowerCase, ns.join('/'));
189
198
  } else {
190
199
  console.log('\nNon existing neo app name:', chalk.red(root));
191
200
  process.exit(1);
@@ -198,31 +207,87 @@ if (programOpts.info) {
198
207
 
199
208
  fs.mkdirpSync(classFolder);
200
209
 
201
- fs.writeFileSync(path.join(classFolder, file + '.mjs'), createContent({baseClass, className, file, folderDelta, ns, root}));
210
+ baseFileName = baseClass.split('.').pop();
202
211
 
203
- if (baseClass === 'controller.Component') {
204
- baseType = 'Neo.controller.Component';
205
- configName = 'controller';
206
- index = file.indexOf('Controller');
212
+ if (baseFileName === file) {
213
+ baseFileName = baseClass.split('.');
214
+ baseFileName = baseFileName.map(e => capitalize(e)).join('');
215
+ }
207
216
 
208
- if (index > 0) {
209
- viewFile = path.join(classFolder, file.substr(0, index) + '.mjs');
217
+ console.log(baseFileName, baseClass);
218
+
219
+ fs.writeFileSync(path.join(classFolder, file + '.mjs'), createContent({
220
+ baseClass,
221
+ baseFileName,
222
+ className,
223
+ file,
224
+ folderDelta,
225
+ ns,
226
+ root
227
+ }));
228
+
229
+ switch(baseClass) {
230
+ case 'controller.Component': {
231
+ baseType = 'Neo.controller.Component';
232
+ configName = 'controller';
233
+ importName = file;
234
+ importPath = `./${importName}.mjs`;
235
+ index = file.indexOf('Controller');
236
+
237
+ if (index > 0) {
238
+ viewFile = path.join(classFolder, file.substr(0, index) + '.mjs');
239
+
240
+ if (fs.existsSync(viewFile)) {
241
+ adjustView({baseType, configName, importName, importPath, viewFile});
242
+ }
243
+ }
244
+ break;
245
+ }
246
+
247
+ case 'data.Store': {
248
+ baseType = 'Neo.data.Model';
249
+ configName = 'model';
250
+ importName = className.replace('.store.', '.model.');
210
251
 
252
+ if (importName.endsWith('ies')) {
253
+ importName.replace(new RegExp('ies$'), 'y')
254
+ } else {
255
+ importName = importName.slice(0, -1);
256
+ }
257
+
258
+ viewFile = importName.split('.');
259
+ viewFile.shift();
260
+
261
+ importPath = `../${viewFile.join('/')}.mjs`;
262
+ viewFile = path.join(classFolder, importPath);
263
+
264
+ // checking for the data.Model file
211
265
  if (fs.existsSync(viewFile)) {
212
- adjustView({baseType, configName, file, viewFile});
266
+ // adjusting the data.Store file
267
+ viewFile = path.join(classFolder, file + '.mjs');
268
+ importName = importName.split('.');
269
+ importName = importName.pop();
270
+
271
+ adjustView({baseType, configName, importName, importPath, viewFile});
213
272
  }
273
+ break;
214
274
  }
215
- } else if (baseClass === 'model.Component') {
216
- baseType = 'Neo.model.Component';
217
- configName = 'model';
218
- index = file.indexOf('Model');
219
275
 
220
- if (index > 0) {
221
- viewFile = path.join(classFolder, file.substr(0, index) + '.mjs');
276
+ case 'model.Component': {
277
+ baseType = 'Neo.model.Component';
278
+ configName = 'model';
279
+ importName = file;
280
+ importPath = `./${importName}.mjs`;
281
+ index = file.indexOf('Model');
222
282
 
223
- if (fs.existsSync(viewFile)) {
224
- adjustView({baseType, configName, file, viewFile});
283
+ if (index > 0) {
284
+ viewFile = path.join(classFolder, file.substr(0, index) + '.mjs');
285
+
286
+ if (fs.existsSync(viewFile)) {
287
+ adjustView({baseType, configName, importName, importPath, viewFile});
288
+ }
225
289
  }
290
+ break;
226
291
  }
227
292
  }
228
293
  }
@@ -274,19 +339,20 @@ if (programOpts.info) {
274
339
  * @param {Object} opts
275
340
  * @param {String} opts.baseType
276
341
  * @param {String} opts.configName
277
- * @param {String} opts.file
342
+ * @param {String} opts.importName
343
+ * @param {String} opts.importPath
278
344
  * @param {String} opts.viewFile
279
345
  */
280
346
  function adjustView(opts) {
281
347
  let baseType = opts.baseType,
282
348
  configName = opts.configName,
283
- file = opts.file,
349
+ importName = opts.importName,
284
350
  viewFile = opts.viewFile,
285
351
  content = fs.readFileSync(viewFile).toString().split(os.EOL),
286
352
  fromMaxPosition = 0,
287
353
  i = 0,
288
354
  len = content.length,
289
- adjustSpaces, className, codeLine, fromPosition, importLength, importName, j, nextLine, spaces;
355
+ adjustSpaces, className, codeLine, existingImportName, fromPosition, importLength, j, nextLine, spaces;
290
356
 
291
357
  // find the index where we want to insert our import statement
292
358
  for (; i < len; i++) {
@@ -296,16 +362,16 @@ if (programOpts.info) {
296
362
  break;
297
363
  }
298
364
 
299
- importName = codeLine.substr(7);
300
- importName = importName.substr(0, importName.indexOf(' '));
301
- importLength = importName.length;
365
+ existingImportName = codeLine.substr(7);
366
+ existingImportName = existingImportName.substr(0, existingImportName.indexOf(' '));
367
+ importLength = existingImportName.length;
302
368
 
303
- if (importName > file) {
369
+ if (existingImportName > importName) {
304
370
  break;
305
371
  }
306
372
  }
307
373
 
308
- content.splice(i, 0, `import ${file} from './${file}.mjs';`);
374
+ content.splice(i, 0, `import ${importName} from '${opts.importPath}';`);
309
375
 
310
376
  // find the longest import module name
311
377
  for (i=0; i < len; i++) {
@@ -357,7 +423,7 @@ if (programOpts.info) {
357
423
  addComma(content, i - 1);
358
424
  addConfig({
359
425
  baseType,
360
- className : file,
426
+ className : importName,
361
427
  configName,
362
428
  contentArray: content,
363
429
  index : i,
@@ -379,7 +445,7 @@ if (programOpts.info) {
379
445
  if (content[j].includes('/**')) {
380
446
  addConfig({
381
447
  baseType,
382
- className : file,
448
+ className : importName,
383
449
  configName,
384
450
  contentArray: content,
385
451
  index : j,
@@ -396,10 +462,20 @@ if (programOpts.info) {
396
462
  fs.writeFileSync(viewFile, content.join(os.EOL));
397
463
  }
398
464
 
465
+ /**
466
+ * Makes the first character of a string uppercase
467
+ * @param {String} value
468
+ * @returns {Boolean|String} Returns false for non string inputs
469
+ */
470
+ function capitalize(value) {
471
+ return typeof value === 'string' && value[0].toUpperCase() + value.slice(1);
472
+ }
473
+
399
474
  /**
400
475
  * Creates the content of the neo-class .mjs file
401
476
  * @param {Object} opts
402
477
  * @param {String} opts.baseClass
478
+ * @param {String} opts.baseFileName
403
479
  * @param {String} opts.className
404
480
  * @param {String} opts.file
405
481
  * @param {String} opts.folderDelta
@@ -408,20 +484,20 @@ if (programOpts.info) {
408
484
  * @returns {String}
409
485
  */
410
486
  function createContent(opts) {
411
- let baseClass = opts.baseClass,
412
- baseClassNs = baseClass.split('.'),
413
- baseFileName = baseClassNs.pop(),
414
- className = opts.className,
415
- file = opts.file,
416
- i = 0,
417
- importDelta = '';
487
+ let baseClass = opts.baseClass,
488
+ baseFileName = opts.baseFileName,
489
+ baseClassPath = baseClass.split('.').join('/'),
490
+ className = opts.className,
491
+ file = opts.file,
492
+ i = 0,
493
+ importDelta = '';
418
494
 
419
495
  for (; i < opts.folderDelta; i++) {
420
496
  importDelta += '../';
421
497
  }
422
498
 
423
499
  let classContent = [
424
- `import ${baseFileName} from '${importDelta}${(insideNeo ? '' : 'node_modules/neo.mjs/')}src/${baseClassNs.join('/')}/${baseFileName}.mjs';`,
500
+ `import ${baseFileName} from '${importDelta}${(insideNeo ? '' : 'node_modules/neo.mjs/')}src/${baseClassPath}.mjs';`,
425
501
  "",
426
502
  "/**",
427
503
  ` * @class ${className}`,
@@ -436,6 +512,16 @@ if (programOpts.info) {
436
512
  ` className: '${className}'`
437
513
  ];
438
514
 
515
+ baseClass === 'data.Model' && addComma(classContent).push(
516
+ " /*",
517
+ " * @member {Object[]} fields",
518
+ " */",
519
+ " fields: [{",
520
+ " name: 'id',",
521
+ " type: 'String'",
522
+ " }]"
523
+ );
524
+
439
525
  baseClass === 'container.Base' && addComma(classContent).push(
440
526
  " /*",
441
527
  " * @member {Object[]} items",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo.mjs",
3
- "version": "4.0.64",
3
+ "version": "4.0.65",
4
4
  "description": "The webworkers driven UI framework",
5
5
  "type": "module",
6
6
  "repository": {
package/src/core/Util.mjs CHANGED
@@ -40,11 +40,11 @@ class Util extends Base {
40
40
 
41
41
  /**
42
42
  * Makes the first character of a string uppercase
43
- * @param {String} string
43
+ * @param {String} value
44
44
  * @returns {Boolean|String} Returns false for non string inputs
45
45
  */
46
- static capitalize(string) {
47
- return Util.isString(string) && string[0].toUpperCase() + string.slice(1);
46
+ static capitalize(value) {
47
+ return Util.isString(value) && value[0].toUpperCase() + value.slice(1);
48
48
  }
49
49
 
50
50
  /**
@@ -100,7 +100,7 @@ class Util extends Base {
100
100
  }
101
101
 
102
102
  /**
103
- * Transforms all uppercase characters of a string into lowercase.
103
+ * Transforms all uppercase characters of a string into -lowercase.
104
104
  * Does not touch special characters.
105
105
  * @param {String} value The input containing uppercase characters
106
106
  * @returns {String} The lowercase output