@progress/kendo-angular-schematics
Version:
Kendo UI Schematics for Angular
102 lines • 4.96 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.npmi = void 0;
exports.computeDefaultStandalone = computeDefaultStandalone;
exports.checkOrAddKendoTheme = checkOrAddKendoTheme;
exports.ngAddLocalize = ngAddLocalize;
const tslib_1 = require("tslib");
const tasks_1 = require("@angular-devkit/schematics/tasks");
const dependencies_1 = require("@schematics/angular/utility/dependencies");
const semver = tslib_1.__importStar(require("semver"));
function computeDefaultStandalone(options, host, project) {
const packageJsonPath = project.root + "/package.json";
if (host.exists(packageJsonPath)) {
try {
const packageJson = JSON.parse(host.read(packageJsonPath).toString("utf-8"));
const angularVersion = semver.minVersion(packageJson?.dependencies?.["@angular/core"]);
if (angularVersion.major <= 13 && options.standalone) {
throw new Error("The --standalone is not supported on Angular 13");
}
else if (angularVersion.major <= 16) {
if (options.standalone === undefined) {
options.standalone = false;
}
}
else {
if (options.standalone === undefined) {
options.standalone = true;
}
}
}
catch {
// we will stick with the default version
}
}
}
/**
* This method will check if there is any Kendo theme added to the project,
* and if we can't find any, will install and add the styles from the default kendo theme.
*/
function checkOrAddKendoTheme(options, project) {
return (tree, _context) => {
try {
const configPath = project.root + "/angular.json";
if (tree.exists(configPath)) {
const json = JSON.parse(tree.read(configPath).toString("utf-8"));
const buildOptions = json?.projects?.[options.project]?.architect?.build?.options;
if (buildOptions) {
const styles = buildOptions?.styles || [];
// Check if there is a kendo theme in styles, and if there is none - add one.
if (!styles.reduce((acc, next) => acc || (typeof next === 'string' && next.includes("@progress/kendo-theme-")), false)) {
styles.push("node_modules/@progress/kendo-theme-default/dist/default-ocean-blue.scss");
buildOptions.styles = styles;
tree.overwrite(configPath, JSON.stringify(json, null, 2));
(0, dependencies_1.addPackageJsonDependency)(tree, {
type: dependencies_1.NodeDependencyType.Dev,
name: '@progress/kendo-theme-default',
version: "^11.0.2",
overwrite: true
});
}
}
}
}
catch (e) {
console.log(`Error while trying to add kendo theme: ${e}`);
}
};
}
const npmi = (name, version = "*") => (tree, _context) => (0, dependencies_1.addPackageJsonDependency)(tree, { type: dependencies_1.NodeDependencyType.Default, name, version, overwrite: false });
exports.npmi = npmi;
function ngAddLocalize(options, project) {
return (tree, context) => {
const packageJsonPath = project.root + "/package.json";
let localizeVersion = "*";
if (tree.exists(packageJsonPath)) {
try {
const packageJson = JSON.parse(tree.read(packageJsonPath).toString("utf-8"));
const angularVersion = semver.minVersion(packageJson?.dependencies?.["@angular/core"]);
const range = packageJson?.dependencies?.["@angular/core"]?.trim()?.startsWith("~") ? "~" : "^";
if (angularVersion) {
localizeVersion = `${range}${angularVersion.major}.${angularVersion.minor}.0`;
}
}
catch {
// we will stick with the default version
}
}
(0, dependencies_1.addPackageJsonDependency)(tree, {
type: dependencies_1.NodeDependencyType.Dev,
name: '@angular/localize',
version: localizeVersion,
overwrite: true,
});
const npmi = context.addTask(new tasks_1.NodePackageInstallTask(), []);
context.addTask(new tasks_1.RunSchematicTask("@angular/localize", "ng-add", {}), [npmi]);
};
}
//# sourceMappingURL=kendo-utils.js.map