UNPKG

devui-admin-test

Version:

Schematics for ng-devui-admin

46 lines 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.modifyAngularJson = exports.addPackage = exports.writePackageJson = exports.readPackageJson = void 0; const schematics_1 = require("@angular-devkit/schematics"); const constants_1 = require("./constants"); const json_operation_1 = require("./json-operation"); function readPackageJson(tree, type) { return json_operation_1.readJson(tree, constants_1.PACKAGE_JSON_PATH, type); } exports.readPackageJson = readPackageJson; function writePackageJson(tree, json) { return json_operation_1.writeJson(tree, constants_1.PACKAGE_JSON_PATH, json); } exports.writePackageJson = writePackageJson; function addPackage(tree, packages, type = 'dependencies') { const packageJson = readPackageJson(tree, type); if (packageJson == null) { return tree; } if (!Array.isArray(packages)) { packages = [packages]; } packages.forEach((pck) => { const splitPosition = pck.lastIndexOf('@'); packageJson[type][pck.substr(0, splitPosition)] = pck.substr(splitPosition + 1); }); writePackageJson(tree, packageJson); return tree; } exports.addPackage = addPackage; function modifyAngularJson(styles, defaultProject) { return (tree) => { if (!tree.exists(constants_1.ANGULAR_JSON_PATH)) { throw new schematics_1.SchematicsException('Please make sure this is an Angular project.'); } const angularJson = JSON.parse(tree.read(constants_1.ANGULAR_JSON_PATH).toString('utf-8')); if (!Array.isArray(styles)) { styles = [styles]; } angularJson.projects[defaultProject].architect.build.options.styles = styles; tree.overwrite(constants_1.ANGULAR_JSON_PATH, JSON.stringify(angularJson, null, 2)); return tree; }; } exports.modifyAngularJson = modifyAngularJson; //# sourceMappingURL=package-manage.js.map