UNPKG

2.55 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.replaceAppNameWithPath = exports.serializeTarget = exports.editTarget = exports.parseTarget = exports.getNpmScope = exports.getWorkspacePath = void 0;
4const ast_utils_1 = require("./ast-utils");
5function getWorkspacePath(host) {
6 const possibleFiles = ['/angular.json', '/workspace.json'];
7 return possibleFiles.filter((path) => host.exists(path))[0];
8}
9exports.getWorkspacePath = getWorkspacePath;
10function getNpmScope(host) {
11 return (0, ast_utils_1.readJsonInTree)(host, 'nx.json').npmScope;
12}
13exports.getNpmScope = getNpmScope;
14function parseTarget(targetString) {
15 const [project, target, config] = targetString.split(':');
16 return {
17 project,
18 target,
19 config,
20 };
21}
22exports.parseTarget = parseTarget;
23function editTarget(targetString, callback) {
24 const parsedTarget = parseTarget(targetString);
25 return serializeTarget(callback(parsedTarget));
26}
27exports.editTarget = editTarget;
28function serializeTarget({ project, target, config }) {
29 return [project, target, config].filter((part) => !!part).join(':');
30}
31exports.serializeTarget = serializeTarget;
32function 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 ]; // Some of the properties should not be renamed
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}
70exports.replaceAppNameWithPath = replaceAppNameWithPath;
71//# sourceMappingURL=cli-config-utils.js.map
\No newline at end of file