Skip to content
Next Next commit
Add constants
  • Loading branch information
nachoiacovino committed Sep 1, 2022
commit 410757e32019c96141c9dd3afd04ff7effa45ab4
7 changes: 7 additions & 0 deletions packages/cli/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const CREATE_MESSAGES = {
typeOfProject: "What type of project do you want to create?",
projectName: "What is your project named?",
framework: "What framework do you want to use?",
language: "What language do you want to use?",
contract: "What contract do you want to start from?",
};
12 changes: 7 additions & 5 deletions packages/cli/e2e/create.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { prepareEnvironment } from "@gmrchk/cli-testing-library";
import { CREATE_MESSAGES } from "../constants/constants";

// this creates an app, can take some time that's fine
jest.setTimeout(120_000);

describe("npx thirdweb create", () => {
it("should create app successfully", async () => {
it("should create app (CRA) successfully", async () => {
const { spawn, cleanup, exists } = await prepareEnvironment();
const {
// wait,
Expand All @@ -17,14 +18,15 @@ describe("npx thirdweb create", () => {
pressKey,
} = await spawn("node", "./dist/cli/index.js create");

await waitForText("What type of project do you want to create?");
await waitForText(CREATE_MESSAGES.typeOfProject);
await pressKey("enter");
await waitForText("What is your project named?");
await waitForText(CREATE_MESSAGES.projectName);
await pressKey("enter");
await waitForText("What framework do you want to use?");
await waitForText(CREATE_MESSAGES.framework);
// Select CRA
await pressKey("arrowDown");
await pressKey("enter");
await waitForText("What language do you want to use?");
await waitForText(CREATE_MESSAGES.language);
await pressKey("enter");

// wait for program to finish
Expand Down
13 changes: 7 additions & 6 deletions packages/cli/src/create/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { validateNpmName } from "./helpers/validate-pkg";
import chalk from "chalk";
import path from "path";
import prompts from "prompts";
import { CREATE_MESSAGES } from "../../constants/constants";

let projectType: string = "";
let projectPath: string = "";
Expand Down Expand Up @@ -65,7 +66,7 @@ export async function twCreate(options: any) {
const res = await prompts({
type: "select",
name: "projectType",
message: "What type of project do you want to create?",
message: CREATE_MESSAGES.typeOfProject,
choices: [
{ title: "App", value: "app" },
{ title: "Contract", value: "contract" },
Expand All @@ -87,7 +88,7 @@ export async function twCreate(options: any) {
const res = await prompts({
type: "text",
name: "path",
message: "What is your project named?",
message: CREATE_MESSAGES.projectName,
initial: options.template || defaultName,
validate: (name) => {
const validation = validateNpmName(path.basename(path.resolve(name)));
Expand Down Expand Up @@ -123,7 +124,7 @@ export async function twCreate(options: any) {
const res = await prompts({
type: "select",
name: "framework",
message: "What framework do you want to use?",
message: CREATE_MESSAGES.framework,
choices: [
{ title: "Next.js", value: "next" },
{ title: "Create React App", value: "cra" },
Expand All @@ -140,7 +141,7 @@ export async function twCreate(options: any) {
const res = await prompts({
type: "select",
name: "language",
message: "What language do you want to use?",
message: CREATE_MESSAGES.language,
choices: [
{ title: "JavaScript", value: "javascript" },
{ title: "TypeScript", value: "typescript" },
Expand All @@ -160,7 +161,7 @@ export async function twCreate(options: any) {
const res = await prompts({
type: "select",
name: "framework",
message: "What framework do you want to use?",
message: CREATE_MESSAGES.framework,
choices: [
{ title: "Hardhat", value: "hardhat" },
{ title: "Forge", value: "forge" },
Expand All @@ -177,7 +178,7 @@ export async function twCreate(options: any) {
const res = await prompts({
type: "select",
name: "baseContract",
message: "What contract do you want to start from?",
message: CREATE_MESSAGES.contract,
choices: [
{ title: "Empty Contract", value: "" },
{ title: "ERC721 Base", value: "ERC721Base" },
Expand Down