neo.mjs 6.7.8 → 6.8.1

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.
@@ -1,132 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
- import webpack from 'webpack';
4
-
5
- const cwd = process.cwd(),
6
- configPath = path.resolve(cwd, 'buildScripts/myApps.json'),
7
- requireJson = path => JSON.parse(fs.readFileSync((path))),
8
- packageJson = requireJson(path.resolve(cwd, 'package.json')),
9
- neoPath = packageJson.name === 'neo.mjs' ? './' : './node_modules/neo.mjs/',
10
- buildTarget = requireJson(path.resolve(neoPath, 'buildScripts/webpack/production/buildTarget.json')),
11
- filenameConfig = requireJson(path.resolve(neoPath, 'buildScripts/webpack/json/build.json')),
12
- plugins = [],
13
- regexIndexNodeModules = /node_modules/g,
14
- regexLineBreak = /(\r\n|\n|\r)/gm,
15
- regexTopLevel = /\.\.\//g,
16
- regexTrimEnd = /\s+$/gm,
17
- regexTrimStart = /^\s+/gm;
18
-
19
- let config;
20
-
21
- if (fs.existsSync(configPath)) {
22
- config = requireJson(configPath);
23
- } else {
24
- const myAppsPath = path.resolve(neoPath, 'buildScripts/webpack/json/myApps.json');
25
-
26
- if (fs.existsSync(myAppsPath)) {
27
- config = requireJson(myAppsPath);
28
- } else {
29
- config = requireJson(path.resolve(neoPath, 'buildScripts/webpack/json/myApps.template.json'));
30
- }
31
- }
32
-
33
- let index = config.apps.indexOf('Docs');
34
-
35
- index > -1 && config.apps.splice(index, 1);
36
-
37
- if (!buildTarget.folder) {
38
- buildTarget.folder = 'dist/production';
39
- }
40
-
41
- export default env => {
42
- let apps = env.apps.split(','),
43
- insideNeo = env.insideNeo == 'true',
44
- buildAll = apps.includes('all'),
45
- choices = [],
46
- basePath, content, i, inputPath, outputPath, lAppName, treeLevel, workerBasePath;
47
-
48
- // MicroLoader.mjs
49
- inputPath = path.resolve(cwd, 'src/MicroLoader.mjs');
50
- outputPath = path.resolve(cwd, buildTarget.folder, 'src/MicroLoader.mjs');
51
-
52
- content = fs.readFileSync(inputPath).toString().replace(/\s/gm, '');
53
- fs.mkdirpSync(path.resolve(cwd, buildTarget.folder, 'src/'));
54
- fs.writeFileSync(outputPath, content);
55
-
56
-
57
-
58
- if (config.apps) {
59
- config.apps.forEach(key => {
60
- choices.push(key);
61
- });
62
-
63
- config.apps.forEach(key => {
64
- if (buildAll || choices.length < 2 || apps.includes(key)) {
65
- basePath = '';
66
- workerBasePath = '';
67
- treeLevel = key.replace('.', '/').split('/').length + 3;
68
-
69
- for (i=0; i < treeLevel; i++) {
70
- basePath += '../';
71
-
72
- if (i > 1) {
73
- workerBasePath += '../';
74
- }
75
- }
76
-
77
- lAppName = key.toLowerCase();
78
-
79
- // neo-config.json
80
- inputPath = path.resolve(cwd, 'apps', lAppName, 'neo-config.json');
81
- outputPath = path.resolve(cwd, buildTarget.folder, 'apps', lAppName, 'neo-config.json');
82
-
83
- content = requireJson(inputPath);
84
- delete content.environment;
85
-
86
- content.appPath = content.appPath.replace(regexTopLevel, '');
87
-
88
- Object.assign(content, {
89
- basePath,
90
- mainPath: '../main.js',
91
- workerBasePath
92
- });
93
-
94
- fs.writeFileSync(outputPath, JSON.stringify(content));
95
-
96
- // index.html
97
- inputPath = path.resolve(cwd, 'apps', lAppName, 'index.html');
98
- outputPath = path.resolve(cwd, buildTarget.folder, 'apps', lAppName, 'index.html');
99
-
100
- content = fs.readFileSync(inputPath).toString()
101
- .replace(regexIndexNodeModules, '../../node_modules')
102
- .replace(regexTrimStart, '')
103
- .replace(regexTrimEnd, '')
104
- .replace(', ', ',')
105
- .replace(regexLineBreak, '');
106
-
107
- fs.writeFileSync(outputPath, content);
108
- }
109
- });
110
- }
111
-
112
- return {
113
- mode : 'production',
114
- entry : {app: path.resolve(neoPath, './src/worker/App.mjs')},
115
- target: 'webworker',
116
-
117
- plugins: [
118
- new webpack.ContextReplacementPlugin(/.*/, context => {
119
- if (!insideNeo && context.context.includes('/src/worker')) {
120
- context.request = '../../' + context.request;
121
- }
122
- }),
123
- ...plugins
124
- ],
125
-
126
- output: {
127
- chunkFilename: 'chunks/app/[id].js',
128
- filename : filenameConfig.workers.app.output,
129
- path : path.resolve(cwd, buildTarget.folder)
130
- }
131
- }
132
- };