diff --git a/src/index.ts b/src/index.ts index 721af00a..b59d8f46 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ import { getOpenApiSpec } from './utils/getOpenApiSpec'; import { writeClient } from './utils/writeClient'; import * as os from 'os'; import * as chalk from 'chalk'; +import * as ts from 'typescript'; import { getOpenApiVersion, OpenApiVersion } from './utils/getOpenApiVersion'; export enum Language { @@ -65,3 +66,19 @@ export function generate(input: string, output: string, language: Language = Lan process.exit(1); } } + +export function compile(dir: string): void { + const config = { + compilerOptions: { + target: 'esnext', + module: 'commonjs', + moduleResolution: 'node', + }, + include: ['./index.ts'], + }; + const configFile = ts.parseConfigFileTextToJson('tsconfig.json', JSON.stringify(config)); + const configFileResult = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.resolve(process.cwd(), dir), undefined, 'tsconfig.json'); + const compilerHost = ts.createCompilerHost(configFileResult.options); + const compiler = ts.createProgram(configFileResult.fileNames, configFileResult.options, compilerHost); + compiler.emit(); +} diff --git a/src/templates/typescript/core/requestUsingXHR.ts b/src/templates/typescript/core/requestUsingXHR.ts index c7d74681..acf30e30 100644 --- a/src/templates/typescript/core/requestUsingXHR.ts +++ b/src/templates/typescript/core/requestUsingXHR.ts @@ -7,9 +7,9 @@ import { Result } from './Result'; import { isSuccess } from './isSuccess'; /** - * Request content using the new legacy XMLHttpRequest API. This method is usefull + * Request content using the new legacy XMLHttpRequest API. This method is useful * when we want to request UTF-16 content, since it natively supports loading UTF-16. - * We could do the same with the Fetch API, but then we will need to conver the + * We could do the same with the Fetch API, but then we will need to convert the * content using JavaScript... And that is very very slow. * @param url The url to request. * @param request The request object, containing method, headers, body, etc. diff --git a/test/index.js b/test/index.js index cc1a7a6e..519da891 100755 --- a/test/index.js +++ b/test/index.js @@ -11,34 +11,44 @@ OpenAPI.generate( OpenAPI.HttpClient.FETCH, ); -// OpenAPI.generate( -// './test/mock/v2/test-addon.json', -// './test/tmp/v2/ts/test-addon', -// OpenAPI.Language.TYPESCRIPT, -// OpenAPI.HttpClient.FETCH, -// ); -// -// OpenAPI.generate( -// './test/mock/v2/test-docs.json', -// './test/tmp/v2/ts/test-docs', -// OpenAPI.Language.TYPESCRIPT, -// OpenAPI.HttpClient.FETCH, -// ); -// +OpenAPI.generate( + './test/mock/v2/test-addon.json', + './test/tmp/v2/ts/test-addon', + OpenAPI.Language.TYPESCRIPT, + OpenAPI.HttpClient.FETCH, +); + +OpenAPI.generate( + './test/mock/v2/test-docs.json', + './test/tmp/v2/ts/test-docs', + OpenAPI.Language.TYPESCRIPT, + OpenAPI.HttpClient.FETCH, +); + OpenAPI.generate( './test/mock/v2/test-sites.json', './test/tmp/v2/ts/test-sites', OpenAPI.Language.TYPESCRIPT, OpenAPI.HttpClient.FETCH, ); -// -// OpenAPI.generate( -// './test/mock/v2/test-petstore.yaml', -// './test/tmp/v2/ts/test-petstore-yaml', -// OpenAPI.Language.TYPESCRIPT, -// OpenAPI.HttpClient.FETCH, -// ); -// + +OpenAPI.generate( + './test/mock/v2/test-petstore.yaml', + './test/tmp/v2/ts/test-petstore-yaml', + OpenAPI.Language.TYPESCRIPT, + OpenAPI.HttpClient.FETCH, +); + +OpenAPI.compile('./test/tmp/v2/ts/spec'); + +OpenAPI.compile('./test/tmp/v2/ts/test-addon'); + +OpenAPI.compile('./test/tmp/v2/ts/test-docs'); + +OpenAPI.compile('./test/tmp/v2/ts/test-sites'); + +OpenAPI.compile('./test/tmp/v2/ts/test-petstore-yaml'); + // OpenAPI.generate( // './test/mock/v3/test-petstore.json', // './test/tmp/v3/test-petstore-json',