@eui/tools 6.10.1 → 6.10.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.
package/.prettierrc.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "quoteProps": "as-needed",
12
12
  "requirePragma": false,
13
13
  "semi": true,
14
- "singleQuote": false,
14
+ "singleQuote": true,
15
15
  "tabWidth": 2,
16
16
  "trailingComma": "es5",
17
17
  "useTabs": false,
@@ -1 +1 @@
1
- 6.10.1
1
+ 6.10.2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 6.10.2 (2023-03-27)
2
+
3
+ ##### Chores
4
+
5
+ * **other:**
6
+ * add remote-metadata.json extraction during routes replacement - refactored route replacement - MWP-9204 [MWP-9204](https://webgate.ec.europa.eu/CITnet/jira/browse/MWP-9204) ([d70be286](https://webgate.ec.europa.eu/CITnet/stash/scm/csdr/eui-tools.git/commits/d70be286e52a0f9a4f2be0f3d854d4fe20776870))
7
+
8
+ * * *
9
+ * * *
1
10
  ## 6.10.1 (2023-03-24)
2
11
 
3
12
  ##### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eui/tools",
3
- "version": "6.10.1",
3
+ "version": "6.10.2",
4
4
  "tag": "latest",
5
5
  "license": "EUPL-1.1",
6
6
  "description": "eUI common tools and scripts",
@@ -8,10 +8,73 @@ const configUtils = require('../../../csdr/config/config-utils');
8
8
 
9
9
  const { debug } = tools.getArgs();
10
10
 
11
+ /**
12
+ *
13
+ * ROUTES REPLACEMENT
14
+ *
15
+ */
16
+
17
+ /**
18
+ * Process routes either for playground local environment OR by envTarget at build time,
19
+ * injects the routesContent generated inside the project/src/app/app.routes.ts file from a base route file and
20
+ * based on definitions in mywp-host-ui/assets/routes folder definitions as data input
21
+ *
22
+ * used by projects pre-build phase
23
+ *
24
+ * PUBLIC
25
+ *
26
+ * @param {project} project The CSDR project object fetched from csdr global projects config
27
+ * @param {string} envTarget The build-time environment target provided to target specific routes for specific environment deployments
28
+ * @param {boolean} build if the script is launched from a release pipeline OR from local CSDR playground environment (false in that case)
29
+ * @returns {Promise} returns a Promise as it involves async I/O processes
30
+ */
31
+ module.exports.buildRoutes = (project, envTarget, build) => {
32
+ tools.logTitle('Starting routes replacement');
33
+
34
+ let config, routesFile, routesFileContent;
35
+
36
+ const euiVersion = configUtils.projects.getProjectEuiVersion(project);
37
+
38
+ return Promise.resolve()
39
+ .then(() => {
40
+ return injectRoutesConfig(project, project.externalRoutesSources.routesConfigNpmPkg);
41
+ })
42
+
43
+ .then(() => {
44
+ return getRoutesFile(project, euiVersion);
45
+ })
46
+ .then((outRoutesFile) => {
47
+ if (!outRoutesFile) {
48
+ throw 'ROUTES_FILE_NOT_FOUND';
49
+ }
50
+ routesFile = outRoutesFile;
51
+ routesFileContent = tools.getFileContent(routesFile);
52
+ })
53
+
54
+ .then(() => {
55
+ return processRoutesConfig(project, envTarget, build, routesFile, routesFileContent, euiVersion);
56
+ })
57
+
58
+ .then(() => {
59
+ tools.logSuccess();
60
+ })
11
61
 
62
+ .catch((e) => {
63
+ throw e;
64
+ });
65
+ };
66
+
67
+ /**
68
+ * Get the env target, transform input envTarget to known files suffix or handle local / playground file
69
+ *
70
+ * PRIVATE
71
+ *
72
+ * @param {string} envTargetIn The build-time environment target provided to target specific routes for specific environment deployments
73
+ * @param {boolean} build if the script is launched from a release pipeline OR from local CSDR playground environment (false in that case) * @return routeContent the text block transformed from the route object as input
74
+ * @returns {string} the envTarget transformed
75
+ */
12
76
  const getEnvTarget = (envTargetIn, build) => {
13
77
  if (!envTargetIn) {
14
-
15
78
  // check if envTarget has been provided as cli args for stand-alone local build of CSDR apps
16
79
  const { envTarget } = tools.getArgs();
17
80
 
@@ -30,7 +93,7 @@ const getEnvTarget = (envTargetIn, build) => {
30
93
  envTargetFinal = 'test';
31
94
  }
32
95
 
33
- // serve configuration based
96
+ // serve configuration based
34
97
  } else {
35
98
  if (envTargetIn.indexOf('local') > -1) {
36
99
  envTargetFinal = envTargetIn.replace('-openid', '');
@@ -40,9 +103,17 @@ const getEnvTarget = (envTargetIn, build) => {
40
103
  }
41
104
 
42
105
  return envTargetFinal;
43
- }
44
-
45
-
106
+ };
107
+
108
+ /**
109
+ * Get routes file of project
110
+ *
111
+ * PRIVATE
112
+ *
113
+ * @param {project} project The CSDR project object fetched from csdr global projects config
114
+ * @param {string} euiVersion the eUI version of the current project used mainly in local CSDR playground environment (format : v.x)
115
+ * @returns {string} routeContent the text block transformed from the route object as input
116
+ */
46
117
  const getRoutesFile = (project, euiVersion) => {
47
118
  tools.logInfo('Getting routes file for replacement');
48
119
 
@@ -56,14 +127,18 @@ const getRoutesFile = (project, euiVersion) => {
56
127
  let routesFilePath;
57
128
  let srcRoutesFilePath;
58
129
 
59
- if (!project.externalRoutesSources.routesConfigNpmPkg || !project.externalRoutesSources.routesFileSource || !project.externalRoutesSources.routesFilePath) {
130
+ if (
131
+ !project.externalRoutesSources.routesConfigNpmPkg ||
132
+ !project.externalRoutesSources.routesFileSource ||
133
+ !project.externalRoutesSources.routesFilePath
134
+ ) {
60
135
  tools.logError('project requires externalRoutesSources.routesConfigNpmPkg, routesFileSources and routesFilePath definitions');
61
136
  return;
62
137
  }
63
138
 
64
139
  // check if package is locally cloned
65
140
  const localPackage = configUtils.packages.getPackages().filter((p) => {
66
- return p.npmPkg === project.externalRoutesSources.routesConfigNpmPkg
141
+ return p.npmPkg === project.externalRoutesSources.routesConfigNpmPkg;
67
142
  })[0];
68
143
 
69
144
  // if local package is found
@@ -73,23 +148,35 @@ const getRoutesFile = (project, euiVersion) => {
73
148
  tools.logInfo(`constructing route path with eUI version provided: ${euiVersion}`);
74
149
 
75
150
  srcRoutesFilePath = path.join(
76
- process.cwd(), 'packages', localPackage.name,
77
- 'assets', euiVersion,
78
- project.externalRoutesSources.routesFileSource,
151
+ process.cwd(),
152
+ 'packages',
153
+ localPackage.name,
154
+ 'assets',
155
+ euiVersion,
156
+ project.externalRoutesSources.routesFileSource
79
157
  );
80
158
 
81
- // if not sources are taken from the npm package def in node_modules
159
+ // if not sources are taken from the npm package def in node_modules
82
160
  } else {
83
161
  tools.logInfo('remote package found, copying from remote');
84
- const npmPkgScope = project.externalRoutesSources.routesConfigNpmPkg.substr(0, project.externalRoutesSources.routesConfigNpmPkg.indexOf('/'));
85
- const npmPkgName = project.externalRoutesSources.routesConfigNpmPkg.substr(project.externalRoutesSources.routesConfigNpmPkg.indexOf('/') + 1);
162
+ const npmPkgScope = project.externalRoutesSources.routesConfigNpmPkg.substr(
163
+ 0,
164
+ project.externalRoutesSources.routesConfigNpmPkg.indexOf('/')
165
+ );
166
+ const npmPkgName = project.externalRoutesSources.routesConfigNpmPkg.substr(
167
+ project.externalRoutesSources.routesConfigNpmPkg.indexOf('/') + 1
168
+ );
86
169
 
87
170
  tools.logInfo(`constructing route path with eUI version provided: ${euiVersion}`);
88
171
 
89
172
  srcRoutesFilePath = path.join(
90
- process.cwd(), 'node_modules', npmPkgScope, npmPkgName,
91
- 'assets', euiVersion,
92
- project.externalRoutesSources.routesFileSource,
173
+ process.cwd(),
174
+ 'node_modules',
175
+ npmPkgScope,
176
+ npmPkgName,
177
+ 'assets',
178
+ euiVersion,
179
+ project.externalRoutesSources.routesFileSource
93
180
  );
94
181
  }
95
182
 
@@ -109,9 +196,17 @@ const getRoutesFile = (project, euiVersion) => {
109
196
 
110
197
  .catch((e) => {
111
198
  throw e;
112
- })
113
- }
114
-
199
+ });
200
+ };
201
+
202
+ /**
203
+ * Replace route object and transform into an Angular / eUI route definition
204
+ *
205
+ * PRIVATE
206
+ *
207
+ * @param {route} route route object containing the result of the route translated into route props
208
+ * @returns {string} routeContent the text block transformed from the route object as input
209
+ */
115
210
  const replaceRoute = (route) => {
116
211
  let routeContent = '{\n';
117
212
 
@@ -143,15 +238,29 @@ const replaceRoute = (route) => {
143
238
  routeContent += ` canActivate: ${route.canActivate},\n`;
144
239
  }
145
240
  if (route.loadChildren) {
146
- routeContent += ` ${route.loadChildren},\n`
241
+ routeContent += ` ${route.loadChildren},\n`;
147
242
  }
148
243
  routeContent += '},\n\n';
149
244
 
150
245
  return routeContent;
151
- }
152
-
153
-
154
- const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVersion) => {
246
+ };
247
+
248
+ /**
249
+ * Process the routes config
250
+ * generates : app.routes.ts project file replacing app.routes-base.ts placehodler / remotes-metadata.json / route-defs-links.json
251
+ * and feature lib modules in playground local env
252
+ *
253
+ * PRIVATE
254
+ *
255
+ * @param {project} project The CSDR project object fetched from csdr global projects config
256
+ * @param {string} envTarget The build-time environment target provided to target specific routes for specific environment deployments
257
+ * @param {boolean} build if the script is launched from a release pipeline OR from local CSDR playground environment (false in that case)
258
+ * @param {string} routesFile the route file at project sources target to replace / update
259
+ * @param {string} routesFileContent the content of the base routes file to inject into the placeholder defined
260
+ * @param {string} euiVersion the eUI version of the current project used mainly in local CSDR playground environment
261
+ * @returns {Promise} returns a Promise as it involves async I/O processes
262
+ */
263
+ const processRoutesConfig = (project, envTarget, build, routesFile, routesFileContent, euiVersion) => {
155
264
  return Promise.resolve()
156
265
  .then(() => {
157
266
  tools.logInfo('Replace routes v2...');
@@ -166,7 +275,6 @@ const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVe
166
275
  const euiVersionNumber = euiVersion.split('.')[0];
167
276
  const envTargetFinal = getEnvTarget(envTarget, build);
168
277
 
169
-
170
278
  // getting the input file definitions of routes for replacements
171
279
  // from tokenized template in config -- allowing to control playground vs normal env (when using the MWP HOST for release)
172
280
  // format :
@@ -184,8 +292,6 @@ const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVe
184
292
 
185
293
  tools.logInfo(`Starting replacement of routes based on generated template : ${routeDefsInputFilename}`);
186
294
 
187
-
188
-
189
295
  // Getting input routeDefs entry
190
296
 
191
297
  const routeDefsInputPath = path.join(projectAssetsPath, routeDefsInputFilename);
@@ -197,20 +303,26 @@ const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVe
197
303
 
198
304
  const routeDefsInputJSON = require(path.join(routeDefsInputPath));
199
305
 
200
- const appRoutes = [], appFeatureLibs = [];
306
+ const appRoutes = [],
307
+ appFeatureLibs = [],
308
+ finalRemotesDefs = [];
309
+
310
+ // processing each routes found in the routeDefs entry
201
311
 
202
312
  routeDefsInputJSON.forEach((route) => {
203
313
  tools.logInfo(`Processing route : ${route.path}`);
204
314
 
205
- const defRoute = routeDefsBaseJSON.filter(r => r.path === route.path)[0];
315
+ const defRoute = routeDefsBaseJSON.filter((r) => r.path === route.path)[0];
206
316
  if (!defRoute) {
207
317
  tools.logError('route not found for: ');
208
318
  console.log(route);
209
319
  throw 'ROUTE_NOT_FOUND';
210
-
211
320
  } else {
212
321
  let loadChildrenGenerated;
213
322
 
323
+ // in case of a lazy route, the route is generated from a import/export feature lib module TS file
324
+ // those files are also generated based on the route "lazyDefs" data definition
325
+
214
326
  if (route.lazy) {
215
327
  const scopeName = defRoute.lazyLoadDef.npmPkg.split('/')[0].substr(1);
216
328
  const pkgName = defRoute.lazyLoadDef.npmPkg.split('/')[1];
@@ -225,9 +337,10 @@ const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVe
225
337
  appFeatureLibs.push({
226
338
  filename: `${lazyFeatureLibName}.ts`,
227
339
  npmPkg: defRoute.lazyLoadDef.npmPkg,
228
- moduleName: defRoute.lazyLoadDef.moduleName
340
+ moduleName: defRoute.lazyLoadDef.moduleName,
229
341
  });
230
342
 
343
+ // if the route is a remote, the elementLoader is then used as a default feature module loaded
231
344
  } else {
232
345
  if (euiVersion === '10.x') {
233
346
  loadChildrenGenerated = 'loadChildren: "./features/element-loader.module#ElementLoaderModule"';
@@ -236,23 +349,28 @@ const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVe
236
349
  }
237
350
  }
238
351
 
352
+ // we define the route item definition, that will be injected in the project app.routes source
239
353
  const newAppRoute = {
240
354
  path: defRoute.path,
241
355
  loadChildren: loadChildrenGenerated,
242
- data: {}
356
+ data: {},
243
357
  };
244
358
 
359
+ // in the case the route is auth guarded, we attach the defition of the auth parameters
245
360
  if (defRoute.authMetadata) {
246
361
  newAppRoute.data.id = defRoute.authMetadata.id;
247
362
  newAppRoute.data.ids = defRoute.authMetadata.ids;
248
363
  newAppRoute.canActivate = defRoute.authMetadata.canActivate;
249
364
  }
250
365
 
366
+ // in case of a remote, the "remoteDefs" data entry are processed
367
+ // in case no remote corresponds to a remote path defined in the definitions, we throw an error and we stop the
368
+ // script to avoid bad route data / or partial routes data generated
251
369
  if (route.remote) {
252
370
  let remoteDef;
253
371
  try {
254
372
  remoteDef = defRoute.remoteDefs.filter((r) => {
255
- return r.euiVersion === route.euiVersion
373
+ return r.euiVersion === route.euiVersion;
256
374
  })[0];
257
375
  } catch {
258
376
  tools.logError('Remote route not found for: ');
@@ -264,18 +382,28 @@ const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVe
264
382
  newAppRoute.data.moduleId = remoteDef.moduleId;
265
383
  newAppRoute.data.elementTag = remoteDef.elementTag;
266
384
  newAppRoute.data.iframe = remoteDef.iframe;
267
-
268
385
  } else {
269
386
  tools.logError('Remote route not found for: ');
270
387
  console.log(route);
271
388
  throw 'REMOTE_ROUTE_DEF_NOT_FOUND';
272
389
  }
390
+
391
+ finalRemotesDefs.push(remoteDef.moduleId);
273
392
  }
274
393
 
275
394
  appRoutes.push(newAppRoute);
276
395
  }
277
- })
396
+ });
397
+
398
+ // writing final remotes metadata file base on routes definitions (loaded at runtime by the app for gathering the list of remotes)
399
+
400
+ if (finalRemotesDefs.length > 0) {
401
+ const finalRemotesDefsFile = path.join(projectAssetsPath, 'remotes-metadata.json');
278
402
 
403
+ tools.logInfo(`Generating ${finalRemotesDefsFile}`);
404
+
405
+ tools.writeJsonFileSync(finalRemotesDefsFile, finalRemotesDefs);
406
+ }
279
407
 
280
408
  // processing creation of features lib modules entries
281
409
 
@@ -301,8 +429,7 @@ const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVe
301
429
  tools.writeFileContent(featureLibPath, featureLibDef);
302
430
  });
