当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript schematics.getSourceFile函数代码示例

本文整理汇总了TypeScript中@angular/cdk/schematics.getSourceFile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getSourceFile函数的具体用法?TypeScript getSourceFile怎么用?TypeScript getSourceFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getSourceFile函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: isImportedInMainModule

export function isImportedInMainModule(tree: Tree, project: WorkspaceProject, moduleName: string,
                                       importPath: string): boolean {
  const appModulePath = getAppModulePath(tree, getProjectMainFile(project));
  const appModuleSource = getSourceFile(tree, appModulePath) as ts.SourceFile;

  return isImported(appModuleSource, moduleName, importPath);
}
开发者ID:kevinheader,项目名称:nebular,代码行数:7,代码来源:ast.ts

示例2: addMissingPaths

function addMissingPaths(tree: Tree, routingModulePath: Path, targetFile: Path): void {
  const targetDir = dirname(targetFile);
  const relativePath = targetDir.replace(dirname(routingModulePath), '');
  const existingPathEnd = targetDir.indexOf(relativePath);
  let existingPath = normalize(targetDir.slice(0, existingPathEnd));
  const pathsToCheck = dirsToRoutePaths(relativePath);

  for (let i = 0; i < pathsToCheck.length; i++) {
    const routePathToCheck = pathsToCheck[i];
    const fullPathToCheck = join(existingPath, routePathToCheck);
    const pathPredicates = routePredicatesFromPath(routingModulePath, fullPathToCheck);
    let routesArray = findRoutesArray(tree, routingModulePath);

    let route = findRouteWithPath(routesArray, pathPredicates);
    if (!route) {
      const routesArrayToAddTo = getParentRouteChildren(routesArray, routingModulePath, fullPathToCheck);
      addRoute(tree, routingModulePath, routesArrayToAddTo, generatePathRoute(routePathToCheck));
      routesArray = findRoutesArray(tree, routingModulePath);
      route = findRouteWithPath(routesArray, pathPredicates) as ts.ObjectLiteralExpression;
    }

    const allChecked = i === pathsToCheck.length - 1;
    if (allChecked) {
      return;
    }

    existingPath = fullPathToCheck;
    if (!getRouteChildren(route)) {
      addObjectProperty(tree, getSourceFile(tree, routingModulePath), route, 'children: []');
    }
  }
}
开发者ID:kevinheader,项目名称:nebular,代码行数:32,代码来源:routing.ts

示例3: findRoutesArray

export function findRoutesArray(tree: Tree, modulePath: Path): ts.ArrayLiteralExpression {
  const source = getSourceFile(tree, modulePath);

  const decoratorNode = getDecoratorMetadata(source, 'NgModule', '@angular/core')[0] as ts.ObjectLiteralExpression;
  if (decoratorNode == null) {
    throw new SchematicsException(`Error in ${modulePath}. Can't find NgModule decorator.`);
  }

  try {
    const imports = getImports(decoratorNode);
    const routerModuleCall = getRouterModuleCall(imports);
    const routesArgument = routerModuleCall.arguments[0];
    if (routesArgument.kind === ts.SyntaxKind.ArrayLiteralExpression) {
      return routesArgument as ts.ArrayLiteralExpression;
    }
    if (routesArgument.kind === ts.SyntaxKind.Identifier) {
      const declaration = getRoutesVariableDeclaration(source, (routesArgument as ts.Identifier));
      return declaration.initializer as ts.ArrayLiteralExpression;
    }

    throw new SchematicsException(`Expecting RouterModule.forChild parameter to be an array or variable identifier.`);
  } catch (e) {
    throw new SchematicsException(`Error in ${modulePath}. ${e.message}`);
  }
}
开发者ID:kevinheader,项目名称:nebular,代码行数:25,代码来源:routing.ts

示例4: addModuleRoute

function addModuleRoute(
  tree: Tree,
  moduleDeclaration: ts.ClassDeclaration,
  modulePath: Path,
  routingModulePath: Path,
): void {
  const moduleDir = dirname(modulePath);
  if (isRootPlaygroundModule(moduleDir)) {
    return;
  }

  const routePredicates = routePredicatesFromPath(routingModulePath, moduleDir);
  let route = findRouteWithPath(findRoutesArray(tree, routingModulePath), routePredicates);
  if (!route) {
    addMissingChildRoutes(tree, routingModulePath, modulePath);
    route = findRouteWithPath(findRoutesArray(tree, routingModulePath), routePredicates) as ts.ObjectLiteralExpression;
  }

  if (getRouteLazyModule(route)) {
    return;
  }

  const moduleClassName = (moduleDeclaration.name as ts.Identifier).getText();
  const lazyModulePath = generateLazyModulePath(routingModulePath, modulePath, moduleClassName);
  const loadChildren = `loadChildren: '${lazyModulePath}'`;
  addObjectProperty(tree, getSourceFile(tree, routingModulePath), route, loadChildren);
}
开发者ID:kevinheader,项目名称:nebular,代码行数:27,代码来源:add-to-modules.ts

