Skip to content

Commit

Permalink
Merge branch 'main' into forkingURL
Browse files Browse the repository at this point in the history
  • Loading branch information
technophile-04 authored Oct 24, 2024
2 parents 165915d + 5ad5d8e commit b1e3bac
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 51 deletions.
5 changes: 0 additions & 5 deletions .changeset/famous-dodos-exercise.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/purple-bulldogs-add.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/purple-kangaroos-rush.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/slow-stingrays-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-eth": patch
---

templates: optional YourContract.sol in extensions
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"create-eth": patch
---

fix foundry generate script
added nextjs config template
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# create-eth

## 0.0.58

### Patch Changes

- e9a969d: Template for externalContracts.ts
- 9151c92: template: allow passing metadata & header logoText and description
- ba4e12e: added recommended templating rules
- 2270abb: fix foundry generate script

## 0.0.57

### Patch Changes
Expand Down
2 changes: 2 additions & 0 deletions contributors/TEMPLATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ import { stringify } from "../path/to/templates/utils.js";
| Array, add new items | `const arrWithAdditionalItems = ${stringify(['a', 'b', ...arrayToSpread[0]])}` | `const arrayToSpread = ["Spread", "This"]` | `const arrWithAdditionalItems = ["a", "b", "Spread", "This"]` |
| BigInt | `const bigInt = ${stringify(someBigInt[0])};` | `const someBigInt = 123n` | `const bigInt = 123n;` |

