UNPKG

@progress/kendo-angular-schematics

Version:

Kendo UI Schematics for Angular

91 lines 3.81 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildRelativePath = exports.resolveModule = exports.findModule = void 0; const core_1 = require("@angular-devkit/core"); /** * Find the module referred by a set of options passed to the schematics. */ function findModule(host, options) { if (Object.hasOwnProperty.call(options, 'skipImport') && options.skipImport) { return undefined; } if (!options.module) { const pathToCheck = (options.path || '') + (options.flat ? '' : '/' + core_1.strings.dasherize(options.name)); return (0, core_1.normalize)(resolveModule(host, pathToCheck)); } else { const modulePath = (0, core_1.normalize)('/' + (options.path) + '/' + options.module); const moduleBaseName = (0, core_1.normalize)(modulePath).split('/').pop(); if (host.exists(modulePath)) { return (0, core_1.normalize)(modulePath); } else if (host.exists(modulePath + '.ts')) { return (0, core_1.normalize)(modulePath + '.ts'); } else if (host.exists(modulePath + '.module.ts')) { return (0, core_1.normalize)(modulePath + '.module.ts'); } else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) { return (0, core_1.normalize)(modulePath + '/' + moduleBaseName + '.module.ts'); } else { throw new Error('Specified module does not exist'); } } } exports.findModule = findModule; /** * Function to find the "closest" module to a generated file's path. */ function resolveModule(host, generateDir) { let dir = host.getDir('/' + generateDir); const moduleRe = /\.module\.ts$/; const routingModuleRe = /-routing\.module\.ts/; while (dir) { const matches = dir.subfiles.filter(p => moduleRe.test(p) && !routingModuleRe.test(p)); if (matches.length == 1) { return (0, core_1.join)(dir.path, matches[0]); } else if (matches.length > 1) { throw new Error('More than one module matches. Use skip-import option to skip importing ' + 'the component into the closest module.'); } dir = dir.parent; } throw new Error('Could not find an NgModule. Use the skip-import ' + 'option to skip importing in NgModule.'); } exports.resolveModule = resolveModule; /** * Build a relative path from one file path to another file path. */ function buildRelativePath(from, to) { from = (0, core_1.normalize)(from); to = (0, core_1.normalize)(to); // Convert to arrays. const fromParts = from.split('/'); const toParts = to.split('/'); // Remove file names (preserving destination) fromParts.pop(); const toFileName = toParts.pop(); const relativePath = (0, core_1.relative)((0, core_1.normalize)(fromParts.join('/')), (0, core_1.normalize)(toParts.join('/'))); let pathPrefix = ''; // Set the path prefix for same dir or child dir, parent dir starts with `..` if (!relativePath) { pathPrefix = '.'; } else if (!relativePath.startsWith('.')) { pathPrefix = `./`; } if (pathPrefix && !pathPrefix.endsWith('/')) { pathPrefix += '/'; } return pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName; } exports.buildRelativePath = buildRelativePath; //# sourceMappingURL=find-module.js.map