@eui/tools 5.3.90 → 6.1.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.
Files changed (55) hide show
  1. package/.version.properties +1 -1
  2. package/CHANGELOG.md +40 -0
  3. package/bin/eui-scripts.js +2 -0
  4. package/bin/scripts/audit-package.js +10 -0
  5. package/bin/scripts/csdr-upgrade-deps.js +1 -4
  6. package/package.json +1 -1
  7. package/sandbox.js +176 -108
  8. package/scripts/csdr/audit/audit-utils.js +3 -98
  9. package/scripts/csdr/audit/deps.js +89 -0
  10. package/scripts/csdr/audit/styles.js +457 -0
  11. package/scripts/csdr/audit/yarn.js +105 -0
  12. package/scripts/csdr/config/angular.js +26 -23
  13. package/scripts/csdr/config/global.js +18 -18
  14. package/scripts/csdr/config/packages.js +86 -14
  15. package/scripts/csdr/config/projects.js +54 -6
  16. package/scripts/csdr/config/sync.js +15 -1
  17. package/scripts/csdr/init/global.js +122 -0
  18. package/scripts/csdr/init/init-utils.js +8 -296
  19. package/scripts/csdr/init/init.js +44 -14
  20. package/scripts/csdr/init/meta.js +3 -2
  21. package/scripts/csdr/init/packages.js +142 -0
  22. package/scripts/csdr/init/projects.js +112 -0
  23. package/scripts/csdr/init/remotes.js +21 -0
  24. package/scripts/csdr/init/repos.js +5 -31
  25. package/scripts/csdr/install/common.js +43 -385
  26. package/scripts/csdr/install/local-dev.js +55 -46
  27. package/scripts/csdr/install/packages.js +183 -3
  28. package/scripts/csdr/install/projects.js +202 -2
  29. package/scripts/csdr/release/package/release-package.js +26 -56
  30. package/scripts/csdr/release/package/ui.js +6 -85
  31. package/scripts/csdr/sync/sync-utils.js +8 -8
  32. package/scripts/csdr/version/app-default.js +0 -3
  33. package/scripts/csdr/version/package-common.js +2 -4
  34. package/scripts/csdr/version/package-remote.js +0 -4
  35. package/scripts/index.js +0 -2
  36. package/scripts/utils/build/package/build-package-utils.js +5 -13
  37. package/scripts/utils/build/package/maven.js +6 -12
  38. package/scripts/utils/build/package/nodeJs.js +0 -1
  39. package/scripts/utils/build/package/postcss.config.js +0 -2
  40. package/scripts/utils/build/package/styles.js +1 -0
  41. package/scripts/utils/changelog-utils.js +4 -2
  42. package/scripts/utils/git-utils.js +46 -0
  43. package/scripts/utils/pre-build/elements.js +1 -1
  44. package/scripts/utils/pre-build/injection/config.js +21 -134
  45. package/scripts/utils/pre-build/injection/externals.js +135 -90
  46. package/scripts/utils/pre-build/injection/routes-replacement.js +67 -15
  47. package/scripts/utils/pre-build/injection/skeletons.js +3 -2
  48. package/scripts/utils/pre-build/projects.js +1 -3
  49. package/scripts/utils/publish/npm.js +1 -2
  50. package/scripts/utils/serve/element.js +17 -2
  51. package/scripts/utils/svg-utils.js +2 -3
  52. package/scripts/utils/test/test-utils.js +5 -49
  53. package/scripts/utils/tools.js +4 -1
  54. package/scripts/utils/build/package/nestJs.js +0 -45
  55. package/scripts/utils/build/package/stencil.js +0 -13
@@ -1,12 +1,30 @@
1
1
  'use strict';
2
2
 
3
+ /*
4
+ PRE-BUILD / INJECTION / CONFIG
5
+
6
+ purpose:
7
+ Inject config into project assets coming from remote packages either locally installed / from node_modules
8
+ used by:
9
+ MyWorkplace for openId config and routes config injection
10
+ triggered by:
11
+ presence of "config" array in CSDR App config entries
12
+
13
+ public methods
14
+ injectConfig(project)
15
+ */
16
+
17
+
18
+ /* IMPORTS */
19
+
3
20
  const path = require('path');
4
21
 
5
22
  const tools = require('../../tools');
6
23
  const configUtils = require('../../../csdr/config/config-utils');
