Kristiyan Kostadinov b14b959901 feat(@schematics/angular): add bootstrap-agnostic utilities for writing ng-add schematics
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.
2023-06-06 15:36:13 +02:00

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';