示例5: return

  return (host: Tree) => {
    const workspace = getWorkspace(host);
    const project = getProjectFromWorkspace(workspace, options.project);
    const appModulePath = getAppModulePath(host, getProjectMainFile(project));
    const moduleSource = getSourceFile(host, appModulePath);

    const locale = getCompatibleLocal(options);
    const localePrefix = locale.split('_')[ 0 ];

    const recorder = host.beginUpdate(appModulePath);

    const changes = [
      insertImport(moduleSource, appModulePath, 'NZ_I18N',
        'ng-zorro-antd'),
      insertImport(moduleSource, appModulePath, locale,
        'ng-zorro-antd'),
      insertImport(moduleSource, appModulePath, 'registerLocaleData',
        '@angular/common'),
      insertImport(moduleSource, appModulePath, localePrefix,
        `@angular/common/locales/${localePrefix}`, true),
      registerLocaleData(moduleSource, appModulePath, localePrefix),
      ...insertI18nTokenProvide(moduleSource, appModulePath, locale)
    ];

    changes.forEach((change) => {
      if (change instanceof InsertChange) {
        recorder.insertLeft(change.pos, change.toAdd);
      }
    });

    host.commitUpdate(recorder);

    return host;
  };
开发者ID:SrgGs,项目名称:ng-zorro-antd,代码行数:34,代码来源:register-locale.ts

示例6: addBaseRoute

export function addBaseRoute(tree: Tree, targetFile: Path): void {
  const isLayout = isLayoutPath(targetFile);
  const baseModulePath = isLayout ? LAYOUT_ROUTING_MODULE_PATH : NO_LAYOUT_ROUTING_MODULE_PATH;
  const routesArray = findRoutesArray(tree, baseModulePath);
  const baseRoute = findRouteWithPath(routesArray, [baseComponentPredicate(targetFile)]);
  if (baseRoute) {
    if (!getRouteChildren(baseRoute)) {
      addObjectProperty(tree, getSourceFile(tree, baseModulePath), baseRoute, 'children: []');
    }
    return;
  }

  const baseModuleComponent = isLayout ? LAYOUT_COMPONENT_CLASS : NO_LAYOUT_COMPONENT_CLASS;
  const routeString = generateComponentRoute('', baseModuleComponent, `children: []`);
  addRoute(tree, baseModulePath, routesArray, routeString);
}
开发者ID:kevinheader,项目名称:nebular,代码行数:16,代码来源:routing.ts

示例7: processService

function processService(tree: Tree, servicePath: Path): void {
  const modulePath = findFeatureModule(tree, dirname(servicePath));
  if (!modulePath) {
    throw new SchematicsException(`Can't find module for service ${servicePath}.`);
  }
  const serviceDeclarations = getClassWithDecorator(tree, servicePath, 'Injectable');

  for (const service of serviceDeclarations) {
    const serviceClassName = (service.name as ts.Identifier).getText();
    const importString = importPath(modulePath, servicePath);
    const source = getSourceFile(tree, servicePath);
    const changes = addProviderToModule(source, modulePath, serviceClassName, importString);

    applyInsertChange(tree, modulePath, ...changes);
  }
}
开发者ID:kevinheader,项目名称:nebular,代码行数:16,代码来源:add-to-modules.ts

示例8: getComponentTemplateDescriptor

export function getComponentTemplateDescriptor(host: Tree, componentPath: string): TemplateDescriptor {
  const compSource: ts.SourceFile = getSourceFile(host, componentPath);
  const compMetadata: ts.Node = getDecoratorMetadata(compSource, 'Component', '@angular/core')[0];
  const templateProp = getMetadataProperty(compMetadata, 'template');
  const templateUrlProp = getMetadataProperty(compMetadata, 'templateUrl');

  const template: string = getComponentTemplate(host, componentPath, {
    templateProp,
    templateUrlProp,
  });

  return new TemplateDescriptor(
    templateProp,
    templateUrlProp,
    componentPath,
    template,
  );
}
开发者ID:kevinheader,项目名称:nebular,代码行数:18,代码来源:component.ts

示例9: processRoutingModule

function processRoutingModule(tree: Tree, modulePath: Path) {
  const moduleDeclarations = getClassWithDecorator(tree, modulePath, 'NgModule');
  if (!moduleDeclarations.length) {
    return;
  }

  const featureModulePath = findFeatureModule(tree, dirname(modulePath));
  if (!featureModulePath) {
    throw new SchematicsException(`Can't find module for routing module ${featureModulePath }.`);
  }

  const featureModuleSource = getSourceFile(tree, featureModulePath);
  const importString = importPath(featureModulePath, modulePath);
  for (const moduleDeclaration of moduleDeclarations) {
    const className = (moduleDeclaration.name as ts.Identifier).getText();
    const changes = addImportToModule(featureModuleSource, featureModulePath, className, importString);
    applyInsertChange(tree, featureModulePath, ...changes);
  }
}
开发者ID:kevinheader,项目名称:nebular,代码行数:19,代码来源:add-to-modules.ts

示例10: addRoute

export function addRoute(
  tree: Tree,
  routingModulePath: Path,
  routes: ts.ArrayLiteralExpression,
  route: string,
  componentClass?: string,
  fileImportPath?: string,
): void {
  const source = getSourceFile(tree, routingModulePath);
  const alreadyInRoutes = routes.getFullText().includes(route);
  if (alreadyInRoutes) {
    return;
  }

  addArrayElement(tree, source, routes, route);

  if (componentClass && fileImportPath) {
    const importChange = insertImport(source, source.fileName, componentClass, fileImportPath);
    applyInsertChange(tree, normalize(source.fileName), importChange);
  }
}
开发者ID:kevinheader,项目名称:nebular,代码行数:21,代码来源:routing.ts


注:本文中的@angular/cdk/schematics.getSourceFile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。