chore: migrate formatting to Oxfmt (#615)
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import { format } from "oxfmt";
|
||||
import config from "../../.oxfmtrc.json" with { type: "json" };
|
||||
|
||||
/** Format generated source with the same options as the repository formatter. */
|
||||
export const formatGeneratedFile = async (fileName, source) => {
|
||||
const result = await format(fileName, source, config);
|
||||
if (result.errors.length > 0)
|
||||
throw new Error(
|
||||
`Cannot format ${fileName}: ${result.errors.map(({ message }) => message).join("; ")}`,
|
||||
);
|
||||
return result.code;
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import { format } from "prettier";
|
||||
import { formatGeneratedFile } from "./format-generated-file.mjs";
|
||||
|
||||
import { assertSameNames, digest, loadSources } from "./catalog-core.mjs";
|
||||
import {
|
||||
@@ -67,4 +67,7 @@ export const createProductCatalog = async (root) => {
|
||||
|
||||
/** Stable checked-in representation of the product catalog. */
|
||||
export const serializeProductCatalog = (catalog) =>
|
||||
format(JSON.stringify(catalog, null, 2), { parser: "json" });
|
||||
formatGeneratedFile(
|
||||
"docs/product-catalog.json",
|
||||
JSON.stringify(catalog, null, 2),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user