Within an npm project, I am looking to execute a custom function with arguments, or ideally provide it as a script in the package.json file like this:
npm run custom-function "Hello, World"
.
Currently, I have a file called src/myFunction.ts:
import * as extLib from 'libFromNodeModules'; // requiring npm to resolve this dependency
export const runFunction = function (arg: string) {
console.log(extLib.process(arg));
};
The closest I've come to calling this function is:
{
...
scripts: {
"custom-function": "ts-node -e 'require(\"./src/myFunction.ts\").runFunction()'",
}
...
}
This method does more than just executing ts-node src/myFunction.ts, however, it still doesn't allow passing arguments and might not be the correct approach. How should I properly set this up?