flowgen icon indicating copy to clipboard operation
flowgen copied to clipboard

The ouputFile is overwritten while iterating over multiple .d.ts files

Open ajbogh opened this issue 7 years ago • 1 comments

I would like to automatically convert typescript files in-place to flow files. I found that I could include multiple typescript files by using a glob pattern, however the output file option seems to only accept a single filename.

When the single output file is generated it only includes the type information for the last file iterated upon.

flowgen ./dist/**/*.d.ts -o ./dist/example.flow.js

The code should either append all types into this single output file, or it should allow a similar Glob pattern and generate flow files based on the same root name (everything before .d.ts).

# concatenate all types to one file
flowgen ./dist/**/*.d.ts -o ./dist/example.flow.js

# create files with similar names and folder structure
flowgen ./dist/**/*.d.ts -o ./dist/**/*.flow.js

https://github.com/joarwilk/flowgen/blob/140e0f0c3c13fe07af63d5ece46c89da93bc76bf/src/cli/runner.js#L61

Workaround:

Add the following code to your package.json

"flowgen": "for file in $(find ./dist -name *.d.ts -type f); do flowgen ${file} -o ${file/.d.ts/.flow.js}; done;"

Run the command with npm run flowgen.

Alternatively, if flowgen is installed globally by npm install -g flowgen then you can use the command directly in the terminal:

for file in $(find ./dist -name *.d.ts -type f); do flowgen ${file} -o ${file/.d.ts/.flow.js}; done;

ajbogh avatar Jun 21 '18 18:06 ajbogh

That makes sense, yeah, would happily take that PR 👍

orta avatar Jun 21 '18 22:06 orta