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


TypeScript Tree.exists方法代碼示例

本文整理匯總了TypeScript中@angular-devkit/schematics.Tree.exists方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Tree.exists方法的具體用法?TypeScript Tree.exists怎麽用?TypeScript Tree.exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@angular-devkit/schematics.Tree的用法示例。


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

示例1: getPackageVersionFromPackageJson

export function getPackageVersionFromPackageJson(tree: Tree, name: string): string | null {
  if (!tree.exists('package.json')) {
    return null;
  }

  const packageJson = JSON.parse(tree.read('package.json')!.toString('utf8'));

  if (packageJson.dependencies && packageJson.dependencies[name]) {
    return packageJson.dependencies[name];
  }

  return null;
}
開發者ID:Nodarii,項目名稱:material2,代碼行數:13,代碼來源:package-config.ts

示例2: findVersion

/**
 * Look for package.json file for package with `packageName` in node_modules and
 * extract its version.
 */
function findVersion(packageName: string, host: Tree): string|null {
  const candidate = `node_modules/${packageName}/package.json`;
  if (host.exists(candidate)) {
    try {
      const packageJson = JSON.parse(host.read(candidate).toString());
      if (packageJson.name === packageName && packageJson.version) {
        return packageJson.version;
      }
    } catch {
    }
  }
  return null;
}
開發者ID:BobChao87,項目名稱:angular,代碼行數:17,代碼來源:index.ts

示例3: envConfig

function envConfig(host: Tree, options: PluginOptions) {
  const defEnvPath = `${options.sourceRoot}/environments/environment.ts`;
  const defContent = host.get(defEnvPath).content;
  if (!host.exists(defEnvPath)) return ;
  // 1. update default env file
  addValueToVariable(host, defEnvPath, 'environment', 'hmr: false');
  // 2. update prod env file
  addValueToVariable(host, `${options.sourceRoot}/environments/environment.prod.ts`, 'environment', 'hmr: false');
  // 3. copy default env file to hmr file
  const hmrEnvPath = `${options.sourceRoot}/environments/environment.hmr.ts`;
  host.create(hmrEnvPath, defContent);
  addValueToVariable(host, hmrEnvPath, 'environment', 'hmr: true');
}
開發者ID:wexz,項目名稱:delon,代碼行數:13,代碼來源:plugin.hmr.ts

示例4: return

  return (host: Tree) => {
    if (!host.exists('tsconfig.json')) { return host; }

    return updateJsonFile(host, 'tsconfig.json', (tsconfig: TsConfigPartialType) => {
      if (!tsconfig.compilerOptions.paths) {
        tsconfig.compilerOptions.paths = {};
      }
      if (!tsconfig.compilerOptions.paths[npmPackageName]) {
        tsconfig.compilerOptions.paths[npmPackageName] = [];
      }
      tsconfig.compilerOptions.paths[npmPackageName].push(`dist/${npmPackageName}`);
    });
  };
開發者ID:iwe7,項目名稱:devkit,代碼行數:13,代碼來源:index.ts

示例5: getDependencyVersionFromPackageJson

export function getDependencyVersionFromPackageJson(tree: Tree, packageName: string): string {
  if (!tree.exists(packageJsonName)) {
    throwNoPackageJsonError();
  }

  const packageJson: PackageJson = readJSON(tree, packageJsonName);

  if (noInfoAboutDependency(packageJson, packageName)) {
    throwNoPackageInfoInPackageJson(packageName);
  }

  return packageJson.dependencies[packageName];
}
開發者ID:kevinheader,項目名稱:nebular,代碼行數:13,代碼來源:package.ts

示例6: createHost

function createHost(tree: Tree): workspaces.WorkspaceHost {
  return {
    async readFile(path: string): Promise<string> {
      const data = tree.read(path);
      if (!data) {
        throw new Error('File not found.');
      }

      return virtualFs.fileBufferToString(data);
    },
    async writeFile(path: string, data: string): Promise<void> {
      return tree.overwrite(path, data);
    },
    async isDirectory(path: string): Promise<boolean> {
      // approximate a directory check
      return !tree.exists(path) && tree.getDir(path).subfiles.length > 0;
    },
    async isFile(path: string): Promise<boolean> {
      return tree.exists(path);
    },
  };
}
開發者ID:angular,項目名稱:angular-cli,代碼行數:22,代碼來源:workspace.ts

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

示例8: return

  return (tree: Tree) => {
    const project = getProject(tree, options.project);
    const stylesPath: string = getProjectStyleFile(project, 'scss') as string;

    if (!tree.exists(stylesPath)) {
      throwSCSSRequiredForCustomizableThemes();
    }

    createThemeSCSS(tree, options.theme, project.sourceRoot as string);
    insertThemeImportInStyles(tree, stylesPath);


    return tree;
  }
開發者ID:kevinheader,項目名稱:nebular,代碼行數:14,代碼來源:index.ts

示例9: return

  return (host: Tree, context: SchematicContext) => {
    if (host.exists(npmrc)) {
      host.delete(npmrc);
    }

    if (options.type === 'remove') {
      return ;
    }

    host.create(npmrc, `sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/
electron_mirror=https://npm.taobao.org/mirrors/electron/
registry=https://registry.npm.taobao.org`);
  };
開發者ID:wexz,項目名稱:delon,代碼行數:14,代碼來源:plugin.npm.ts

示例10: return

  return (host: Tree) => {
    const tsLintPath = '/tslint.json';
    if (!host.exists(tsLintPath)) {
      return;
    }

    const rootTslintConfig = readTsLintConfig(parentHost, tsLintPath);
    const appTslintConfig = readTsLintConfig(host, tsLintPath);

    const recorder = host.beginUpdate(tsLintPath);
    rootTslintConfig.properties.forEach(prop => {
      if (findPropertyInAstObject(appTslintConfig, prop.key.value)) {
        // property already exists. Skip!
        return;
      }

      insertPropertyInAstObjectInOrder(
        recorder,
        appTslintConfig,
        prop.key.value,
        prop.value.value,
        2,
      );
    });

    const rootRules = findPropertyInAstObject(rootTslintConfig, 'rules');
    const appRules = findPropertyInAstObject(appTslintConfig, 'rules');

    if (!appRules || appRules.kind !== 'object' || !rootRules || rootRules.kind !== 'object') {
      // rules are not valid. Skip!
      return;
    }

    rootRules.properties.forEach(prop => {
      insertPropertyInAstObjectInOrder(
        recorder,
        appRules,
        prop.key.value,
        prop.value.value,
        4,
      );
    });

    host.commitUpdate(recorder);

    // this shouldn't be needed but at the moment without this formatting is not correct.
    const content = readTsLintConfig(host, tsLintPath);
    host.overwrite(tsLintPath, JSON.stringify(content.value, undefined, 2));
  };
開發者ID:angular,項目名稱:angular-cli,代碼行數:49,代碼來源:index.ts


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