neo.mjs 3.0.6 → 3.1.3

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 (37) hide show
  1. package/README.md +0 -2
  2. package/apps/covid/Util.mjs +3 -3
  3. package/apps/sharedcovid/Util.mjs +3 -3
  4. package/apps/sharedcovid/view/MainContainerController.mjs +1 -1
  5. package/apps/website/data/blog.json +26 -0
  6. package/buildScripts/buildAll.mjs +137 -0
  7. package/buildScripts/buildThemes.mjs +436 -0
  8. package/buildScripts/{copyFolder.js → copyFolder.mjs} +3 -5
  9. package/buildScripts/createApp.mjs +289 -0
  10. package/buildScripts/docs/{jsdocx.js → jsdocx.mjs} +32 -32
  11. package/buildScripts/webpack/buildMyApps.mjs +126 -0
  12. package/buildScripts/webpack/buildThreads.mjs +116 -0
  13. package/buildScripts/webpack/development/{webpack.config.appworker.js → webpack.config.appworker.mjs} +20 -22
  14. package/buildScripts/webpack/development/webpack.config.main.mjs +24 -0
  15. package/buildScripts/webpack/development/{webpack.config.myapps.js → webpack.config.myapps.mjs} +15 -15
  16. package/buildScripts/webpack/development/{webpack.config.worker.js → webpack.config.worker.mjs} +12 -9
  17. package/buildScripts/webpack/production/{webpack.config.appworker.js → webpack.config.appworker.mjs} +20 -22
  18. package/buildScripts/webpack/production/webpack.config.main.mjs +23 -0
  19. package/buildScripts/webpack/production/{webpack.config.myapps.js → webpack.config.myapps.mjs} +15 -15
  20. package/buildScripts/webpack/production/{webpack.config.worker.js → webpack.config.worker.mjs} +12 -9
  21. package/buildScripts/webpack/{webpack.server.config.js → webpack.server.config.mjs} +2 -2
  22. package/docs/app/view/classdetails/MembersList.mjs +7 -13
  23. package/package.json +14 -13
  24. package/src/DefaultConfig.mjs +1 -1
  25. package/src/Neo.mjs +13 -13
  26. package/src/core/Base.mjs +8 -6
  27. package/src/main/addon/AmCharts.mjs +2 -2
  28. package/src/manager/DomEvent.mjs +1 -1
  29. package/src/worker/Base.mjs +6 -5
  30. package/buildScripts/buildAll.js +0 -148
  31. package/buildScripts/buildThemes.js +0 -442
  32. package/buildScripts/createApp.js +0 -283
  33. package/buildScripts/webpack/buildMyApps.js +0 -125
  34. package/buildScripts/webpack/buildThreads.js +0 -112
  35. package/buildScripts/webpack/development/webpack.config.main.js +0 -21
  36. package/buildScripts/webpack/index.ejs +0 -25
  37. package/buildScripts/webpack/production/webpack.config.main.js +0 -20
