UNPKG

@alyle/ui

Version:

Minimal Design, a set of components for Angular

52 lines 3.03 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAppComponentPath = getAppComponentPath; const ng_ast_utils_1 = require("@schematics/angular/utility/ng-ast-utils"); const vendored_ast_utils_1 = require("./vendored-ast-utils"); const ts = require("typescript"); const path_1 = require("path"); const core_1 = require("@angular-devkit/core"); const ast_1 = require("./ast"); const schematics_1 = require("@angular/cdk/schematics"); const workspace_1 = require("@schematics/angular/utility/workspace"); function getAppComponentPath(host, options) { return __awaiter(this, void 0, void 0, function* () { const workspace = yield (0, workspace_1.getWorkspace)(host); const project = (0, schematics_1.getProjectFromWorkspace)(workspace, options.project); const mainPath = (0, schematics_1.getProjectMainFile)(project); const modulePath = (0, ng_ast_utils_1.getAppModulePath)(host, mainPath); const moduleSource = (0, ast_1.getTsSourceFile)(host, modulePath); const decoratorMetadata = (0, vendored_ast_utils_1.getDecoratorMetadata)(moduleSource, 'NgModule', '@angular/core'); const propertyName = 'bootstrap'; const { properties } = decoratorMetadata[0]; const property = properties .filter(prop => prop.kind === ts.SyntaxKind.PropertyAssignment) .filter((prop) => { const name = prop.name; switch (name.kind) { case ts.SyntaxKind.Identifier: return name.getText() === propertyName; case ts.SyntaxKind.StringLiteral: return name.text === propertyName; } return false; })[0]; const bootstrapValue = (property.initializer.getText()).split(/\[|\]|\,\s?/g).filter(s => s)[0]; const appComponentPath = moduleSource.statements .filter(prop => prop.kind === ts.SyntaxKind.ImportDeclaration) .filter(prop => (0, vendored_ast_utils_1.findNode)(prop, ts.SyntaxKind.ImportSpecifier, bootstrapValue)) .map(({ moduleSpecifier }) => moduleSpecifier.text)[0]; const mainDir = (0, path_1.dirname)(modulePath); return (0, core_1.normalize)(`/${mainDir}/${appComponentPath}.ts`); }); } //# sourceMappingURL=get-app-component-path.js.map