Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lookup project tsconfig #2068

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading