Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add quickstart template options #132

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions src/commands/create/groups/quickstart.ts
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/quickstart/hello-zksync",
git: "https://github.com/matter-labs/zksync-contract-templates/",
},
{
name: "Quickstart - Hardhat + Solidity",
value: "qs-factories",
framework: "Hardhat",
ethereumFramework: "Ethers v6",
language: "Solidity",
path: "templates/quickstart/factories",
git: "https://github.com/matter-labs/zksync-contract-templates/",
},
{
name: "Quickstart - Hardhat + Solidity",
value: "qs-testing",
framework: "Hardhat",
ethereumFramework: "Ethers v6",
language: "Solidity",
path: "templates/quickstart/testing",
git: "https://github.com/matter-labs/zksync-contract-templates/",
},
{
name: "Quickstart - Hardhat + Solidity",
value: "qs-upgrade",
framework: "Hardhat",
ethereumFramework: "Ethers v6",
language: "Solidity",
path: "templates/quickstart/upgradability",
git: "https://github.com/matter-labs/zksync-contract-templates/",
},
{
name: "Quickstart - Hardhat + Solidity",
value: "qs-paymaster",
framework: "Hardhat",
ethereumFramework: "Ethers v6",
language: "Solidity",
path: "templates/quickstart/paymaster",
git: "https://github.com/matter-labs/zksync-contract-templates/",
},
];

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);
};
10 changes: 8 additions & 2 deletions src/commands/create/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from "path";

import useContractTemplates, { templates as contractTemplates } from "./groups/contracts.js";
import useFrontendTemplates, { templates as frontendTemplates } from "./groups/frontend.js";
import useQuickstartTemplates, { templates as quickstartTemplates } from "./groups/quickstart.js";
import useScriptingTemplates, { templates as scriptingTemplates } from "./groups/scripting.js";
import { zeekOption } from "../../common/options.js";
import Program from "../../program.js";
Expand All @@ -20,10 +21,12 @@ export type GenericTemplate = {
git: string;
path?: string;
};
type ProjectType = "frontend" | "contracts" | "scripting";
type ProjectType = "frontend" | "contracts" | "scripting" | "quickstart";

const templateOption = new Option("--template <name>", "Project template to use").choices(
[...contractTemplates, ...frontendTemplates, ...scriptingTemplates].map((template) => template.value)
[...contractTemplates, ...frontendTemplates, ...scriptingTemplates, ...quickstartTemplates].map(
(template) => template.value
)
);
const projectTypeOption = new Option("--project <name>", "Project type to select templates from").choices([
"contracts",
Expand Down Expand Up @@ -75,6 +78,7 @@ export const handler = async (predefinedFolderName: string | undefined, options:
} = {
contracts: useContractTemplates,
frontend: useFrontendTemplates,
quickstart: useQuickstartTemplates,
scripting: useScriptingTemplates,
};

Expand Down Expand Up @@ -115,6 +119,8 @@ export const handler = async (predefinedFolderName: string | undefined, options:
projectType = "frontend";
} else if (scriptingTemplates.some((template) => template.value === options.template)) {
projectType = "scripting";
} else if (quickstartTemplates.some((template) => template.value === options.template)) {
projectType = "quickstart";
}
if (!projectType) throw new Error(`Could not find project type for template ${options.template}`);

Expand Down
Loading