當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript core.dirname函數代碼示例

本文整理匯總了TypeScript中@angular-devkit/core.dirname函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript dirname函數的具體用法?TypeScript dirname怎麽用?TypeScript dirname使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了dirname函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: 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

示例2: importPath

export function importPath(from: Path, to: Path): string {
  const relativePath = relative(dirname(from), dirname(to));

  if (relativePath.startsWith('.')) {
    return relativePath;
  }

  if (!relativePath) {
    return generateCurrentDirImport(basename(to));
  }

  return generateCurrentDirImport(join(relativePath, basename(to)));
}
開發者ID:kevinheader,項目名稱:nebular,代碼行數:13,代碼來源:path.ts

示例3: findModuleFromOptions

export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path | undefined {
  if (options.hasOwnProperty('skipImport') && options.skipImport) {
    return undefined;
  }

  const moduleExt = options.moduleExt || MODULE_EXT;
  const routingModuleExt = options.routingModuleExt || ROUTING_MODULE_EXT;

  if (!options.module) {
    const pathToCheck = (options.path || '')
      + (options.flat ? '' : '/' + strings.dasherize(options.name));

    return normalize(findModule(host, pathToCheck, moduleExt, routingModuleExt));
  } else {
    const modulePath = normalize(`/${options.path}/${options.module}`);
    const componentPath = normalize(`/${options.path}/${options.name}`);
    const moduleBaseName = normalize(modulePath).split('/').pop();

    const candidateSet = new Set<Path>([
      normalize(options.path || '/'),
    ]);

    for (let dir = modulePath; dir != NormalizedRoot; dir = dirname(dir)) {
      candidateSet.add(dir);
    }
    for (let dir = componentPath; dir != NormalizedRoot; dir = dirname(dir)) {
      candidateSet.add(dir);
    }

    const candidatesDirs = [...candidateSet].sort((a, b) => b.length - a.length);
    for (const c of candidatesDirs) {
      const candidateFiles = [
        '',
        `${moduleBaseName}.ts`,
        `${moduleBaseName}${moduleExt}`,
      ].map(x => join(c, x));

      for (const sc of candidateFiles) {
        if (host.exists(sc)) {
          return normalize(sc);
        }
      }
    }

    throw new Error(
      `Specified module '${options.module}' does not exist.\n`
        + `Looked in the following directories:\n    ${candidatesDirs.join('\n    ')}`,
    );
  }
}
開發者ID:baconwaffles,項目名稱:angular-cli,代碼行數:50,代碼來源:find-module.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: getBootstrapComponentPath

function getBootstrapComponentPath(
  host: Tree,
  project: WorkspaceProject,
): string {
  const projectTargets = getProjectTargets(project);
  if (!projectTargets.build) {
    throw targetBuildNotFoundError();
  }

  const mainPath = projectTargets.build.options.main;
  const modulePath = getAppModulePath(host, mainPath);
  const moduleSource = getSourceFile(host, modulePath);

  const metadataNode = getDecoratorMetadata(moduleSource, 'NgModule', '@angular/core')[0];
  const bootstrapProperty = getMetadataProperty(metadataNode, 'bootstrap');

  const arrLiteral = (bootstrapProperty as ts.PropertyAssignment)
    .initializer as ts.ArrayLiteralExpression;

  const componentSymbol = arrLiteral.elements[0].getText();

  const relativePath = getSourceNodes(moduleSource)
    .filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)
    .filter(imp => {
      return findNode(imp, ts.SyntaxKind.Identifier, componentSymbol);
    })
    .map((imp: ts.ImportDeclaration) => {
      const pathStringLiteral = imp.moduleSpecifier as ts.StringLiteral;

      return pathStringLiteral.text;
    })[0];

  return join(dirname(normalize(modulePath)), relativePath + '.ts');
}
開發者ID:DevIntent,項目名稱:angular-cli,代碼行數:34,代碼來源:index.ts

示例6: addComponentRoute

function addComponentRoute(
  tree: Tree,
  componentDeclarations: ts.ClassDeclaration[],
  modulePath: Path,
  context: SchematicContext,
  componentPath: Path,
): void {
  const routingModulePath = findRoutingModule(tree, dirname(componentPath));
  if (!routingModulePath) {
    throw new SchematicsException(`Can't find routing module for module ${modulePath}.`);
  }
  if (componentDeclarations.length > 1) {
    context.logger.warn(`Found more than one component declaration in ${componentPath}. ` +
      'Route will be created only for the first one.\n' +
      'Move all helper components which don\'t need own routes to sub directory without routing module in it.');
  }

  const componentClassName = (componentDeclarations[0].name as ts.Identifier).getText();
  const routes = findRoutesArray(tree, routingModulePath);

  if (findRoute(routes, componentRoutePredicate.bind(null, componentClassName))) {
    return;
  }

  const routingImport = importPath(routingModulePath, componentPath);
  const routePath = isInPlaygroundRoot(componentPath) ? '' : removeExtension(componentPath);
  const route = generateComponentRoute(routePath, componentClassName);
  addRoute(tree, routingModulePath, routes, route, componentClassName, routingImport);
}
開發者ID:kevinheader,項目名稱:nebular,代碼行數:29,代碼來源:add-to-modules.ts

示例7: findRoutingModule

export function findRoutingModule(tree: Tree, path: Path): Path | undefined {
  if (isOutsidePlayground(path)) {
    return;
  }

  const moduleFile = tree.getDir(path).subfiles.find(isRoutingModule);
  return moduleFile ? join(path, moduleFile) : findRoutingModule(tree, dirname(path));
}
開發者ID:kevinheader,項目名稱:nebular,代碼行數:8,代碼來源:playground.ts

示例8: routePredicatesFromPath

export function routePredicatesFromPath(routingModulePath: Path, targetDirPath: Path): RoutePredicate[] {
  const routingModuleDir = dirname(routingModulePath);
  if (isRootPlaygroundModule(routingModuleDir)) {
    return [rootRoutePredicate(targetDirPath)];
  }

  const predicates: RoutePredicate[] = [];
  if (isBasePlaygroundModule(routingModuleDir)) {
    predicates.push(baseComponentPredicate(targetDirPath));
  }
  const relativeToRoutingModule = targetDirPath.replace(dirname(routingModulePath), '');
  const routePaths = dirsToRoutePaths(relativeToRoutingModule);
  for (const path of routePaths) {
    predicates.push((route: ts.ObjectLiteralExpression) => pathRoutePredicate(path, route));
  }

  return predicates;
}
開發者ID:kevinheader,項目名稱:nebular,代碼行數:18,代碼來源:routing.ts

示例9: parseName

export function parseName(path: string, name: string): Location {
  const nameWithoutPath = basename(name as Path);
  const namePath = dirname((path + '/' + name) as Path);

  return {
    name: nameWithoutPath,
    path: normalize('/' + namePath),
  };
}
開發者ID:AlexChar,項目名稱:platform,代碼行數:9,代碼來源:parse-name.ts

示例10: wrapHtmlFileTemplate

function wrapHtmlFileTemplate(tree: Tree, templateDescriptor: TemplateDescriptor) {
  const { templateUrlProp, componentPath, template } = templateDescriptor;

  const templateUrl = (templateUrlProp.initializer as ts.StringLiteral).text;
  const dir = dirname(normalize(componentPath));
  const templatePath = join(dir, templateUrl);

  writeText(tree, templatePath, wrapHtmlFileTemplateInLayout(template));
}
開發者ID:kevinheader,項目名稱:nebular,代碼行數:9,代碼來源:index.ts


注:本文中的@angular-devkit/core.dirname函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。