create-for-yeyu 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ye Yu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # create-for-yeyu
2
+
3
+ 一个用于快速创建项目的脚手架工具。
4
+
5
+ ## 功能特性
6
+
7
+ - 快速克隆 Git 仓库模板
8
+ - 支持 Vite 官方模板
9
+ - 支持 Create Next App
10
+ - 交互式命令行界面
11
+ - Cowsay 风格的欢迎界面,显示用户名和当前日期
12
+ - Clone 时显示 ASCII 火车动画
13
+
14
+ ## 安装
15
+
16
+ ```bash
17
+ npm install -g create-for-yeyu
18
+ ```
19
+
20
+ 或者直接使用 npx:
21
+
22
+ ```bash
23
+ npx create-for-yeyu
24
+ ```
25
+
26
+ ## 使用方法
27
+
28
+ ### 交互式创建
29
+
30
+ ```bash
31
+ npx create-for-yeyu
32
+ ```
33
+
34
+ ### 指定项目名称
35
+
36
+ ```bash
37
+ npx create-for-yeyu my-project
38
+ ```
39
+
40
+ ### 指定模板
41
+
42
+ ```bash
43
+ # 使用 NestJS 模板
44
+ npx create-for-yeyu my-project --template nest
45
+
46
+ # 使用 EVM DApp 模板
47
+ npx create-for-yeyu my-project --template evm-dapp
48
+
49
+ # 使用 Vite 创建项目
50
+ npx create-for-yeyu my-project --template vite
51
+
52
+ # 使用 Create Next App 创建项目
53
+ npx create-for-yeyu my-project --template next
54
+ ```
55
+
56
+ ## 可用模板
57
+
58
+ | 模板名称 | 命令参数 | 说明 |
59
+ | ---------------- | ---------- | -------------------- |
60
+ | NestJS Starter | `nest` | NestJS 应用启动模板 |
61
+ | EVM DApp Starter | `evm-dapp` | EVM DApp 启动模板 |
62
+ | Vite | `vite` | 使用 Vite 官方模板 |
63
+ | Next.js | `next` | 使用 Create Next App |
64
+
65
+ ## 界面预览
66
+
67
+ 启动时会显示 Cowsay 风格的欢迎界面:
68
+
69
+ ```
70
+ ______________________________
71
+ / Hello, username! \
72
+ \ Today is 2024-12-23 Monday /
73
+ ------------------------------
74
+ \ ^__^
75
+ \ (oo)\_______
76
+ (__)\ )\/ \
77
+ ||----w |
78
+ || ||
79
+ ```
80
+
81
+ Clone 模板时会显示 ASCII 火车动画,灵感来自经典的 sl 命令。
82
+
83
+ ## 开发
84
+
85
+ ```bash
86
+ # 安装依赖
87
+ pnpm install
88
+
89
+ # 开发模式
90
+ pnpm dev
91
+
92
+ # 构建
93
+ pnpm build
94
+
95
+ # 本地测试运行
96
+ pnpm start
97
+ ```
98
+
99
+ ## 项目结构
100
+
101
+ ```
102
+ create-for-yeyu/
103
+ ├── src/
104
+ │ ├── index.ts # CLI 入口
105
+ │ ├── cli.ts # 命令行解析
106
+ │ ├── prompts.ts # 交互式问答
107
+ │ ├── templates.ts # 模板配置
108
+ │ ├── actions/
109
+ │ │ ├── clone-repo.ts # Clone Git 仓库
110
+ │ │ ├── create-vite.ts # 调用 Vite
111
+ │ │ └── create-next.ts # 调用 Create Next App
112
+ │ └── utils/
113
+ │ ├── logger.ts # 日志工具
114
+ │ ├── spinner.ts # 加载动画
115
+ │ ├── cowsay.ts # Cowsay 工具
116
+ │ └── train-animation.ts # 火车动画
117
+ ├── package.json
118
+ ├── tsconfig.json
119
+ └── README.md
120
+ ```
121
+
122
+ ## 添加新模板
123
+
124
+ 在 `src/templates.ts` 文件中添加新的模板配置:
125
+
126
+ ```typescript
127
+ {
128
+ name: '模板名称',
129
+ value: 'template-value',
130
+ description: '模板描述',
131
+ type: 'git',
132
+ repo: 'username/repo-name',
133
+ }
134
+ ```
135
+
136
+ ## 技术栈
137
+
138
+ - Node.js >= 18
139
+ - TypeScript
140
+ - Commander - 命令行参数解析
141
+ - Inquirer - 交互式命令行界面
142
+ - Chalk - 终端颜色输出
143
+ - Degit - 快速 clone Git 仓库
144
+
145
+ ## License
146
+
147
+ MIT
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/index.js ADDED
@@ -0,0 +1,418 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli.ts
4
+ import { Command } from "commander";
5
+ import chalk2 from "chalk";
6
+ import fs from "fs-extra";
7
+ import path2 from "path";
8
+
9
+ // src/prompts.ts
10
+ import inquirer from "inquirer";
11
+
12
+ // src/templates.ts
13
+ var templates = [
14
+ {
15
+ name: "NestJS Starter",
16
+ value: "nest",
17
+ description: "NestJS application starter template",
18
+ type: "git",
19
+ repo: "NeilYeTAT/nest-app-starter-for-yeyu"
20
+ },
21
+ {
22
+ name: "EVM DApp Starter",
23
+ value: "evm-dapp",
24
+ description: "EVM DApp starter template",
25
+ type: "git",
26
+ repo: "NeilYeTAT/evm-dapp-starter-for-yeyu"
27
+ },
28
+ {
29
+ name: "Vite",
30
+ value: "vite",
31
+ description: "Create project with Vite official template",
32
+ type: "vite"
33
+ },
34
+ {
35
+ name: "Next.js",
36
+ value: "next",
37
+ description: "Create project with Create Next App",
38
+ type: "next"
39
+ }
40
+ ];
41
+ function getTemplateByValue(value) {
42
+ return templates.find((t) => t.value === value);
43
+ }
44
+
45
+ // src/prompts.ts
46
+ async function promptProjectName() {
47
+ const { projectName } = await inquirer.prompt([
48
+ {
49
+ type: "input",
50
+ name: "projectName",
51
+ message: "Enter project name:",
52
+ default: "my-project",
53
+ validate: (input) => {
54
+ if (!input.trim()) {
55
+ return "Project name cannot be empty";
56
+ }
57
+ if (!/^[a-zA-Z0-9-_]+$/.test(input)) {
58
+ return "Project name can only contain letters, numbers, hyphens and underscores";
59
+ }
60
+ return true;
61
+ }
62
+ }
63
+ ]);
64
+ return projectName;
65
+ }
66
+ async function promptTemplate() {
67
+ const gitTemplates = templates.filter((t) => t.type === "git");
68
+ const officialTemplates = templates.filter((t) => t.type !== "git");
69
+ const choices = [
70
+ ...gitTemplates.map((t) => ({
71
+ name: `${t.name.padEnd(20)} - ${t.description}`,
72
+ value: t.value
73
+ })),
74
+ new inquirer.Separator("\u2500".repeat(50)),
75
+ ...officialTemplates.map((t) => ({
76
+ name: `${t.name.padEnd(20)} - ${t.description}`,
77
+ value: t.value
78
+ }))
79
+ ];
80
+ const { templateValue } = await inquirer.prompt([
81
+ {
82
+ type: "list",
83
+ name: "templateValue",
84
+ message: "Select a project template:",
85
+ choices
86
+ }
87
+ ]);
88
+ const selectedTemplate = templates.find((t) => t.value === templateValue);
89
+ if (!selectedTemplate) {
90
+ throw new Error(`Template not found: ${templateValue}`);
91
+ }
92
+ return selectedTemplate;
93
+ }
94
+
95
+ // src/actions/clone-repo.ts
96
+ import degit from "degit";
97
+ import path from "path";
98
+
99
+ // src/utils/train-animation.ts
100
+ import readline from "readline";
101
+ var TRAIN_FRAMES = [
102
+ [
103
+ " ==== ________ ___________",
104
+ " _D _| |_______/ \\__I_I_____===__|_________|",
105
+ " |(_)--- | H\\________/ | | =|___ ___|",
106
+ " / | | H | | | | ||_| |_||",
107
+ " | | | H |__--------------------| [___] |",
108
+ " | ________|___H__/__|_____/[][]~\\_______| |",
109
+ " |/ | |-----------I_____I [][] [] D |=======|__",
110
+ "__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__",
111
+ " \\_/ \\__/ \\__/ \\__/ \\__/ \\_/"
112
+ ],
113
+ [
114
+ " ==== ________ ___________",
115
+ " _D _| |_______/ \\__I_I_____===__|_________|",
116
+ " |(_)--- | H\\________/ | | =|___ ___|",
117
+ " / | | H | | | | ||_| |_||",
118
+ " | | | H |__--------------------| [___] |",
119
+ " | ________|___H__/__|_____/[][]~\\_______| |",
120
+ " |/ | |-----------I_____I [][] [] D |=======|__",
121
+ "__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__",
122
+ " \\_/ \\O/ \\O/ \\O/ \\O/ \\_/"
123
+ ]
124
+ ];
125
+ var SMOKE_FRAMES = [
126
+ [
127
+ " ( ) (@@) ( ) (@) () @@ O @ O @ O"
128
+ ],
129
+ [" (@@@) ( ) (@@@) () @ () @ ()"],
130
+ [
131
+ " ( ) (@@@@) ( ) @@ () @ () @ @"
132
+ ],
133
+ [" (@@) (@@@) O () @ () @"]
134
+ ];
135
+ function createTrainAnimation(initialMessage) {
136
+ let isRunning = false;
137
+ let frameIndex = 0;
138
+ let smokeIndex = 0;
139
+ let position = 0;
140
+ let message = initialMessage;
141
+ let intervalId = null;
142
+ const terminalWidth = process.stdout.columns || 80;
143
+ const trainWidth = 55;
144
+ const startPosition = terminalWidth;
145
+ function clearLines(count) {
146
+ for (let i = 0; i < count; i++) {
147
+ readline.moveCursor(process.stdout, 0, -1);
148
+ readline.clearLine(process.stdout, 0);
149
+ }
150
+ }
151
+ function render() {
152
+ const train = TRAIN_FRAMES[frameIndex % TRAIN_FRAMES.length];
153
+ const smoke = SMOKE_FRAMES[smokeIndex % SMOKE_FRAMES.length];
154
+ const offset = startPosition - position;
155
+ const displayLines = [];
156
+ for (const line of smoke) {
157
+ const paddedLine = offset > 0 ? " ".repeat(Math.max(0, offset)) + line : line.slice(-offset);
158
+ displayLines.push(paddedLine.slice(0, terminalWidth));
159
+ }
160
+ for (const line of train) {
161
+ const paddedLine = offset > 0 ? " ".repeat(Math.max(0, offset)) + line : line.slice(-offset);
162
+ displayLines.push(paddedLine.slice(0, terminalWidth));
163
+ }
164
+ displayLines.push("");
165
+ displayLines.push(` \u{1F682} ${message}`);
166
+ if (position > 0) {
167
+ clearLines(displayLines.length);
168
+ }
169
+ for (const line of displayLines) {
170
+ console.log(line);
171
+ }
172
+ frameIndex = (frameIndex + 1) % TRAIN_FRAMES.length;
173
+ smokeIndex = (smokeIndex + 1) % SMOKE_FRAMES.length;
174
+ position += 3;
175
+ if (position > startPosition + trainWidth + 10) {
176
+ position = 0;
177
+ }
178
+ }
179
+ return {
180
+ start() {
181
+ if (isRunning) return;
182
+ isRunning = true;
183
+ process.stdout.write("\x1B[?25l");
184
+ const totalLines = SMOKE_FRAMES[0].length + TRAIN_FRAMES[0].length + 2;
185
+ for (let i = 0; i < totalLines; i++) {
186
+ console.log("");
187
+ }
188
+ clearLines(totalLines);
189
+ intervalId = setInterval(render, 100);
190
+ },
191
+ stop(success, finalMessage) {
192
+ if (!isRunning) return;
193
+ isRunning = false;
194
+ if (intervalId) {
195
+ clearInterval(intervalId);
196
+ intervalId = null;
197
+ }
198
+ const totalLines = SMOKE_FRAMES[0].length + TRAIN_FRAMES[0].length + 2;
199
+ clearLines(totalLines);
200
+ process.stdout.write("\x1B[?25h");
201
+ const icon = success ? "\u2714" : "\u2716";
202
+ const color = success ? "\x1B[32m" : "\x1B[31m";
203
+ console.log(`${color}${icon}\x1B[0m ${finalMessage}`);
204
+ },
205
+ updateMessage(newMessage) {
206
+ message = newMessage;
207
+ }
208
+ };
209
+ }
210
+
211
+ // src/utils/logger.ts
212
+ import chalk from "chalk";
213
+ var logger = {
214
+ info: (message) => {
215
+ console.log(chalk.blue("\u2139"), message);
216
+ },
217
+ success: (message) => {
218
+ console.log(chalk.green("\u2714"), message);
219
+ },
220
+ warning: (message) => {
221
+ console.log(chalk.yellow("\u26A0"), message);
222
+ },
223
+ error: (message) => {
224
+ console.log(chalk.red("\u2716"), message);
225
+ },
226
+ log: (message) => {
227
+ console.log(message);
228
+ }
229
+ };
230
+
231
+ // src/actions/clone-repo.ts
232
+ async function cloneRepo(repo, projectName) {
233
+ const targetPath = path.resolve(process.cwd(), projectName);
234
+ const train = createTrainAnimation(`Cloning template ${repo}...`);
235
+ train.start();
236
+ try {
237
+ const emitter = degit(repo, {
238
+ cache: false,
239
+ force: true,
240
+ verbose: false
241
+ });
242
+ await emitter.clone(targetPath);
243
+ train.stop(true, "Template cloned successfully!");
244
+ } catch (error) {
245
+ train.stop(false, "Failed to clone template");
246
+ if (error instanceof Error) {
247
+ logger.error(error.message);
248
+ }
249
+ throw error;
250
+ }
251
+ }
252
+
253
+ // src/actions/create-vite.ts
254
+ import { execa } from "execa";
255
+ async function createViteProject(projectName) {
256
+ logger.info("Creating project with Vite...");
257
+ logger.log("");
258
+ try {
259
+ await execa("npm", ["create", "vite@latest", projectName], {
260
+ stdio: "inherit",
261
+ cwd: process.cwd()
262
+ });
263
+ } catch (error) {
264
+ if (error instanceof Error) {
265
+ logger.error(`Failed to create Vite project: ${error.message}`);
266
+ }
267
+ throw error;
268
+ }
269
+ }
270
+
271
+ // src/actions/create-next.ts
272
+ import { execa as execa2 } from "execa";
273
+ async function createNextProject(projectName) {
274
+ logger.info("Creating project with Create Next App...");
275
+ logger.log("");
276
+ try {
277
+ await execa2("npx", ["create-next-app@latest", projectName], {
278
+ stdio: "inherit",
279
+ cwd: process.cwd()
280
+ });
281
+ } catch (error) {
282
+ if (error instanceof Error) {
283
+ logger.error(`Failed to create Next.js project: ${error.message}`);
284
+ }
285
+ throw error;
286
+ }
287
+ }
288
+
289
+ // src/utils/cowsay.ts
290
+ import os from "os";
291
+ function cowsay(text) {
292
+ const lines = text.split("\n");
293
+ const maxLength = Math.max(...lines.map((line) => line.length));
294
+ const paddedLines = lines.map((line) => line.padEnd(maxLength));
295
+ const top = " " + "_".repeat(maxLength + 2);
296
+ const bottom = " " + "-".repeat(maxLength + 2);
297
+ let bubble;
298
+ if (paddedLines.length === 1) {
299
+ bubble = [top, `< ${paddedLines[0]} >`, bottom];
300
+ } else {
301
+ bubble = [top];
302
+ paddedLines.forEach((line, index) => {
303
+ if (index === 0) {
304
+ bubble.push(`/ ${line} \\`);
305
+ } else if (index === paddedLines.length - 1) {
306
+ bubble.push(`\\ ${line} /`);
307
+ } else {
308
+ bubble.push(`| ${line} |`);
309
+ }
310
+ });
311
+ bubble.push(bottom);
312
+ }
313
+ const cow = [
314
+ " \\ ^__^",
315
+ " \\ (oo)\\_______",
316
+ " (__)\\ )\\/\\",
317
+ " ||----w |",
318
+ " || ||"
319
+ ];
320
+ return [...bubble, ...cow].join("\n");
321
+ }
322
+ function getFormattedDate() {
323
+ const now = /* @__PURE__ */ new Date();
324
+ const year = now.getFullYear();
325
+ const month = String(now.getMonth() + 1).padStart(2, "0");
326
+ const day = String(now.getDate()).padStart(2, "0");
327
+ const weekdays = [
328
+ "Sunday",
329
+ "Monday",
330
+ "Tuesday",
331
+ "Wednesday",
332
+ "Thursday",
333
+ "Friday",
334
+ "Saturday"
335
+ ];
336
+ const weekday = weekdays[now.getDay()];
337
+ return `${year}-${month}-${day} ${weekday}`;
338
+ }
339
+ function getGreetingMessage() {
340
+ const username = os.userInfo().username;
341
+ const date = getFormattedDate();
342
+ return `Hello, ${username}!
343
+ Today is ${date}`;
344
+ }
345
+
346
+ // src/cli.ts
347
+ var VERSION = "1.0.0";
348
+ async function executeTemplate(template, projectName) {
349
+ const targetPath = path2.resolve(process.cwd(), projectName);
350
+ if (template.type === "git") {
351
+ if (fs.existsSync(targetPath)) {
352
+ logger.error(`Directory ${projectName} already exists`);
353
+ process.exit(1);
354
+ }
355
+ if (!template.repo) {
356
+ logger.error("Template repository not configured");
357
+ process.exit(1);
358
+ }
359
+ await cloneRepo(template.repo, projectName);
360
+ printSuccessMessage(projectName);
361
+ } else if (template.type === "vite") {
362
+ await createViteProject(projectName);
363
+ } else if (template.type === "next") {
364
+ await createNextProject(projectName);
365
+ }
366
+ }
367
+ function printSuccessMessage(projectName) {
368
+ console.log();
369
+ logger.success(chalk2.green.bold("\u{1F389} Project created successfully!"));
370
+ console.log();
371
+ logger.log(chalk2.cyan(" Next steps:"));
372
+ logger.log(` cd ${chalk2.yellow(projectName)}`);
373
+ logger.log(` ${chalk2.yellow("pnpm install")}`);
374
+ logger.log(` ${chalk2.yellow("pnpm dev")}`);
375
+ console.log();
376
+ }
377
+ function printBanner() {
378
+ console.log();
379
+ console.log(chalk2.cyan(cowsay(getGreetingMessage())));
380
+ console.log();
381
+ }
382
+ async function run() {
383
+ const program = new Command();
384
+ program.name("create-for-yeyu").description("A CLI tool to scaffold projects from templates").version(VERSION).argument("[project-name]", "Project name").option(
385
+ "-t, --template <template>",
386
+ "Specify template (nest, evm-dapp, vite, next)"
387
+ ).action(async (projectName, options) => {
388
+ printBanner();
389
+ try {
390
+ let finalProjectName = projectName;
391
+ let template;
392
+ if (!finalProjectName) {
393
+ finalProjectName = await promptProjectName();
394
+ }
395
+ if (options.template) {
396
+ const foundTemplate = getTemplateByValue(options.template);
397
+ if (!foundTemplate) {
398
+ logger.error(`Template not found: ${options.template}`);
399
+ logger.info("Available templates: nest, evm-dapp, vite, next");
400
+ process.exit(1);
401
+ }
402
+ template = foundTemplate;
403
+ } else {
404
+ template = await promptTemplate();
405
+ }
406
+ await executeTemplate(template, finalProjectName);
407
+ } catch (error) {
408
+ if (error instanceof Error) {
409
+ logger.error(error.message);
410
+ }
411
+ process.exit(1);
412
+ }
413
+ });
414
+ await program.parseAsync(process.argv);
415
+ }
416
+
417
+ // src/index.ts
418
+ run();
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "create-for-yeyu",
3
+ "version": "2.0.0",
4
+ "description": "A CLI tool to scaffold projects from templates",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-for-yeyu": "./dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "keywords": [
13
+ "cli",
14
+ "scaffold",
15
+ "template"
16
+ ],
17
+ "author": "yeyu",
18
+ "license": "MIT",
19
+ "dependencies": {
20
+ "chalk": "^5.3.0",
21
+ "commander": "^12.0.0",
22
+ "degit": "^2.8.4",
23
+ "execa": "^8.0.1",
24
+ "fs-extra": "^11.2.0",
25
+ "inquirer": "^9.2.12",
26
+ "ora": "^8.0.1"
27
+ },
28
+ "devDependencies": {
29
+ "@changesets/cli": "^2.29.8",
30
+ "@types/chalk": "^2.2.4",
31
+ "@types/degit": "^2.8.6",
32
+ "@types/fs-extra": "^11.0.4",
33
+ "@types/inquirer": "^9.0.7",
34
+ "@types/node": "^20.11.0",
35
+ "tsup": "^8.0.1",
36
+ "typescript": "^5.3.3"
37
+ },
38
+ "engines": {
39
+ "node": ">=18"
40
+ },
41
+ "scripts": {
42
+ "build": "tsup src/index.ts --format esm --dts",
43
+ "dev": "tsup src/index.ts --format esm --watch",
44
+ "start": "node dist/index.js",
45
+ "release": "changeset publish"
46
+ }
47
+ }