-
Notifications
You must be signed in to change notification settings - Fork 664
Expand file tree
/
Copy pathcreate.ts
More file actions
188 lines (178 loc) · 7.13 KB
/
create.ts
File metadata and controls
188 lines (178 loc) · 7.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import { spawnSync } from "node:child_process";
import ora from "ora";
import prompts from "prompts";
import { checkPrerequisites } from "./check-prerequisites.js";
export async function createStylusProject() {
const spinner = ora();
checkPrerequisites(spinner, "cargo", ["--version"], "Rust (cargo)");
checkPrerequisites(spinner, "rustc", ["--version"], "Rust compiler (rustc)");
// Step 1: Ensure cargo is installed
const cargoCheck = spawnSync("cargo", ["--version"]);
if (cargoCheck.status !== 0) {
console.error("Error: `cargo` is not installed");
process.exit(1);
}
// Step 2: Install stylus etc.
spinner.start("Installing Stylus...");
const install = spawnSync("cargo", ["install", "cargo-stylus"], {
stdio: "inherit",
});
if (install.status !== 0) {
spinner.fail("Failed to install Stylus.");
process.exit(1);
}
spinner.succeed("Stylus installed.");
spawnSync("rustup", ["default", "stable"], {
stdio: "inherit",
});
spawnSync("rustup", ["target", "add", "wasm32-unknown-unknown"], {
stdio: "inherit",
});
// Step 3: Create the project
const { projectName } = await prompts({
initial: "my-stylus-project",
message: "Project name:",
name: "projectName",
type: "text",
});
// Step 4: Select project type
const { projectType } = await prompts({
choices: [
{ title: "Default", value: "default" },
{ title: "ERC20", value: "erc20" },
{ title: "ERC721", value: "erc721" },
{ title: "ERC1155", value: "erc1155" },
{ title: "Airdrop ERC20", value: "airdrop20" },
{ title: "Airdrop ERC721", value: "airdrop721" },
{ title: "Airdrop ERC1155", value: "airdrop1155" },
{ title: "ZK ERC721", value: "zk-erc721" },
{ title: "ZK ERC20", value: "zk-erc20" },
{ title: "Mint module - ERC20", value: "mintable20" },
{ title: "Transfer module - ERC20", value: "transferable20" },
{ title: "Mint module - ERC721", value: "mintable721" },
{ title: "Transfer module - ERC721", value: "transferable721" },
{ title: "Mint module - ERC1155", value: "mintable1155" },
{ title: "Transfer module - ERC1155", value: "transferable1155" },
],
message: "Select a template:",
name: "projectType",
type: "select",
});
// Step 5: Create the project
// biome-ignore lint/suspicious/noImplicitAnyLet: <>
let newProject;
if (projectType === "default") {
spinner.start(`Creating new Stylus project: ${projectName}...`);
newProject = spawnSync("cargo", ["stylus", "new", projectName], {
stdio: "inherit",
});
} else if (projectType === "erc20") {
const repoUrl = "git@github.com:thirdweb-example/stylus-erc20-template.git";
spinner.start(`Creating new ERC20 Stylus project: ${projectName}...`);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
} else if (projectType === "erc721") {
const repoUrl =
"git@github.com:thirdweb-example/stylus-erc721-template.git";
spinner.start(`Creating new ERC721 Stylus project: ${projectName}...`);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
} else if (projectType === "erc1155") {
const repoUrl =
"git@github.com:thirdweb-example/stylus-erc1155-template.git";
spinner.start(`Creating new ERC1155 Stylus project: ${projectName}...`);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
} else if (projectType === "airdrop20") {
const repoUrl =
"git@github.com:thirdweb-example/stylus-airdrop-erc20-template.git";
spinner.start(
`Creating new Airdrop ERC20 Stylus project: ${projectName}...`,
);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
} else if (projectType === "airdrop721") {
const repoUrl =
"git@github.com:thirdweb-example/stylus-airdrop-erc721-template.git";
spinner.start(
`Creating new Airdrop ERC721 Stylus project: ${projectName}...`,
);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
} else if (projectType === "airdrop1155") {
const repoUrl =
"git@github.com:thirdweb-example/stylus-airdrop-erc1155-template.git";
spinner.start(
`Creating new Airdrop ERC1155 Stylus project: ${projectName}...`,
);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
} else if (projectType === "zk-erc721") {
const repoUrl = "git@github.com:thirdweb-example/stylus-zk-erc721.git";
spinner.start(`Creating new ZK ERC721 Stylus project: ${projectName}...`);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
} else if (projectType === "zk-erc20") {
const repoUrl = "git@github.com:thirdweb-example/stylus-zk-erc20.git";
spinner.start(`Creating new ZK ERC20 Stylus project: ${projectName}...`);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
} else if (projectType === "mintable20") {
const repoUrl = "git@github.com:thirdweb-example/stylus-mintable-erc20.git";
spinner.start(`Creating new ERC20 Mintable module: ${projectName}...`);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
} else if (projectType === "transferable20") {
const repoUrl =
"git@github.com:thirdweb-example/stylus-transferable-erc20.git";
spinner.start(`Creating new ERC20 Transferable module: ${projectName}...`);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
} else if (projectType === "mintable721") {
const repoUrl =
"git@github.com:thirdweb-example/stylus-mintable-erc721.git";
spinner.start(`Creating new ERC721 Mintable module: ${projectName}...`);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
} else if (projectType === "transferable721") {
const repoUrl =
"git@github.com:thirdweb-example/stylus-transferable-erc721.git";
spinner.start(`Creating new ERC721 Transferable module: ${projectName}...`);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
} else if (projectType === "mintable1155") {
const repoUrl =
"git@github.com:thirdweb-example/stylus-mintable-erc1155.git";
spinner.start(`Creating new ERC1155 Mintable module: ${projectName}...`);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
} else if (projectType === "transferable1155") {
const repoUrl =
"git@github.com:thirdweb-example/stylus-transferable-erc1155.git";
spinner.start(
`Creating new ERC1155 Transferable module: ${projectName}...`,
);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
}
if (!newProject || newProject.status !== 0) {
spinner.fail("Failed to create Stylus project.");
process.exit(1);
}
spinner.succeed("Project created successfully.");
console.log(`\n✅ cd into your project: ${projectName}`);
}