Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ng-barrel

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-barrel

CLI tool to add generated Angular files to barrel files

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

ng-barrel npm version

ng-barrel is a small CLI tool, that takes the output of ng generate commands and adds the new service / component / ... to the closest index.ts file.

Installation

npm i -g ng-barrel

You can now pipe ng generate output into ng-barrel or ngb.

Example

└───src
    ├───app
    │   └───foo
    │       └───components
    |           └───index.ts
    ...
$ ng generate component foo/components/example Example | ng-barrel
Angular:
        CREATE src/app/foo/components/example/example.component.html (26 bytes)
        CREATE src/app/foo/components/example/example.component.spec.ts (635 bytes)
        CREATE src/app/foo/components/example/example.component.ts (273 bytes)
        CREATE src/app/foo/components/example/example.component.css (0 bytes)
        UPDATE src/app/app.module.ts (4077 bytes)

NgBarrel:
        export * from './example/example.component'; >> src/app/foo/components/index.ts
└───src
    ├───app
    │   └───foo
    │       └───components
    │           │   index.ts
    │           └───example
    │                   example.component.css
    │                   example.component.html
    │                   example.component.spec.ts
    │                   example.component.ts
    ...
$ cat src/app/foo/components/index.ts
export * from './example/example.component';

How it works

ng-barrel takes the CLI output and searches for newly created .ts files (excluding .spec.ts) and adds all their exports to the closest barrel.

To find the closest barrel the tools starts from the newly created file and traverses upwards. The first barrel file will be used.

By default it searches for index.ts. You can change this behaviour via --barrel / -b. With this option you can use it for Angular libraries as well:

ng g s services/foo Foo --project=my-lib | ng-barrel --barrel public_api.ts

Creating missing barrels

You can also pass --create / -c to specify where a barrel file should be created. If this option is specified it takes priority over tree traversing.

If a barrel file at the specified path already exists, the export will be appended. Otherwise a new file will be written.

--create takes a relative path, which will be combined with the path of the newly added files.

$ ng g s foo/services/Data data | ng-barrel -c ./
Angular:
        CREATE src/app/foo/services/data.service.spec.ts (323 bytes)
        CREATE src/app/foo/services/data.service.ts (133 bytes)

NgBarrel:
        export * from './data.service'; >> src\app\foo\services\index.ts (NEW)
└───src
    ├───app
    │   └───foo
    │       ├───components
    │       │   └─── ...
    │       └───services
    │               data.service.spec.ts
    │               data.service.ts
    │               index.ts
    ...

Keywords

FAQs

Package last updated on 06 May 2019

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc