@ionic/angular
Version:
Angular specific wrappers for @ionic/core
25 lines (24 loc) • 840 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addPackageToPackageJson = addPackageToPackageJson;
const schematics_1 = require("@angular-devkit/schematics");
/**
* Adds a package to the package.json
*/
function addPackageToPackageJson(host, type, pkg, version) {
if (host.exists('package.json')) {
const sourceText = host.read('package.json')?.toString('utf-8');
if (sourceText === undefined) {
throw new schematics_1.SchematicsException('Could not read package.json');
}
const json = JSON.parse(sourceText);
if (!json[type]) {
json[type] = {};
}
if (!json[type][pkg]) {
json[type][pkg] = version;
}
host.overwrite('package.json', JSON.stringify(json, null, 2));
}
return host;
}