Skip to content

Commit ff00349

Browse files
committed
make conditions more readable
1 parent 2fce0fe commit ff00349

File tree

1 file changed

+4
-2
lines changed
  • packages/openapi-typescript/bin

1 file changed

+4
-2
lines changed

packages/openapi-typescript/bin/cli.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ async function main() {
174174
// handle local schema(s)
175175
const inputSpecPaths = await glob(pathToSpec);
176176
const isGlob = inputSpecPaths.length > 1;
177+
const isDirUrl = outputDir.pathname === outputFile.pathname;
178+
const isFile = fs.existsSync(outputDir) && fs.lstatSync(outputDir).isFile();
177179

178180
// error: no matches for glob
179181
if (inputSpecPaths.length === 0) {
@@ -182,7 +184,7 @@ async function main() {
182184
}
183185

184186
// error: tried to glob output to single file
185-
if (isGlob && output === OUTPUT_FILE && ((fs.existsSync(outputDir) && fs.lstatSync(outputDir).isFile()) || outputDir.pathname !== outputFile.pathname)) {
187+
if (isGlob && output === OUTPUT_FILE && (isFile || !isDirUrl)) {
186188
error(`Expected directory for --output if using glob patterns. Received "${flags.output}".`);
187189
process.exit(1);
188190
}
@@ -191,7 +193,7 @@ async function main() {
191193
await Promise.all(
192194
inputSpecPaths.map(async (specPath) => {
193195
if (flags.output !== "." && output === OUTPUT_FILE) {
194-
if (isGlob || outputDir.pathname === outputFile.pathname) {
196+
if (isGlob || isDirUrl) {
195197
fs.mkdirSync(new URL(path.dirname(specPath), outputDir), { recursive: true }); // recursively make parent dirs
196198
} else {
197199
fs.mkdirSync(outputDir, { recursive: true }); // recursively make parent dirs

0 commit comments

Comments
 (0)