UNPKG

@progress/kendo-angular-schematics

Version:

Kendo UI Schematics for Angular

57 lines 2.83 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.getAppModulePath = getAppModulePath; exports.findBootstrapModuleCall = findBootstrapModuleCall; exports.findBootstrapModulePath = findBootstrapModulePath; const tslib_1 = require("tslib"); const ts = tslib_1.__importStar(require("typescript")); const path_1 = require("path"); const core_1 = require("@angular-devkit/core"); const schematics_1 = require("@angular-devkit/schematics"); const _1 = require("."); const ast_utils_1 = require("./ast-utils"); function getAppModulePath(host, mainPath) { if (!mainPath) { return undefined; } const moduleRelativePath = findBootstrapModulePath(host, mainPath); const mainDir = (0, path_1.dirname)(mainPath); const modulePath = (0, core_1.normalize)(`/${mainDir}/${moduleRelativePath}.ts`); return modulePath; } function findBootstrapModuleCall(host, mainPath) { const sourceText = (0, _1.fileContent)(host, mainPath); const source = ts.createSourceFile(mainPath, sourceText, ts.ScriptTarget.Latest, true); const calls = (0, ast_utils_1.nodesByKind)(source, ts.SyntaxKind.CallExpression) .filter(call => (0, ast_utils_1.findNode)(call, ts.SyntaxKind.Identifier, 'bootstrapModule')); return calls[calls.length - 1]; } function findBootstrapModulePath(host, mainPath) { const bootstrapCall = findBootstrapModuleCall(host, mainPath); if (!bootstrapCall) { throw new schematics_1.SchematicsException('Bootstrap call not found'); } const bootstrapModule = bootstrapCall.arguments[0]; const mainBuffer = host.read(mainPath); if (!mainBuffer) { throw new schematics_1.SchematicsException(`Client app main file (${mainPath}) not found`); } const mainText = mainBuffer.toString('utf-8'); const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true); const allImports = (0, ast_utils_1.nodesByKind)(source, ts.SyntaxKind.ImportDeclaration); const bootstrapModuleRelativePath = allImports .filter(node => node.kind === ts.SyntaxKind.ImportDeclaration) .filter(imp => { return (0, ast_utils_1.findNode)(imp, ts.SyntaxKind.Identifier, bootstrapModule.getText()); }) .map((imp) => { const modulePathStringLiteral = imp.moduleSpecifier; return modulePathStringLiteral.text; })[0]; return bootstrapModuleRelativePath; } //# sourceMappingURL=bootstrap-module.js.map