@@ -0,0 +1,289 @@
1
+ import chalk from 'chalk';
2
+ import { spawnSync } from 'child_process';
3
+ import { Command } from 'commander/esm.mjs';
4
+ import envinfo from 'envinfo';
5
+ import fs from 'fs-extra';
6
+ import inquirer from 'inquirer';
7
+ import os from 'os';
8
+ import path from 'path';
9
+ import { fileURLToPath } from 'url';
10
+
11
+ const __dirname = fileURLToPath(path.dirname(import.meta.url)),
12
+ cwd = process.cwd(),
13
+ requireJson = path => JSON.parse(fs.readFileSync((path))),
14
+ packageJson = requireJson(path.join(__dirname, 'package.json')),
15
+ insideNeo = packageJson.name === 'neo.mjs',
16
+ neoPath = insideNeo ? './' : './node_modules/neo.mjs/',
17
+ addonChoices = fs.readdirSync(path.join(neoPath, '/src/main/addon')).map(item => item.slice(0, -4)),
18
+ program = new Command(),
19
+ programName = `${packageJson.name} create-app`,
20
+ questions = [],
21
+ scssFolders = fs.readdirSync(path.join(neoPath, '/resources/scss')),
22
+ themeFolders = [];
23
+
24
+ scssFolders.forEach(folder => {
25
+ if (folder.includes('theme')) {
26
+ themeFolders.push(`neo-${folder}`);
27
+ }
28
+ });
29
+
30
+ program
31
+ .name(programName)
32
+ .version(packageJson.version)
33
+ .option('-i, --info', 'print environment debug info')
34
+ .option('-a, --appName <value>')
35
+ .option('-m, --mainThreadAddons <value>', `Comma separated list of:\n${addonChoices.join(', ')}\nDefaults to DragDrop, Stylesheet`)
36
+ .option('-t, --themes <value>', ['all', ...themeFolders, 'none'].join(", "))
37
+ .option('-u, --useSharedWorkers <value>', '"yes", "no"')
38
+ .allowUnknownOption()
39
+ .on('--help', () => {
40
+ console.log('\nIn case you have any issues, please create a ticket here:');
41
+ console.log(chalk.cyan(process.env.npm_package_bugs_url));
42
+ })
43
+ .parse(process.argv);
44
+
45
+ const programOpts = program.opts();
46
+
47
+ if (programOpts.info) {
48
+ console.log(chalk.bold('\nEnvironment Info:'));
49
+ console.log(`\n current version of ${packageJson.name}: ${packageJson.version}`);
50
+ console.log(` running from ${__dirname}`);
51
+
52
+ envinfo
53
+ .run({
54
+ System : ['OS', 'CPU'],
55
+ Binaries : ['Node', 'npm', 'Yarn'],
56
+ Browsers : ['Chrome', 'Edge', 'Firefox', 'Safari'],
57
+ npmPackages: ['neo.mjs']
58
+ }, {
59
+ duplicates : true,
60
+ showNotFound: true
61
+ })
62
+ .then(console.log);
63
+ } else {
64
+ console.log(chalk.green(programName));
65
+
66
+ if (programOpts.mainThreadAddons) {
67
+ programOpts.mainThreadAddons = programOpts.mainThreadAddons.split(',');
68
+ }
69
+
70
+ if (!programOpts.appName) {
71
+ questions.push({
72
+ type : 'input',
73
+ name : 'appName',
74
+ message: 'Please choose a name for your neo app:',
75
+ default: 'MyApp'
76
+ });
77
+ }
78
+
79
+ if (!programOpts.themes) {
80
+ questions.push({
81
+ type : 'list',
82
+ name : 'themes',
83
+ message: 'Please choose a theme for your neo app:',
84
+ choices: ['all', ...themeFolders, 'none'],
85
+ default: 'all'
86
+ });
87
+ }
88
+
89
+ if (!programOpts.mainThreadAddons) {
90
+ questions.push({
91
+ type : 'checkbox',
92
+ name : 'mainThreadAddons',
93
+ message: 'Please choose your main thread addons:',
94
+ choices: addonChoices,
95
+ default: ['DragDrop', 'Stylesheet']
96
+ });
97
+ }
98
+
99
+ if (!programOpts.useSharedWorkers) {
100
+ questions.push({
101
+ type : 'list',
102
+ name : 'useSharedWorkers',
103
+ message: 'Do you want to use SharedWorkers? Pick yes for multiple main threads (Browser Windows):',
104
+ choices: ['yes', 'no'],
105
+ default: 'no'
106
+ });
107
+ }
108
+
109
+ inquirer.prompt(questions).then(answers => {
110
+ let appName = programOpts.appName || answers.appName,
111
+ mainThreadAddons = programOpts.mainThreadAddons || answers.mainThreadAddons,
112
+ themes = programOpts.themes || answers.themes,
113
+ useSharedWorkers = programOpts.useSharedWorkers || answers.useSharedWorkers,
114
+ lAppName = appName.toLowerCase(),
115
+ appPath = 'apps/' + lAppName + '/',
116
+ dir = 'apps/' + lAppName,
117
+ folder = path.resolve(cwd, dir),
118
+ startDate = new Date();
119
+
120
+ if (!Array.isArray(themes)) {
121
+ themes = [themes];
122
+ }
123
+
124
+ if (themes.length > 0 && !themes.includes('none') && !mainThreadAddons.includes('Stylesheet')) {
125
+ console.error('ERROR! The Stylesheet mainThreadAddon is mandatory in case you are using themes');
126
+ console.log('Exiting with error.');
127
+ process.exit(1);
128
+ }
129
+
130
+ fs.mkdir(path.join(folder, '/view'), { recursive: true }, (err) => {
131
+ if (err) {
132
+ throw err;
133
+ }
134
+
135
+ const appContent = [
136
+ "import MainContainer from './view/MainContainer.mjs';",
137
+ "",
138
+ "const onStart = () => Neo.app({",
139
+ " mainView: MainContainer,",
140
+ " name : '" + appName + "'",
141
+ "});",
142
+ "",
143
+ "export {onStart as onStart};"
144
+ ].join(os.EOL);
145
+
146
+ fs.writeFileSync(folder + '/app.mjs', appContent);
147
+
148
+ const indexContent = [
149
+ "<!DOCTYPE HTML>",
150
+ "<html>",
151
+ "<head>",
152
+ ' <meta name="viewport" content="width=device-width, initial-scale=1">',
153
+ ' <meta charset="UTF-8">',
154
+ " <title>" + appName + "</title>",
155
+ "</head>",
156
+ "<body>",
157
+ ' <script src="../../src/MicroLoader.mjs" type="module"></script>',
158
+ "</body>",
159
+ "</html>",
160
+ ];
161
+
162
+ fs.writeFileSync(path.join(folder, 'index.html'), indexContent.join(os.EOL));
163
+
164
+ let neoConfig = {
165
+ appPath : `${insideNeo ? '' : '../../'}${appPath}app.mjs`,
166
+ basePath : '../../',
167
+ environment: 'development',
168
+ mainPath : './Main.mjs'
169
+ };
170
+
171
+ if (!(mainThreadAddons.includes('DragDrop') && mainThreadAddons.includes('Stylesheet') && mainThreadAddons.length === 2)) {
172
+ neoConfig.mainThreadAddons = mainThreadAddons;
173
+ }
174
+
175
+ if (!themes.includes('all')) { // default value
176
+ if (themes.includes('none')) {
177
+ neoConfig.themes = [];
178
+ } else {
179
+ neoConfig.themes = themes;
180
+ }
181
+ }
182
+
183
+ if (useSharedWorkers !== 'no') {
184
+ neoConfig.useSharedWorkers = true;
185
+ }
186
+
187
+ if (!insideNeo) {
188
+ neoConfig.workerBasePath = '../../node_modules/neo.mjs/src/worker/';
189
+ }
190
+
191
+ let configs = Object.entries(neoConfig).sort((a, b) => a[0].localeCompare(b[0]));
192
+ neoConfig = {};
193
+
194
+ configs.forEach(([key, value]) => {
195
+ neoConfig[key] = value;
196
+ });
197
+
198
+ fs.writeFileSync(path.join(folder, 'neo-config.json'), JSON.stringify(neoConfig, null, 4));
199
+
200
+ const mainContainerContent = [
201
+ "import Component from '../../../" + (insideNeo ? '' : 'node_modules/neo.mjs/') + "src/component/Base.mjs';",
202
+ "import TabContainer from '../../../" + (insideNeo ? '' : 'node_modules/neo.mjs/') + "src/tab/Container.mjs';",
203
+ "import Viewport from '../../../" + (insideNeo ? '' : 'node_modules/neo.mjs/') + "src/container/Viewport.mjs';",
204
+ "",
205
+ "/**",
206
+ " * @class " + appName + ".view.MainContainer",
207
+ " * @extends Neo.container.Viewport",
208
+ " */",
209
+ "class MainContainer extends Viewport {",
210
+ " static getConfig() {return {",
211
+ " className: '" + appName + ".view.MainContainer',",
212
+ " autoMount: true,",
213
+ " layout : {ntype: 'fit'},",
214
+ "",
215
+ " items: [{",
216
+ " module: TabContainer,",
217
+ " height: 300,",
218
+ " width : 500,",
219
+ " style : {flex: 'none', margin: '20px'},",
220
+ "",
221
+ " itemDefaults: {",
222
+ " module: Component,",
223
+ " cls : ['neo-examples-tab-component'],",
224
+ " style : {padding: '20px'},",
225
+ " },",
226
+ "",
227
+ " items: [{",
228
+ " tabButtonConfig: {",
229
+ " iconCls: 'fa fa-home',",
230
+ " text : 'Tab 1'",
231
+ " },",
232
+ " vdom: {innerHTML: 'Welcome to your new Neo App.'}",
233
+ " }, {",
234
+ " tabButtonConfig: {",
235
+ " iconCls: 'fa fa-play-circle',",
236
+ " text : 'Tab 2'",
237
+ " },",
238
+ " vdom: {innerHTML: 'Have fun creating something awesome!'}",
239
+ " }]",
240
+ " }]",
241
+ " }}",
242
+ "}",
243
+ "",
244
+ "Neo.applyClassConfig(MainContainer);",
245
+ "",
246
+ "export {MainContainer as default};"
247
+ ].join(os.EOL);
248
+
249
+ fs.writeFileSync(path.join(folder + '/view/MainContainer.mjs'), mainContainerContent);
250
+
251
+ let appJsonPath = path.resolve(cwd, 'buildScripts/myApps.json'),
252
+ appJson;
253
+
254
+ if (fs.existsSync(appJsonPath)) {
255
+ appJson = requireJson(appJsonPath);
256
+ } else {
257
+ appJsonPath = path.resolve(__dirname, 'buildScripts/webpack/json/myApps.json');
258
+
259
+ if (fs.existsSync(appJsonPath)) {
260
+ appJson = requireJson(appJsonPath);
261
+ } else {
262
+ appJson = requireJson(path.resolve(__dirname, 'buildScripts/webpack/json/myApps.template.json'));
263
+ }
264
+ }
265
+
266
+ if (!appJson.apps.includes(appName)) {
267
+ appJson.apps.push(appName);
268
+ appJson.apps.sort();
269
+ }
270
+
271
+ fs.writeFileSync(appJsonPath, JSON.stringify(appJson, null, 4));
272
+
273
+ if (mainThreadAddons.includes('HighlightJS')) {
274
+ spawnSync('node', [
275
+ './buildScripts/copyFolder.mjs',
276
+ '-s',
277
+ path.resolve(neoPath, 'docs/resources'),
278
+ '-t',
279
+ path.resolve(folder, 'resources'),
280
+ ], { env: process.env, cwd: process.cwd(), stdio: 'inherit' });
281
+ }
282
+
283
+ const processTime = (Math.round((new Date - startDate) * 100) / 100000).toFixed(2);
284
+ console.log(`\nTotal time for ${programName}: ${processTime}s`);
285
+
286
+ process.exit();
287
+ });
288
+ });
289
+ }
@@ -1,9 +1,13 @@
1
- const fs = require('fs-extra'),
2
- jsdocx = require('neo-jsdoc-x'),
3
- path = require('path'),
1
+ import fs from 'fs-extra';
2
+ import helper from 'neo-jsdoc-x/src/lib/helper.js';
3
+ import jsdocx from 'neo-jsdoc-x';
4
+ import path from 'path';
5
+ import { fileURLToPath } from 'url';
6
+
7
+ const __dirname = fileURLToPath(path.dirname(import.meta.url)),
4
8
  cwd = process.cwd(),