> NOTE: If the object contains function as a value `stringify` utility truncates it to `[Function keyName]`. In this case we have to use object spread operator while merging the objects and `JSON.stringify` while replacing the objects. Checkout [`next.config.template.mjs`](https://github.com/scaffold-eth/create-eth/blob/main/templates/base/packages/nextjs/next.config.template.mjs) for an example.
## Merging package.json files

The package we use to merge `package.json` files [merge-packages](https://www.npmjs.com/package/merge-packages) will attempt to find intersections of dependencies. If there is a conflict, the version from the last `package.json` will be taken.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-eth",
"version": "0.0.57",
"version": "0.0.58",
"description": "Create a Scaffold-ETH-2 app",
"repository": {
"type": "git",
Expand Down
45 changes: 42 additions & 3 deletions src/tasks/copy-template-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import path from "path";
import { promisify } from "util";
import link from "../utils/link";
import { getArgumentFromExternalExtensionOption } from "../utils/external-extensions";
import { BASE_DIR, SOLIDITY_FRAMEWORKS, SOLIDITY_FRAMEWORKS_DIR } from "../utils/consts";
import { BASE_DIR, SOLIDITY_FRAMEWORKS, SOLIDITY_FRAMEWORKS_DIR, EXAMPLE_CONTRACTS_DIR } from "../utils/consts";

const EXTERNAL_EXTENSION_TMP_DIR = "tmp-external-extension";

Expand Down Expand Up @@ -129,6 +129,7 @@ const processTemplatedFiles = async (
{ solidityFramework, externalExtension, dev: isDev }: Options,
basePath: string,
solidityFrameworkPath: string | null,
exampleContractsPath: string | null,
targetDir: string,
) => {
const baseTemplatedFileDescriptors: TemplateDescriptor[] = findFilesRecursiveSync(basePath, path =>
Expand All @@ -151,6 +152,17 @@ const processTemplatedFiles = async (
.flat()
: [];

const starterContractsTemplateFileDescriptors: TemplateDescriptor[] = exampleContractsPath
? findFilesRecursiveSync(exampleContractsPath, filePath => isTemplateRegex.test(filePath))
.map(exampleContractTemplatePath => ({
path: exampleContractTemplatePath,
fileUrl: pathToFileURL(exampleContractTemplatePath).href,
relativePath: exampleContractTemplatePath.split(exampleContractsPath)[1],
source: `example-contracts ${solidityFramework}`,
}))
.flat()
: [];

const externalExtensionFolder = isDev
? typeof externalExtension === "string"
? path.join(basePath, "../../externalExtensions", externalExtension, "extension")
Expand All @@ -174,6 +186,7 @@ const processTemplatedFiles = async (
...baseTemplatedFileDescriptors,
...solidityFrameworkTemplatedFileDescriptors,
...externalExtensionTemplatedFileDescriptors,
...starterContractsTemplateFileDescriptors,
].map(async templateFileDescriptor => {
const templateTargetName = templateFileDescriptor.path.match(isTemplateRegex)?.[1] as string;

Expand All @@ -189,6 +202,14 @@ const processTemplatedFiles = async (
}
}

if (exampleContractsPath) {
const argsFilePath = path.join(exampleContractsPath, argsPath);
const fileExists = fs.existsSync(argsFilePath);
if (fileExists) {
argsFileUrls.push(pathToFileURL(argsFilePath).href);
}
}

if (externalExtension) {
const argsFilePath = isDev
? path.join(basePath, "../../externalExtensions", externalExtension as string, "extension", argsPath)
Expand Down Expand Up @@ -302,11 +323,13 @@ export async function copyTemplateFiles(options: Options, templateDir: string, t
// 2. Copy solidity framework folder
const solidityFrameworkPath =
options.solidityFramework && getSolidityFrameworkPath(options.solidityFramework, templateDir);

if (solidityFrameworkPath) {
await copyExtensionFiles(options, solidityFrameworkPath, targetDir);
}

const exampleContractsPath =
options.solidityFramework && path.resolve(templateDir, EXAMPLE_CONTRACTS_DIR, options.solidityFramework);

// 3. Set up external extension if needed
if (options.externalExtension) {
let externalExtensionPath = path.join(tmpDir, "extension");
Expand All @@ -321,11 +344,27 @@ export async function copyTemplateFiles(options: Options, templateDir: string, t
await setUpExternalExtensionFiles(options, tmpDir);
}

if (options.solidityFramework) {
const externalExtensionSolidityPath = path.join(
externalExtensionPath,
"packages",
options.solidityFramework,
"contracts",
);
// if external extension does not have solidity framework, we copy the example contracts
if (!fs.existsSync(externalExtensionSolidityPath) && exampleContractsPath) {
await copyExtensionFiles(options, exampleContractsPath, targetDir);
}
}

await copyExtensionFiles(options, externalExtensionPath, targetDir);
}

if (!options.externalExtension && options.solidityFramework && exampleContractsPath) {
await copyExtensionFiles(options, exampleContractsPath, targetDir);
}
// 4. Process templated files and generate output
await processTemplatedFiles(options, basePath, solidityFrameworkPath, targetDir);
await processTemplatedFiles(options, basePath, solidityFrameworkPath, exampleContractsPath, targetDir);

// 5. Delete tmp directory
if (options.externalExtension && !options.dev) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/consts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const BASE_DIR = "base";
export const SOLIDITY_FRAMEWORKS_DIR = "solidity-frameworks";
export const EXAMPLE_CONTRACTS_DIR = "example-contracts";

export const SOLIDITY_FRAMEWORKS = {
HARDHAT: "hardhat",
Expand Down
3 changes: 2 additions & 1 deletion src/utils/prompt-for-missing-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ export async function promptForMissingOptions(

const answers = await inquirer.prompt(questions, cliAnswers);

const solidityFramework = options.solidityFramework ?? answers.solidityFramework;
const mergedOptions: Options = {
project: options.project ?? answers.project,
install: options.install,
dev: options.dev ?? defaultOptions.dev,
solidityFramework: options.solidityFramework ?? answers.solidityFramework,
solidityFramework: solidityFramework === "none" ? null : solidityFramework,
externalExtension: options.externalExtension,
};

Expand Down
3 changes: 1 addition & 2 deletions src/utils/show-help-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import chalk from "chalk";

export const showHelpMessage = () => {
console.log(` ${chalk.bold.blue("Usage:")}
${chalk.bold.green("npx create-eth<@version>")} ${chalk.gray("[-i | --install | --skip | --skip-install] [-s <solidity-framework> | --solidity-framework <solidity-framework>] [-e <extension> | --extension <extension>] [-h | --help]")}
${chalk.bold.green("npx create-eth<@version>")} ${chalk.gray("[--skip | --skip-install] [-s <solidity-framework> | --solidity-framework <solidity-framework>] [-e <extension> | --extension <extension>] [-h | --help]")}
`);
console.log(` ${chalk.bold.blue("Options:")}
${chalk.gray("-i, --install")} Install packages
${chalk.gray("--skip, --skip-install")} Skip packages installation
${chalk.gray("-s, --solidity-framework")} Choose solidity framework
${chalk.gray("-e, --extension")} Add curated or third-party extension
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { withDefaults } from "../../../../utils.js";
const contents = ({ menuIconImports, menuObjects, logoText, logoDescription }) => {
const contents = ({ menuIconImports, menuObjects, logoTitle, logoSubtitle }) => {
const stringifiedAdditionalMenuLinks = menuObjects.filter(Boolean).join(",\n");

return `"use client";
Expand Down Expand Up @@ -99,8 +99,8 @@ export const Header = () => {
<Image alt="SE2 logo" className="cursor-pointer" fill src="/logo.svg" />
</div>
<div className="flex flex-col">
<span className="font-bold leading-tight">${logoText}</span>
<span className="text-xs">${logoDescription}</span>
<span className="font-bold leading-tight">${logoTitle}</span>
<span className="text-xs">${logoSubtitle}</span>
</div>
</Link>
<ul className="hidden lg:flex lg:flex-nowrap menu menu-horizontal px-1 gap-2">
Expand All @@ -119,6 +119,6 @@ export const Header = () => {
export default withDefaults(contents, {
menuIconImports: "",
menuObjects: "",
logoText: "Scaffold-ETH",
logoDescription: "Ethereum dev stack"
logoTitle: "Scaffold-ETH",
logoSubtitle: "Ethereum dev stack"
});
19 changes: 0 additions & 19 deletions templates/base/packages/nextjs/next.config.js

This file was deleted.

29 changes: 29 additions & 0 deletions templates/base/packages/nextjs/next.config.js.template.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { stringify, withDefaults } from '../../../utils.js'

const contents = ({ ignoreTsAndLintBuildErrors, extraConfig }) =>
`// @ts-check
/** @type {import('next').NextConfig} */
const nextConfig = {
${extraConfig[0] ? `...${stringify(extraConfig[0])},` : ''}
reactStrictMode: true,
typescript: {
ignoreBuildErrors: ${ignoreTsAndLintBuildErrors},
},
eslint: {
ignoreDuringBuilds: ${ignoreTsAndLintBuildErrors},
},
webpack: config => {
config.resolve.fallback = { fs: false, net: false, tls: false };
config.externals.push("pino-pretty", "lokijs", "encoding");
return config;
},
};
module.exports = nextConfig;
`

export default withDefaults(contents, {
ignoreTsAndLintBuildErrors: 'process.env.NEXT_PUBLIC_IGNORE_BUILD_ERROR === "true"',
extraConfig: null
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const deploymentsScriptsImports = `import { DeployYourContract } from "./DeployYourContract.s.sol";`;
export const deploymentsLogic = `
DeployYourContract deployYourContract = new DeployYourContract();
deployYourContract.run();
`;
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ const content = ({ deploymentsScriptsImports, deploymentsLogic }) => `//SPDX-Lic
pragma solidity ^0.8.19;
import "./DeployHelpers.s.sol";
import { DeployYourContract } from "./DeployYourContract.s.sol";
${deploymentsScriptsImports.filter(Boolean).join("\n")}
contract DeployScript is ScaffoldETHDeploy {
function run() external {
DeployYourContract deployYourContract = new DeployYourContract();
deployYourContract.run();
${deploymentsLogic.filter(Boolean).join("\n")}
// deploy more contracts here
Expand Down

0 comments on commit b1e3bac

Please sign in to comment.