source: trip-planner-front/node_modules/@angular/cdk/schematics/ng-add/package-config.js@ e29cc2e

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

initial commit

  • Property mode set to 100644
File size: 6.1 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.getPackageVersionFromPackageJson = exports.addPackageToPackageJson = void 0;
11/**
12 * Sorts the keys of the given object.
13 * @returns A new object instance with sorted keys
14 */
15function sortObjectByKeys(obj) {
16 return Object.keys(obj).sort().reduce((result, key) => {
17 result[key] = obj[key];
18 return result;
19 }, {});
20}
21/** Adds a package to the package.json in the given host tree. */
22function addPackageToPackageJson(host, pkg, version) {
23 if (host.exists('package.json')) {
24 const sourceText = host.read('package.json').toString('utf-8');
25 const json = JSON.parse(sourceText);
26 if (!json.dependencies) {
27 json.dependencies = {};
28 }
29 if (!json.dependencies[pkg]) {
30 json.dependencies[pkg] = version;
31 json.dependencies = sortObjectByKeys(json.dependencies);
32 }
33 host.overwrite('package.json', JSON.stringify(json, null, 2));
34 }
35 return host;
36}
37exports.addPackageToPackageJson = addPackageToPackageJson;
38/** Gets the version of the specified package by looking at the package.json in the given tree. */
39function getPackageVersionFromPackageJson(tree, name) {
40 if (!tree.exists('package.json')) {
41 return null;
42 }
43 const packageJson = JSON.parse(tree.read('package.json').toString('utf8'));
44 if (packageJson.dependencies && packageJson.dependencies[name]) {
45 return packageJson.dependencies[name];
46 }
47 return null;
48}
49exports.getPackageVersionFromPackageJson = getPackageVersionFromPackageJson;
50//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGFja2FnZS1jb25maWcuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL3NjaGVtYXRpY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pIHtcbiAgICAgIGpzb24uZGVwZW5kZW5jaWVzID0ge307XG4gICAgfVxuXG4gICAgaWYgKCFqc29uLmRlcGVuZGVuY2llc1twa2ddKSB7XG4gICAgICBqc29uLmRlcGVuZGVuY2llc1twa2ddID0gdmVyc2lvbjtcbiAgICAgIGpzb24uZGVwZW5kZW5jaWVzID0gc29ydE9iamVjdEJ5S2V5cyhqc29uLmRlcGVuZGVuY2llcyk7XG4gICAgfVxuXG4gICAgaG9zdC5vdmVyd3JpdGUoJ3BhY2thZ2UuanNvbicsIEpTT04uc3RyaW5naWZ5KGpzb24sIG51bGwsIDIpKTtcbiAgfVxuXG4gIHJldHVybiBob3N0O1xufVxuXG4vKiogR2V0cyB0aGUgdmVyc2lvbiBvZiB0aGUgc3BlY2lmaWVkIHBhY2thZ2UgYnkgbG9va2luZyBhdCB0aGUgcGFja2FnZS5qc29uIGluIHRoZSBnaXZlbiB0cmVlLiAqL1xuZXhwb3J0IGZ1bmN0aW9uIGdldFBhY2thZ2VWZXJzaW9uRnJvbVBhY2thZ2VKc29uKHRyZWU6IFRyZWUsIG5hbWU6IHN0cmluZyk6IHN0cmluZyB8IG51bGwge1xuICBpZiAoIXRyZWUuZXhpc3RzKCdwYWNrYWdlLmpzb24nKSkge1xuICAgIHJldHVybiBudWxsO1xuICB9XG5cbiAgY29uc3QgcGFja2FnZUpzb24gPSBKU09OLnBhcnNlKHRyZWUucmVhZCgncGFja2FnZS5qc29uJykhLnRvU3RyaW5nKCd1dGY4JykpIGFzIFBhY2thZ2VKc29uO1xuXG4gIGlmIChwYWNrYWdlSnNvbi5kZXBlbmRlbmNpZXMgJiYgcGFja2FnZUpzb24uZGVwZW5kZW5jaWVzW25hbWVdKSB7XG4gICAgcmV0dXJuIHBhY2thZ2VKc29uLmRlcGVuZGVuY2llc1tuYW1lXTtcbiAgfVxuXG4gIHJldHVybiBudWxsO1xufVxuIl19
Note: See TracBrowser for help on using the repository browser.