@progress/kendo-angular-schematics
Version:
Kendo UI Schematics for Angular
105 lines • 5.83 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
const schematics_1 = require("@angular-devkit/schematics");
const third_party_1 = require("../third_party");
const schema_1 = require("./schema");
const kendo_utils_1 = require("../utils/kendo-utils");
// The code for the schematic is forked from:
// https://github.com/angular/angular-cli/blob/main/packages/schematics/angular/component/index.ts
// We have some added code that we will have to merge.
function templateOptions(options) {
if (options.dataSource == schema_1.DataSource.Example || !options?.columns?.length) {
// If the data source is "Example", use a predefined template for data and columns.
// if the user didn't care to fill in columns - use a predefined set.
options.columns = ["ProductID", "ProductName", "UnitPrice"];
}
}
function createDataSource(options) {
return async (tree, _context) => {
if (options.dataSource == schema_1.DataSource['Mock Data']) {
// Generate mocked data out of the column definitions
let dataSourceCode = `export const data = [{\n`;
for (let i = 0; i <= 15; i++) {
for (const column of options.columns) {
dataSourceCode += ` "${third_party_1.strings.camelize(column)}": "${third_party_1.strings.capitalize(column)} ${i}",\n`;
}
if (i < 15) {
dataSourceCode += ` }, {\n`;
}
}
dataSourceCode += ` }];\n`;
dataSourceCode += `export default data;`;
tree.create(`${options.path}/${third_party_1.strings.dasherize(options.name)}/${third_party_1.strings.dasherize(options.name)}.sample-data.ts`, dataSourceCode);
}
};
}
function default_1(options) {
return async (host, context) => {
const workspace = await (0, third_party_1.getWorkspace)(host);
const project = workspace.projects.get(options.project);
(0, kendo_utils_1.computeDefaultStandalone)(options, host, project);
if (!project) {
throw new schematics_1.SchematicsException(`Project "${options.project}" does not exist.`);
}
if (options.path === undefined) {
options.path = (0, third_party_1.buildDefaultPath)(project);
}
options.module = (0, third_party_1.findModuleFromOptions)(host, options);
const parsedPath = (0, third_party_1.parseName)(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
options.selector =
options.selector || (0, third_party_1.buildSelector)(options, (project && project.prefix) || '');
(0, third_party_1.validateHtmlSelector)(options.selector);
const skipStyleFile = options.inlineStyle || options.style === third_party_1.Style.None;
// Kendo specific template options
templateOptions(options);
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
// Kendo specific, filters all .include files used as partials in templates.
(0, schematics_1.filter)(path => !path.endsWith('.include')),
// Kendo template specific, include sample data if data source is set to "Example"
options.dataSource != schema_1.DataSource.Example ? (0, schematics_1.filter)((path) => !path.endsWith('.sample-data.ts.template')) : (0, schematics_1.noop)(),
options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
skipStyleFile ? (0, schematics_1.filter)((path) => !path.endsWith('.__style__.template')) : (0, schematics_1.noop)(),
options.inlineTemplate ? (0, schematics_1.filter)((path) => !path.endsWith('.html.template')) : (0, schematics_1.noop)(),
(0, schematics_1.applyTemplates)({
...third_party_1.strings,
'if-flat': (s) => (options.flat ? '' : s),
...options,
// Kendo specific, allows the component content to be included in inline and html files.
include(path) {
return (0, schematics_1.applyContentTemplate)(this)((0, schematics_1.url)("./files")(context).get(path)).content.toString();
},
}),
!options.type
? (0, schematics_1.forEach)(((file) => {
return file.path.includes('..')
? {
content: file.content,
path: file.path.replace('..', '.'),
}
: file;
}))
: (0, schematics_1.noop)(),
(0, schematics_1.move)(parsedPath.path),
]);
return (0, schematics_1.chain)([
(0, third_party_1.addDeclarationToNgModule)({
type: 'component',
...options,
}),
(0, kendo_utils_1.checkOrAddKendoTheme)(options, project),
(0, kendo_utils_1.ngAddLocalize)(options, project),
(0, kendo_utils_1.npmi)("@progress/kendo-angular-grid"),
(0, schematics_1.mergeWith)(templateSource),
// Kendo template specific, will add a sample data source file
createDataSource(options),
]);
};
}
//# sourceMappingURL=index.js.map