mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 18:43:42 +08:00
Currently writing schematics that support both NgModule-based and standalone projects is tricky, because they have different layouts. These changes introduce two new APIs that work both on NgModule and standalone projects and can be used by library authors to create their `ng add` schematics. Example rule for adding a `ModuleWithProviders`-style library: ```ts import { Rule } from '@angular-devkit/schematics'; import { addRootImport } from '@schematics/angular/utility'; export default function(): Rule { return addRootImport('default', ({code, external}) => { return code`${external('MyModule', '@my/module')}.forRoot({})`; }); } ``` This rulle will add `imports: [MyModule.forRoot({})]` to an NgModule app and `providers: [importProvidersFrom(MyModule.forRoot({}))]` to a standalone one. It also adds all of the necessary imports.
23 lines
644 B
TypeScript
23 lines
644 B
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
// Workspace related rules and types
|
|
export {
|
|
ProjectDefinition,
|
|
TargetDefinition,
|
|
WorkspaceDefinition,
|
|
getWorkspace as readWorkspace,
|
|
updateWorkspace,
|
|
writeWorkspace,
|
|
} from './workspace';
|
|
export { Builders as AngularBuilder } from './workspace-models';
|
|
export * from './standalone';
|
|
|
|
// Package dependency related rules and types
|
|
export { DependencyType, ExistingBehavior, InstallBehavior, addDependency } from './dependency';
|