source: trip-planner-front/node_modules/@angular/cli/commands/config-impl.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 5.3 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.ConfigCommand = void 0;
11const core_1 = require("@angular-devkit/core");
12const uuid_1 = require("uuid");
13const command_1 = require("../models/command");
14const interface_1 = require("../models/interface");
15const config_1 = require("../utilities/config");
16const json_file_1 = require("../utilities/json-file");
17const validCliPaths = new Map([
18 ['cli.warnings.versionMismatch', undefined],
19 ['cli.defaultCollection', undefined],
20 ['cli.packageManager', undefined],
21 ['cli.analytics', undefined],
22 ['cli.analyticsSharing.tracking', undefined],
23 ['cli.analyticsSharing.uuid', (v) => (v ? `${v}` : uuid_1.v4())],
24]);
25/**
26 * Splits a JSON path string into fragments. Fragments can be used to get the value referenced
27 * by the path. For example, a path of "a[3].foo.bar[2]" would give you a fragment array of
28 * ["a", 3, "foo", "bar", 2].
29 * @param path The JSON string to parse.
30 * @returns {(string|number)[]} The fragments for the string.
31 * @private
32 */
33function parseJsonPath(path) {
34 const fragments = (path || '').split(/\./g);
35 const result = [];
36 while (fragments.length > 0) {
37 const fragment = fragments.shift();
38 if (fragment == undefined) {
39 break;
40 }
41 const match = fragment.match(/([^\[]+)((\[.*\])*)/);
42 if (!match) {
43 throw new Error('Invalid JSON path.');
44 }
45 result.push(match[1]);
46 if (match[2]) {
47 const indices = match[2]
48 .slice(1, -1)
49 .split('][')
50 .map((x) => (/^\d$/.test(x) ? +x : x.replace(/\"|\'/g, '')));
51 result.push(...indices);
52 }
53 }
54 return result.filter((fragment) => fragment != null);
55}
56function normalizeValue(value) {
57 var _a, _b;
58 const valueString = `${value}`.trim();
59 switch (valueString) {
60 case 'true':
61 return true;
62 case 'false':
63 return false;
64 case 'null':
65 return null;
66 case 'undefined':
67 return undefined;
68 }
69 if (isFinite(+valueString)) {
70 return +valueString;
71 }
72 return (_b = (_a = json_file_1.parseJson(valueString)) !== null && _a !== void 0 ? _a : value) !== null && _b !== void 0 ? _b : undefined;
73}
74class ConfigCommand extends command_1.Command {
75 async run(options) {
76 const level = options.global ? 'global' : 'local';
77 if (!options.global) {
78 await this.validateScope(interface_1.CommandScope.InProject);
79 }
80 let [config] = config_1.getWorkspaceRaw(level);
81 if (options.global && !config) {
82 try {
83 if (config_1.migrateLegacyGlobalConfig()) {
84 config = config_1.getWorkspaceRaw(level)[0];
85 this.logger.info(core_1.tags.oneLine `
86 We found a global configuration that was used in Angular CLI 1.
87 It has been automatically migrated.`);
88 }
89 }
90 catch { }
91 }
92 if (options.value == undefined) {
93 if (!config) {
94 this.logger.error('No config found.');
95 return 1;
96 }
97 return this.get(config, options);
98 }
99 else {
100 return this.set(options);
101 }
102 }
103 get(jsonFile, options) {
104 let value;
105 if (options.jsonPath) {
106 value = jsonFile.get(parseJsonPath(options.jsonPath));
107 }
108 else {
109 value = jsonFile.content;
110 }
111 if (value === undefined) {
112 this.logger.error('Value cannot be found.');
113 return 1;
114 }
115 else if (typeof value === 'string') {
116 this.logger.info(value);
117 }
118 else {
119 this.logger.info(JSON.stringify(value, null, 2));
120 }
121 return 0;
122 }
123 async set(options) {
124 var _a, _b, _c;
125 if (!((_a = options.jsonPath) === null || _a === void 0 ? void 0 : _a.trim())) {
126 throw new Error('Invalid Path.');
127 }
128 if (options.global &&
129 !options.jsonPath.startsWith('schematics.') &&
130 !validCliPaths.has(options.jsonPath)) {
131 throw new Error('Invalid Path.');
132 }
133 const [config, configPath] = config_1.getWorkspaceRaw(options.global ? 'global' : 'local');
134 if (!config || !configPath) {
135 this.logger.error('Confguration file cannot be found.');
136 return 1;
137 }
138 const jsonPath = parseJsonPath(options.jsonPath);
139 const value = (_c = (_b = validCliPaths.get(options.jsonPath)) === null || _b === void 0 ? void 0 : _b(options.value)) !== null && _c !== void 0 ? _c : options.value;
140 const modified = config.modify(jsonPath, normalizeValue(value));
141 if (!modified) {
142 this.logger.error('Value cannot be found.');
143 return 1;
144 }
145 try {
146 await config_1.validateWorkspace(json_file_1.parseJson(config.content));
147 }
148 catch (error) {
149 this.logger.fatal(error.message);
150 return 1;
151 }
152 config.save();
153 return 0;
154 }
155}
156exports.ConfigCommand = ConfigCommand;
Note: See TracBrowser for help on using the repository browser.