Skip to content

Commit

Permalink
fix(args): use correct default paths when running from cli, clarify docs
Browse files Browse the repository at this point in the history
closes #1
  • Loading branch information
BenShelton committed May 28, 2021
1 parent b1835ee commit e426221
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@ yarn add -D vue-script-tsc
```

### CLI
You can run `vue-script-tsc` as a script.

You can run `vue-script-tsc` as a script, for example in package.json or on the command line.

```json
// package.json
"scripts": {
"tsc": "yarn vue-script-tsc --root ."
}
```

```bash
vue-script-tsc --root .
# Command line
yarn vue-script-tsc --root .
```

### Programmatic
Expand All @@ -32,13 +41,16 @@ You can call `vue-script-tsc` within your own script.
```ts
const { tsc } = require('vue-script-tsc');

async function checkFiles() {
await tsc({
root: __dirname
tsc({
root: process.cwd()
})
.then(() => {
console.log('Type Check Complete')
})
.catch((err) => {
console.error(err)
process.exit(1)
})
}

checkFiles()
```

### Arguments
Expand All @@ -50,7 +62,7 @@ You can specify some arguments with either usage. For CLI arguments prepend with
| `root` | Current Directory | The relative path to the directory to be treated as the root (where your `tsconfig.json` file exists) |
| `src` | `<root>/src` | The relative path to the src directory containing your vue files |
| `tsconfig` | `tsconfig.json` | The name of your `tsconfig.json` file |
| `tsbuildinfo` | Settings in `tsconfig.json` | If using `incremental` builds, the relative path to where to store the `.tsbuildinfo` file |
| `tsbuildinfo` | Setting in `tsconfig.json` | If using `incremental` builds, the relative path to where to store the `.tsbuildinfo` file |

## Comparisons

Expand Down
4 changes: 2 additions & 2 deletions src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export interface Options {
}

export function parseArgs(opts: Options): Required<Options> {
const cwd = resolve(__dirname)
const cwd = process.cwd()
const root = opts.root ? resolve(cwd, opts.root) : cwd
const src = opts.src ? resolve(cwd, opts.src) : resolve(cwd, 'src')
const src = opts.src ? resolve(cwd, opts.src) : resolve(root, 'src')
const tsconfig = opts.tsconfig || 'tsconfig.json'
const tsbuildinfo = opts.tsbuildinfo ? resolve(cwd, opts.tsbuildinfo) : ''

Expand Down
7 changes: 7 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ import { Options } from './args'
const options = minimist(process.argv.slice(2)) as Options

tsc(options)
.then(() => {
console.log('Type Check Complete')
})
.catch((err) => {
console.error(err.message)
process.exit(1)
})

0 comments on commit e426221

Please sign in to comment.