7
- const installUtils = require('../../../csdr/install/install-utils');
8
24
 
9
25
 
26
+ /* PRIVATE METHODS */
27
+
10
28
  const injectConfigCore = (project, npmPkg) => {
11
29
  // check if package is locally cloned
12
30
  const localPackage = configUtils.packages.getPackages().filter((p) => {
@@ -44,8 +62,9 @@ const injectConfigCore = (project, npmPkg) => {
44
62
  }
45
63
 
46
64
 
65
+ /* PUBLIC METHODS */
47
66
 
48
- const injectConfig = (project) => {
67
+ module.exports.injectConfig = (project) => {
49
68
 
50
69
  tools.logTitle('Injecting project external config');
51
70
 
@@ -68,139 +87,7 @@ const injectConfig = (project) => {
68
87
  }
69
88
  })
70
89
 
71
- // .then(() => {
72
- // return injectPackagesConfig(project);
73
- // })
74
-
75
90
  .catch((e) => {
76
91
  throw e;
77
92
  })
78
93
  }
79
-
80
-
81
- // const injectPackagesConfig = (project) => {
82
- // tools.logTitle('Injecting package config');
83
-
84
- // return Promise.resolve()
85
-
86
- // // fetching current project linked composite packages dependencies
87
- // .then(() => {
88
- // return installUtils.common.getLocalProjectDeps(project);
89
- // })
90
-
91
-
92
- // // remapping dependencies with package names
93
- // .then((prjDeps) => {
94
-
95
- // // gather only the locally installed projects,
96
- // const localPackagesConfig = configUtils.packages.getPackages();
97
-
98
- // let localPackagesArray = [];
99
-
100
- // Object.keys(prjDeps).forEach((p) => {
101
- // const filteredPackage = localPackagesConfig.filter((fp) => {
102
- // // filtering from the current deps pkg
103
- // return fp.npmPkg === p;
104
- // })[0];
105
-
106
- // if (filteredPackage) localPackagesArray.push(filteredPackage.name);
107
- // });
108
-
109
-
110
-
111
- // // gather the full CSDR packages from project dependencies
112
- // const csdrPackagesConfig = configUtils.packages.getCsdrPackagesFull();
113
-
114
- // let csdrPackagesArray = [];
115
-
116
- // Object.keys(prjDeps).forEach((p) => {
117
- // const filteredPackage = csdrPackagesConfig.filter((fp) => {
118
- // // filtering from the current deps pkg; excluding the ones found locally
119
- // return fp.npmPkg === p && !localPackagesArray.includes(fp.name);
120
- // })[0];
121
-
122
- // if (filteredPackage) csdrPackagesArray.push(filteredPackage.npmPkg);
123
- // });
124
-
125
-
126
- // return {
127
- // csdrPackages: csdrPackagesArray,
128
- // localPackages: localPackagesArray,
129
- // };
130
- // })
131
-
132
-
133
- // // checking filtered packages if config overrides is provided
134
- // .then((filteredPackages) => {
135
-
136
- // // checking installed packages
137
- // filteredPackages.csdrPackages.forEach((p) => {
138
- // const pkgPath = path.join(process.cwd(), 'node_modules', p);
139
- // processPackageConfig(project, pkgPath);
140
- // })
141
-
142
- // // checking local packages
143
- // filteredPackages.localPackages.forEach((p) => {
144
- // const pkgPath = path.join(process.cwd(), 'packages', p);
145
- // processPackageConfig(project, pkgPath);
146
- // })
147
-
148
- // })
149
-
150
-
151
- // .catch((e) => {
152
- // throw e;
153
- // })
154
- // }
155
-
156
- // const processPackageConfig = (project, folder) => {
157
- // const configPath = path.join(folder, 'assets', 'config');
158
- // tools.logInfo(`checking ${configPath}`);
159
-
160
- // // checking if pkg contains overriden config
161
- // if (!tools.isDirExists(configPath)) {
162
- // tools.logWarning('not found...skipping');
163
-
164
- // // processing the files found and mapping them to base config files
165
- // } else {
166
- // const configFiles = tools.getFiles(configPath);
167
- // tools.logSuccess('OK, found config files : ');
168
- // console.log(configFiles);
169
-
170
- // // checking if files maps the base config file
171
- // const projectAssetsPath = path.join(process.cwd(), project.folder, 'src', 'assets');
172
- // const baseConfigFiles = tools.getFiles(projectAssetsPath);
173
-
174
- // configFiles.forEach((f) => {
175
- // if (!baseConfigFiles.includes(f)) {
176
- // tools.logWarning(`${f} is not matching base config files`);
177
-
178
- // } else {
179
- // tools.logSuccess(`${f} matched in base config files...processing`);
180
-
181
- // // fetching files content
182
- // const configFileContent = tools.getJsonFileContent(path.join(configPath, f));
183
- // const baseConfigFileContent = tools.getJsonFileContent(path.join(projectAssetsPath, f));
184
-
185
- // baseConfigFileContent.openIdConnect.apiGatewayServices = {
186
- // ...baseConfigFileContent.openIdConnect.apiGatewayServices,
187
- // ...configFileContent.apiGatewayServices
188
- // };
189
-
190
- // baseConfigFileContent.modules = {
191
- // ...baseConfigFileContent.modules,
192
- // ...configFileContent.modules
193
- // };
194
-
195
- // tools.writeJsonFileSync(path.join(projectAssetsPath, f), baseConfigFileContent);
196
-
197
- // tools.logSuccess('OK => file processed');
198
- // }
199
-
200
- // })
201
- // }
202
- // }
203
-
204
-
205
- module.exports.injectConfig = injectConfig;
206
- // module.exports.injectPackagesConfig = injectPackagesConfig;
@@ -7,67 +7,10 @@ const gitUtils = require('../../git-utils');
7
7
  const configUtils = require('../../../csdr/config/config-utils');
8
8
 
9
9
 
10
- module.exports.injectExternalFeatures = (project) => {
11
-
12
- tools.logTitle(`Injecting project external features for : ${project.name}`);
13
-
14
- return Promise.resolve()
15
- .then(() => {
16
- if (!project.features) {
17
- tools.logInfo('No external features setup...skipping');
18
- return;
19
- }
20
10
 
21
- if (!project.features.npmPkg || !project.features.folder) {
22
- return tools.logWarning('External features use requires a source [npmPkg] and a [folder] declared');
23
-
24
- } else {
25
- // check if package is locally cloned
26
- const localPackage = configUtils.packages.getPackages().filter((p) => {
27
- return p.npmPkg === project.features.npmPkg
28
- })[0];
11
+ const injectExternalAppSourcesCore = (project, build = false, injectedNpmPkg, injectedFolder, euiVersion) => {
29
12
 
30
- var featuresSrcPath;
31
- const projectSrcPath = path.join(process.cwd(), project.folder, 'src', 'app', 'features');
32
-
33
- // if local package is found
34
- if (localPackage) {
35
- tools.logInfo('local project found, copying from local');
36
- featuresSrcPath = path.join(process.cwd(), 'packages', localPackage.name, project.features.folder);
37
-
38
- // if not sources are taken from the npm package def in node_modules
39
- } else {
40
- tools.logInfo('remote project found, copying from remote');
41
- const npmPkgScope = project.features.npmPkg.substr(0, project.features.npmPkg.indexOf('/'));
42
- const npmPkgName = project.features.npmPkg.substr(project.features.npmPkg.indexOf('/') + 1);
43
-
44
- featuresSrcPath = path.join(process.cwd(), 'node_modules', npmPkgScope, npmPkgName, project.features.folder);
45
- }
46
-
47
- if (!tools.isDirExists(featuresSrcPath)) {
48
- tools.logWarning(`External features location : ${featuresSrcPath} cannot be found in node_modules`);
49
- throw new Error('External features not found');
50
-
51
- } else {
52
- tools.logInfo(`Removing ${projectSrcPath} content`);
53
- tools.rmdirFull(projectSrcPath, false);
54
-
55
- tools.logInfo(`${featuresSrcPath} injecting in ${projectSrcPath}`);
56
- return tools.copydir(featuresSrcPath, projectSrcPath, true);
57
- }
58
- }
59
- })
60
- .catch((e) => {
61
- throw e;
62
- })
63
-
64
- }
65
-
66
-
67
-
68
- const injectExternalAppSourcesCore = (project, build = false, injectedNpmPkg, injectedFolder) => {
69
-
70
- tools.logInfo(`Injecting app sources : ${injectedNpmPkg} / ${injectedFolder}`);
13
+ tools.logInfo(`Injecting app sources : ${injectedNpmPkg} / ${injectedFolder} for eUI verison : ${euiVersion}`);
71
14
 
72
15
  return Promise.resolve()
73
16
  .then(() => {
@@ -84,7 +27,16 @@ const injectExternalAppSourcesCore = (project, build = false, injectedNpmPkg, in
84
27
  if (localPackage) {
85
28
  tools.logInfo('local project found, copying from local');
86
29
 
87
- appSourcesSrcPath = path.join(process.cwd(), 'packages', localPackage.name, injectedFolder);
30
+ if (euiVersion) {
31
+ appSourcesSrcPath = path.join(process.cwd(), 'packages', localPackage.name, 'assets', euiVersion, injectedFolder);
32
+ } else {
33
+ // maintain old compat for transition
34
+ if (injectedFolder.indexOf('assets') > -1) {
35
+ appSourcesSrcPath = path.join(process.cwd(), 'packages', localPackage.name, injectedFolder);
36
+ } else {
37
+ appSourcesSrcPath = path.join(process.cwd(), 'packages', localPackage.name, 'assets', injectedFolder);
38
+ }
39
+ }
88
40
 
89
41
  // if not sources are taken from the npm package def in node_modules
90
42
  } else {
@@ -93,7 +45,16 @@ const injectExternalAppSourcesCore = (project, build = false, injectedNpmPkg, in
93
45
  const npmPkgScope = injectedNpmPkg.substr(0, injectedNpmPkg.indexOf('/'));
94
46
  const npmPkgName = injectedNpmPkg.substr(injectedNpmPkg.indexOf('/') + 1);
95
47
 
96
- appSourcesSrcPath = path.join(process.cwd(), 'node_modules', npmPkgScope, npmPkgName, injectedFolder);
48
+ if (euiVersion) {
49
+ appSourcesSrcPath = path.join(process.cwd(), 'node_modules', npmPkgScope, npmPkgName, 'assets', euiVersion, injectedFolder);
50
+ } else {
51
+ // maintain old compat for transition
52
+ if (injectedFolder.indexOf('assets') > -1) {
53
+ appSourcesSrcPath = path.join(process.cwd(), 'node_modules', npmPkgScope, npmPkgName, injectedFolder);
54
+ } else {
55
+ appSourcesSrcPath = path.join(process.cwd(), 'node_modules', npmPkgScope, npmPkgName, 'assets', injectedFolder);
56
+ }
57
+ }
97
58
  }
98
59
 
99
60
  if (!tools.isDirExists(appSourcesSrcPath)) {
@@ -121,9 +82,9 @@ const injectExternalAppSourcesCore = (project, build = false, injectedNpmPkg, in
121
82
  }
122
83
 
123
84
 
124
- const injectExternalAppRootCore = (project, build = false, injectedNpmPkg, injectedFolder) => {
85
+ const injectExternalAppRootCore = (project, build = false, injectedNpmPkg, injectedFolder, euiVersion) => {
125
86
 
126
- tools.logInfo(`Injecting app root files : ${injectedNpmPkg} / ${injectedFolder}`);
87
+ tools.logInfo(`Injecting app root files : ${injectedNpmPkg} / ${injectedFolder} - eUI version : ${euiVersion}`);
127
88
 
128
89
  return Promise.resolve()
129
90
  .then(() => {
@@ -139,7 +100,11 @@ const injectExternalAppRootCore = (project, build = false, injectedNpmPkg, injec
139
100
  if (localPackage) {
140
101
  tools.logInfo('local project found, copying from local');
141
102
 
142
- appRootSrcPath = path.join(process.cwd(), 'packages', localPackage.name, injectedFolder);
103
+ if (euiVersion) {
104
+ appRootSrcPath = path.join(process.cwd(), 'packages', localPackage.name, 'assets', euiVersion, injectedFolder);
105
+ } else {
106
+ appRootSrcPath = path.join(process.cwd(), 'packages', localPackage.name, 'assets', injectedFolder);
107
+ }
143
108
 
144
109
  // if not sources are taken from the npm package def in node_modules
145
110
  } else {
@@ -148,7 +113,11 @@ const injectExternalAppRootCore = (project, build = false, injectedNpmPkg, injec
148
113
  const npmPkgScope = injectedNpmPkg.substr(0, injectedNpmPkg.indexOf('/'));
149
114
  const npmPkgName = injectedNpmPkg.substr(injectedNpmPkg.indexOf('/') + 1);
150
115
 
151
- appRootSrcPath = path.join(process.cwd(), 'node_modules', npmPkgScope, npmPkgName, injectedFolder);
116
+ if (euiVersion) {
117
+ appRootSrcPath = path.join(process.cwd(), 'node_modules', npmPkgScope, npmPkgName, 'assets', euiVersion, injectedFolder);
118
+ } else {
119
+ appRootSrcPath = path.join(process.cwd(), 'node_modules', npmPkgScope, npmPkgName, 'assets', injectedFolder);
120
+ }
152
121
  }
153
122
 
154
123
  if (!tools.isDirExists(appRootSrcPath)) {
@@ -164,6 +133,18 @@ const injectExternalAppRootCore = (project, build = false, injectedNpmPkg, injec
164
133
  return tools.copydirFiles(appRootSrcPath, projectRootPath, true);
165
134
  })
166
135
 
136
+ .then(() => {
137
+ tools.logInfo('Check angular-config.json replacement of project');
138
+
139
+ const angularConfigFile = path.join(projectRootPath, 'angular-config.json');
140
+ let angularConfigJson = tools.getJsonFileContent(angularConfigFile);
141
+ angularConfigJson = JSON.stringify(angularConfigJson, null, 2);
142
+
143
+ angularConfigJson = tools.replaceAll(angularConfigJson, '@project.name@', project.name);
144
+
145
+ return tools.writeFileContent(angularConfigFile, angularConfigJson);
146
+ })
147
+
167
148
  .catch((e) => {
168
149
  throw e;
169
150
  })
@@ -181,13 +162,27 @@ const injectExternalAppRootCore = (project, build = false, injectedNpmPkg, injec
181
162
 
182
163
  module.exports.injectExternalAppSources = (project, build = false) => {
183
164
 
184
- tools.logTitle(`Injecting project external application sources for : ${project.name}`);
185
-
186
165
  if (!project.externalSources) {
187
166
  tools.logInfo('No external app sources setup...skipping');
188
167
  return;
189
168
  }
190
169
 
170
+ let { euiVersion } = tools.getArgs();
171
+
172
+ if (!euiVersion && project.virtual) {
173
+ euiVersion = configUtils.projects.getProjectEuiVersion(project);
174
+
175
+ if (!euiVersion) {
176
+ throw new Error(`
177
+ eUI version of ${project.name} cannot be found...
178
+ if you're initializing the project, pass the "euiVersion" as parameter :
179
+ f.e. : npm run init -- --project ${project.name} .... --euiVersion 10.x
180
+ `);
181
+ }
182
+ }
183
+
184
+ tools.logTitle(`Injecting project external application sources for : ${project.name} for eUI version : ${euiVersion}`);
185
+
191
186
  return Promise.resolve()
192
187
  .then(() => {
193
188
  if (!build) {
@@ -215,47 +210,41 @@ module.exports.injectExternalAppSources = (project, build = false) => {
215
210
  })
216
211
  }
217
212
  })
213
+
218
214
  .then(() => {
219
- // in case of multiple injection are defined, we promise loop on each injection
220
- if (Array.isArray(project.externalSources)) {
215
+ if (!Array.isArray(project.externalSources)) {
216
+ throw new Error('externalSources present but not an array...stopping');
217
+
218
+ } else {
221
219
  return Promise.resolve().then(() => {
222
220
  return project.externalSources.reduce((promise, appSource) => {
223
221
  return promise.then(() => (
224
- injectExternalAppSourcesCore(project, build, appSource.npmPkg, appSource.folder, appSource.injectRootFiles)
222
+ injectExternalAppSourcesCore(project, build, appSource.npmPkg, appSource.folder, euiVersion)
225
223
  ));
226
224
  }, Promise.resolve());
227
225
  })
228
-
229
- // if only one injection externalSources is defined
230
- } else {
231
- if (!project.externalSources.npmPkg || !project.externalSources.folder) {
232
- return tools.logWarning('External externalSources use requires a source [npmPkg] and a [folder] declared');
233
-
234
- } else {
235
- return injectExternalAppSourcesCore(
236
- project, build,
237
- project.externalSources.npmPkg, project.externalSources.folder,
238
- );
239
- }
240
226
  }
241
227
  })
242
228
 
243
-
244
- // inject external root files
229
+ // inject external root files (optional)
245
230
  .then(() => {
246
231
  if (!project.externalRootFiles) {
247
232
  tools.logInfo('No external app root files setup...skipping');
248
233
  return;
249
234
  }
250
235
 
251
- if (!project.externalRootFiles.npmPkg || !project.externalRootFiles.folder) {
252
- return tools.logWarning('External externalRootFiles use requires a source [npmPkg] and a [folder] declared');
236
+ // in case of multiple injection are defined, we promise loop on each injection
237
+ if (!Array.isArray(project.externalRootFiles)) {
238
+ throw new Error('externalSources present but not an array...stopping');
253
239
 
254
240
  } else {
255
- return injectExternalAppRootCore(
256
- project, build,
257
- project.externalRootFiles.npmPkg, project.externalRootFiles.folder,
258
- );
241
+ return Promise.resolve().then(() => {
242
+ return project.externalRootFiles.reduce((promise, appRootFiles) => {
243
+ return promise.then(() => (
244
+ injectExternalAppRootCore(project, build, appRootFiles.npmPkg, appRootFiles.folder, euiVersion)
245
+ ));
246
+ }, Promise.resolve());
247
+ })
259
248
  }
260
249
  })
261
250
  .catch((e) => {
@@ -323,6 +312,62 @@ module.exports.injectElementExternalSources = (pkg) => {
323
312
  }
324
313
 
325
314
 
315
+ module.exports.injectExternalFeatures = (project) => {
316
+
317
+ tools.logTitle(`Injecting project external features for : ${project.name}`);
318
+
319
+ return Promise.resolve()
320
+ .then(() => {
321
+ if (!project.features) {
322
+ tools.logInfo('No external features setup...skipping');
323
+ return;
324
+ }
325
+
326
+ if (!project.features.npmPkg || !project.features.folder) {
327
+ return tools.logWarning('External features use requires a source [npmPkg] and a [folder] declared');
328
+
329
+ } else {
330
+ // check if package is locally cloned
331
+ const localPackage = configUtils.packages.getPackages().filter((p) => {
332
+ return p.npmPkg === project.features.npmPkg
333
+ })[0];
334
+
335
+ var featuresSrcPath;
336
+ const projectSrcPath = path.join(process.cwd(), project.folder, 'src', 'app', 'features');
337
+
338
+ // if local package is found
339
+ if (localPackage) {
340
+ tools.logInfo('local project found, copying from local');
341
+ featuresSrcPath = path.join(process.cwd(), 'packages', localPackage.name, project.features.folder);
342
+
343
+ // if not sources are taken from the npm package def in node_modules
344
+ } else {
345
+ tools.logInfo('remote project found, copying from remote');
346
+ const npmPkgScope = project.features.npmPkg.substr(0, project.features.npmPkg.indexOf('/'));
347
+ const npmPkgName = project.features.npmPkg.substr(project.features.npmPkg.indexOf('/') + 1);
348
+
349
+ featuresSrcPath = path.join(process.cwd(), 'node_modules', npmPkgScope, npmPkgName, project.features.folder);
350
+ }
351
+
352
+ if (!tools.isDirExists(featuresSrcPath)) {
353
+ tools.logWarning(`External features location : ${featuresSrcPath} cannot be found in node_modules`);
354
+ throw new Error('External features not found');
355
+
356
+ } else {
357
+ tools.logInfo(`Removing ${projectSrcPath} content`);
358
+ tools.rmdirFull(projectSrcPath, false);
359
+
360
+ tools.logInfo(`${featuresSrcPath} injecting in ${projectSrcPath}`);
361
+ return tools.copydir(featuresSrcPath, projectSrcPath, true);
362
+ }
363
+ }
364
+ })
365
+ .catch((e) => {
366
+ throw e;
367
+ })
368
+ }
369
+
370
+
326
371
 
327
372
  module.exports.injectExternalMock = (project) => {
328
373
 
@@ -6,11 +6,9 @@ const _ = require('lodash');
6
6
  const tools = require('../../tools');
7
7
  const configUtils = require('../../../csdr/config/config-utils');
8
8
 
9
- // const { subRoutes, debug } = tools.getArgs();
10
9
  const { debug } = tools.getArgs();
11
10
 
12
11
 
13
-
14
12
  const getEnvTarget = (envTargetIn, build) => {
15
13
  if (!envTargetIn) {
16
14
 
@@ -58,7 +56,7 @@ const getEnvConfig = (project, envTarget, build) => {
58
56
 
59
57
  tools.logInfo(`checking ${configFile}`);
60
58
  if (!tools.isFileExists(configFile)) {
61
- tools.logError(`config file for ${envTarget} do not exists`);
59
+ tools.logError(`config file for ${envTarget} does not exists`);
62
60
  return;
63
61
  }
64
62
 
@@ -70,7 +68,7 @@ const getEnvConfig = (project, envTarget, build) => {
70
68
  })
71
69
  }
72
70
 
73
- const getRoutesFile = (project) => {
71
+ const getRoutesFile = (project, euiVersion) => {
74
72
  tools.logInfo('Getting routes file for replacement');
75
73
 
76
74
  return Promise.resolve()
@@ -96,7 +94,25 @@ const getRoutesFile = (project) => {
96
94
  // if local package is found
97
95
  if (localPackage) {
98
96
  tools.logInfo('local package found, copying from local');
99
- srcRoutesFilePath = path.join(process.cwd(), 'packages', localPackage.name, project.externalRoutesSources.routesFileSource);
97
+
98
+ if (tools.isFalse(project.externalRoutesSources.includeEuiVersion)) {
99
+ tools.logInfo('include eUI version in routes path...skipped');
100
+
101
+ srcRoutesFilePath = path.join(
102
+ process.cwd(), 'packages', localPackage.name,
103
+ project.externalRoutesSources.routesFileSource,
104
+ );
105
+
106
+ } else {
107
+ tools.logInfo(`constructing route path with eUI version provided: ${euiVersion}`);
108
+
109
+ srcRoutesFilePath = path.join(
110
+ process.cwd(), 'packages', localPackage.name,
111
+ 'assets', euiVersion,
112
+ project.externalRoutesSources.routesFileSource,
113
+ );
114
+ }
115
+
100
116
 
101
117
  // if not sources are taken from the npm package def in node_modules
102
118
  } else {
@@ -104,7 +120,23 @@ const getRoutesFile = (project) => {
104
120
  const npmPkgScope = project.externalRoutesSources.routesFileNpmPkg.substr(0, project.externalRoutesSources.routesFileNpmPkg.indexOf('/'));
105
121
  const npmPkgName = project.externalRoutesSources.routesFileNpmPkg.substr(project.externalRoutesSources.routesFileNpmPkg.indexOf('/') + 1);
106
122
 
107
- srcRoutesFilePath = path.join(process.cwd(), 'node_modules', npmPkgScope, npmPkgName, project.externalRoutesSources.routesFileSource);
123
+ if (tools.isFalse(project.externalRoutesSources.includeEuiVersion)) {
124
+ tools.logInfo('include eUI version in routes path...skipped');
125
+
126
+ srcRoutesFilePath = path.join(
127
+ process.cwd(), 'node_modules', npmPkgScope, npmPkgName,
128
+ project.externalRoutesSources.routesFileSource,
129
+ );
130
+
131
+ } else {
132
+ tools.logInfo(`constructing route path with eUI version provided: ${euiVersion}`);
133
+
134
+ srcRoutesFilePath = path.join(
135
+ process.cwd(), 'node_modules', npmPkgScope, npmPkgName,
136
+ 'assets', euiVersion,
137
+ project.externalRoutesSources.routesFileSource,
138
+ );
139
+ }
108
140
  }
109
141
 
110
142
  routesFilePath = path.join(project.paths.rootPath, project.externalRoutesSources.routesFilePath);
@@ -210,17 +242,30 @@ const replaceRoute = (route) => {
210
242
 
211
243
 
212
244
 
213
- const replaceRoutes = (project, envTarget, build, routesFileContent) => {
214
- tools.logInfo('config.routesRemapping not found...Starting full routes replacement');
215
-
245
+ const replaceRoutes = (project, envTarget, build, routesFileContent, euiVersion) => {
216
246
  return Promise.resolve()
217
247
  .then(() => {
248
+
218
249
  // getting base route defs content
219
- const projectAssetsPath = path.join(process.cwd(), project.folder, 'src', 'assets');
250
+ // default route
220
251
  let routeDefsBaseFilename = 'route-defs-base.json';
252
+
253
+ // if full route base name is setup
221
254
  if (project.externalRoutesSources.routesBaseFilename) {
222
255
  routeDefsBaseFilename = project.externalRoutesSources.routesBaseFilename;
256
+
257
+ // if prefix and type, we construct the route base name (dynamic following eUI version of host installed)
258
+ // format is : route-defs-base-vVERSION_NUMBER[-TYPE].json
259
+ } else if (project.externalRoutesSources.routesBaseFilenamePrefix) {
260
+ let routesBaseType = '';
261
+ if (project.externalRoutesSources.routesBaseFilenameType) {
262
+ routesBaseType = `-${project.externalRoutesSources.routesBaseFilenameType}`;
263
+ }
264
+ const euiVersionNumber = euiVersion.split('.')[0];
265
+ routeDefsBaseFilename = `${project.externalRoutesSources.routesBaseFilenamePrefix}-v${euiVersionNumber}${routesBaseType}.json`;
223
266
  }
267
+
268
+ const projectAssetsPath = path.join(process.cwd(), project.folder, 'src', 'assets');
224
269
  const baseRouteDefsPath = path.join(projectAssetsPath, routeDefsBaseFilename);
225
270
 
226
271
  if (!tools.isFileExists(baseRouteDefsPath)) {
@@ -228,6 +273,7 @@ const replaceRoutes = (project, envTarget, build, routesFileContent) => {
228
273
  throw 'BASE_ROUTE_DEFS_FILE_NOT_FOUND';
229
274
  }
230
275
 
276
+ // fetching base route defs file content
231
277
  const baseRouteDefsJSON = require(baseRouteDefsPath);
232
278
 
233
279
  // getting env route defs content if build mode (not serve)
@@ -240,6 +286,8 @@ const replaceRoutes = (project, envTarget, build, routesFileContent) => {
240
286
  tools.logError(`${envRouteDefsPath} File NOT FOUND`);
241
287
  throw 'ENV_ROUTE_DEFS_FILE_NOT_FOUND';
242
288
  }
289
+
290
+ // fetching file content
243
291
  envRouteDefsJSON = require(envRouteDefsPath);
244
292
 
245
293
  // merging content of base + env
@@ -252,14 +300,16 @@ const replaceRoutes = (project, envTarget, build, routesFileContent) => {
252
300
  let placeHolderContent = '';
253
301
 
254
302
  tools.logInfo('Processing routes replacement');
303
+
255
304
  finalRouteDefs.forEach((route) => {
256
305
  if (debug) tools.logInfo(`====> route : ${route.path}`);
257
306
 
258
- if (project.build && (!project.build.euiVersion || project.build.euiVersion === '7.x' || project.build.euiVersion === '10.x')) {
259
- tools.logInfo('Legacy routes replacement for v7 and v10');
307
+ if (euiVersion === 'DEFAULT' || euiVersion === '10.x') {
308
+ tools.logInfo(`Legacy routes replacement for v7 and v10 => replacing ${route.path}`);
260
309
  placeHolderContent += replaceRouteLegacy(route);
310
+
261
311
  } else {
262
- tools.logInfo('New route replacement for v14+');
312
+ tools.logInfo(`New route replacement for v14+ => replacing ${route.path}`);
263
313
  placeHolderContent += replaceRoute(route);
264
314
  }
265
315
 
@@ -288,6 +338,8 @@ module.exports.buildRoutes = (project, envTarget, build) => {
288
338
 
289
339
  let config, routesFile, routesFileContent;
290
340
 
341
+ const euiVersion = configUtils.projects.getProjectEuiVersion(project);
342
+
291
343
  return Promise.resolve()
292
344
  .then(() => {
293
345
  return getEnvConfig(project, envTarget, build);
@@ -300,7 +352,7 @@ module.exports.buildRoutes = (project, envTarget, build) => {
300
352
  })
301
353
 
302
354
  .then(() => {
303
- return getRoutesFile(project);
355
+ return getRoutesFile(project, euiVersion);
304
356
  })
305
357
  .then((outRoutesFile) => {
306
358
  if (!outRoutesFile) {
@@ -311,7 +363,7 @@ module.exports.buildRoutes = (project, envTarget, build) => {
311
363
  })
312
364
 
313
365
  .then(() => {
314
- return replaceRoutes(project, envTarget, build, routesFileContent);
366
+ return replaceRoutes(project, envTarget, build, routesFileContent, euiVersion);
315
367
  })
316
368
 
317
369
  .then((finalRouteFileContent) => {