ts-script-runner is a tool for running and managing local TypeScript and Bash scripts in a consistent, interactive way.
- Discover and run TypeScript or Bash scripts from specified folders
- Interactive selection of scripts and exported functions
- Prompt for arguments interactively or via CLI flags
- Annotate functions with descriptions for better UX
- Register cleanup logic to run after script execution
Add to your project:
npm install ts-script-runnerYou can use ts-script-runner in several flexible ways:
yarn ts-script-runner my-script.tsRuns a TypeScript file directly.
yarn ts-script-runner src/scripts/index.tsWhere index.ts is your own entrypoint that calls run({...}) from ts-script-runner with custom options.
You can pass options (matching the Args type) directly to the runner:
yarn ts-script-runner -o --tsScriptsFolder src/scriptsor
npx ts-script-runner --tsScriptsFolder src/scriptsnpm run ts-script-runner -- --tsScriptsFolder src/scripts(Assuming you add a script in your package.json.)
- You will be prompted to select a script and, for TypeScript, a function to run.
- If both TypeScript and Bash folders are provided, you can choose which type to run.
Add descriptions to your exported functions for better prompts:
import { describeFunction } from 'ts-script-runner';
function myTask() {
// ...
}
describeFunction(myTask, 'Does something important');
export { myTask };Prompt for arguments in your scripts:
import { getOrPromptArg } from 'ts-script-runner';
const filename = await getOrPromptArg({ name: 'file', message: 'Enter filename:' });Register cleanup callbacks to run after your script:
import { registerCleanup } from 'ts-script-runner';
registerCleanup(() => {
// cleanup logic
});run(options): Start the script runner (usually not called directly unless you want custom options).describeFunction(fn, description): Attach a description to a function.getOrPromptArg(options): Get an argument from CLI or prompt the user.registerCleanup(callback): Register a cleanup callback.
npx ts-script-runner --tsScriptsFolder ./scripts --bashScriptsFolder ./bashSee more usage examples at:
https://github.com/adpopescu338/ts-script-runner-examples