Skip to content

Commit 4e3e7c9

Browse files
Pete Westdomoritz
authored andcommitted
Convert compiler options from JSON format to Typescript format
Adding an optional argument for base path
1 parent 3aba8c2 commit 4e3e7c9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ const compilerOptions: TJS.CompilerOptions = {
5959
strictNullChecks: true
6060
}
6161

62-
const program = TJS.getProgramFromFiles([resolve("my-file.ts")], compilerOptions);
62+
// optionally pass a base path
63+
const basePath = "./my-dir";
64+
65+
const program = TJS.getProgramFromFiles([resolve("my-file.ts")], compilerOptions, basePath);
6366

6467
// We can either get the schema for one file and one type...
6568
const schema = TJS.generateSchema(program, "MyType", settings);

typescript-json-schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,9 @@ export class JsonSchemaGenerator {
886886
}
887887
}
888888

889-
export function getProgramFromFiles(files: string[], compilerOptions: ts.CompilerOptions = {}): ts.Program {
889+
export function getProgramFromFiles(files: string[], jsonCompilerOptions: any = {}, basePath: string = "./"): ts.Program {
890890
// use built-in default options
891+
const compilerOptions = ts.convertCompilerOptionsFromJson(jsonCompilerOptions, basePath).options;
891892
const options: ts.CompilerOptions = {
892893
noEmit: true, emitDecoratorMetadata: true, experimentalDecorators: true, target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS
893894
};

0 commit comments

Comments
 (0)