gristlabs / ts-interface-builder

Compile TypeScript interfaces into a description that allows runtime validation
Apache License 2.0
132 stars 28 forks source link

npm scripts #33

Closed rattkin closed 3 years ago

rattkin commented 3 years ago

I'm trying to run it in npm script and to process all files in a directory:

   "scripts": {
        "generate-ts-interface": "ts-interface-builder ./src/shared/api-model/models/*.ts -o ./src/shared/api-ts-checker"
    },

the script seems to start, but has this error: Error: Can't process ./src/shared/api-model/models/*.ts: error TS6053: File 'src/shared/api-model/models/*.ts' not found.

however, if I run this in bash, it works: node_modules/ts-interface-builder/bin/ts-interface-builder src/shared/api-model/models/*.ts -o src/shared/api-ts-checker

how can I set the path?

dsagal commented 3 years ago

It works for me as long as there are actually any files matching the pattern (./src/shared/api-model/models/*.ts). If not, bash does not expand * -- it's a function of bash rather than of ts-interface-builder. If it works from command-line, there is probably a difference in which shell is used.

You could work around it using xargs, e.g.

find ./src/shared/api-model/models - name '*.ts' | xargs ts-interface-builder  -o ./src/shared/api-ts-checker
rattkin commented 3 years ago

Thank you for your reply. It is in the * expansion indeed. If I run named file, it works: "generate-ts-interface": "ts-interface-builder \"./src/app/shared/api-model/models/address.ts\" -o ./src/app/shared/api-ts-checker"

I'm on windows unfortunately.

rattkin commented 3 years ago

Can the script please work on all files in the specified path? So using glob * would not be necessary..

dsagal commented 3 years ago

A good solution to this would be to use the node-glob within ts-interface-builder, and to quote the glob in the npm-script line. If you want to give it a shot with a PR, I'd be happy to review. Otherwise, I could do it, but it might take me some time to get to it.

rattkin commented 3 years ago

Ok this is cleaner commit