@progress/kendo-angular-schematics
Version:
Kendo UI Schematics for Angular
79 lines • 3.57 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2026 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.applyChanges = applyChanges;
exports.addDeclarationToNgModule = addDeclarationToNgModule;
exports.addToPackageJson = addToPackageJson;
exports.withBase = withBase;
const tslib_1 = require("tslib");
const schematics_1 = require("@angular-devkit/schematics");
const core_1 = require("@angular-devkit/core");
const ts = tslib_1.__importStar(require("typescript"));
const rxjs_1 = require("rxjs");
const utils_1 = require("../utils");
function applyChanges(host, path, changes) {
const recorder = host.beginUpdate(path);
for (const change of changes) {
recorder.insertLeft(change.position, change.toAdd);
}
host.commitUpdate(recorder);
}
function addDeclarationToNgModule(options) {
return (host) => {
const modulePath = options.module;
if (!modulePath) {
return host;
}
const sourceText = host.read(modulePath).toString('utf-8');
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
const changes = (0, utils_1.addDeclarationToModule)({
source,
symbolName: options.symbolName,
modulePath: options.symbolImport
});
applyChanges(host, modulePath, changes);
return host;
};
}
function addToPackageJson(options) {
return (host) => {
if (!host.exists('package.json'))
return host;
const dependencies = options.dependencies;
const text = host.read('package.json').toString('utf-8');
const json = JSON.parse(text);
json['dependencies'] = Object.assign({}, json['dependencies'], dependencies);
host.overwrite('package.json', (0, utils_1.stringify)(json));
return host;
};
}
const inlineTemplate = ({ inlineTemplate }) => inlineTemplate ? (0, schematics_1.filter)((path) => !path.endsWith('html')) : (0, schematics_1.noop)();
const inlineStyle = ({ inlineStyle }) => inlineStyle ? (0, schematics_1.filter)((path) => !path.endsWith('__styleext__')) : (0, schematics_1.noop)();
function withBase(componentTemplate, rules) {
return (options) => async (host, context) => {
const extendTemplateContext = (additional = {}) => (0, schematics_1.template)({
...core_1.strings,
...options,
'folder-name': (0, utils_1.folderName)(options),
'full-path': `${options.sourceDir}/${options.path}`,
selector: (0, utils_1.buildSelector)(options),
...additional
});
const templateContext = await (0, rxjs_1.lastValueFrom)(componentTemplate(context));
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('../component/files'), [
inlineTemplate(options),
inlineStyle(options),
extendTemplateContext(templateContext)
]);
const chainRule = (0, schematics_1.chain)([
(0, schematics_1.branchAndMerge)((0, schematics_1.mergeWith)(templateSource)),
rules
]);
const fn = await chainRule(host, context);
return (0, rxjs_1.lastValueFrom)(fn());
};
}
//# sourceMappingURL=index.js.map