Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,9 @@ export async function apigen() {
.map(([key, value]) => `${key}=${value}`)
.join(",");

const format = await prettier();
// bypass .prettierignore since it excludes src/clients/ (to prevent other tools from
// reformatting generated code), but apigen itself should always format its own output
const format = await prettier({ ignoreIgnoreFile: true });

for (const [spec, path] of clients) {
// other client generator types: https://openapi-generator.tech/docs/generators#client-generators
Expand Down Expand Up @@ -1053,18 +1055,20 @@ export async function format() {
);
}

async function prettier() {
async function prettier({ ignoreIgnoreFile = false } = {}) {
const { check, format, getFileInfo, resolveConfigFile, resolveConfig } = await import("prettier");
const configFile = (await resolveConfigFile()) ?? ".prettierrc";
const config = await resolveConfig(configFile);
/** @param {AsyncIterator<import("vinyl")>} source */
return async function* process(source) {
for await (const file of source) {
if (file.contents != null) {
// check if the file is in .prettierignore before trying to format it
const fileInfo = await getFileInfo(file.path, { ignorePath: ".prettierignore" });
if (fileInfo.ignored) {
continue;
if (!ignoreIgnoreFile) {
// check if the file is in .prettierignore before trying to format it
const fileInfo = await getFileInfo(file.path, { ignorePath: ".prettierignore" });
if (fileInfo.ignored) {
continue;
}
}
const options = { filepath: file.path, ...config };
const code = file.contents.toString();
Expand Down