@eui/tools 6.12.29 → 6.12.30
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/.version.properties +1 -1
- package/CHANGELOG.md +10 -0
- package/package.json +1 -1
- package/scripts/csdr/config/projects.js +2 -0
- package/scripts/index.js +4 -1
- package/scripts/utils/pre-build/injection/injection-utils.js +0 -1
- package/scripts/utils/pre-build/projects.js +5 -3
- package/scripts/utils/pre-build/routes-replacement/routes-replacement-subs.js +143 -0
- package/scripts/utils/pre-build/routes-replacement/routes-replacement.js +682 -0
- package/scripts/utils/pre-build/injection/routes-replacement.js +0 -776
|
@@ -1,776 +0,0 @@
|
|
|
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
|
-
const initUtils = require('../../../csdr/init/init-utils');
|
|
9
|
-
|
|
10
|
-
const { debug } = tools.getArgs();
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* ROUTES REPLACEMENT
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Process routes either for playground local environment OR by envTarget at build time,
|
|
20
|
-
* injects the routesContent generated inside the project/src/app/app.routes.ts file from a base route file and
|
|
21
|
-
* based on definitions in mywp-host-ui/assets/routes folder definitions as data input
|
|
22
|
-
*
|
|
23
|
-
* used by projects pre-build phase
|
|
24
|
-
*
|
|
25
|
-
* PUBLIC
|
|
26
|
-
*
|
|
27
|
-
* @param {project} project The CSDR project object fetched from csdr global projects config
|
|
28
|
-
* @param {string} envTarget The build-time environment target provided to target specific routes for specific environment deployments
|
|
29
|
-
* @param {boolean} build if the script is launched from a release pipeline OR from local CSDR playground environment (false in that case)
|
|
30
|
-
* @returns {Promise} returns a Promise as it involves async I/O processes
|
|
31
|
-
*/
|
|
32
|
-
module.exports.buildRoutes = (project, envTarget, build) => {
|
|
33
|
-
tools.logTitle('Starting routes replacement');
|
|
34
|
-
|
|
35
|
-
let config, routesFile, routesFileContent;
|
|
36
|
-
|
|
37
|
-
const euiVersion = configUtils.projects.getProjectEuiVersion(project);
|
|
38
|
-
|
|
39
|
-
return Promise.resolve()
|
|
40
|
-
.then(() => {
|
|
41
|
-
return injectRoutesConfig(project, project.externalRoutesSources.routesConfigNpmPkg);
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
.then(() => {
|
|
45
|
-
return getRoutesFile(project, euiVersion);
|
|
46
|
-
})
|
|
47
|
-
.then((outRoutesFile) => {
|
|
48
|
-
if (!outRoutesFile) {
|
|
49
|
-
throw 'ROUTES_FILE_NOT_FOUND';
|
|
50
|
-
}
|
|
51
|
-
routesFile = outRoutesFile;
|
|
52
|
-
routesFileContent = tools.getFileContent(routesFile);
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
.then(() => {
|
|
56
|
-
return processRoutesConfig(project, envTarget, build, routesFile, routesFileContent, euiVersion);
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
.then(() => {
|
|
60
|
-
tools.logSuccess();
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
.catch((e) => {
|
|
64
|
-
throw e;
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Get the env target, transform input envTarget to known files suffix or handle local / playground file
|
|
70
|
-
*
|
|
71
|
-
* PRIVATE
|
|
72
|
-
*
|
|
73
|
-
* @param {string} envTargetIn The build-time environment target provided to target specific routes for specific environment deployments
|
|
74
|
-
* @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
|
|
75
|
-
* @returns {string} the envTarget transformed
|
|
76
|
-
*/
|
|
77
|
-
const getEnvTarget = (envTargetIn, build) => {
|
|
78
|
-
if (!envTargetIn) {
|
|
79
|
-
// check if envTarget has been provided as cli args for stand-alone local build of CSDR apps
|
|
80
|
-
const { envTarget } = tools.getArgs();
|
|
81
|
-
|
|
82
|
-
if (!envTarget) {
|
|
83
|
-
throw 'ENV_TARGET_NOT_FOUND';
|
|
84
|
-
} else {
|
|
85
|
-
envTargetIn = envTarget;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
let envTargetFinal = envTargetIn.toLowerCase();
|
|
90
|
-
|
|
91
|
-
if (build) {
|
|
92
|
-
// dirty fix as openid files do not respect envTarget names
|
|
93
|
-
if (envTargetFinal === 'tst') {
|
|
94
|
-
envTargetFinal = 'test';
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// serve configuration based
|
|
98
|
-
} else {
|
|
99
|
-
if (envTargetIn.indexOf('local') > -1) {
|
|
100
|
-
envTargetFinal = envTargetIn.replace('-openid', '');
|
|
101
|
-
} else {
|
|
102
|
-
envTargetFinal = 'local-' + envTargetFinal;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return envTargetFinal;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Get routes file of project
|
|
111
|
-
*
|
|
112
|
-
* PRIVATE
|
|
113
|
-
*
|
|
114
|
-
* @param {project} project The CSDR project object fetched from csdr global projects config
|
|
115
|
-
* @param {string} euiVersion the eUI version of the current project used mainly in local CSDR playground environment (format : v.x)
|
|
116
|
-
* @returns {string} routeContent the text block transformed from the route object as input
|
|
117
|
-
*/
|
|
118
|
-
const getRoutesFile = (project, euiVersion) => {
|
|
119
|
-
tools.logInfo('Getting routes file for replacement');
|
|
120
|
-
|
|
121
|
-
return Promise.resolve()
|
|
122
|
-
.then(() => {
|
|
123
|
-
if (!project.externalRoutesSources) {
|
|
124
|
-
tools.logError('project requires externalRoutesSources definition');
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
let routesFilePath;
|
|
129
|
-
let srcRoutesFilePath;
|
|
130
|
-
|
|
131
|
-
if (
|
|
132
|
-
!project.externalRoutesSources.routesConfigNpmPkg ||
|
|
133
|
-
!project.externalRoutesSources.routesFileSource ||
|
|
134
|
-
!project.externalRoutesSources.routesFilePath
|
|
135
|
-
) {
|
|
136
|
-
tools.logError('project requires externalRoutesSources.routesConfigNpmPkg, routesFileSources and routesFilePath definitions');
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// check if package is locally cloned
|
|
141
|
-
const localPackage = configUtils.packages.getPackages().filter((p) => {
|
|
142
|
-
return p.npmPkg === project.externalRoutesSources.routesConfigNpmPkg;
|
|
143
|
-
})[0];
|
|
144
|
-
|
|
145
|
-
// if local package is found
|
|
146
|
-
if (localPackage) {
|
|
147
|
-
tools.logInfo('local package found, copying from local');
|
|
148
|
-
|
|
149
|
-
tools.logInfo(`constructing route path with eUI version provided: ${euiVersion}`);
|
|
150
|
-
|
|
151
|
-
srcRoutesFilePath = path.join(
|
|
152
|
-
process.cwd(),
|
|
153
|
-
'packages',
|
|
154
|
-
localPackage.name,
|
|
155
|
-
'assets',
|
|
156
|
-
euiVersion,
|
|
157
|
-
project.externalRoutesSources.routesFileSource
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
// if not sources are taken from the npm package def in node_modules
|
|
161
|
-
} else {
|
|
162
|
-
tools.logInfo('remote package found, copying from remote');
|
|
163
|
-
const npmPkgScope = project.externalRoutesSources.routesConfigNpmPkg.substr(
|
|
164
|
-
0,
|
|
165
|
-
project.externalRoutesSources.routesConfigNpmPkg.indexOf('/')
|
|
166
|
-
);
|
|
167
|
-
const npmPkgName = project.externalRoutesSources.routesConfigNpmPkg.substr(
|
|
168
|
-
project.externalRoutesSources.routesConfigNpmPkg.indexOf('/') + 1
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
tools.logInfo(`constructing route path with eUI version provided: ${euiVersion}`);
|
|
172
|
-
|
|
173
|
-
srcRoutesFilePath = path.join(
|
|
174
|
-
process.cwd(),
|
|
175
|
-
'node_modules',
|
|
176
|
-
npmPkgScope,
|
|
177
|
-
npmPkgName,
|
|
178
|
-
'assets',
|
|
179
|
-
euiVersion,
|
|
180
|
-
project.externalRoutesSources.routesFileSource
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
routesFilePath = path.join(project.paths.rootPath, project.externalRoutesSources.routesFilePath);
|
|
185
|
-
|
|
186
|
-
// copy source file to project destination
|
|
187
|
-
tools.copy(srcRoutesFilePath, routesFilePath);
|
|
188
|
-
|
|
189
|
-
// checking is routes path declared
|
|
190
|
-
if (!tools.isFileExists(routesFilePath)) {
|
|
191
|
-
tools.logError(`Unable to find ${routesFilePath}`);
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return routesFilePath;
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
.catch((e) => {
|
|
199
|
-
throw e;
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Replace route object and transform into an Angular / eUI route definition
|
|
205
|
-
*
|
|
206
|
-
* PRIVATE
|
|
207
|
-
*
|
|
208
|
-
* @param {route} route route object containing the result of the route translated into route props
|
|
209
|
-
* @returns {string} routeContent the text block transformed from the route object as input
|
|
210
|
-
*/
|
|
211
|
-
const replaceRoute = (route) => {
|
|
212
|
-
let routeContent = '{\n';
|
|
213
|
-
|
|
214
|
-
routeContent += ` path: '${route.path}',\n`;
|
|
215
|
-
if (Object.keys(route.data).length > 0) {
|
|
216
|
-
routeContent += ' data: {\n';
|
|
217
|
-
|
|
218
|
-
if (route.data.id) {
|
|
219
|
-
routeContent += ` id: '${route.data.id}',\n`;
|
|
220
|
-
}
|
|
221
|
-
if (route.data.ids) {
|
|
222
|
-
routeContent += ` ids: ${route.data.ids},\n`;
|
|
223
|
-
}
|
|
224
|
-
if (route.data.featureName) {
|
|
225
|
-
routeContent += ` featureName: '${route.data.featureName}',\n`;
|
|
226
|
-
}
|
|
227
|
-
if (route.data.moduleId) {
|
|
228
|
-
routeContent += ` moduleId: '${route.data.moduleId}',\n`;
|
|
229
|
-
}
|
|
230
|
-
if (route.data.elementTag) {
|
|
231
|
-
routeContent += ` elementTag: '${route.data.elementTag}',\n`;
|
|
232
|
-
}
|
|
233
|
-
if (route.data.iframe) {
|
|
234
|
-
routeContent += ` iframe: ${route.data.iframe},\n`;
|
|
235
|
-
}
|
|
236
|
-
routeContent += ' },\n';
|
|
237
|
-
}
|
|
238
|
-
if (route.canActivate) {
|
|
239
|
-
routeContent += ` canActivate: ${route.canActivate},\n`;
|
|
240
|
-
}
|
|
241
|
-
if (route.loadChildren) {
|
|
242
|
-
routeContent += ` ${route.loadChildren},\n`;
|
|
243
|
-
}
|
|
244
|
-
routeContent += '},\n\n';
|
|
245
|
-
|
|
246
|
-
return routeContent;
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Process the routes config
|
|
251
|
-
* generates : app.routes.ts project file replacing app.routes-base.ts placehodler / remotes-metadata.json / route-defs-links.json
|
|
252
|
-
* and feature lib modules in playground local env
|
|
253
|
-
*
|
|
254
|
-
* PRIVATE
|
|
255
|
-
*
|
|
256
|
-
* @param {project} project The CSDR project object fetched from csdr global projects config
|
|
257
|
-
* @param {string} envTarget The build-time environment target provided to target specific routes for specific environment deployments
|
|
258
|
-
* @param {boolean} build if the script is launched from a release pipeline OR from local CSDR playground environment (false in that case)
|
|
259
|
-
* @param {string} routesFile the route file at project sources target to replace / update
|
|
260
|
-
* @param {string} routesFileContent the content of the base routes file to inject into the placeholder defined
|
|
261
|
-
* @param {string} euiVersion the eUI version of the current project used mainly in local CSDR playground environment
|
|
262
|
-
* @returns {Promise} returns a Promise as it involves async I/O processes
|
|
263
|
-
*/
|
|
264
|
-
const processRoutesConfig = (project, envTarget, build, routesFile, routesFileContent, euiVersion) => {
|
|
265
|
-
return Promise.resolve()
|
|
266
|
-
.then(() => {
|
|
267
|
-
tools.logInfo('Replace routes v2...');
|
|
268
|
-
|
|
269
|
-
// source of all routes - routes defs base
|
|
270
|
-
const projectAssetsPath = path.join(process.cwd(), project.folder, 'src', 'assets');
|
|
271
|
-
|
|
272
|
-
const routeDefsBaseFilename = 'route-defs-base.json';
|
|
273
|
-
const routeDefsBaseJSON = require(path.join(projectAssetsPath, routeDefsBaseFilename));
|
|
274
|
-
|
|
275
|
-
// getting generated from input params
|
|
276
|
-
const euiVersionNumber = euiVersion.split('.')[0];
|
|
277
|
-
const envTargetFinal = getEnvTarget(envTarget, build);
|
|
278
|
-
|
|
279
|
-
tools.logInfo(`Processing for envTarget : ${envTargetFinal}`);
|
|
280
|
-
|
|
281
|
-
// getting the input file definitions of routes for replacements
|
|
282
|
-
// from tokenized template in config -- allowing to control playground vs normal env (when using the MWP HOST for release)
|
|
283
|
-
// format :
|
|
284
|
-
// playground : "routesFilenameTemplate": "route-defs-base-v@eui.version@-playground.json"
|
|
285
|
-
// host : "routesFilenameTemplate": "route-defs.@env.target@.json"
|
|
286
|
-
|
|
287
|
-
let routeDefsInputFilename;
|
|
288
|
-
|
|
289
|
-
if (!project.externalRoutesSources.routesFilenameTemplate) {
|
|
290
|
-
throw 'ROUTES_CONFIG_V2_TEMPLATE_NOT_FOUND';
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
routeDefsInputFilename = project.externalRoutesSources.routesFilenameTemplate.replace('@eui.version@', euiVersionNumber);
|
|
295
|
-
routeDefsInputFilename = routeDefsInputFilename.replace('@env.target@', envTargetFinal);
|
|
296
|
-
|
|
297
|
-
tools.logInfo(`Starting replacement of routes based on generated template : ${routeDefsInputFilename}`);
|
|
298
|
-
|
|
299
|
-
// Getting input routeDefs entry
|
|
300
|
-
|
|
301
|
-
const routeDefsInputPath = path.join(projectAssetsPath, routeDefsInputFilename);
|
|
302
|
-
|
|
303
|
-
if (!tools.isFileExists(routeDefsInputPath)) {
|
|
304
|
-
tools.logError(`${routeDefsInputPath} File NOT FOUND`);
|
|
305
|
-
throw 'ROUTE_DEFS_INPUT_FILE_NOT_FOUND';
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const routeDefsInputJSON = require(path.join(routeDefsInputPath));
|
|
309
|
-
|
|
310
|
-
// Merging content with "local" route file defs if existing
|
|
311
|
-
|
|
312
|
-
let mergedRoutes = [];
|
|
313
|
-
|
|
314
|
-
if (envTargetFinal.indexOf('local') > -1) {
|
|
315
|
-
const localRouteDefsInputFilename = `route-defs.${envTargetFinal}.json`;
|
|
316
|
-
const localRouteDefsInputPath = path.join(projectAssetsPath, localRouteDefsInputFilename);
|
|
317
|
-
|
|
318
|
-
if (tools.isFileExists(localRouteDefsInputPath)) {
|
|
319
|
-
tools.logInfo(`Merging local configuration found : ${localRouteDefsInputFilename}`);
|
|
320
|
-
const localRouteDefsInputJSON = require(path.join(localRouteDefsInputPath));
|
|
321
|
-
|
|
322
|
-
routeDefsInputJSON.forEach((route) => {
|
|
323
|
-
const matchedRoute = localRouteDefsInputJSON.filter(newRoute => newRoute.path === route.path)[0];
|
|
324
|
-
if (matchedRoute) {
|
|
325
|
-
tools.logInfo(`-- replacing ${route.path} route entry with overriden local config`);
|
|
326
|
-
tools.logInfo(`-----> ${JSON.stringify(matchedRoute)}`);
|
|
327
|
-
mergedRoutes.push(matchedRoute);
|
|
328
|
-
} else {
|
|
329
|
-
mergedRoutes.push(route);
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
} else {
|
|
334
|
-
mergedRoutes = routeDefsInputJSON;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const appRoutes = [],
|
|
338
|
-
appFeatureLibs = [],
|
|
339
|
-
finalRemotesDefs = [];
|
|
340
|
-
|
|
341
|
-
// processing each routes found in the routeDefs entry
|
|
342
|
-
|
|
343
|
-
mergedRoutes.forEach((route) => {
|
|
344
|
-
tools.logInfo(`Processing route : `);
|
|
345
|
-
console.log(route);
|
|
346
|
-
|
|
347
|
-
const defRoute = routeDefsBaseJSON.filter((r) => r.path === route.path)[0];
|
|
348
|
-
if (!defRoute) {
|
|
349
|
-
tools.logError('route not found for: ');
|
|
350
|
-
console.log(route);
|
|
351
|
-
throw 'ROUTE_NOT_FOUND';
|
|
352
|
-
} else {
|
|
353
|
-
let loadChildrenGenerated;
|
|
354
|
-
|
|
355
|
-
// in case of a lazy route, the route is generated from a import/export feature lib module TS file
|
|
356
|
-
// those files are also generated based on the route "lazyDefs" data definition
|
|
357
|
-
|
|
358
|
-
if (route.lazy) {
|
|
359
|
-
const scopeName = defRoute.lazyLoadDef.npmPkg.split('/')[0].substr(1);
|
|
360
|
-
const pkgName = defRoute.lazyLoadDef.npmPkg.split('/')[1];
|
|
361
|
-
const lazyFeatureLibName = `${scopeName}-${pkgName}-${defRoute.lazyLoadDef.moduleName}.lib.module`;
|
|
362
|
-
|
|
363
|
-
if (euiVersion === '10.x') {
|
|
364
|
-
loadChildrenGenerated = `loadChildren: "./features/${lazyFeatureLibName}#Module"`;
|
|
365
|
-
} else {
|
|
366
|
-
loadChildrenGenerated = `loadChildren: () => import("./features/${lazyFeatureLibName}").then(m => m.Module)`;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
appFeatureLibs.push({
|
|
370
|
-
filename: `${lazyFeatureLibName}.ts`,
|
|
371
|
-
npmPkg: defRoute.lazyLoadDef.npmPkg,
|
|
372
|
-
moduleName: defRoute.lazyLoadDef.moduleName,
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
// if the route is a remote, the elementLoader is then used as a default feature module loaded
|
|
376
|
-
} else {
|
|
377
|
-
if (euiVersion === '10.x') {
|
|
378
|
-
loadChildrenGenerated = 'loadChildren: "./features/element-loader.module#ElementLoaderModule"';
|
|
379
|
-
} else {
|
|
380
|
-
loadChildrenGenerated = 'loadChildren: () => import("./features/element-loader.module").then(m => m.ElementLoaderModule)';
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// we define the route item definition, that will be injected in the project app.routes source
|
|
385
|
-
const newAppRoute = {
|
|
386
|
-
path: defRoute.path,
|
|
387
|
-
loadChildren: loadChildrenGenerated,
|
|
388
|
-
data: {},
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
// in the case the route is auth guarded, we attach the defition of the auth parameters
|
|
392
|
-
if (defRoute.authMetadata) {
|
|
393
|
-
newAppRoute.data.id = defRoute.authMetadata.id;
|
|
394
|
-
newAppRoute.data.ids = defRoute.authMetadata.ids;
|
|
395
|
-
newAppRoute.canActivate = defRoute.authMetadata.canActivate;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// in case of a remote, the "remoteDefs" data entry are processed
|
|
399
|
-
// in case no remote corresponds to a remote path defined in the definitions, we throw an error and we stop the
|
|
400
|
-
// script to avoid bad route data / or partial routes data generated
|
|
401
|
-
if (route.remote) {
|
|
402
|
-
let remoteDef;
|
|
403
|
-
try {
|
|
404
|
-
remoteDef = defRoute.remoteDefs.filter((r) => {
|
|
405
|
-
return r.euiVersion === route.euiVersion;
|
|
406
|
-
})[0];
|
|
407
|
-
} catch {
|
|
408
|
-
tools.logError('Remote route not found for: ');
|
|
409
|
-
console.log(route);
|
|
410
|
-
throw 'REMOTE_ROUTE_DEF_NOT_FOUND';
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if (remoteDef) {
|
|
414
|
-
newAppRoute.data.moduleId = remoteDef.moduleId;
|
|
415
|
-
newAppRoute.data.elementTag = remoteDef.elementTag;
|
|
416
|
-
newAppRoute.data.iframe = remoteDef.iframe;
|
|
417
|
-
} else {
|
|
418
|
-
tools.logError('Remote route not found for: ');
|
|
419
|
-
console.log(route);
|
|
420
|
-
throw 'REMOTE_ROUTE_DEF_NOT_FOUND';
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
finalRemotesDefs.push(remoteDef.moduleId);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
appRoutes.push(newAppRoute);
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
// writing final remotes metadata file base on routes definitions (loaded at runtime by the app for gathering the list of remotes)
|
|
431
|
-
|
|
432
|
-
if (finalRemotesDefs.length > 0) {
|
|
433
|
-
const finalRemotesDefsFile = path.join(projectAssetsPath, 'remotes-metadata.json');
|
|
434
|
-
|
|
435
|
-
tools.logInfo(`Generating ${finalRemotesDefsFile}`);
|
|
436
|
-
|
|
437
|
-
tools.writeJsonFileSync(finalRemotesDefsFile, finalRemotesDefs);
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// processing creation of features lib modules entries
|
|
441
|
-
|
|
442
|
-
tools.logInfo('Processing creation of features lib modules entries');
|
|
443
|
-
|
|
444
|
-
appFeatureLibs.forEach((f) => {
|
|
445
|
-
const featureLibPath = path.join(process.cwd(), project.folder, 'src', 'app', 'features', f.filename);
|
|
446
|
-
|
|
447
|
-
const featureLibDef = `
|
|
448
|
-
import { NgModule } from '@angular/core';
|
|
449
|
-
import { ${f.moduleName} as LibModule } from '${f.npmPkg}';
|
|
450
|
-
|
|
451
|
-
@NgModule({
|
|
452
|
-
imports: [LibModule],
|
|
453
|
-
exports: [LibModule],
|
|
454
|
-
})
|
|
455
|
-
export class Module {
|
|
456
|
-
}
|
|
457
|
-
`;
|
|
458
|
-
|
|
459
|
-
tools.logInfo(`Creating lazy feature lib module : ${f.filename}`);
|
|
460
|
-
|
|
461
|
-
tools.writeFileContent(featureLibPath, featureLibDef);
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
// processing links generation : generates a routes-defs-links.json based on the routes-defs-base-links.json definitions
|
|
465
|
-
|
|
466
|
-
const routeDefsBaseLinksFileName = 'route-defs-base-links.json';
|
|
467
|
-
const routeDefsBaseLinksJSON = require(path.join(projectAssetsPath, routeDefsBaseLinksFileName));
|
|
468
|
-
|
|
469
|
-
tools.logInfo('Processing links generation');
|
|
470
|
-
|
|
471
|
-
const getRouteMenuDef = (link) => {
|
|
472
|
-
let routeDef = null;
|
|
473
|
-
|
|
474
|
-
if (link.url) {
|
|
475
|
-
routeDefsBaseJSON.forEach((r) => {
|
|
476
|
-
if (r.menuLinkDefs && r.menuLinkDefs.length > 0) {
|
|
477
|
-
r.menuLinkDefs.forEach((md) => {
|
|
478
|
-
if (md.url === link.url) {
|
|
479
|
-
routeDef = md;
|
|
480
|
-
if (link.id) {
|
|
481
|
-
routeDef.id = link.id;
|
|
482
|
-
}
|
|
483
|
-
if (link.optional) {
|
|
484
|
-
routeDef.optional = link.optional;
|
|
485
|
-
}
|
|
486
|
-
if (link.workspace) {
|
|
487
|
-
routeDef.workspace = link.workspace;
|
|
488
|
-
}
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
return routeDef;
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
const getRouteDefFromMenuLink = (link) => {
|
|
500
|
-
let routeDef = null;
|
|
501
|
-
|
|
502
|
-
if (link.url) {
|
|
503
|
-
routeDefsBaseJSON.forEach((r) => {
|
|
504
|
-
if (r.menuLinkDefs && r.menuLinkDefs.length > 0) {
|
|
505
|
-
r.menuLinkDefs.forEach((md) => {
|
|
506
|
-
if (md.url === link.url) {
|
|
507
|
-
routeDef = r;
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
return routeDef;
|
|
516
|
-
};
|
|
517
|
-
|
|
518
|
-
// inner method for checking based on the "allowedEnvs" option provided on the links definition if the link has to be added
|
|
519
|
-
// to the links list
|
|
520
|
-
|
|
521
|
-
const isLinkAllowed = (link) => {
|
|
522
|
-
// allow all link for playground - local env
|
|
523
|
-
if (envTargetFinal.indexOf('local') > -1) {
|
|
524
|
-
return true;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
// checking if current envTarget generated is allowed
|
|
528
|
-
if (link.allowedEnvs) {
|
|
529
|
-
if (link.allowedEnvs.includes(envTargetFinal)) {
|
|
530
|
-
return true;
|
|
531
|
-
} else {
|
|
532
|
-
return false;
|
|
533
|
-
}
|
|
534
|
-
} else {
|
|
535
|
-
return true;
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
|
|
539
|
-
// processing each link and matching route from routes base data definitions
|
|
540
|
-
|
|
541
|
-
const linksGenerated = [];
|
|
542
|
-
|
|
543
|
-
routeDefsBaseLinksJSON.forEach((link) => {
|
|
544
|
-
let newLink;
|
|
545
|
-
|
|
546
|
-
if (link.parentId) {
|
|
547
|
-
if (isLinkAllowed(link)) {
|
|
548
|
-
newLink = { ...link };
|
|
549
|
-
newLink.children = [];
|
|
550
|
-
|
|
551
|
-
link.children.forEach((subLink) => {
|
|
552
|
-
if (isLinkAllowed(subLink)) {
|
|
553
|
-
const defRoute = getRouteMenuDef(subLink);
|
|
554
|
-
|
|
555
|
-
if (defRoute) {
|
|
556
|
-
newLink.children.push(defRoute);
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
} else {
|
|
562
|
-
if (isLinkAllowed(link)) {
|
|
563
|
-
const defRoute = getRouteMenuDef(link);
|
|
564
|
-
|
|
565
|
-
if (defRoute) {
|
|
566
|
-
newLink = defRoute;
|
|
567
|
-
} else {
|
|
568
|
-
newLink = link;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
if (link.alwaysDisplayed) {
|
|
572
|
-
newLink.alwaysDisplayed = true;
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
if (newLink) {
|
|
578
|
-
linksGenerated.push(newLink);
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
if (debug) {
|
|
582
|
-
console.log('Links generated');
|
|
583
|
-
console.log(JSON.stringify(linksGenerated));
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
tools.logInfo(`Links generated : ${linksGenerated.length} found`);
|
|
588
|
-
|
|
589
|
-
// checking if in playground route mode (local dev), in this case we mark the non-existing routes
|
|
590
|
-
// as disabled locally
|
|
591
|
-
let finalLinksGenerated = [];
|
|
592
|
-
if (project.externalRoutesSources.routesFilenameTemplate.indexOf('playground') > 0) {
|
|
593
|
-
tools.logInfo('Disabling non-active routes for playground');
|
|
594
|
-
|
|
595
|
-
linksGenerated.forEach((link) => {
|
|
596
|
-
let newLink = link;
|
|
597
|
-
|
|
598
|
-
if (link.parentId) {
|
|
599
|
-
let newLinkChildren = [];
|
|
600
|
-
|
|
601
|
-
link.children.forEach((subLink) => {
|
|
602
|
-
const defRoute = getRouteDefFromMenuLink(subLink);
|
|
603
|
-
|
|
604
|
-
if (defRoute) {
|
|
605
|
-
const routePathInInputRoutes = mergedRoutes.filter(r => r.path === defRoute.path)[0];
|
|
606
|
-
|
|
607
|
-
if (!routePathInInputRoutes) {
|
|
608
|
-
subLink.disabled = true;
|
|
609
|
-
|
|
610
|
-
} else {
|
|
611
|
-
tools.logInfo(`[${subLink.url}] --> route found in input routes - enabled`);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
newLinkChildren.push(subLink);
|
|
615
|
-
});
|
|
616
|
-
newLink.children = newLinkChildren;
|
|
617
|
-
|
|
618
|
-
const enabledChildren = newLink.children.filter(c => !c.disabled);
|
|
619
|
-
if (enabledChildren.length === 0) {
|
|
620
|
-
newLink.disabled = true;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
} else {
|
|
624
|
-
const defRoute = getRouteDefFromMenuLink(link);
|
|
625
|
-
|
|
626
|
-
if (defRoute) {
|
|
627
|
-
const routePathInInputRoutes = mergedRoutes.filter(r => r.path === defRoute.path)[0];
|
|
628
|
-
|
|
629
|
-
if (!routePathInInputRoutes) {
|
|
630
|
-
newLink.disabled = true;
|
|
631
|
-
} else {
|
|
632
|
-
tools.logInfo(`[${link.url}] --> route found in input routes - enabled`);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
finalLinksGenerated.push(newLink);
|
|
638
|
-
});
|
|
639
|
-
|
|
640
|
-
} else {
|
|
641
|
-
finalLinksGenerated = linksGenerated;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
tools.writeJsonFileSync(path.join(projectAssetsPath, 'route-defs-links.json'), finalLinksGenerated);
|
|
645
|
-
|
|
646
|
-
// getting routes content for replacement
|
|
647
|
-
|
|
648
|
-
tools.logInfo('Processing routes replacement');
|
|
649
|
-
|
|
650
|
-
let placeHolderContent = '';
|
|
651
|
-
|
|
652
|
-
appRoutes.forEach((route) => {
|
|
653
|
-
placeHolderContent += replaceRoute(route);
|
|
654
|
-
});
|
|
655
|
-
|
|
656
|
-
const placeHolderToken = '// routes-placeholder';
|
|
657
|
-
routesFileContent = tools.replaceAll(routesFileContent, placeHolderToken, placeHolderContent);
|
|
658
|
-
|
|
659
|
-
if (debug) {
|
|
660
|
-
tools.logInfo('Routes file content replaced : ');
|
|
661
|
-
console.log(routesFileContent);
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
// writing final routes content into project sources
|
|
665
|
-
tools.writeFileContent(routesFile, routesFileContent);
|
|
666
|
-
})
|
|
667
|
-
|
|
668
|
-
.catch((e) => {
|
|
669
|
-
throw e;
|
|
670
|
-
});
|
|
671
|
-
};
|
|
672
|
-
|
|
673
|
-
/**
|
|
674
|
-
* Inject the routes config assets from mywp-host-ui / assets / routes to virtual project assets folder
|
|
675
|
-
*
|
|
676
|
-
* PRIVATE
|
|
677
|
-
*
|
|
678
|
-
* @param {project} project The CSDR project object fetched from csdr global projects config
|
|
679
|
-
* @param {string} npmPkg The npm package dependency containing the routes definition (for MyWorkplace : mywp-host-ui => @mywp/host)
|
|
680
|
-
* @returns undefined
|
|
681
|
-
*/
|
|
682
|
-
const injectRoutesConfig = (project, npmPkg) => {
|
|
683
|
-
// check if package is locally cloned
|
|
684
|
-
const localPackage = configUtils.packages.getPackages().filter((p) => {
|
|
685
|
-
return p.npmPkg === npmPkg;
|
|
686
|
-
})[0];
|
|
687
|
-
|
|
688
|
-
var pkgAssetsPath;
|
|
689
|
-
const projectAssetsPath = path.join(process.cwd(), project.folder, 'src', 'assets');
|
|
690
|
-
|
|
691
|
-
// if local package is found
|
|
692
|
-
if (localPackage) {
|
|
693
|
-
pkgAssetsPath = path.join(process.cwd(), 'packages', localPackage.name, 'assets');
|
|
694
|
-
|
|
695
|
-
// if not sources are taken from the npm package def in node_modules
|
|
696
|
-
} else {
|
|
697
|
-
const npmPkgScope = npmPkg.substr(0, npmPkg.indexOf('/'));
|
|
698
|
-
const npmPkgName = npmPkg.substr(npmPkg.indexOf('/') + 1);
|
|
699
|
-
pkgAssetsPath = path.join(process.cwd(), 'node_modules', npmPkgScope, npmPkgName, 'assets');
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
if (!tools.isDirExists(pkgAssetsPath)) {
|
|
703
|
-
tools.logWarning(`Linked config pkg : ${npmPkg} cannot be found in node_modules`);
|
|
704
|
-
return;
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
const routesConfigPath = path.join(pkgAssetsPath, project.externalRoutesSources.routesConfigAssetsPath);
|
|
708
|
-
|
|
709
|
-
tools.logInfo(`${routesConfigPath} - injecting in ${projectAssetsPath}`);
|
|
710
|
-
tools.copydir(routesConfigPath, projectAssetsPath);
|
|
711
|
-
};
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
module.exports.extractRemotesMetadata = (project) => {
|
|
715
|
-
tools.logTitle('Extracting remotes-metadata.json for known participant remotes');
|
|
716
|
-
|
|
717
|
-
const projectAssetsPath = path.join(process.cwd(), project.folder, 'src', 'assets');
|
|
718
|
-
const openidConfigFile = path.join(projectAssetsPath, 'openid-login-config.json');
|
|
719
|
-
const finalRemotesDefsFile = path.join(projectAssetsPath, 'remotes-metadata.json');
|
|
720
|
-
|
|
721
|
-
if (!tools.isFileExists(finalRemotesDefsFile)) {
|
|
722
|
-
tools.logInfo('...remotes-metadata.json not found / not previously generated ... skipping');
|
|
723
|
-
return;
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
return Promise.resolve()
|
|
727
|
-
.then(() => {
|
|
728
|
-
return initUtils.remotes.cloneRemotesConfig();
|
|
729
|
-
})
|
|
730
|
-
|
|
731
|
-
.then(() => {
|
|
732
|
-
let remoteMetadataJSON = tools.getJsonFileContent(finalRemotesDefsFile);
|
|
733
|
-
const openidConfigJSON = tools.getJsonFileContent(openidConfigFile);
|
|
734
|
-
|
|
735
|
-
remoteMetadataJSON.forEach((r) => {
|
|
736
|
-
tools.logInfo(`Fetching remote info for : ${r}`);
|
|
737
|
-
|
|
738
|
-
let remote;
|
|
739
|
-
if (configUtils.remotes.isVirtualRemote(r)) {
|
|
740
|
-
remote = configUtils.remotes.getRemote(r);
|
|
741
|
-
} else {
|
|
742
|
-
remote = configUtils.packages.getPackage(r, true, true);
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
if (remote && remote.build && remote.build.hasParticipants) {
|
|
746
|
-
let participantsList;
|
|
747
|
-
if (remote.euiVersion === '15.x') {
|
|
748
|
-
participantsList = openidConfigJSON.modules[remote.build.configModuleName].participants_v15
|
|
749
|
-
} else {
|
|
750
|
-
participantsList = openidConfigJSON.modules[remote.build.configModuleName].participants
|
|
751
|
-
}
|
|
752
|
-
if (participantsList) {
|
|
753
|
-
let participantRemotes = [];
|
|
754
|
-
Object.keys(participantsList).forEach((p) => {
|
|
755
|
-
participantRemotes.push(participantsList[p].moduleId);
|
|
756
|
-
});
|
|
757
|
-
tools.logInfo('Found participant remotes : ');
|
|
758
|
-
console.log(participantRemotes);
|
|
759
|
-
|
|
760
|
-
remoteMetadataJSON = [...remoteMetadataJSON, ...participantRemotes];
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
})
|
|
764
|
-
|
|
765
|
-
remoteMetadataJSON = tools.removeArrayDuplicates(remoteMetadataJSON);
|
|
766
|
-
|
|
767
|
-
tools.logInfo('Final remotes metadata list found :');
|
|
768
|
-
console.log(remoteMetadataJSON);
|
|
769
|
-
|
|
770
|
-
return tools.writeJsonFileSync(finalRemotesDefsFile, remoteMetadataJSON);
|
|
771
|
-
})
|
|
772
|
-
|
|
773
|
-
.catch((e) => {
|
|
774
|
-
throw e;
|
|
775
|
-
});
|
|
776
|
-
}
|