本文整理匯總了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;
}
示例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;
}
示例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');
}
示例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}`);
});
};
示例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];
}
示例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);
},
};
}
示例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 ')}`,
);
}
}
示例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;
}
示例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`);
};
示例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));
};