neo.mjs 3.0.5 → 3.1.2

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.
Files changed (34) hide show
  1. package/README.md +0 -2
  2. package/apps/website/data/blog.json +26 -0
  3. package/buildScripts/buildAll.mjs +136 -0
  4. package/buildScripts/buildThemes.mjs +434 -0
  5. package/buildScripts/{copyFolder.js → copyFolder.mjs} +3 -5
  6. package/buildScripts/createApp.mjs +288 -0
  7. package/buildScripts/docs/{jsdocx.js → jsdocx.mjs} +31 -32
  8. package/buildScripts/webpack/buildMyApps.mjs +125 -0
  9. package/buildScripts/webpack/buildThreads.mjs +115 -0
  10. package/buildScripts/webpack/development/{webpack.config.appworker.js → webpack.config.appworker.mjs} +20 -22
  11. package/buildScripts/webpack/development/webpack.config.main.mjs +24 -0
  12. package/buildScripts/webpack/development/{webpack.config.myapps.js → webpack.config.myapps.mjs} +15 -15
  13. package/buildScripts/webpack/development/{webpack.config.worker.js → webpack.config.worker.mjs} +12 -9
  14. package/buildScripts/webpack/production/{webpack.config.appworker.js → webpack.config.appworker.mjs} +20 -22
  15. package/buildScripts/webpack/production/webpack.config.main.mjs +23 -0
  16. package/buildScripts/webpack/production/{webpack.config.myapps.js → webpack.config.myapps.mjs} +15 -15
  17. package/buildScripts/webpack/production/{webpack.config.worker.js → webpack.config.worker.mjs} +12 -9
  18. package/buildScripts/webpack/{webpack.server.config.js → webpack.server.config.mjs} +2 -2
  19. package/docs/app/view/classdetails/MembersList.mjs +7 -13
  20. package/package.json +14 -13
  21. package/src/DefaultConfig.mjs +1 -1
  22. package/src/Neo.mjs +13 -13
  23. package/src/list/plugin/Animate.mjs +59 -11
  24. package/src/main/addon/AmCharts.mjs +2 -2
  25. package/src/manager/DomEvent.mjs +1 -1
  26. package/src/worker/Base.mjs +6 -5
  27. package/buildScripts/buildAll.js +0 -148
  28. package/buildScripts/buildThemes.js +0 -442
  29. package/buildScripts/createApp.js +0 -283
  30. package/buildScripts/webpack/buildMyApps.js +0 -125
  31. package/buildScripts/webpack/buildThreads.js +0 -112
  32. package/buildScripts/webpack/development/webpack.config.main.js +0 -21
  33. package/buildScripts/webpack/index.ejs +0 -25
  34. package/buildScripts/webpack/production/webpack.config.main.js +0 -20
