devui-admin-test
Version:
Schematics for ng-devui-admin
64 lines • 3.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const core_1 = require("@angular-devkit/core");
const find_module_1 = require("@schematics/angular/utility/find-module");
const utils_1 = require("../utils");
function genAddMaterialsRules(blocks, options) {
let rules = [];
blocks.forEach((block) => {
rules.push(schematics_1.schematic('blocks', {
blockName: block,
dirPath: `${options.dirPath}/${core_1.strings.dasherize(options.viewName)}`,
importWay: options.importWay,
}));
});
return schematics_1.chain(rules);
}
function buildPageRoute(options, modulePath) {
return `{ title: '${core_1.strings.classify(options.viewName)}', link: '/pages/${utils_1.getModuleName(modulePath)}/${options.routePath}' },`;
}
function default_1(options) {
return (tree) => {
const templateSource = schematics_1.apply(schematics_1.url('./files'), [
schematics_1.applyTemplates({
viewName: options.viewName,
style: options.style,
selector: options.selector,
dasherize: core_1.strings.dasherize,
classify: core_1.strings.classify,
}),
schematics_1.move(options.dirPath),
]);
// 创建空页面啊后,在插入的module中引入页面的declaration
const modulePath = find_module_1.findModule(tree, options.dirPath);
const componentName = `${core_1.strings.classify(options.viewName)}Component`;
const relativePath = find_module_1.buildRelativePath(modulePath, `/${options.dirPath}/${core_1.strings.dasherize(options.viewName)}/${core_1.strings.dasherize(options.viewName)}.component`);
let routingModulePath = utils_1.getRoutingModule(tree, modulePath);
if (routingModulePath) {
utils_1.addRouteToNgModule(tree, routingModulePath, options.viewName, options.routePath, relativePath);
if (options.addToNav) {
utils_1.insertTSArray(tree, '/src/app/pages/pages.component.ts', buildPageRoute(options, modulePath), 'this.menu', 'end');
}
}
else {
throw new schematics_1.SchematicsException('Please make sure a routing module is existed.');
}
let blocks = [];
if (options.blocks) {
blocks = options.blocks.split(' ');
}
if (blocks.length > 0) {
return schematics_1.chain([
schematics_1.mergeWith(templateSource),
utils_1.addDeclaration(componentName, modulePath, relativePath),
genAddMaterialsRules(blocks, options),
]);
}
else {
return schematics_1.chain([schematics_1.mergeWith(templateSource), utils_1.addDeclaration(componentName, modulePath, relativePath)]);
}
};
}
exports.default = default_1;
//# sourceMappingURL=index.js.map