@eui/tools 4.19.6 → 4.19.7

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 +1 @@
1
- 4.19.6
1
+ 4.19.7
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 4.19.7 (2022-02-13)
2
+
3
+ ##### Chores
4
+
5
+ * **other:**
6
+ * activate route replacement - added backward compatibility with current route replacement for higher envs - MWP-7941 [MWP-7941](https://webgate.ec.europa.eu/CITnet/jira/browse/MWP-7941) ([be5735d6](https://webgate.ec.europa.eu/CITnet/stash/scm/csdr/eui-tools.git/commits/be5735d645e360389b64da44b2b9fcae4739febf))
7
+
8
+ * * *
9
+ * * *
1
10
  ## 4.19.6 (2022-02-07)
2
11
 
3
12
  ##### Bug Fixes
package/global.test.js CHANGED
@@ -28,6 +28,7 @@ describe('eUI tools - test imports', () => {
28
28
  const prebuildInjectionConfig = require('./scripts/utils/pre-build/injection/config');
29
29
  const prebuildInjectionSkeletons = require('./scripts/utils/pre-build/injection/skeletons');
30
30
  const prebuildInjectionExternals = require('./scripts/utils/pre-build/injection/externals');
31
+ const prebuildInjectionRoutesReplacement = require('./scripts/utils/pre-build/injection/routes-replacement');
31
32
 
32
33
  // utils -pre-build - translations
33
34
  const prebuildTranslationUtils = require('./scripts/utils/pre-build/translations/translation-utils');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eui/tools",
3
- "version": "4.19.6",
3
+ "version": "4.19.7",
4
4
  "tag": "latest",
5
5
  "license": "EUPL-1.1",
6
6
  "description": "eUI common tools and scripts",
package/sandbox.js CHANGED
@@ -648,5 +648,6 @@ return Promise.resolve()
648
648
  // return injectionUtils.externals.injectExternalAppSources(prj);
649
649
  // })
650
650
  .then(() => {
651
- return injectionUtils.externals.remapRoutesByEnvConfig(prj, 'DEV', true);
651
+ // return injectionUtils.externals.remapRoutesByEnvConfig(prj, 'DEV', true);
652
+ return injectionUtils.routesReplacement.buildRoutes(prj, 'DEV', false);
652
653
  })
@@ -9,7 +9,7 @@ const configUtils = require('../../../csdr/config/config-utils');
9
9
 
10
10
  module.exports.injectExternalFeatures = (project) => {
11
11
 
12
- tools.logInfo(`Injecting project external features for : ${project.name}`);
12
+ tools.logTitle(`Injecting project external features for : ${project.name}`);
13
13
 
14
14
  return Promise.resolve()
15
15
  .then(() => {
@@ -66,7 +66,7 @@ module.exports.injectExternalFeatures = (project) => {
66
66
 
67
67
  module.exports.injectExternalAppSources = (project) => {
68
68
 
69
- tools.logInfo(`Injecting project external application sources for : ${project.name}`);
69
+ tools.logTitle(`Injecting project external application sources for : ${project.name}`);
70
70
 
71
71
  return Promise.resolve()
72
72
  .then(() => {
@@ -123,7 +123,7 @@ module.exports.injectExternalAppSources = (project) => {
123
123
 
124
124
  module.exports.injectElementExternalSources = (pkg) => {
125
125
 
126
- tools.logInfo(`Injecting package external sources for : ${pkg.name}`);
126
+ tools.logTitle(`Injecting package external sources for : ${pkg.name}`);
127
127
 
128
128
  return Promise.resolve()
129
129
  .then(() => {
@@ -181,7 +181,7 @@ module.exports.injectElementExternalSources = (pkg) => {
181
181
 
182
182
  module.exports.injectExternalMock = (project) => {
183
183
 
184
- tools.logInfo(`Injecting project external mock for : ${project.name}`);
184
+ tools.logTitle(`Injecting project external mock for : ${project.name}`);
185
185
 
186
186
  return Promise.resolve()
187
187
  .then(() => {
@@ -197,148 +197,3 @@ module.exports.injectExternalMock = (project) => {
197
197
  throw e;
198
198
  })
199
199
  }
200
-
201
- module.exports.remapRoutesByEnvConfig = (project, envTarget, build) => {
202
- tools.logInfo(`Remapping routes by env config for ${envTarget}`);
203
-
204
- return Promise.resolve()
205
- .then(() => {
206
- // getting config file
207
- const projectAssetsPath = path.join(process.cwd(), project.folder, 'src', 'assets');
208
- let configFile;
209
-
210
- // build - envTarget based
211
- if (build) {
212
- let envTargetFinal = envTarget.toLowerCase();
213
- // dirty fix as openid files do not respect envTarget names
214
- if (envTargetFinal === 'tst') {
215
- envTargetFinal = 'test';
216
- }
217
- configFile = path.join(projectAssetsPath, 'openid-login-config.' + envTargetFinal + '.json');
218
-
219
- // serve configuration based
220
- } else {
221
- if (envTarget.indexOf('local') > -1) {
222
- configFile = path.join(projectAssetsPath, 'openid-login-config.' + envTarget.replace('-openid', '') + '.json');
223
- } else {
224
- configFile = path.join(projectAssetsPath, 'openid-login-config.local-' + envTarget + '.json');
225
- }
226
- }
227
-
228
- tools.logInfo(`checking ${configFile}`);
229
- if (!tools.isFileExists(configFile)) {
230
- tools.logError(`config file for ${envTarget} do not exists`);
231
- return;
232
- }
233
-
234
- // getting config file content and checking if routesRemapping is set
235
- const config = require(configFile);
236
- const routesRemapping = config.routesRemapping;
237
- if (!routesRemapping) {
238
- tools.logWarning('No routes remapping found in current config...skipping');
239
- return;
240
- }
241
-
242
- // checking is routes path declared
243
- if (!project.appSources.routesFilePath) {
244
- tools.logError('project appSources.routesFilePath is not declared in app config');
245
- return;
246
- }
247
-
248
- // checking is routes file exists
249
- const routesFilePath = path.join(project.paths.rootPath, project.appSources.routesFilePath);
250
- if (!tools.isFileExists(routesFilePath)) {
251
- tools.logError(`Unable to find routes files : ${routesFilePath}`);
252
- return;
253
- }
254
-
255
- let routesFileContent = tools.getFileContent(routesFilePath);
256
-
257
- // get routes file content and replace tokens
258
- routesRemapping.forEach((route) => {
259
- tools.logInfo(`\nchecking replacement for : ${JSON.stringify(route)}`);
260
- const tokenToSearch = `./features/${route.featureModule}-lib.module#Module`;
261
- tools.logInfo(`Searching token : ${tokenToSearch}`);
262
- if (routesFileContent.indexOf(tokenToSearch) > -1) {
263
- tools.logInfo(`token ${tokenToSearch} found...replacing by ${route.routeModuleDef}`);
264
- routesFileContent = tools.replaceAll(routesFileContent, tokenToSearch, route.routeModuleDef);
265
- } else {
266
- tools.logWarning(`token ${tokenToSearch} NOT FOUND`);
267
- }
268
- })
269
-
270
- // extra physical routes remapping
271
- const extraRoutesRemapping = config.extraRoutesRemapping;
272
- if (!extraRoutesRemapping) {
273
- tools.logWarning('No extra routes remapping found in current config...skipping');
274
-
275
- } else {
276
- tools.logInfo('Extra routes remapping');
277
- extraRoutesRemapping.forEach((route) => {
278
- tools.logInfo(`checking replacement ${JSON.stringify(route)}`);
279
- const tokenToSearch = route.currentRoute;
280
- if (routesFileContent.indexOf(tokenToSearch) > -1) {
281
- tools.logInfo(`token ${tokenToSearch} found...replacing by ${route.updatedRoute}`);
282
- routesFileContent = tools.replaceAll(routesFileContent, tokenToSearch, route.updatedRoute);
283
- } else {
284
- tools.logWarning(`token ${tokenToSearch} NOT FOUND`);
285
- }
286
- })
287
- }
288
-
289
- // checking paths mapping (new method for v10 remotes)
290
- const pathsMapping = config.pathsMapping;
291
- if (!pathsMapping) {
292
- tools.logWarning('No pathsMapping found in current config...skipping');
293
-
294
- } else {
295
- tools.logInfo('Paths mappings for v10 remotes activation');
296
- pathsMapping.forEach((pathMapping) => {
297
- tools.logInfo(`Checking path: ${pathMapping.path}`);
298
- const placeholderToSearch = `// ${pathMapping.path}-placeholder`;
299
-
300
- if (routesFileContent.indexOf(placeholderToSearch) > -1) {
301
- tools.logInfo(`path placeholder: "${placeholderToSearch}" found...replacing`);
302
-
303
- let placeholderContent = '';
304
- if (pathMapping.data) {
305
- placeholderContent += 'data:{';
306
- if (pathMapping.data.featureName) {
307
- placeholderContent += `featureName: "${pathMapping.data.featureName}"`;
308
- }
309
- if (pathMapping.data.moduleId) {
310
- placeholderContent += `, moduleId: "${pathMapping.data.moduleId}"`;
311
- }
312
- if (pathMapping.data.elementTag) {
313
- placeholderContent += `, elementTag: "${pathMapping.data.elementTag}"`;
314
- }
315
- if (pathMapping.data.iframe) {
316
- placeholderContent += `, iframe: ${pathMapping.data.iframe}`;
317
- }
318
- placeholderContent += '}';
319
- }
320
- if (pathMapping.loadChildren) {
321
- placeholderContent += `, loadChildren: "${pathMapping.loadChildren}"`;
322
- }
323
-
324
- tools.logInfo('Generated content for route: ');
325
- console.log(placeholderContent);
326
-
327
- routesFileContent = tools.replaceAll(routesFileContent, placeholderToSearch, placeholderContent);
328
-
329
- } else {
330
- tools.logWarning(`token ${placeholderToSearch} NOT FOUND`);
331
- }
332
- })
333
- }
334
-
335
- return tools.writeFileContent(routesFilePath, routesFileContent);
336
- })
337
- .then(() => {
338
- tools.logSuccess();
339
- })
340
-
341
- .catch((e) => {
342
- throw e;
343
- })
344
- }
@@ -4,8 +4,10 @@
4
4
  const innerConfig = require('./config');
5
5
  const innerSkeletons = require('./skeletons');
6
6
  const innerExternals = require('./externals');
7
+ const innerRoutesReplacement = require('./routes-replacement');
7
8
 
8
9
  // re-exports inner modules
9
10
  module.exports.config = innerConfig;
10
11
  module.exports.skeletons = innerSkeletons;
11
12
  module.exports.externals = innerExternals;
13
+ module.exports.routesReplacement = innerRoutesReplacement;
@@ -0,0 +1,312 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const _ = require('lodash');
5
+
6
+ const tools = require('../../tools');
7
+ const configUtils = require('../../../csdr/config/config-utils');
8
+
9
+
10
+ const getEnvConfig = (project, envTarget, build) => {
11
+ tools.logInfo(`Getting config file for env : ${envTarget}`);
12
+
13
+ return Promise.resolve()
14
+ .then(() => {
15
+ // getting config file
16
+ const projectAssetsPath = path.join(process.cwd(), project.folder, 'src', 'assets');
17
+ let configFile;
18
+
19
+ // build - envTarget based
20
+ if (build) {
21
+ let envTargetFinal = envTarget.toLowerCase();
22
+ // dirty fix as openid files do not respect envTarget names
23
+ if (envTargetFinal === 'tst') {
24
+ envTargetFinal = 'test';
25
+ }
26
+ configFile = path.join(projectAssetsPath, 'openid-login-config.' + envTargetFinal + '.json');
27
+
28
+ // serve configuration based
29
+ } else {
30
+ if (envTarget.indexOf('local') > -1) {
31
+ configFile = path.join(projectAssetsPath, 'openid-login-config.' + envTarget.replace('-openid', '') + '.json');
32
+ } else {
33
+ configFile = path.join(projectAssetsPath, 'openid-login-config.local-' + envTarget + '.json');
34
+ }
35
+ }
36
+
37
+ tools.logInfo(`checking ${configFile}`);
38
+ if (!tools.isFileExists(configFile)) {
39
+ tools.logError(`config file for ${envTarget} do not exists`);
40
+ return;
41
+ }
42
+
43
+ return require(configFile);
44
+ })
45
+
46
+ .catch((e) => {
47
+ throw e;
48
+ })
49
+ }
50
+
51
+ const getRoutesFile = (project, isFullReplacement) => {
52
+ tools.logInfo('Getting routes file for replacement');
53
+
54
+ return Promise.resolve()
55
+ .then(() => {
56
+ if (!project.appSources) {
57
+ tools.logError('project requires appSources definition');
58
+ return;
59
+ }
60
+
61
+ let routesFilePath;
62
+
63
+ if (isFullReplacement) {
64
+ let srcRoutesFilePath;
65
+
66
+ if (!project.appSources.routesFileNpmPkg || !project.appSources.routesFileSource || !project.appSources.routesFilePath) {
67
+ tools.logError('project requires appSources.routesFileNpmPkg, routesFileSources and routesFilePath definitions');
68
+ return;
69
+ }
70
+
71
+ // check if package is locally cloned
72
+ const localPackage = configUtils.packages.getPackages().filter((p) => {
73
+ return p.npmPkg === project.appSources.routesFileNpmPkg
74
+ })[0];
75
+
76
+ // if local package is found
77
+ if (localPackage) {
78
+ tools.logInfo('local package found, copying from local');
79
+ srcRoutesFilePath = path.join(process.cwd(), 'packages', localPackage.name, project.appSources.routesFileSource);
80
+
81
+ // if not sources are taken from the npm package def in node_modules
82
+ } else {
83
+ tools.logInfo('remote package found, copying from remote');
84
+ const npmPkgScope = project.appSources.routesFileNpmPkg.substr(0, project.appSources.routesFileNpmPkg.indexOf('/'));
85
+ const npmPkgName = project.appSources.routesFileNpmPkg.substr(project.appSources.routesFileNpmPkg.indexOf('/') + 1);
86
+
87
+ srcRoutesFilePath = path.join(process.cwd(), 'node_modules', npmPkgScope, npmPkgName, project.appSources.routesFileSource);
88
+ }
89
+
90
+ routesFilePath = path.join(project.paths.rootPath, project.appSources.routesFilePath);
91
+
92
+ // copy source file to project destination
93
+ tools.copy(srcRoutesFilePath, routesFilePath);
94
+
95
+ } else {
96
+ if (!project.appSources.routesFilePath) {
97
+ tools.logError('project requires appSources.routesFilePath definition');
98
+ return;
99
+ }
100
+
101
+ routesFilePath = path.join(project.paths.rootPath, project.appSources.routesFilePath);
102
+ }
103
+
104
+ // checking is routes path declared
105
+ if (!tools.isFileExists(routesFilePath)) {
106
+ tools.logError(`Unable to find ${routesFilePath}`);
107
+ return;
108
+ }
109
+
110
+ return routesFilePath;
111
+ })
112
+
113
+ .catch((e) => {
114
+ throw e;
115
+ })
116
+ }
117
+
118
+ const remapRoutes = (config, routesFileContent) => {
119
+ tools.logInfo('config.routesRemapping found...Staring routes remapping');
120
+
121
+ console.log(routesFileContent);
122
+
123
+ return Promise.resolve()
124
+ .then(() => {
125
+ config.routesRemapping.forEach((route) => {
126
+ tools.logInfo(`\nchecking replacement for : ${JSON.stringify(route)}`);
127
+ const tokenToSearch = `./features/${route.featureModule}-lib.module#Module`;
128
+ tools.logInfo(`Searching token : ${tokenToSearch}`);
129
+ if (routesFileContent.indexOf(tokenToSearch) > -1) {
130
+ tools.logInfo(`token ${tokenToSearch} found...replacing by ${route.routeModuleDef}`);
131
+ routesFileContent = tools.replaceAll(routesFileContent, tokenToSearch, route.routeModuleDef);
132
+ } else {
133
+ tools.logWarning(`token ${tokenToSearch} NOT FOUND`);
134
+ }
135
+ })
136
+
137
+ if (!config.extraRoutesRemapping) {
138
+ tools.logWarning('No extra routes remapping found in current config...skipping');
139
+
140
+ } else {
141
+ tools.logInfo('Extra routes remapping');
142
+ config.extraRoutesRemapping.forEach((route) => {
143
+ tools.logInfo(`checking replacement ${JSON.stringify(route)}`);
144
+ const tokenToSearch = route.currentRoute;
145
+ if (routesFileContent.indexOf(tokenToSearch) > -1) {
146
+ tools.logInfo(`token ${tokenToSearch} found...replacing by ${route.updatedRoute}`);
147
+ routesFileContent = tools.replaceAll(routesFileContent, tokenToSearch, route.updatedRoute);
148
+ } else {
149
+ tools.logWarning(`token ${tokenToSearch} NOT FOUND`);
150
+ }
151
+ })
152
+ }
153
+
154
+ return routesFileContent;
155
+ })
156
+
157
+ .catch((e) => {
158
+ throw e;
159
+ })
160
+ }
161
+
162
+
163
+ const replaceRoutes = (project, envTarget, build, routesFileContent) => {
164
+ tools.logInfo('config.routesRemapping not found...Starting full routes replacement');
165
+
166
+ return Promise.resolve()
167
+ .then(() => {
168
+ // getting base route defs content
169
+ const projectAssetsPath = path.join(process.cwd(), project.folder, 'src', 'assets');
170
+ const baseRouteDefsPath = path.join(projectAssetsPath, 'route-defs-base.json');
171
+
172
+ if (!tools.isFileExists(baseRouteDefsPath)) {
173
+ tools.logError(`${baseRouteDefsPath} File NOT FOUND`);
174
+ throw 'BASE_ROUTE_DEFS_FILE_NOT_FOUND';
175
+ }
176
+
177
+ const baseRouteDefsJSON = require(baseRouteDefsPath);
178
+
179
+ // getting env route defs content if build mode (not serve)
180
+ let envRouteDefsPath, envRouteDefsJSON = [];
181
+ if (build) {
182
+ envRouteDefsPath = path.join(projectAssetsPath, 'route-defs.' + envTarget.toLowerCase() + '.json');
183
+
184
+ if (!tools.isFileExists(envRouteDefsPath)) {
185
+ tools.logError(`${envRouteDefsPath} File NOT FOUND`);
186
+ throw 'ENV_ROUTE_DEFS_FILE_NOT_FOUND';
187
+ }
188
+ envRouteDefsJSON = require(envRouteDefsPath);
189
+ }
190
+
191
+ // merging content of base + env
192
+ tools.logInfo(`Merging ${baseRouteDefsPath} with ${envRouteDefsPath}`);
193
+
194
+ const mergedRouteDefs = _.merge(_.keyBy(baseRouteDefsJSON, 'path'), _.keyBy(envRouteDefsJSON, 'path'));
195
+ const finalRouteDefs = _.values(mergedRouteDefs);
196
+
197
+
198
+ // processing routes
199
+ let placeHolderContent = '';
200
+
201
+ tools.logInfo('Processing routes replacement');
202
+ finalRouteDefs.forEach((route) => {
203
+ tools.logInfo(`====> route : ${route.path}`);
204
+
205
+ let routeContent = '{\n';
206
+
207
+ routeContent += ` path: '${route.path}',\n`;
208
+ if (route.data) {
209
+ routeContent += ' data: {\n';
210
+
211
+ if (route.data.id) {
212
+ routeContent += ` id: '${route.data.id}',\n`;
213
+ }
214
+ if (route.data.ids) {
215
+ routeContent += ` ids: '${route.data.ids}',\n`;
216
+ }
217
+ if (route.data.featureName) {
218
+ routeContent += ` featureName: '${route.data.featureName}',\n`;
219
+ }
220
+ if (route.data.moduleId) {
221
+ routeContent += ` moduleId: '${route.data.moduleId}',\n`;
222
+ }
223
+ if (route.data.elementTag) {
224
+ routeContent += ` elementTag: '${route.data.elementTag}',\n`;
225
+ }
226
+ if (route.data.iframe) {
227
+ routeContent += ` iframe: ${route.data.iframe},\n`;
228
+ }
229
+ routeContent += ' },\n';
230
+ }
231
+ if (route.canActivate) {
232
+ routeContent += ` canActivate: ${route.canActivate},\n`;
233
+ }
234
+ if (route.loadChildren) {
235
+ routeContent += ` loadChildren: '${route.loadChildren}',\n`
236
+ }
237
+ routeContent += '},\n\n';
238
+
239
+ placeHolderContent += routeContent;
240
+
241
+ tools.logSuccess('======> OK replaced');
242
+ })
243
+
244
+ const placeHolderToken = '// routes-placeholder';
245
+ routesFileContent = tools.replaceAll(routesFileContent, placeHolderToken, placeHolderContent);
246
+
247
+ tools.logInfo('Routes file content replaced : ');
248
+ console.log(routesFileContent);
249
+
250
+ return routesFileContent;
251
+ })
252
+
253
+ .catch((e) => {
254
+ throw e;
255
+ })
256
+ }
257
+
258
+
259
+ module.exports.buildRoutes = (project, envTarget, build) => {
260
+ tools.logTitle('Starting routes replacement');
261
+
262
+ let config, routesFile, routesFileContent;
263
+
264
+ return Promise.resolve()
265
+ .then(() => {
266
+ return getEnvConfig(project, envTarget, build);
267
+ })
268
+ .then((envConfig) => {
269
+ if (!envConfig) {
270
+ throw 'ENV_CONFIG_NOT_FOUND';
271
+ }
272
+ config = envConfig;
273
+ })
274
+
275
+ .then(() => {
276
+ if (config.routesRemapping) {
277
+ return getRoutesFile(project);
278
+
279
+ } else {
280
+ return getRoutesFile(project, true);
281
+ }
282
+ })
283
+ .then((outRoutesFile) => {
284
+ if (!outRoutesFile) {
285
+ throw 'ROUTES_FILE_NOT_FOUND';
286
+ }
287
+ routesFile = outRoutesFile;
288
+ routesFileContent = tools.getFileContent(routesFile);
289
+ })
290
+
291
+
292
+ .then(() => {
293
+ if (config.routesRemapping) {
294
+ return remapRoutes(config, routesFileContent);
295
+
296
+ } else {
297
+ return replaceRoutes(project, envTarget, build, routesFileContent);
298
+ }
299
+ })
300
+
301
+ .then((finalRouteFileContent) => {
302
+ return tools.writeFileContent(routesFile, finalRouteFileContent);
303
+ })
304
+ .then(() => {
305
+ tools.logSuccess();
306
+ })
307
+
308
+ .catch((e) => {
309
+ throw e;
310
+ })
311
+ }
312
+
@@ -60,7 +60,7 @@ module.exports.preBuild = (project, envTarget, build, configEnvTarget) => {
60
60
 
61
61
  .then(() => {
62
62
  if (project.config && project.appSources && project.appSources.external && project.appSources.remapRoutesByEnvConfig) {
63
- return injectionUtils.externals.remapRoutesByEnvConfig(project, envTarget, build);
63
+ return injectionUtils.routesReplacement.buildRoutes(project, envTarget, build);
64
64
  }
65
65
  })
66
66