biesbjerg / ngx-translate-extract

Extract translatable (using ngx-translate) strings and save as a JSON or Gettext pot file
MIT License
524 stars 196 forks source link

Usage as a library #241

Open P4 opened 3 years ago

P4 commented 3 years ago

Hi, I've been using @biesbjerg/ngx-translate-extract in my project at work for several years now. However, we needed to make enough changes to the resulting files that we ended up writing our own custom script that's using the parsers and collections provided by the package, essentially treating the tool as a library.

We're currently using @biesbjerg/ngx-translate-extract version 7.0.4

A small problem we have right now is that any attempt to import something from the package's main entrypoint causes the CLI task to execute and kill the process. I suspect this is caused by the index.ts file re-exporting another file which defines and executes the task:

https://github.com/biesbjerg/ngx-translate-extract/blob/82eb652e4bfec73f60f06cbc5ed4ddf8179f58f7/src/index.ts#L4

https://github.com/biesbjerg/ngx-translate-extract/blob/82eb652e4bfec73f60f06cbc5ed4ddf8179f58f7/src/cli/cli.ts#L152-L158

We currently work around that by importing everything from internals instead of the main entrypoint:

import {JsonCompiler} from '@biesbjerg/ngx-translate-extract/dist/compilers/json.compiler';
import {ParserInterface} from '@biesbjerg/ngx-translate-extract/dist/parsers/parser.interface';
import {PipeParser} from '@biesbjerg/ngx-translate-extract/dist/parsers/pipe.parser';
...

This works, but looks messy is generally not a good practice, so I was wondering if there's any good way to solve that issue. I'm not certain why cli is re-exported as it does not seem to be used through index, and the bin script that actually runs as ngx-translate-extract imports it directly.

Thanks!