-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d72f445
commit e4f680a
Showing
2 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import chalk from "chalk"; | ||
import inquirer from "inquirer"; | ||
|
||
import Logger from "../../../utils/logger.js"; | ||
import { packageManagers } from "../../../utils/packageManager.js"; | ||
import { isPrivateKey } from "../../../utils/validators.js"; | ||
import { askForTemplate, setupTemplate, askForPackageManager, successfulMessage, getUniqueValues } from "../utils.js"; | ||
|
||
import type { GenericTemplate } from "../index.js"; | ||
|
||
type Template = GenericTemplate & { | ||
framework: "Hardhat"; | ||
ethereumFramework: "Ethers v5" | "Ethers v6"; | ||
language: "Solidity" | "Vyper"; | ||
}; | ||
|
||
export const templates: Template[] = [ | ||
{ | ||
name: "Quickstart - Hardhat + Solidity", | ||
value: "qs-hello-zksync", | ||
framework: "Hardhat", | ||
ethereumFramework: "Ethers v6", | ||
language: "Solidity", | ||
path: "templates/hello-zksync", | ||
git: "https://github.com/dutterbutter/zksync-quickstart-guide", | ||
}, | ||
{ | ||
name: "Quickstart - Hardhat + Solidity", | ||
value: "qs-factories", | ||
framework: "Hardhat", | ||
ethereumFramework: "Ethers v6", | ||
language: "Solidity", | ||
path: "templates/factories", | ||
git: "https://github.com/dutterbutter/zksync-quickstart-guide", | ||
}, | ||
{ | ||
name: "Quickstart - Hardhat + Solidity", | ||
value: "qs-testing", | ||
framework: "Hardhat", | ||
ethereumFramework: "Ethers v6", | ||
language: "Solidity", | ||
path: "templates/testing", | ||
git: "https://github.com/dutterbutter/zksync-quickstart-guide", | ||
}, | ||
{ | ||
name: "Quickstart - Hardhat + Solidity", | ||
value: "qs-upgrade", | ||
framework: "Hardhat", | ||
ethereumFramework: "Ethers v6", | ||
language: "Solidity", | ||
path: "templates/upgradability", | ||
git: "https://github.com/dutterbutter/zksync-quickstart-guide", | ||
}, | ||
{ | ||
name: "Quickstart - Hardhat + Solidity", | ||
value: "qs-paymaster", | ||
framework: "Hardhat", | ||
ethereumFramework: "Ethers v6", | ||
language: "Solidity", | ||
path: "templates/paymaster", | ||
git: "https://github.com/dutterbutter/zksync-quickstart-guide", | ||
}, | ||
]; | ||
|
||
export default async (folderLocation: string, folderRelativePath: string, templateKey?: string) => { | ||
let env: Record<string, string> = {}; | ||
let template: Template; | ||
if (!templateKey) { | ||
const { ethereumFramework }: { ethereumFramework: Template["ethereumFramework"] } = await inquirer.prompt([ | ||
{ | ||
message: "Ethereum framework", | ||
name: "ethereumFramework", | ||
type: "list", | ||
choices: getUniqueValues(templates.map((template) => template.ethereumFramework)), | ||
required: true, | ||
}, | ||
]); | ||
template = await askForTemplate(templates.filter((template) => template.ethereumFramework === ethereumFramework)); | ||
} else { | ||
template = templates.find((e) => e.value === templateKey)!; | ||
Logger.info(`Using ${chalk.magentaBright(template.name)} template`); | ||
} | ||
const { privateKey }: { privateKey: string } = await inquirer.prompt([ | ||
{ | ||
message: "Private key of the wallet responsible for deploying contracts", | ||
name: "privateKey", | ||
suffix: chalk.gray(" (optional)"), | ||
type: "input", | ||
validate: (input: string) => { | ||
if (!input) return true; // since it's optional | ||
return isPrivateKey(input); | ||
}, | ||
transformer: (input: string) => { | ||
return input.replace(/./g, "*"); | ||
}, | ||
}, | ||
]); | ||
env = { | ||
...env, | ||
WALLET_PRIVATE_KEY: privateKey, | ||
}; | ||
const packageManager = await askForPackageManager(); | ||
await setupTemplate(template, folderLocation, env, packageManager); | ||
|
||
successfulMessage.start(folderRelativePath); | ||
Logger.info(`${chalk.magentaBright("Directory Overview:")} | ||
- Contracts: /contracts | ||
- Deployment Scripts: /deploy | ||
${chalk.magentaBright("Commands:")} | ||
- Compile your contracts: ${chalk.blueBright(packageManagers[packageManager].run("compile"))} | ||
- Deploy your contract: ${chalk.blueBright(packageManagers[packageManager].run("deploy"))} | ||
- Tip: You can use the ${chalk.blueBright("--network")} option to specify the network to deploy to.`); | ||
successfulMessage.end(folderRelativePath); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters