typera-openapi
Advanced tools
Comparing version 0.9.1 to 0.10.0
@@ -15,8 +15,14 @@ #!/usr/bin/env node | ||
const path = require("path"); | ||
const ts = require("typescript"); | ||
const yargs = require("yargs"); | ||
const _1 = require("."); | ||
const prettify_1 = require("./prettify"); | ||
const yargs = require("yargs"); | ||
const log = (location, level, ...args) => console.log(`${location}: ${level}:`, ...args); | ||
const parseArgs = () => yargs | ||
.usage('Usage: $0 [options] FILE...') | ||
.option('verbose', { | ||
description: 'Verbose output', | ||
type: 'boolean', | ||
default: false, | ||
}) | ||
.option('format', { | ||
@@ -27,2 +33,6 @@ description: 'Output file format', | ||
}) | ||
.option('tsconfig', { | ||
description: 'Which tsconfig.json to use', | ||
default: 'tsconfig.json', | ||
}) | ||
.option('prettify', { | ||
@@ -45,3 +55,11 @@ alias: 'p', | ||
const ext = `.openapi.${args.format}`; | ||
const results = _1.generate(sourceFiles, { strict: true }, { log }).map((result) => (Object.assign(Object.assign({}, result), { outputFileName: outputFileName(result.fileName, ext) }))); | ||
const compilerOptions = readCompilerOptions(args.tsconfig); | ||
if (!compilerOptions) | ||
process.exit(1); | ||
if (args.verbose) { | ||
console.log(`Compiler options: ${JSON.stringify(compilerOptions, null, 2)}`); | ||
} | ||
const results = _1.generate(sourceFiles, compilerOptions, { | ||
log, | ||
}).map((result) => (Object.assign(Object.assign({}, result), { outputFileName: outputFileName(result.fileName, ext) }))); | ||
let success = true; | ||
@@ -65,2 +83,11 @@ for (const { outputFileName, paths } of results) { | ||
}); | ||
const readCompilerOptions = (tsconfigPath) => { | ||
const tsconfig = ts.readConfigFile(tsconfigPath, (path) => fs.readFileSync(path, 'utf-8')); | ||
if (tsconfig.error) { | ||
console.error(`Unable to read ${tsconfigPath}: ${tsconfig.error.messageText}`); | ||
console.error(`(Tip: Use --tsconfig to specify configuration file path)`); | ||
return; | ||
} | ||
return tsconfig.config.compilerOptions; | ||
}; | ||
const checkOutput = (fileName, content) => { | ||
@@ -67,0 +94,0 @@ const current = fs.readFileSync(fileName, 'utf-8'); |
{ | ||
"name": "typera-openapi", | ||
"version": "0.9.1", | ||
"version": "0.10.0", | ||
"description": "Generate OpenAPI spec from typera routes", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/akheron/typera-openapi", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36899
703