From 7d5626fbb7e863256f90675722f7bb554240222e Mon Sep 17 00:00:00 2001 From: "Shiv Bhonde | shivbhonde.eth" Date: Fri, 30 Aug 2024 20:40:30 +0900 Subject: [PATCH] cli: templatise tailwind and hardhat config (#106) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Carlos Sánchez --- .changeset/odd-bananas-know.md | 5 ++ ...fig.js => tailwind.config.js.template.mjs} | 49 +++++++++++-------- ...nfig.ts => hardhat.config.ts.template.mjs} | 37 ++++++++------ 3 files changed, 55 insertions(+), 36 deletions(-) create mode 100644 .changeset/odd-bananas-know.md rename templates/base/packages/nextjs/{tailwind.config.js => tailwind.config.js.template.mjs} (87%) rename templates/solidity-frameworks/hardhat/packages/hardhat/{hardhat.config.ts => hardhat.config.ts.template.mjs} (74%) diff --git a/.changeset/odd-bananas-know.md b/.changeset/odd-bananas-know.md new file mode 100644 index 000000000..8e315326e --- /dev/null +++ b/.changeset/odd-bananas-know.md @@ -0,0 +1,5 @@ +--- +"create-eth": patch +--- + +cli: templatise tailwind and hardhat config diff --git a/templates/base/packages/nextjs/tailwind.config.js b/templates/base/packages/nextjs/tailwind.config.js.template.mjs similarity index 87% rename from templates/base/packages/nextjs/tailwind.config.js rename to templates/base/packages/nextjs/tailwind.config.js.template.mjs index 9099dc5f4..411fbeb62 100644 --- a/templates/base/packages/nextjs/tailwind.config.js +++ b/templates/base/packages/nextjs/tailwind.config.js.template.mjs @@ -1,4 +1,6 @@ -/** @type {import('tailwindcss').Config} */ +import { withDefaults } from "../../../utils.js"; + +const contents = ({ lightTheme, darkTheme }) => `/** @type {import('tailwindcss').Config} */ module.exports = { content: ["./app/**/*.{js,ts,jsx,tsx}", "./components/**/*.{js,ts,jsx,tsx}", "./utils/**/*.{js,ts,jsx,tsx}"], plugins: [require("daisyui")], @@ -8,7 +10,27 @@ module.exports = { daisyui: { themes: [ { - light: { + light: ${lightTheme}, + }, + { + dark: ${darkTheme}, + }, + ], + }, + theme: { + extend: { + boxShadow: { + center: "0 0 12px -2px rgb(0 0 0 / 0.05)", + }, + animation: { + "pulse-fast": "pulse 1s cubic-bezier(0.4, 0, 0.6, 1) infinite", + }, + }, + }, +};`; + +export default withDefaults(contents, { + lightTheme: `{ primary: "#93BBFB", "primary-content": "#212638", secondary: "#DAE8FF", @@ -37,10 +59,8 @@ module.exports = { ".link:hover": { opacity: "80%", }, - }, - }, - { - dark: { + }`, + darkTheme: `{ primary: "#212638", "primary-content": "#F9FBFF", secondary: "#323f61", @@ -70,18 +90,5 @@ module.exports = { ".link:hover": { opacity: "80%", }, - }, - }, - ], - }, - theme: { - extend: { - boxShadow: { - center: "0 0 12px -2px rgb(0 0 0 / 0.05)", - }, - animation: { - "pulse-fast": "pulse 1s cubic-bezier(0.4, 0, 0.6, 1) infinite", - }, - }, - }, -}; + }`, +}); diff --git a/templates/solidity-frameworks/hardhat/packages/hardhat/hardhat.config.ts b/templates/solidity-frameworks/hardhat/packages/hardhat/hardhat.config.ts.template.mjs similarity index 74% rename from templates/solidity-frameworks/hardhat/packages/hardhat/hardhat.config.ts rename to templates/solidity-frameworks/hardhat/packages/hardhat/hardhat.config.ts.template.mjs index d165b65b1..06b120391 100644 --- a/templates/solidity-frameworks/hardhat/packages/hardhat/hardhat.config.ts +++ b/templates/solidity-frameworks/hardhat/packages/hardhat/hardhat.config.ts.template.mjs @@ -1,4 +1,6 @@ -import * as dotenv from "dotenv"; +import { withDefaults } from "../../../../utils.js"; + +const contents = ({ imports }) => `import * as dotenv from "dotenv"; dotenv.config(); import { HardhatUserConfig } from "hardhat/config"; import "@nomicfoundation/hardhat-ethers"; @@ -9,6 +11,7 @@ import "solidity-coverage"; import "@nomicfoundation/hardhat-verify"; import "hardhat-deploy"; import "hardhat-deploy-ethers"; +${imports.filter(Boolean).join("\n")} // If not set, it uses ours Alchemy's default API key. // You can get your own at https://dashboard.alchemyapi.io @@ -42,48 +45,48 @@ const config: HardhatUserConfig = { // If the network you are looking for is not here you can add new network settings hardhat: { forking: { - url: `https://eth-mainnet.alchemyapi.io/v2/${providerApiKey}`, + url: \`https://eth-mainnet.alchemyapi.io/v2/\${providerApiKey}\`, enabled: process.env.MAINNET_FORKING_ENABLED === "true", }, }, mainnet: { - url: `https://eth-mainnet.alchemyapi.io/v2/${providerApiKey}`, + url: \`https://eth-mainnet.alchemyapi.io/v2/\${providerApiKey}\`, accounts: [deployerPrivateKey], }, sepolia: { - url: `https://eth-sepolia.g.alchemy.com/v2/${providerApiKey}`, + url: \`https://eth-sepolia.g.alchemy.com/v2/\${providerApiKey}\`, accounts: [deployerPrivateKey], }, arbitrum: { - url: `https://arb-mainnet.g.alchemy.com/v2/${providerApiKey}`, + url: \`https://arb-mainnet.g.alchemy.com/v2/\${providerApiKey}\`, accounts: [deployerPrivateKey], }, arbitrumSepolia: { - url: `https://arb-sepolia.g.alchemy.com/v2/${providerApiKey}`, + url: \`https://arb-sepolia.g.alchemy.com/v2/\${providerApiKey}\`, accounts: [deployerPrivateKey], }, optimism: { - url: `https://opt-mainnet.g.alchemy.com/v2/${providerApiKey}`, + url: \`https://opt-mainnet.g.alchemy.com/v2/\${providerApiKey}\`, accounts: [deployerPrivateKey], }, optimismSepolia: { - url: `https://opt-sepolia.g.alchemy.com/v2/${providerApiKey}`, + url: \`https://opt-sepolia.g.alchemy.com/v2/\${providerApiKey}\`, accounts: [deployerPrivateKey], }, polygon: { - url: `https://polygon-mainnet.g.alchemy.com/v2/${providerApiKey}`, + url: \`https://polygon-mainnet.g.alchemy.com/v2/\${providerApiKey}\`, accounts: [deployerPrivateKey], }, polygonMumbai: { - url: `https://polygon-mumbai.g.alchemy.com/v2/${providerApiKey}`, + url: \`https://polygon-mumbai.g.alchemy.com/v2/\${providerApiKey}\`, accounts: [deployerPrivateKey], }, polygonZkEvm: { - url: `https://polygonzkevm-mainnet.g.alchemy.com/v2/${providerApiKey}`, + url: \`https://polygonzkevm-mainnet.g.alchemy.com/v2/\${providerApiKey}\`, accounts: [deployerPrivateKey], }, polygonZkEvmTestnet: { - url: `https://polygonzkevm-testnet.g.alchemy.com/v2/${providerApiKey}`, + url: \`https://polygonzkevm-testnet.g.alchemy.com/v2/\${providerApiKey}\`, accounts: [deployerPrivateKey], }, gnosis: { @@ -121,12 +124,12 @@ const config: HardhatUserConfig = { }, // configuration for harhdat-verify plugin etherscan: { - apiKey: `${etherscanApiKey}`, + apiKey: \`\${etherscanApiKey}\`, }, // configuration for etherscan-verify from hardhat-deploy plugin verify: { etherscan: { - apiKey: `${etherscanApiKey}`, + apiKey: \`\${etherscanApiKey}\`, }, }, sourcify: { @@ -134,4 +137,8 @@ const config: HardhatUserConfig = { }, }; -export default config; +export default config;`; + +export default withDefaults(contents, { + imports: "", +});