You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@ngx-ext/schematics-api

Package Overview
Dependencies
2
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ngx-ext/schematics-api

Set of tools wrapping Angular Schematics.


Version published
Maintainers
1
Created

Readme

Source

Simplified Angular Schematics API

@ngx-ext/schematics-api

If you are an Angular library author, looking for user-friendly Angular Schematics API wrapper, then you are in the perfect place.

Installation

npm install @ngx-ext/schematics-api @schematics/angular @angular-devkit/schematics

Usage example:

add-imports-to-root-module.rule.ts file:

import { Rule, Tree } from '@angular-devkit/schematics';
import { RootModule } from '@ngx-ext/schematics';

export function addImportsToRootModule(): Rule {
    return (tree: Tree) => {
        const rootModule = RootModule.getInstance(tree, '@my/lib');
        rootModule.addImport('MyLibModule.forRoot()');
        rootModule.addImport('MyLibModule2.forRoot()');
        rootModule.addExport('MyLibNestModule', '/nested');
        return rootModule.applyAllChanges();
    };
}

schematics/ng-add/index.ts:

import { chain, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import { addImportsToRootModule } from './add-imports-to-root-module.rule';
import { installDependencies } from './install-dependencies.rule';

export function ngAdd(_options: any): Rule {
  return (_tree: Tree, _context: SchematicContext) => {
    return chain([
      installDependencies(),
      addImportsToRootModule(),
    ]);
  };
}

After firing ng add @my/lib in Angular project, proper import statements and declarations will be added to its root module. Example simplified output:

import { MyLibModule, MyLibModule2 } from '@my/lib';
import { MyLibNestedModule } from '@my/lib/nested';

@NgModule({
  declarations: [/* no changes */],
  imports: [
    MyLibModule.forRoot(),
    MyLibModule2.forRoot(),
    MyLibNestedModule,
  ],
  exports: [MyLibNestedModule],
  providers: [/* no changes */],
  bootstrap: [AppComponent],
})
export class AppModule { }

Keywords

FAQs

Package last updated on 29 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc