Skip to content

Commit b03c011

Browse files
add prettier task (#750)
1 parent 898f92f commit b03c011

File tree

17 files changed

+77
-48
lines changed

17 files changed

+77
-48
lines changed

.changeset/silly-coins-share.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-eth": patch
3+
---
4+
5+
Add format with prettier task

src/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
createProjectDirectory,
44
installPackages,
55
createFirstGitCommit,
6+
prettierFormat,
67
} from "./tasks";
78
import type { Options } from "./types";
89
import { renderOutroMessage } from "./utils/render-outro-message";
@@ -44,6 +45,10 @@ export async function createProject(options: Options) {
4445
}
4546
},
4647
},
48+
{
49+
title: "🪄 Formatting files with prettier",
50+
task: () => prettierFormat(targetDirectory),
51+
},
4752
{
4853
title: `📡 Initializing Git repository ${
4954
options.extensions.includes("foundry") ? "and submodules" : ""

src/tasks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from "./copy-template-files";
22
export * from "./create-project-directory";
33
export * from "./install-packages";
44
export * from "./create-first-git-commit";
5+
export * from "./prettier-format";

src/tasks/prettier-format.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { execa } from "execa";
2+
3+
export async function prettierFormat(targetDir: string) {
4+
try {
5+
const result = await execa("yarn", ["format"], { cwd: targetDir });
6+
7+
if (result.failed) {
8+
throw new Error("There was a problem running the format command");
9+
}
10+
} catch (error) {
11+
throw new Error("Failed to create directory", { cause: error });
12+
}
13+
14+
return true;
15+
}

templates/base/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"next:lint": "yarn workspace @se-2/nextjs lint",
1414
"next:format": "yarn workspace @se-2/nextjs format",
1515
"next:check-types": "yarn workspace @se-2/nextjs check-types",
16+
"format": "yarn next:format",
1617
"postinstall": "husky install",
1718
"precommit": "lint-staged",
1819
"vercel": "yarn workspace @se-2/nextjs vercel",

templates/extensions/foundry/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
"deploy:verify": "yarn workspace @se-2/foundry deploy:verify",
99
"foundry:lint": "yarn workspace @se-2/foundry lint",
1010
"foundry:test": "yarn workspace @se-2/foundry test",
11+
"foundry:format": "yarn workspace @se-2/foundry format",
1112
"test": "yarn foundry:test",
1213
"verify": "yarn workspace @se-2/foundry verify",
13-
"generate": "yarn workspace @se-2/foundry generate"
14+
"generate": "yarn workspace @se-2/foundry generate",
15+
"format": "yarn next:format && yarn foundry:format"
1416
}
1517
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"arrowParens": "avoid",
3+
"printWidth": 120,
4+
"tabWidth": 2,
5+
"trailingComma": "all"
6+
}

templates/extensions/foundry/packages/foundry/contracts/YourContract.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ contract YourContract {
7373
* The function can only be called by the owner of the contract as defined by the isOwner modifier
7474
*/
7575
function withdraw() public isOwner {
76-
(bool success, ) = owner.call{value: address(this).balance}("");
76+
(bool success,) = owner.call{value: address(this).balance}("");
7777
require(success, "Failed to send Ether");
7878
}
7979

templates/extensions/foundry/packages/foundry/foundry.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ scroll = "https://rpc.scroll.io"
3333
polygonMumbai = { key = "${ETHERSCAN_API_KEY}" }
3434
goerli = { key = "${ETHERSCAN_API_KEY}" }
3535

36+
37+
[fmt]
38+
line_length = 80
39+
multiline_func_header = "params_first"
40+
3641
# See more config options https://github.com/foundry-rs/foundry/tree/master/config

templates/extensions/foundry/packages/foundry/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"deploy": "forge build --build-info --build-info-path out/build-info/ && forge script script/Deploy.s.sol --rpc-url ${1:-default_network} --broadcast --legacy && node script/generateTsAbis.js",
1111
"deploy:verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/Deploy.s.sol --rpc-url ${1:-default_network} --broadcast --legacy --verify ; node script/generateTsAbis.js",
1212
"verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/VerifyAll.s.sol --ffi --rpc-url ${1:-default_network}",
13-
"lint": "forge fmt",
13+
"lint": "forge fmt --check && prettier --check ./script/**/*.js",
14+
"format": "forge fmt && prettier --write ./script/**/*.js",
1415
"test": "forge test"
1516
},
1617
"devDependencies": {

0 commit comments

Comments
 (0)