本文整理汇总了TypeScript中@angular/cdk/schematics.hasNgModuleImport函数的典型用法代码示例。如果您正苦于以下问题:TypeScript hasNgModuleImport函数的具体用法?TypeScript hasNgModuleImport怎么用?TypeScript hasNgModuleImport使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hasNgModuleImport函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: return
return (tree: Tree, context: SchematicContext) => {
const project = getProject(tree, options.project);
const appModulePath = getAppModulePath(tree, getProjectMainFile(project));
const browserAnimationsModuleName = 'BrowserAnimationsModule';
const noopAnimationsModuleName = 'NoopAnimationsModule';
const animationsPackage = '@angular/platform-browser/animations';
if (options.animations) {
// In case the project explicitly uses the NoopAnimationsModule, we should print a warning
// message that makes the user aware of the fact that we won't automatically set up
// animations. If we would add the BrowserAnimationsModule while the NoopAnimationsModule
// is already configured, we would cause unexpected behavior and runtime exceptions.
if (hasNgModuleImport(tree, appModulePath, noopAnimationsModuleName)) {
return context.logger.warn(red(`Could not set up "${bold(browserAnimationsModuleName)}" ` +
`because "${bold(noopAnimationsModuleName)}" is already imported. Please manually ` +
`set up browser animations.`));
}
addModuleImportToRootModule(tree, browserAnimationsModuleName, animationsPackage, project);
} else if (!hasNgModuleImport(tree, appModulePath, browserAnimationsModuleName)) {
// Do not add the NoopAnimationsModule module if the project already explicitly uses
// the BrowserAnimationsModule.
addModuleImportToRootModule(tree, noopAnimationsModuleName, animationsPackage, project);
}
}
示例2: return
return (host: Tree) => {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
const appModulePath = getAppModulePath(host, getProjectMainFile(project));
if (options.animations) {
// In case the project explicitly uses the NoopAnimationsModule, we should print a warning
// message that makes the user aware of the fact that we won't automatically set up
// animations. If we would add the BrowserAnimationsModule while the NoopAnimationsModule
// is already configured, we would cause unexpected behavior and runtime exceptions.
if (hasNgModuleImport(host, appModulePath, noopAnimationsModuleName)) {
return console.warn(red(`Could not set up "${bold(browserAnimationsModuleName)}" ` +
`because "${bold(noopAnimationsModuleName)}" is already imported. Please manually ` +
`set up browser animations.`));
}
addModuleImportToRootModule(host, browserAnimationsModuleName,
'@angular/platform-browser/animations', project);
} else if (!hasNgModuleImport(host, appModulePath, browserAnimationsModuleName)) {
// Do not add the NoopAnimationsModule module if the project already explicitly uses
// the BrowserAnimationsModule.
addModuleImportToRootModule(host, noopAnimationsModuleName,
'@angular/platform-browser/animations', project);
}
return host;
};
示例3: addModuleImportToApptModule
function addModuleImportToApptModule(host: Tree, moduleName: string, src: string,
project: WorkspaceProject, appModulePath: string,
options: Schema): void {
if (hasNgModuleImport(host, appModulePath, moduleName)) {
console.log(chalk.yellow(`Could not set up "${chalk.blue(moduleName)}" ` +
`because "${chalk.blue(moduleName)}" is already imported. Please manually ` +
`check "${chalk.blue(appModulePath)}" file.`));
return;
}
addModuleImportToRootModule(host, moduleName, src, project);
}
示例4: return
return (host: Tree) => {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
const appModulePath = getAppModulePath(host, getProjectMainFile(project));
if (options.animations) {
if (hasNgModuleImport(host, appModulePath, noopAnimationsModuleName)) {
console.log();
return console.log(chalk.yellow(`Could not set up "${chalk.blue(browserAnimationsModuleName)}" ` +
`because "${chalk.blue(noopAnimationsModuleName)}" is already imported. Please manually ` +
`set up browser animations.`));
}
addModuleImportToRootModule(host, browserAnimationsModuleName,
animationsModulePath, project);
} else if (!hasNgModuleImport(host, appModulePath, browserAnimationsModuleName)) {
addModuleImportToRootModule(host, noopAnimationsModuleName,
animationsModulePath, project);
}
return host;
};