This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

run-ts
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

run-ts

A tools to use Typescript files as npm scripts

Gist

before

{
  "scripts": {
    "setup": "ts-node --project ./scripts/tsconfig.json ./scripts/setup.ts some-argument",
    "build": "ts-node --project ./scripts/tsconfig.json ./scripts/build.ts"
  }
}

after

{
  "scripts": {
    "setup": "run-ts some-argument",
    "build": "run-ts"
  }
}

How to

1. Install run-ts

npm install --save-dev run-ts
# or 
yarn add --dev run-ts

2. Create a scripts folder

mkdir scripts

3. Create a scripts/tsconfig.json file

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "target": "es6",
    "baseUrl": "."
  }
}

4. Create a scripts/my-script.ts file

const foo: number = 42;
console.log(foo);

5. Create a my-script scripts in your package.json

{
  "scripts": {
    "my-script": "run-ts"
  }
}

That's it, now when you run npm run my-script the scripts/my-script.ts file is executed.

Using args

If your file export a function as default, run-ts will execute this function with the arguments as first parameter:

// scripts/setup.ts
export default function setup(args: Array<string>) {
  console.log(args);
}

Note: You can also use process.argv but you have to strip the first two items (node and run-ts)

Readme

Keywords

none

Package Sidebar

Install

npm i run-ts

Weekly Downloads

3

Version

1.1.2

License

MIT

Unpacked Size

13.4 kB

Total Files

15

Last publish

Collaborators

  • etienne-dldc-graveyard