1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.replaceAppNameWithPath = exports.serializeTarget = exports.editTarget = exports.parseTarget = exports.getNpmScope = exports.getWorkspacePath = void 0;
|
4 | const ast_utils_1 = require("./ast-utils");
|
5 | function getWorkspacePath(host) {
|
6 | const possibleFiles = ['/angular.json', '/workspace.json'];
|
7 | return possibleFiles.filter((path) => host.exists(path))[0];
|
8 | }
|
9 | exports.getWorkspacePath = getWorkspacePath;
|
10 | function getNpmScope(host) {
|
11 | return (0, ast_utils_1.readJsonInTree)(host, 'nx.json').npmScope;
|
12 | }
|
13 | exports.getNpmScope = getNpmScope;
|
14 | function parseTarget(targetString) {
|
15 | const [project, target, config] = targetString.split(':');
|
16 | return {
|
17 | project,
|
18 | target,
|
19 | config,
|
20 | };
|
21 | }
|
22 | exports.parseTarget = parseTarget;
|
23 | function editTarget(targetString, callback) {
|
24 | const parsedTarget = parseTarget(targetString);
|
25 | return serializeTarget(callback(parsedTarget));
|
26 | }
|
27 | exports.editTarget = editTarget;
|
28 | function serializeTarget({ project, target, config }) {
|
29 | return [project, target, config].filter((part) => !!part).join(':');
|
30 | }
|
31 | exports.serializeTarget = serializeTarget;
|
32 | function replaceAppNameWithPath(node, appName, root) {
|
33 | if (typeof node === 'string') {
|
34 | const matchPattern = new RegExp(`([^a-z0-9]*(${appName}))|((${appName})[^a-z0-9:]*)`, 'gi');
|
35 | if (!!node.match(matchPattern) &&
|
36 | node !== 'application' &&
|
37 | node !== 'library') {
|
38 | const r = node.replace(appName, root);
|
39 | return r.startsWith('/apps') || r.startsWith('/libs')
|
40 | ? r.substring(1)
|
41 | : r;
|
42 | }
|
43 | else {
|
44 | return node;
|
45 | }
|
46 | }
|
47 | else if (Array.isArray(node)) {
|
48 | return node.map((j) => replaceAppNameWithPath(j, appName, root));
|
49 | }
|
50 | else if (typeof node === 'object' && node) {
|
51 | const forbiddenPropertyList = [
|
52 | 'prefix',
|
53 | 'builder',
|
54 | 'executor',
|
55 | 'browserTarget',
|
56 | 'tags',
|
57 | 'defaultConfiguration',
|
58 | 'maximumError',
|
59 | 'name',
|
60 | ];
|
61 | return Object.keys(node).reduce((m, c) => ((m[c] = !forbiddenPropertyList.includes(c)
|
62 | ? replaceAppNameWithPath(node[c], appName, root)
|
63 | : node[c]),
|
64 | m), {});
|
65 | }
|
66 | else {
|
67 | return node;
|
68 | }
|
69 | }
|
70 | exports.replaceAppNameWithPath = replaceAppNameWithPath;
|
71 |
|
\ | No newline at end of file |