Skip to content

Commit

Permalink
feat: adds prettier run after updating orbit chains list (#2009)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglance authored Oct 22, 2024
1 parent d4c70d5 commit 0654a93
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/scripts/src/addOrbitChain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
updateAndValidateOrbitChainsList,
commitChangesAndCreatePR,
setOutputs,
runPrettier,
} from "./transforms";

/**
Expand Down Expand Up @@ -36,6 +37,8 @@ export async function addOrbitChain(targetJsonPath: string): Promise<void> {
targetJsonPath
);

await runPrettier(targetJsonPath);

await commitChangesAndCreatePR(
branchName,
targetJsonPath,
Expand Down
16 changes: 16 additions & 0 deletions packages/scripts/src/addOrbitChain/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { JsonRpcProvider } from "@ethersproject/providers";
import axios from "axios";
import * as fs from "fs";
import sharp from "sharp";
import prettier from "prettier";

import {
commitChanges,
Expand Down Expand Up @@ -437,3 +438,18 @@ export const updateOrbitChainsFile = (

return orbitChains;
};

export async function runPrettier(targetJsonPath: string): Promise<void> {
try {
const fileContent = fs.readFileSync(targetJsonPath, "utf8");
const prettierConfig = await prettier.resolveConfig(targetJsonPath);
const formattedContent = await prettier.format(fileContent, {
...prettierConfig,
filepath: targetJsonPath,
});
fs.writeFileSync(targetJsonPath, formattedContent);
console.log(`Prettier formatting applied to ${targetJsonPath}`);
} catch (error) {
warning(`Failed to run Prettier: ${error}`);
}
}

0 comments on commit 0654a93

Please sign in to comment.