|
1 | 1 | #!/usr/bin/env node
|
2 | 2 |
|
3 | 3 | import fs from "node:fs";
|
4 |
| -import path from "path"; |
| 4 | +import path from "node:path"; |
5 | 5 | import { URL } from "node:url";
|
6 | 6 | import glob from "fast-glob";
|
7 | 7 | import parser from "yargs-parser";
|
@@ -114,7 +114,10 @@ async function generateSchema(pathToSpec) {
|
114 | 114 | let outputFilePath = new URL(flags.output, CWD); // note: may be directory
|
115 | 115 | const isDir = fs.existsSync(outputFilePath) && fs.lstatSync(outputFilePath).isDirectory();
|
116 | 116 | if (isDir) {
|
117 |
| - const filename = pathToSpec.replace(EXT_RE, ".ts"); |
| 117 | + if (typeof flags.output === 'string' && !flags.output.endsWith('/')) { |
| 118 | + outputFilePath = new URL(`${flags.output}/`, CWD) |
| 119 | + } |
| 120 | + const filename = path.basename(pathToSpec).replace(EXT_RE, ".ts"); |
118 | 121 | const originalOutputFilePath = outputFilePath;
|
119 | 122 | outputFilePath = new URL(filename, originalOutputFilePath);
|
120 | 123 | if (outputFilePath.protocol !== 'file:') {
|
@@ -189,7 +192,7 @@ async function main() {
|
189 | 192 | inputSpecPaths.map(async (specPath) => {
|
190 | 193 | if (flags.output !== "." && output === OUTPUT_FILE) {
|
191 | 194 | if (isGlob) {
|
192 |
| - fs.mkdirSync(new URL(path.dirname(specPath), outputDir), { recursive: true }); // recursively make parent dirs |
| 195 | + fs.mkdirSync(outputFile, { recursive: true }); // recursively make parent dirs |
193 | 196 | }
|
194 | 197 | else {
|
195 | 198 | fs.mkdirSync(outputDir, { recursive: true }); // recursively make parent dirs
|
|
0 commit comments