303
431
 
304
-
305
- // processing links generation
432
+ // processing links generation : generates a routes-defs-links.json based on the routes-defs-base-links.json definitions
306
433
 
307
434
  const routeDefsBaseLinksFileName = 'route-defs-base-links.json';
308
435
  const routeDefsBaseLinksJSON = require(path.join(projectAssetsPath, routeDefsBaseLinksFileName));
@@ -326,7 +453,10 @@ const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVe
326
453
  }
327
454
 
328
455
  return routeDef;
329
- }
456
+ };
457
+
458
+ // inner method for checking based on the "allowedEnvs" option provided on the links definition if the link has to be added
459
+ // to the links list
330
460
 
331
461
  const isLinkAllowed = (link) => {
332
462
  // allow all link for playground - local env
@@ -344,7 +474,9 @@ const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVe
344
474
  } else {
345
475
  return true;
346
476
  }
347
- }
477
+ };
478
+
479
+ // processing each link and matching route from routes base data definitions
348
480
 
349
481
  const linksGenerated = [];
350
482
 
@@ -353,7 +485,7 @@ const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVe
353
485
 
354
486
  if (link.parentId) {
355
487
  if (isLinkAllowed(link)) {
356
- newLink = { ...link};
488
+ newLink = { ...link };
357
489
  newLink.children = [];
358
490
 
359
491
  link.children.forEach((subLink) => {
@@ -364,9 +496,8 @@ const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVe
364
496
  newLink.children.push(defRoute);
365
497
  }
366
498
  }
367
- })
499
+ });
368
500
  }
