- Also checking if we can compile, looking good

This commit is contained in:
Ferdi Koomen 2019-11-21 23:53:11 +01:00
parent 05d5a10599
commit ea6a46a4c3
3 changed files with 51 additions and 24 deletions

View File

@ -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();
}

View File

@ -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.

View File

@ -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',