npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-barrel

v2.0.1

Published

CLI tool to add generated Angular files to barrel files

Downloads

5

Readme

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 a relative path as an argument to specify where a barrel file should be created. If this argument 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.

The argument should be a path relative to the created TS files.

$ ng g s foo/services/Data data | ngb .
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
    ...