5
- helper = require(path.join(cwd, 'node_modules/neo-jsdoc-x/src/lib/helper.js')),
6
- packageJson = require(path.resolve(process.cwd(), 'package.json')),
9
+ requireJson = path => JSON.parse(fs.readFileSync((path))),
10
+ packageJson = requireJson(path.resolve(cwd, 'package.json')),
7
11
  insideNeo = packageJson.name === 'neo.mjs',
8
12
  neoPath = insideNeo ? '' : 'node_modules/neo.mjs/',
9
13
  appNames = [],
@@ -20,25 +24,23 @@ let appJsonPath = path.resolve(cwd, 'buildScripts/myApps.json'),
20
24
  appJson;
21
25
 
22
26
  if (fs.existsSync(appJsonPath)) {
23
- appJson = require(appJsonPath);
27
+ appJson = requireJson(appJsonPath);
24
28
  } else {
25
- appJsonPath = path.resolve(__dirname, '../webpack/json/myApps.json');
29
+ appJsonPath = path.resolve(__dirname, 'buildScripts/webpack/json/myApps.json');
26
30
 
27
31
  if (fs.existsSync(appJsonPath)) {
28
- appJson = require(appJsonPath);
32
+ appJson = requireJson(appJsonPath);
29
33
  } else {
30
- appJson = require(path.resolve(__dirname, '../webpack/json/myApps.template.json'));
34
+ appJson = requireJson(path.resolve(__dirname, 'buildScripts/webpack/json/myApps.template.json'));
31
35
  }
32
36
  }
33
37
 
34
- if (appJson) {
35
- appJson.apps.forEach(key => {
36
- if (key !== 'Docs') { // the docs app is automatically included
37
- appNames.push(key);
38
- options.files.push(`apps/${key.toLowerCase()}/**/*.mjs`);
39
- }
40
- });
41
- }
38
+ appJson?.apps.forEach(key => {
39
+ if (key !== 'Docs') { // the docs app is automatically included
40
+ appNames.push(key);
41
+ options.files.push(`apps/${key.toLowerCase()}/**/*.mjs`);
42
+ }
43
+ });
42
44
 
43
45
  function ns(names, create) {
44
46
  names = Array.isArray(names) ? names : names.split('.');
@@ -50,7 +52,7 @@ function ns(names, create) {
50
52
  if (prev) {
51
53
  return prev[current];
52
54
  }
53
- }, this);
55
+ }, globalThis);
54
56
  }
55
57
 
56
58
  const neoStructure = [{
@@ -199,15 +201,15 @@ function generateStructure(target, parentId, docs) {
199
201
  // console.log(srcPath);
200
202
 
201
203
  neoStructure.push({
202
- className: className,
204
+ className,
203
205
  collapsed: appNames.includes(key) || key === 'Docs',
204
- id : id,
205
- isLeaf : isLeaf,
206
+ id,
207
+ isLeaf,
206
208
  name : key,
207
- path : path,
208
- parentId : parentId,
209
- singleton: singleton,
210
- srcPath : srcPath
209
+ path,
210
+ parentId,
211
+ singleton,
212
+ srcPath
211
213
  });
212
214
 
213
215
  generateStructure(target + '.' + key, id, docs);
@@ -326,13 +328,11 @@ jsdocx.parse(options)
326
328
  item.description = item.description.replace(/\n/g, "<br />");
327
329
  }
328
330
 
329
- if (item.params) {
330
- item.params.forEach(param => {
331
- if (param.description) {
332
- param.description = param.description.replace(/\n/g, "<br />");
333
- }
334
- });
335
- }
331
+ item.params?.forEach(param => {
332
+ if (param.description) {
333
+ param.description = param.description.replace(/\n/g, "<br />");
334
+ }
335
+ });
336
336
 
337
337
  if (item.kind === 'member') {
338
338
  if (item.comment) {
@@ -0,0 +1,126 @@
1
+ import chalk from 'chalk';
2
+ import { spawnSync } from 'child_process';
3
+ import { Command } from 'commander/esm.mjs';
4
+ import envinfo from 'envinfo';
5
+ import fs from 'fs-extra';
6
+ import inquirer from 'inquirer';
7
+ import os from 'os';
8
+ import path from 'path';
9
+ import { fileURLToPath } from 'url';
10
+
11
+ const __dirname = fileURLToPath(path.dirname(import.meta.url)),
12
+ cwd = process.cwd(),
13
+ cpOpts = {env: process.env, cwd: cwd, stdio: 'inherit', shell: true},
14
+ requireJson = path => JSON.parse(fs.readFileSync((path))),
15
+ packageJson = requireJson(path.resolve(cwd, 'package.json')),
16
+ program = new Command(),
17
+ configPath = path.resolve(cwd, 'buildScripts/myApps.json'),
18
+ neoPath = packageJson.name === 'neo.mjs' ? './' : './node_modules/neo.mjs/',
19
+ webpackPath = path.resolve(neoPath, 'buildScripts/webpack'),
20
+ programName = `${packageJson.name} buildMyApps`,
21
+ questions = [];
22
+
23
+ let webpack = './node_modules/.bin/webpack',
24
+ config;
25
+
26
+ if (fs.existsSync(configPath)) {
27
+ config = requireJson(configPath);
28
+ } else {
29
+ const myAppsPath = path.resolve(neoPath, 'buildScripts/webpack/json/myApps.json');
30
+
31
+ if (fs.existsSync(myAppsPath)) {
32
+ config = requireJson(myAppsPath);
33
+ } else {
34
+ config = requireJson(path.resolve(neoPath, 'buildScripts/webpack/json/myApps.template.json'));
35
+ }
36
+ }
37
+
38
+ let index = config.apps.indexOf('Docs');
39
+
40
+ index > -1 && config.apps.splice(index, 1);
41
+
42
+ program
43
+ .name(programName)
44
+ .version(packageJson.version)
45
+ .option('-i, --info', 'print environment debug info')
46
+ .option('-a, --apps <value>', ['all'].concat(config.apps).map(e => `"${e}"`).join(', '))
47
+ .option('-e, --env <value>', '"all", "dev", "prod"')
48
+ .option('-f, --framework')
49
+ .option('-n, --noquestions')
50
+ .allowUnknownOption()
51
+ .on('--help', () => {
52
+ console.log('\nIn case you have any issues, please create a ticket here:');
53
+ console.log(chalk.cyan(packageJson.bugs.url));
54
+ })
55
+ .parse(process.argv);
56
+
57
+ const programOpts = program.opts();
58
+
59
+ if (programOpts.info) {
60
+ console.log(chalk.bold('\nEnvironment Info:'));
61
+ console.log(`\n current version of ${packageJson.name}: ${packageJson.version}`);
62
+ console.log(` running from ${__dirname}`);
63
+
64
+ envinfo
65
+ .run({
66
+ System : ['OS', 'CPU'],
67
+ Binaries : ['Node', 'npm', 'Yarn'],
68
+ Browsers : ['Chrome', 'Edge', 'Firefox', 'Safari'],
69
+ npmPackages: ['neo.mjs']
70
+ }, {
71
+ duplicates : true,
72
+ showNotFound: true
73
+ })
74
+ .then(console.log);
75
+ } else {
76
+ console.log(chalk.green(programName));
77
+
78
+ if (!programOpts.noquestions) {
79
+ if (!programOpts.env) {
80
+ questions.push({
81
+ type : 'list',
82
+ name : 'env',
83
+ message: 'Please choose the environment:',
84
+ choices: ['all', 'dev', 'prod'],
85
+ default: 'all'
86
+ });
87
+ }
88
+
89
+ if (!programOpts.apps && config.apps.length > 1) {
90
+ questions.push({
91
+ type : 'checkbox',
92
+ name : 'apps',
93
+ message: 'Please choose which apps you want to build:',
94
+ choices: config.apps
95
+ });
96
+ }
97
+ }
98
+
99
+ inquirer.prompt(questions).then(answers => {
100
+ const apps = (answers.apps.length > 0 ? answers.apps : null) || programOpts.apps || ['all'],
101
+ env = answers.env || programOpts.env || ['all'],
102
+ insideNeo = !!programOpts.framework || false,
103
+ startDate = new Date();
104
+
105
+ if (os.platform().startsWith('win')) {
106
+ webpack = path.resolve(webpack).replace(/\\/g,'/');
107
+ }
108
+
109
+ // dist/development
110
+ if (env === 'all' || env === 'dev') {
111
+ console.log(chalk.blue(`${programName} starting dist/development`));
112
+ spawnSync(webpack, ['--config', `${webpackPath}/development/webpack.config.myapps.mjs`, `--env apps=${apps}`, `--env insideNeo=${insideNeo}`], cpOpts);
113
+ }
114
+
115
+ // dist/production
116
+ if (env === 'all' || env === 'prod') {
117
+ console.log(chalk.blue(`${programName} starting dist/production`));
118
+ spawnSync(webpack, ['--config', `${webpackPath}/production/webpack.config.myapps.mjs`, `--env apps=${apps}`, `--env insideNeo=${insideNeo}`], cpOpts);
119
+ }
120
+
121
+ const processTime = (Math.round((new Date - startDate) * 100) / 100000).toFixed(2);
122
+ console.log(`\nTotal time for ${programName}: ${processTime}s`);
123
+
124
+ process.exit();
125
+ });
126
+ }
@@ -0,0 +1,116 @@
1
+ import chalk from 'chalk';
2
+ import { spawnSync } from 'child_process';
3
+ import { Command } from 'commander/esm.mjs';
4
+ import envinfo from 'envinfo';
5
+ import fs from 'fs-extra';
6
+ import inquirer from 'inquirer';
7
+ import path from 'path';
8
+ import { fileURLToPath } from 'url';
9
+
10
+ const __dirname = fileURLToPath(path.dirname(import.meta.url)),
11
+ cwd = process.cwd(),
12
+ cpOpts = {env: process.env, cwd: cwd, stdio: 'inherit', shell: true},
13
+ requireJson = path => JSON.parse(fs.readFileSync((path))),
14
+ packageJson = requireJson(path.resolve(cwd, 'package.json')),
15
+ neoPath = packageJson.name === 'neo.mjs' ? './' : './node_modules/neo.mjs/',
16
+ program = new Command(),
17
+ webpackPath = path.resolve(neoPath, 'buildScripts/webpack'),
18
+ programName = `${packageJson.name} buildThreads`,
19
+ questions = [];
20
+
21
+ let webpack = './node_modules/.bin/webpack';
22
+
23
+ program
24
+ .name(programName)
25
+ .version(packageJson.version)
26
+ .option('-i, --info', 'print environment debug info')
27
+ .option('-e, --env <value>', '"all", "dev", "prod"')
28
+ .option('-f, --framework')
29
+ .option('-n, --noquestions')
30
+ .option('-t, --threads <value>', '"all", "app", "data", "main", "vdom"')
31
+ .allowUnknownOption()
32
+ .on('--help', () => {
33
+ console.log('\nIn case you have any issues, please create a ticket here:');
34
+ console.log(chalk.cyan(packageJson.bugs.url));
35
+ })
36
+ .parse(process.argv);
37
+
38
+ const programOpts = program.opts();
39
+
40
+ if (programOpts.info) {
41
+ console.log(chalk.bold('\nEnvironment Info:'));
42
+ console.log(`\n current version of ${packageJson.name}: ${packageJson.version}`);
43
+ console.log(` running from ${__dirname}`);
44
+
45
+ envinfo
46
+ .run({
47
+ System : ['OS', 'CPU'],
48
+ Binaries : ['Node', 'npm', 'Yarn'],
49
+ Browsers : ['Chrome', 'Edge', 'Firefox', 'Safari'],
50
+ npmPackages: ['neo.mjs']
51
+ }, {
52
+ duplicates : true,
53
+ showNotFound: true
54
+ })
55
+ .then(console.log);
56
+ } else {
57
+ console.log(chalk.green(programName));
58
+
59
+ if (!programOpts.noquestions) {
60
+ if (!programOpts.threads) {
61
+ questions.push({
62
+ type : 'list',
63
+ name : 'threads',
64
+ message: 'Please choose the threads to build:',
65
+ choices: ['all', 'app', 'canvas', 'data', 'main', 'vdom'],
66
+ default: 'all'
67
+ });
68
+ }
69
+
70
+ if (!programOpts.env) {
71
+ questions.push({
72
+ type : 'list',
73
+ name : 'env',
74
+ message: 'Please choose the environment:',
75
+ choices: ['all', 'dev', 'prod'],
76
+ default: 'all'
77
+ });
78
+ }
79
+ }
80
+
81
+ inquirer.prompt(questions).then(answers => {
82
+ const env = answers.env || programOpts.env || 'all',
83
+ threads = answers.threads || programOpts.threads || 'all',
84
+ insideNeo = programOpts.framework || false,
85
+ startDate = new Date();
86
+
87
+ if (path.sep === '\\') {
88
+ webpack = path.resolve(webpack).replace(/\\/g,'/');
89
+ }
90
+
91
+ function parseThreads(tPath) {
92
+ (threads === 'all' || threads === 'main') && spawnSync(webpack, ['--config', `${tPath}.main.mjs`], cpOpts);
93
+ (threads === 'all' || threads === 'app') && spawnSync(webpack, ['--config', `${tPath}.appworker.mjs`, `--env insideNeo=${insideNeo}`], cpOpts);
94
+ (threads === 'all' || threads === 'canvas') && spawnSync(webpack, ['--config', `${tPath}.worker.mjs`, `--env insideNeo=${insideNeo} worker=canvas`], cpOpts);
95
+ (threads === 'all' || threads === 'data') && spawnSync(webpack, ['--config', `${tPath}.worker.mjs`, `--env insideNeo=${insideNeo} worker=data`], cpOpts);
96
+ (threads === 'all' || threads === 'vdom') && spawnSync(webpack, ['--config', `${tPath}.worker.mjs`, `--env insideNeo=${insideNeo} worker=vdom`], cpOpts);
97
+ }
98
+
99
+ // dist/development
100
+ if (env === 'all' || env === 'dev') {
101
+ console.log(chalk.blue(`${programName} starting dist/development`));
102
+ parseThreads(`${webpackPath}/development/webpack.config`);
103
+ }
104
+
105
+ // dist/production
106
+ if (env === 'all' || env === 'prod') {
107
+ console.log(chalk.blue(`${programName} starting dist/production`));
108
+ parseThreads(`${webpackPath}/production/webpack.config`);
109
+ }
110
+
111
+ const processTime = (Math.round((new Date - startDate) * 100) / 100000).toFixed(2);
112
+ console.log(`\nTotal time for ${programName}: ${processTime}s`);
113
+
114
+ process.exit();
115
+ });
116
+ }