@ng-zen/cli
Version:
Angular UI components generator – Zen UI Kit CLI for schematics-based creation of customizable components like alert, avatar, button, card, checkbox, dialog, divider, form-control, icon, input, popover, radio, skeleton, switch, textarea with Storybook dem
39 lines • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.uiGenerator = uiGenerator;
const core_1 = require("@angular-devkit/core");
const schematics_1 = require("@angular-devkit/schematics");
const workspace_1 = require("@schematics/angular/utility/workspace");
const utils_1 = require("../../utils");
const DEFAULT_GENERATION_PATH = 'ui'; // src/app/ui
const FORM_CONTROL_DEPS = new Set(['input', 'checkbox', 'switch', 'radio']);
function resolveFormControlDependency(tree, logger, ui, workingDirectory) {
if (!ui.some(u => FORM_CONTROL_DEPS.has(u)))
return;
const fcPath = (0, core_1.normalize)(`${workingDirectory}/form-control/form-control.ts`);
if (tree.exists(fcPath)) {
logger.info('ℹ form-control skipped — already exists');
}
else {
ui.push('form-control');
logger.info('✔ form-control included (auto-included for form components)');
}
}
function uiGenerator({ ui: selected, project, ...options }) {
return async (tree, context) => {
const workspace = await (0, workspace_1.getWorkspace)(tree);
const projectName = project || workspace.extensions['defaultProject'];
const projectObj = workspace.projects.get(projectName);
if (!projectObj) {
throw new Error(`Project "${projectName}" not found in workspace.`);
}
if (options.path === undefined) {
options.path = ((0, workspace_1.buildDefaultPath)(projectObj) + '/' + DEFAULT_GENERATION_PATH);
}
const workingDirectory = (0, core_1.normalize)((0, core_1.join)(options.currentDirectory, options.path));
const ui = [...selected];
resolveFormControlDependency(tree, context.logger, ui, workingDirectory);
return (0, schematics_1.chain)([...(0, utils_1.applyFileTemplateUtil)(ui, { ...options, path: workingDirectory })]);
};
}
//# sourceMappingURL=index.js.map