Skip to content

Commit

Permalink
feat: lookup project tsconfig (#2068)
Browse files Browse the repository at this point in the history
  • Loading branch information
slhck authored Sep 30, 2024
1 parent 7cc6466 commit 83e31c5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Note that different platforms (e.g. Windows) may use different path separators s

Also note that you need to quote paths with `*` as otherwise the shell will expand the paths and therefore only pass the first path to the generator.

By default, the command-line generator will use the `tsconfig.json` file in the current working directory, or the first parent directory that contains a `tsconfig.json` file up to the root of the filesystem. If you want to use a different `tsconfig.json` file, you can use the `--tsconfig` option. In particular, if you need to use different compilation options for types, you may want to create a separate `tsconfig.json` file for the schema generation only.

### Options

```
Expand Down
4 changes: 3 additions & 1 deletion ts-json-schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Command, Option } from "commander";
import { mkdirSync, writeFileSync } from "node:fs";
import { dirname } from "node:path";
import stableStringify from "safe-stable-stringify";
import { findConfigFile, sys as tsSys } from "typescript";
import { createGenerator } from "./factory/generator.js";
import type { Config } from "./src/Config.js";
import { BaseError } from "./src/Error/BaseError.js";
Expand Down Expand Up @@ -56,7 +57,8 @@ const args = new Command()
const config: Config = {
minify: args.minify,
path: args.path,
tsconfig: args.tsconfig,
tsconfig:
typeof args.tsconfig === "string" ? args.tsconfig : findConfigFile(process.cwd(), (f) => tsSys.fileExists(f)),
type: args.type,
schemaId: args.id,
expose: args.expose,
Expand Down

0 comments on commit 83e31c5

Please sign in to comment.