@@ -1,442 +0,0 @@
1
- 'use strict';
2
-
3
- const autoprefixer = require('autoprefixer'),
4
- chalk = require('chalk'),
5
- {program} = require('commander'),
6
- cssnano = require('cssnano'),
7
- cwd = process.cwd(),
8
- envinfo = require('envinfo'),
9
- fs = require('fs-extra'),
10
- inquirer = require('inquirer'),
11
- path = require('path'),
12
- packageJson = require(path.resolve(cwd, 'package.json')),
13
- neoPath = packageJson.name === 'neo.mjs' ? './' : './node_modules/neo.mjs/',
14
- programName = `${packageJson.name} buildThemes`,
15
- postcss = require('postcss'),
16
- sass = require('sass'),
17
- regexComments = /\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,
18
- regexLineBreak = /(\r\n|\n|\r)/gm,
19
- regexSassImport = /@import[^'"]+?['"](.+?)['"];?/g,
20
- scssFolders = fs.readdirSync(path.join(neoPath, '/resources/scss')),
21
- scssPath = 'resources/scss/',
22
- themeMapFile = 'resources/theme-map.json',
23
- themeMapFileNoVars = 'resources/theme-map-no-vars.json',
24
- themeFolders = [],
25
- questions = [];
26
-
27
- scssFolders.forEach(folder => {
28
- if (folder.includes('theme')) {
29
- themeFolders.push(folder);
30
- }
31
- });
32
-
33
- program
34
- .name(programName)
35
- .version(packageJson.version)
36
- .option('-i, --info', 'print environment debug info')
37
- .option('-c, --cssVars <value>', '"all", "true", "false"')
38
- .option('-e, --env <value>', '"all", "dev", "prod"')
39
- .option('-f, --framework')
40
- .option('-n, --noquestions')
41
- .option('-t, --themes <value>', ["all", ...themeFolders].join(", "))
42
- .allowUnknownOption()
43
- .on('--help', () => {
44
- console.log('\nIn case you have any issues, please create a ticket here:');
45
- console.log(chalk.cyan(packageJson.bugs.url));
46
- })
47
- .parse(process.argv);
48
-
49
- const programOpts = program.opts();
50
-
51
- if (programOpts.info) {
52
- console.log(chalk.bold('\nEnvironment Info:'));
53
- console.log(`\n current version of ${packageJson.name}: ${packageJson.version}`);
54
- console.log(` running from ${__dirname}`);
55
- return envinfo
56
- .run({
57
- System : ['OS', 'CPU'],
58
- Binaries : ['Node', 'npm', 'Yarn'],
59
- Browsers : ['Chrome', 'Edge', 'Firefox', 'Safari'],
60
- npmPackages : ['neo.mjs'],
61
- npmGlobalPackages: ['neo-app']
62
- }, {
63
- duplicates : true,
64
- showNotFound: true
65
- })
66
- .then(console.log);
67
- }
68
-
69
- console.log(chalk.green(programName));
70
-
71
- if (!programOpts.noquestions) {
72
- if (!programOpts.themes) {
73
- questions.push({
74
- type : 'list',
75
- name : 'themes',
76
- message: 'Please choose the themes to build:',
77
- choices: ['all', ...themeFolders],
78
- default: 'all'
79
- });
80
- }
81
-
82
- if (!programOpts.env) {
83
- questions.push({
84
- type : 'list',
85
- name : 'env',
86
- message: 'Please choose the environment:',
87
- choices: ['all', 'dev', 'prod'],
88
- default: 'all'
89
- });
90
- }
91
-
92
- if (!programOpts.cssVars) {
93
- questions.push({
94
- type : 'list',
95
- name : 'cssVars',
96
- message: 'Build using CSS variables?',
97
- choices: ['all', 'yes', 'no'],
98
- default: 'yes'
99
- });
100
- }
101
- }
102
-
103
- inquirer.prompt(questions).then(answers => {
104
- const cssVars = answers.cssVars || programOpts.cssVars || 'all',
105
- env = answers.env || programOpts.env || 'all',
106
- themes = answers.themes || programOpts.themes || 'all',
107
- insideNeo = programOpts.framework || false,
108
- startDate = new Date(),
109
- fileCount = {development: {vars: 0, noVars: 0}, production: {vars: 0, noVars: 0}},
110
- totalFiles = {development: {vars: 0, noVars: 0}, production: {vars: 0, noVars: 0}},
111
- sassThemes = [];
112
-
113
- let themeMap, themeMapNoVars;
114
-
115
- /**
116
- *
117
- * @param {Object} file
118
- * @param {String} target
119
- * @param {Boolean} useCssVars
120
- */
121
- function addItemToThemeMap(file, target, useCssVars) {
122
- let classPath = file.className.split('.'),
123
- fileName = classPath.pop(),
124
- namespace;
125
-
126
- classPath = classPath.join('.');
127
- namespace = ns(classPath, true, useCssVars ? themeMap : themeMapNoVars);
128
-
129
- if (!namespace[fileName]) {
130
- namespace[fileName] = [target];
131
- } else {
132
- if (!namespace[fileName].includes(target)) {
133
- namespace[fileName].push(target);
134
- }
135
- }
136
- }
137
-
138
- /**
139
- *
140
- * @param {String} p
141
- * @param {String} mode development or production
142
- */
143
- function buildEnv(p, mode) {
144
- if (cssVars !== 'no') {
145
- parseScssFiles(getAllScssFiles(path.join(p, 'src')), mode, 'src', true);
146
- }
147
-
148
- if (cssVars !== 'no') {
149
- themeFolders.forEach(themeFolder => {
150
- if (themes === 'all' || themes === themeFolder) {
151
- parseScssFiles(getAllScssFiles(path.join(p, themeFolder)), mode, themeFolder, true);
152
- }
153
- });
154
- }
155
-
156
- if (cssVars !== 'yes') {
157
- themeFolders.forEach(themeFolder => {
158
- if (themes === 'all' || themes === themeFolder) {
159
- parseScssFiles(getAllScssFiles(path.join(p, 'src')), mode, themeFolder, false);
160
- }
161
- });
162
- }
163
- }
164
-
165
- /**
166
- *
167
- * @param {String} dirPath
168
- * @returns {Object[]}
169
- */
170
- function getAllScssFiles(dirPath) {
171
- const files = getScssFiles(path.resolve(neoPath, dirPath));
172
-
173
- if (!insideNeo) {
174
- files.push(...getScssFiles(path.resolve(cwd, dirPath)));
175
- }
176
-
177
- return files;
178
- }
179
-
180
- /**
181
- *
182
- * @param {String} dirPath
183
- * @param [arrayOfFiles=[]]
184
- * @param [relativePath='']
185
- * @returns {Object[]}
186
- */
187
- function getScssFiles(dirPath, arrayOfFiles=[], relativePath='') {
188
- let files = fs.readdirSync(dirPath),
189
- className, fileInfo, filePath;
190
-
191
- files.forEach(file => {
192
- filePath = path.join(dirPath + '/' + file);
193
-
194
- if (fs.statSync(filePath).isDirectory()) {
195
- arrayOfFiles = getScssFiles(filePath, arrayOfFiles, relativePath + '/' + file);
196
- } else {
197
- fileInfo = path.parse(file);
198
-
199
- if (!fileInfo.name.startsWith('_')) {
200
- className = relativePath === '' ? fileInfo.name : `${relativePath.substring(1)}/${fileInfo.name}`;
201
- className = className.split('/').join('.');
202
-
203
- if (className.startsWith('apps.')) {
204
- className = className.split('.');
205
- className[0].toLowerCase();
206
- className = className.join('.');
207
- } else {
208
- className = 'Neo.' + className;
209
- }
210
-
211
- arrayOfFiles.push({
212
- className : className,
213
- name : fileInfo.name,
214
- path : filePath,
215
- relativePath: relativePath
216
- });
217
- }
218
- }
219
- });
220
-
221
- return arrayOfFiles;
222
- }
223
-
224
- /**
225
- *
226
- * @param {String} filePath
227
- * @returns {Object}
228
- */
229
- function getThemeMap(filePath) {
230
- let themeMapJson = path.resolve(cwd, filePath),
231
- themeMap;
232
-
233
- if (fs.existsSync(themeMapJson)) {
234
- themeMap = require(themeMapJson);
235
- } else {
236
- themeMapJson = path.resolve(neoPath, filePath);
237
-
238
- if (fs.existsSync(themeMapJson)) {
239
- themeMap = require(themeMapJson);
240
- } else {
241
- themeMap = {};
242
- }
243
- }
244
-
245
- return themeMap;
246
- }
247
-
248
- /**
249
- *
250
- * @param {Array|String} names The class name string containing dots or an Array of the string parts
251
- * @param {Boolean} [create] Set create to true to create empty objects for non existing parts
252
- * @param {Object} [scope] Set a different starting point as self
253
- * @returns {Object} reference to the toplevel namespace
254
- */
255
- function ns(names, create, scope) {
256
- names = Array.isArray(names) ? names : names.split('.');
257
-
258
- return names.reduce((prev, current) => {
259
- if (create && !prev[current]) {
260
- prev[current] = {};
261
- }
262
- if (prev) {
263
- return prev[current];
264
- }
265
- }, scope);
266
- }
267
-
268
- /**
269
- *
270
- * @param {Object[]} files
271
- * @param {String} mode development or production
272
- * @param {String} target src or a theme
273
- * @param {Boolean} useCssVars
274
- */
275
- function parseScssFiles(files, mode, target, useCssVars) {
276
- let data = '',
277
- devMode = mode === 'development',
278
- mixinPath = path.resolve(neoPath, 'resources/scss/mixins/_all.scss'),
279
- suffix = useCssVars ? '' : '-no-vars',
280
- varsFlag = useCssVars ? 'vars' : 'noVars',
281
- map, neoThemePath, themeBuffer, themePath, workspaceThemePath;
282
-
283
- totalFiles[mode][varsFlag] += files.length;
284
-
285
- if (path.sep === '\\') {
286
- mixinPath = mixinPath.replace(/\\/g, '/');
287
- }
288
-
289
- if (target.includes('theme')) {
290
- themePath = `resources/scss/${target}/_all.scss`;
291
- neoThemePath = path.resolve(neoPath, themePath);
292
-
293
- if (!sassThemes[target]) {
294
- themeBuffer = scssCombine(fs.readFileSync(neoThemePath).toString(), path.dirname(neoThemePath));
295
-
296
- if (!insideNeo) {
297
- workspaceThemePath = path.resolve(cwd, themePath);
298
- themeBuffer += scssCombine(fs.readFileSync(workspaceThemePath).toString(), path.dirname(workspaceThemePath));
299
- }
300
-
301
- themeBuffer = themeBuffer.replace(regexComments, '');
302
- themeBuffer = themeBuffer.replace(regexLineBreak, '');
303
-
304
- sassThemes[target] = themeBuffer;
305
- }
306
-
307
- data = [
308
- `@use "sass:map";`,
309
- `@use "sass:math";`,
310
- `$neoMap: ();`,
311
- `$useCssVars: ${useCssVars};`,
312
- `@import "${mixinPath}";`,
313
- `$useCssVars: false;`,
314
- `${sassThemes[target]}`,
315
- `$useCssVars: ${useCssVars};`
316
- ].join('');
317
- } else {
318
- data = [
319
- `@use "sass:map";`,
320
- `@use "sass:math";`,
321
- `$neoMap: ();`,
322
- `$useCssVars: ${useCssVars};`,
323
- `@import "${mixinPath}";`
324
- ].join('');
325
- }
326
-
327
- files.forEach(file => {
328
- addItemToThemeMap(file, target, useCssVars);
329
-
330
- let folderPath = path.resolve(cwd, `dist/${mode}/css${suffix}/${target}/${file.relativePath}`),
331
- destPath = path.resolve(folderPath, `${file.name}.css`);
332
-
333
- fs.readFile(file.path).then(content => {
334
- let result = sass.renderSync({
335
- data : data + scssCombine(content.toString(), path.resolve(neoPath, scssPath, target, file.relativePath)),
336
- outFile : destPath,
337
- sourceMap : devMode,
338
- sourceMapEmbed: false
339
- });
340
-
341
- const plugins = [autoprefixer];
342
-
343
- if (mode === 'production') {
344
- plugins.push(cssnano);
345
- }
346
-
347
- map = result.map?.toString();
348
-
349
- if (map) {
350
- // https://github.com/neomjs/neo/issues/1970
351
- map = JSON.parse(map);
352
- let len = file.relativePath.split('/').length,
353
- src = `${target}${file.relativePath}/${file.name}.scss`,
354
- i = 0;
355
-
356
- for (; i < len; i++) {
357
- src = '../' + src;
358
- }
359
-
360
- map.sources = [src];
361
- }
362
-
363
- postcss(plugins).process(result.css, {
364
- from: file.path,
365
- to : destPath,
366
- map : !devMode ? null : {
367
- prev: map && JSON.stringify(map)
368
- }
369
- }).then(result => {
370
- fs.mkdirpSync(folderPath);
371
- fileCount[mode][varsFlag]++;
372
-
373
- const processTime = (Math.round((new Date - startDate) * 100) / 100000).toFixed(2);
374
- console.log('Writing file:', (fileCount[mode].vars + fileCount[mode].noVars), chalk.blue(`${processTime}s`), destPath);
375
- fs.writeFileSync(destPath, result.css, () => true);
376
-
377
- if (result.map) {
378
- fs.writeFileSync(result.opts.to + '.map', result.map.toString());
379
- }
380
-
381
- if (fileCount[mode][varsFlag] === totalFiles[mode][varsFlag]) {
382
- fs.writeFileSync(
383
- path.resolve(cwd, useCssVars ? themeMapFile : themeMapFileNoVars),
384
- JSON.stringify(useCssVars ? themeMap : themeMapNoVars, null, 0)
385
- );
386
-
387
- fs.mkdirpSync(path.join(cwd, '/dist/', mode, '/resources'), {
388
- recursive: true
389
- });
390
-
391
- fs.writeFileSync(
392
- path.join(cwd, '/dist/', mode, useCssVars ? themeMapFile : themeMapFileNoVars),
393
- JSON.stringify(useCssVars ? themeMap : themeMapNoVars, null, 0)
394
- );
395
- }
396
- });
397
- });
398
- });
399
- }
400
-
401
- /**
402
- *
403
- * @param {String} content
404
- * @param {String} baseDir
405
- * @returns {String}
406
- */
407
- function scssCombine (content, baseDir) {
408
- if (regexSassImport.test(content)) {
409
- content = content.replace(regexSassImport, (m, capture) => {
410
- let parse = path.parse(path.resolve(baseDir, capture)),
411
- file = path.resolve(`${parse.dir}/${parse.name}.scss`);
412
-
413
- if (!fs.existsSync(file)) {
414
- file = path.resolve(`${parse.dir}/_${parse.name}.scss`);
415
-
416
- if (!fs.existsSync(file)) {
417
- return '';
418
- }
419
- }
420
-
421
- return scssCombine(fs.readFileSync(file).toString(), path.dirname(file));
422
- });
423
- }
424
-
425
- return content;
426
- }
427
-
428
- if (cssVars !== 'no') {themeMap = getThemeMap(themeMapFile);}
429
- if (cssVars !== 'yes') {themeMapNoVars = getThemeMap(themeMapFileNoVars);}
430
-
431
- // dist/development
432
- if (env === 'all' || env === 'dev') {
433
- console.log(chalk.blue(`${programName} starting dist/development`));
434
- buildEnv(path.join(scssPath), 'development');
435
- }
436
-
437
- // dist/production
438
- if (env === 'all' || env === 'prod') {
439
- console.log(chalk.blue(`${programName} starting dist/production`));
440
- buildEnv(path.join(scssPath), 'production');
441
- }
442
- });