Skip to content

Commit

Permalink
Merge branch 'main' into update-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
technophile-04 authored Jan 9, 2025
2 parents 5bed5cb + 4db867d commit 55f09e0
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-panthers-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-eth": patch
---

templatise `foundry.toml` file
5 changes: 5 additions & 0 deletions .changeset/bright-pigs-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-eth": patch
---

validate project name inline with npm name rules
1 change: 1 addition & 0 deletions contributors/TEMPLATE-FILES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ If you're interested in developing third-party extensions, the [THIRD-PARTY-EXTE
| Template | Example args file |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| [(script) `Deploy.s.sol.template.mjs`](https://github.com/scaffold-eth/create-eth/blob/main/templates/solidity-frameworks/foundry/packages/foundry/script/Deploy.s.sol.template.mjs) | [`Deploy.s.sol.args.mjs`](https://github.com/scaffold-eth/create-eth-extensions/blob/example/extension/packages/foundry/script/Deploy.s.sol.args.mjs) |
| [(config) `foundry.toml.template.mjs`](https://github.com/scaffold-eth/create-eth/blob/main/templates/solidity-frameworks/foundry/packages/foundry/foundry.toml.template.mjs) | [`foundry.toml.args.mjs`](https://github.com/scaffold-eth/create-eth-extensions/blob/example/extension/packages/foundry/foundry.toml.args.mjs) |
| [(config) `Makefile.template.mjs`](https://github.com/scaffold-eth/create-eth/blob/main/templates/solidity-frameworks/foundry/packages/foundry/Makefile.template.mjs) | [`Makefile.args.mjs`](https://github.com/scaffold-eth/create-eth-extensions/blob/example/extension/packages/foundry/Makefile.args.mjs) |

#### Hardhat
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@types/inquirer": "9.0.3",
"@types/ncp": "2.0.5",
"@types/node": "18.16.0",
"@types/validate-npm-package-name": "4.0.2",
"eslint": "^9.15.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
Expand All @@ -58,7 +59,8 @@
"inquirer": "9.2.0",
"listr2": "^8.2.1",
"merge-packages": "^0.1.6",
"ncp": "2.0.0"
"ncp": "2.0.0",
"validate-npm-package-name": "6.0.0"
},
"packageManager": "[email protected]"
}
10 changes: 8 additions & 2 deletions src/utils/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import path from "path";

const { mkdir, link } = promises;

const passesFilter = (source: string, options?: Options) =>
options?.filter === undefined
const passesFilter = (source: string, options?: Options) => {
const isDSStore = /\.DS_Store$/.test(source);
if (isDSStore) {
return false; // Exclude .DS_Store files
}

return options?.filter === undefined
? true // no filter
: typeof options.filter === "function"
? options.filter(source) // filter is function
: options.filter.test(source); // filter is regex
};
/**
* The goal is that this function has the same API as ncp, so they can be used
* interchangeably.
Expand Down
17 changes: 15 additions & 2 deletions src/utils/parse-arguments-into-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { validateFoundryUp } from "./system-validation";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { validateNpmName } from "./validate-name";

const validateExternalExtension = async (
extensionName: string,
Expand Down Expand Up @@ -74,7 +75,7 @@ export async function parseArgumentsIntoOptions(
"-h": "--help",
},
{
argv: rawArgs.slice(2).map(a => a.toLowerCase()),
argv: rawArgs.slice(2),
},
);

Expand All @@ -84,7 +85,7 @@ export async function parseArgumentsIntoOptions(

const help = args["--help"] ?? false;

const project = args._[0] ?? null;
let project: string | null = args._[0] ?? null;

// use the original extension arg
const extensionName = args["--extension"] && rawArgs.slice(2).find(a => a.toLowerCase() === args["--extension"]);
Expand All @@ -101,6 +102,18 @@ export async function parseArgumentsIntoOptions(
);
}

if (project) {
const validation = validateNpmName(project);
if (!validation.valid) {
console.error(
`Could not create a project called ${chalk.yellow(`"${project}"`)} because of naming restrictions:`,
);

validation.problems.forEach(p => console.error(`${chalk.red(">>")} Project ${p}`));
project = null;
}
}

let solidityFrameworkChoices = [
SOLIDITY_FRAMEWORKS.HARDHAT,
SOLIDITY_FRAMEWORKS.FOUNDRY,
Expand Down
10 changes: 9 additions & 1 deletion src/utils/prompt-for-missing-options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Options, RawOptions, SolidityFrameworkChoices } from "../types";
import inquirer from "inquirer";
import { SOLIDITY_FRAMEWORKS } from "./consts";
import { validateNpmName } from "./validate-name";
import { basename, resolve } from "path";

// default values for unspecified args
const defaultOptions: RawOptions = {
Expand All @@ -23,7 +25,13 @@ export async function promptForMissingOptions(
name: "project",
message: "Your project name:",
default: defaultOptions.project,
validate: (value: string) => value.length > 0,
validate: (name: string) => {
const validation = validateNpmName(basename(resolve(name)));
if (validation.valid) {
return true;
}
return "Project " + validation.problems[0];
},
},
{
type: "list",
Expand Down
22 changes: 22 additions & 0 deletions src/utils/validate-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import validateProjectName from "validate-npm-package-name";

type ValidateNpmNameResult =
| {
valid: true;
}
| {
valid: false;
problems: string[];
};

export function validateNpmName(name: string): ValidateNpmNameResult {
const nameValidation = validateProjectName(name);
if (nameValidation.validForNewPackages) {
return { valid: true };
}

return {
valid: false,
problems: [...(nameValidation.errors || []), ...(nameValidation.warnings || [])],
};
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

import { withDefaults } from "../../../../utils.js";

const content = ({ recipes, postDeployRecipeToRun }) => `.PHONY: build deploy generate-abis verify-keystore account chain compile flatten fork format lint test verify
const content = ({
recipes,
postDeployRecipeToRun,
}) => `.PHONY: build deploy generate-abis verify-keystore account chain compile flatten fork format lint test verify
DEPLOY_SCRIPT ?= script/Deploy.s.sol
Expand All @@ -27,12 +29,12 @@ deploy:
fi
@if [ "$(RPC_URL)" = "localhost" ]; then \
if [ "$(ETH_KEYSTORE_ACCOUNT)" = "scaffold-eth-default" ]; then \
forge script $(DEPLOY_SCRIPT) --rpc-url localhost --password localhost --broadcast --via-ir --legacy --ffi; \
forge script $(DEPLOY_SCRIPT) --rpc-url localhost --password localhost --broadcast --legacy --ffi; \
else \
forge script $(DEPLOY_SCRIPT) --rpc-url localhost --broadcast --legacy --via-ir --ffi; \
forge script $(DEPLOY_SCRIPT) --rpc-url localhost --broadcast --legacy --ffi; \
fi \
else \
forge script $(DEPLOY_SCRIPT) --rpc-url $(RPC_URL) --broadcast --legacy --via-ir --ffi; \
forge script $(DEPLOY_SCRIPT) --rpc-url $(RPC_URL) --broadcast --legacy --ffi; \
fi
# Deploy and generate ABIs
Expand Down Expand Up @@ -82,8 +84,7 @@ lint:
verify:
forge script script/VerifyAll.s.sol --ffi --rpc-url $(RPC_URL)
${recipes.filter(Boolean).join("\n")}`

${recipes.filter(Boolean).join("\n")}`;

export default withDefaults(content, {
recipes: ``,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { withDefaults } from "../../../../utils.js";

const content = ({
extraProfileDefaults,
extraRpcEndpoints,
extraEthercsanConfig,
extraFormattingConfig,
extraConfig,
}) => `[profile.default]
src = 'contracts'
out = 'out'
libs = ['lib']
fs_permissions = [{ access = "read-write", path = "./"}]
${extraProfileDefaults.filter(Boolean).join("\n")}
[rpc_endpoints]
default_network = "http://127.0.0.1:8545"
localhost = "http://127.0.0.1:8545"
mainnet = "https://eth-mainnet.alchemyapi.io/v2/\${ALCHEMY_API_KEY}"
sepolia = "https://eth-sepolia.g.alchemy.com/v2/\${ALCHEMY_API_KEY}"
arbitrum = "https://arb-mainnet.g.alchemy.com/v2/\${ALCHEMY_API_KEY}"
arbitrumSepolia = "https://arb-sepolia.g.alchemy.com/v2/\${ALCHEMY_API_KEY}"
optimism = "https://opt-mainnet.g.alchemy.com/v2/\${ALCHEMY_API_KEY}"
optimismSepolia = "https://opt-sepolia.g.alchemy.com/v2/\${ALCHEMY_API_KEY}"
polygon = "https://polygon-mainnet.g.alchemy.com/v2/\${ALCHEMY_API_KEY}"
polygonMumbai = "https://polygon-mumbai.g.alchemy.com/v2/\${ALCHEMY_API_KEY}"
polygonZkEvm = "https://zkevm-rpc.com"
polygonZkEvmTestnet = "https://rpc.public.zkevm-test.net"
gnosis = "https://rpc.gnosischain.com"
chiado = "https://rpc.chiadochain.net"
base = "https://mainnet.base.org"
baseSepolia = "https://sepolia.base.org"
scrollSepolia = "https://sepolia-rpc.scroll.io"
scroll = "https://rpc.scroll.io"
pgn = "https://rpc.publicgoods.network"
pgnTestnet = "https://sepolia.publicgoods.network"
${extraRpcEndpoints.filter(Boolean).join("\n")}
[etherscan]
polygonMumbai = { key = "\${ETHERSCAN_API_KEY}" }
sepolia = { key = "\${ETHERSCAN_API_KEY}" }
${extraEthercsanConfig.filter(Boolean).join("\n")}
[fmt]
line_length = 120
tab_width = 4
quote_style = "double"
bracket_spacing = true
int_types = "long"
${extraFormattingConfig.filter(Boolean).join("\n")}
${extraConfig.filter(Boolean).join("\n")}
# See more config options https://book.getfoundry.sh/reference/config/overview`;

export default withDefaults(content, {
extraProfileDefaults: "",
extraRpcEndpoints: "",
extraEthercsanConfig: "",
extraFormattingConfig: "",
extraConfig: "",
});
16 changes: 16 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,13 @@ __metadata:
languageName: node
linkType: hard

"@types/validate-npm-package-name@npm:4.0.2":
version: 4.0.2
resolution: "@types/validate-npm-package-name@npm:4.0.2"
checksum: 3f35a3cc8ddd919b456843f36d55a4f1df5f03d5d9b6494b4d8f5f3b24e3f24a11c922772d9970a67f1249214da18c157776e9c6d2e72227799459849dfd9c76
languageName: node
linkType: hard

"@typescript-eslint/eslint-plugin@npm:8.15.0":
version: 8.15.0
resolution: "@typescript-eslint/eslint-plugin@npm:8.15.0"
Expand Down Expand Up @@ -1389,6 +1396,7 @@ __metadata:
"@types/inquirer": 9.0.3
"@types/ncp": 2.0.5
"@types/node": 18.16.0
"@types/validate-npm-package-name": 4.0.2
arg: 5.0.2
chalk: 5.2.0
eslint: ^9.15.0
Expand All @@ -1406,6 +1414,7 @@ __metadata:
tslib: 2.5.0
typescript: ^5.6.3
typescript-eslint: ^8.15.0
validate-npm-package-name: 6.0.0
bin:
create-eth: bin/create-dapp-se2.js
languageName: unknown
Expand Down Expand Up @@ -5026,6 +5035,13 @@ __metadata:
languageName: node
linkType: hard

"validate-npm-package-name@npm:6.0.0":
version: 6.0.0
resolution: "validate-npm-package-name@npm:6.0.0"
checksum: 4d018c4fa07f95534a5fea667adc653b1ef52f08bf56aff066c28394499d0a6949c0b00edbd7077c4dc1e041da9220af7c742ced67d7d2d6a1b07d10cbe91b29
languageName: node
linkType: hard

"wcwidth@npm:^1.0.1":
version: 1.0.1
resolution: "wcwidth@npm:1.0.1"
Expand Down

0 comments on commit 55f09e0

Please sign in to comment.