-
-
Notifications
You must be signed in to change notification settings - Fork 528
mirror directory structure if output is a directory #1345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
drwpow
merged 10 commits into
openapi-ts:main
from
SchabaJo:globbing_fix_directory_structure
Sep 22, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b6543be
mirror directory structure if output is a directory
SchabaJo 5e82c87
add a changeset
SchabaJo 7d4ac35
move mkdir to appropriate place,
SchabaJo e856c24
remove leftover
SchabaJo 8a1ae00
fix weird output paths
SchabaJo 520897f
add glob tests
SchabaJo 81aa451
fix remaining test case
SchabaJo ec136a8
ignore test output directory
SchabaJo 2fce0fe
run prettier
SchabaJo ff00349
make conditions more readable
SchabaJo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"openapi-typescript": patch | ||
--- | ||
|
||
Mirror directory structure of input files if output is a directory to prevent overwriting the same file again and again. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
.astro | ||
dist | ||
node_modules | ||
|
||
packages/openapi-typescript/test/fixtures/cli-outputs/out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
import { execa } from "execa"; | ||
import glob from "fast-glob"; | ||
import fs from "node:fs"; | ||
import path from "node:path/posix"; // prevent issues with `\` on windows | ||
import { URL, fileURLToPath } from "node:url"; | ||
import os from "node:os"; | ||
|
||
const root = new URL("../", import.meta.url); | ||
const cwd = os.platform() === "win32" ? fileURLToPath(root) : root; // execa bug: fileURLToPath required on Windows | ||
const cmd = "./bin/cli.js"; | ||
const inputDir = "test/fixtures/cli-outputs/"; | ||
const outputDir = path.join(inputDir, "out/"); | ||
const TIMEOUT = 90000; | ||
|
||
// fast-glob does not sort results | ||
async function getOutputFiles() { | ||
return (await glob("**", { cwd: outputDir })).sort((a, b) => a.localeCompare(b, undefined, { numeric: true })); | ||
} | ||
|
||
describe("CLI", () => { | ||
// note: the snapshots in index.test.ts test the Node API; these test the CLI | ||
describe("snapshots", () => { | ||
|
@@ -76,4 +85,59 @@ describe("CLI", () => { | |
expect(stdout).toEqual(expect.stringMatching(/^v[\d.]+(-.*)?$/)); | ||
}); | ||
}); | ||
|
||
describe("outputs", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 |
||
beforeEach(() => { | ||
fs.rmSync(new URL(outputDir, root), { recursive: true, force: true }); | ||
}); | ||
|
||
test("single file to file", async () => { | ||
const inputFile = path.join(inputDir, "file-a.yaml"); | ||
const outputFile = path.join(outputDir, "file-a.ts"); | ||
await execa(cmd, [inputFile, "--output", outputFile], { cwd }); | ||
const result = await getOutputFiles(); | ||
expect(result).toEqual(["file-a.ts"]); | ||
}); | ||
|
||
test("single file to directory", async () => { | ||
const inputFile = path.join(inputDir, "file-a.yaml"); | ||
await execa(cmd, [inputFile, "--output", outputDir], { cwd }); | ||
const result = await getOutputFiles(); | ||
expect(result).toEqual(["test/fixtures/cli-outputs/file-a.ts"]); | ||
}); | ||
|
||
test("single file (glob) to file", async () => { | ||
const inputFile = path.join(inputDir, "*-a.yaml"); | ||
const outputFile = path.join(outputDir, "file-a.ts"); | ||
await execa(cmd, [inputFile, "--output", outputFile], { cwd }); | ||
const result = await getOutputFiles(); | ||
expect(result).toEqual(["file-a.ts"]); | ||
}); | ||
|
||
test("multiple files to file", async () => { | ||
const inputFile = path.join(inputDir, "*.yaml"); | ||
const outputFile = path.join(outputDir, "file-a.ts"); | ||
await expect(execa(cmd, [inputFile, "--output", outputFile], { cwd })).rejects.toThrow(); | ||
}); | ||
|
||
test("multiple files to directory", async () => { | ||
const inputFile = path.join(inputDir, "*.yaml"); | ||
await execa(cmd, [inputFile, "--output", outputDir], { cwd }); | ||
const result = await getOutputFiles(); | ||
expect(result).toEqual(["test/fixtures/cli-outputs/file-a.ts", "test/fixtures/cli-outputs/file-b.ts"]); | ||
}); | ||
|
||
test("multiple nested files to directory", async () => { | ||
const inputFile = path.join(inputDir, "**/*.yaml"); | ||
await execa(cmd, [inputFile, "--output", outputDir], { cwd }); | ||
const result = await getOutputFiles(); | ||
expect(result).toEqual([ | ||
"test/fixtures/cli-outputs/file-a.ts", | ||
"test/fixtures/cli-outputs/file-b.ts", | ||
"test/fixtures/cli-outputs/nested/deep/file-e.ts", | ||
"test/fixtures/cli-outputs/nested/file-c.ts", | ||
"test/fixtures/cli-outputs/nested/file-d.ts", | ||
]); | ||
}); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/openapi-typescript/test/fixtures/cli-outputs/file-a.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
openapi: "3.0" | ||
info: | ||
title: test file a | ||
version: "1.0" | ||
paths: | ||
/endpoint: | ||
get: | ||
description: OK |
8 changes: 8 additions & 0 deletions
8
packages/openapi-typescript/test/fixtures/cli-outputs/file-b.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
openapi: "3.0" | ||
info: | ||
title: test file b | ||
version: "1.0" | ||
paths: | ||
/endpoint: | ||
get: | ||
description: OK |
8 changes: 8 additions & 0 deletions
8
packages/openapi-typescript/test/fixtures/cli-outputs/nested/deep/file-e.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
openapi: "3.0" | ||
info: | ||
title: test file e | ||
version: "1.0" | ||
paths: | ||
/endpoint: | ||
get: | ||
description: OK |
8 changes: 8 additions & 0 deletions
8
packages/openapi-typescript/test/fixtures/cli-outputs/nested/file-c.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
openapi: "3.0" | ||
info: | ||
title: test file c | ||
version: "1.0" | ||
paths: | ||
/endpoint: | ||
get: | ||
description: OK |
8 changes: 8 additions & 0 deletions
8
packages/openapi-typescript/test/fixtures/cli-outputs/nested/file-d.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
openapi: "3.0" | ||
info: | ||
title: test file d | ||
version: "1.0" | ||
paths: | ||
/endpoint: | ||
get: | ||
description: OK |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we’re accidentally skipping this from linting/Prettier. Thanks for fixing this file.