@feeloor/ng-extension-schematics
Version:
Angular extension schematics
36 lines • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const core_1 = require("@angular-devkit/core");
function default_1(options) {
return schematics_1.chain([
(tree, _context) => {
_context.logger.debug(`Adding shortcut ${options.name} to point to ${options.path}`);
// Find tsconfig.json
const tsConfigFile = tree.root.subfiles.find((value) => {
return value === 'tsconfig.json';
});
// If tsconfig wasn't found
if (!tsConfigFile) {
_context.logger.debug(`tsconfig.json was not found.`);
return tree;
}
// Get tsconfig content
const tsConfigContent = tree.read(core_1.normalize(tree.root.path + '/' + tsConfigFile));
// Read file json and parse to object
const tsConfigData = JSON.parse(tsConfigContent ? tsConfigContent.toString() : '');
// tsconfig doesn't have paths
if (!tsConfigData.compilerOptions.hasOwnProperty('paths')) {
_context.logger.debug(`No paths object was found, initializing new...`);
tsConfigData.compilerOptions.paths = {};
}
// Add new alias
tsConfigData.compilerOptions.paths[`${options.name}/*`] = [`${options.path}/*`];
// Convert data to json and write to file
tree.overwrite(tsConfigFile, JSON.stringify(tsConfigData, null, '\t'));
return tree;
}
]);
}
exports.default = default_1;
//# sourceMappingURL=index.js.map