369
-
370
501
  } else {
371
502
  if (isLinkAllowed(link)) {
372
503
  const defRoute = getRouteMenuDef(link);
@@ -376,6 +507,10 @@ const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVe
376
507
  } else {
377
508
  newLink = link;
378
509
  }
510
+
511
+ if (link.alwaysDisplayed) {
512
+ newLink.alwaysDisplayed = true;
513
+ }
379
514
  }
380
515
  }
381
516
 
@@ -393,7 +528,6 @@ const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVe
393
528
 
394
529
  tools.writeJsonFileSync(path.join(projectAssetsPath, 'route-defs-links.json'), linksGenerated);
395
530
 
396
-
397
531
  // getting routes content for replacement
398
532
 
399
533
  tools.logInfo('Processing routes replacement');
@@ -412,21 +546,28 @@ const processRoutesConfig = (project, envTarget, build, routesFileContent, euiVe
412
546
  console.log(routesFileContent);
413
547
  }
414
548
 
415
- return routesFileContent;
549
+ // writing final routes content into project sources
550
+ tools.writeFileContent(routesFile, routesFileContent);
416
551
  })
417
552
 
418
553
  .catch((e) => {
419
554
  throw e;
420
- })
421
- }
422
-
423
-
424
-
425
-
555
+ });
556
+ };
557
+
558
+ /**
559
+ * Inject the routes config assets from mywp-host-ui / assets / routes to virtual project assets folder
560
+ *
561
+ * PRIVATE
562
+ *
563
+ * @param {project} project The CSDR project object fetched from csdr global projects config
564
+ * @param {string} npmPkg The npm package dependency containing the routes definition (for MyWorkplace : mywp-host-ui => @mywp/host)
565
+ * @returns undefined
566
+ */
426
567
  const injectRoutesConfig = (project, npmPkg) => {
427
568
  // check if package is locally cloned
428
569
  const localPackage = configUtils.packages.getPackages().filter((p) => {
429
- return p.npmPkg === npmPkg
570
+ return p.npmPkg === npmPkg;
430
571
  })[0];
431
572
 
432
573
  var pkgAssetsPath;
@@ -436,7 +577,7 @@ const injectRoutesConfig = (project, npmPkg) => {
436
577
  if (localPackage) {
437
578
  pkgAssetsPath = path.join(process.cwd(), 'packages', localPackage.name, 'assets');
438
579
 
439
- // if not sources are taken from the npm package def in node_modules
580
+ // if not sources are taken from the npm package def in node_modules
440
581
  } else {
441
582
  const npmPkgScope = npmPkg.substr(0, npmPkg.indexOf('/'));
442
583
  const npmPkgName = npmPkg.substr(npmPkg.indexOf('/') + 1);
@@ -452,48 +593,4 @@ const injectRoutesConfig = (project, npmPkg) => {
452
593
 
453
594
  tools.logInfo(`${routesConfigPath} - injecting in ${projectAssetsPath}`);
454
595
  tools.copydir(routesConfigPath, projectAssetsPath);
455
- }
456
-
457
-
458
-
459
-
460
- module.exports.buildRoutes = (project, envTarget, build) => {
461
- tools.logTitle('Starting routes replacement');
462
-
463
- let config, routesFile, routesFileContent;
464
-
465
- const euiVersion = configUtils.projects.getProjectEuiVersion(project);
466
-
467
- return Promise.resolve()
468
- .then(() => {
469
- return injectRoutesConfig(project, project.externalRoutesSources.routesConfigNpmPkg);
470
- })
471
-
472
- .then(() => {
473
- return getRoutesFile(project, euiVersion);
474
- })
475
- .then((outRoutesFile) => {
476
- if (!outRoutesFile) {
477
- throw 'ROUTES_FILE_NOT_FOUND';
478
- }
479
- routesFile = outRoutesFile;
480
- routesFileContent = tools.getFileContent(routesFile);
481
- })
482
-
483
- .then(() => {
484
- return processRoutesConfig(project, envTarget, build, routesFileContent, euiVersion);
485
- })
486
-
487
- .then((finalRouteFileContent) => {
488
- return tools.writeFileContent(routesFile, finalRouteFileContent);
489
- })
490
-
491
- .then(() => {
492
- tools.logSuccess();
493
- })
494
-
495
- .catch((e) => {
496
- throw e;
497
- })
498
- }
499
-
596
+ };