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(create-mako): refactor create-mako #1751

Merged
merged 1 commit into from
Jan 13, 2025
Merged

feat(create-mako): refactor create-mako #1751

merged 1 commit into from
Jan 13, 2025

Conversation

sorrycc
Copy link
Member

@sorrycc sorrycc commented Jan 13, 2025

see picture.

image

Summary by CodeRabbit

  • 依赖变更

    • 移除了 create-mako 包中的 globinquireryargs-parser 依赖
    • 添加了新的开发依赖,如 @umijs/clack-promptgradient-stringpicocolors
  • 脚本更新

    • 修改了 release:create-mako 脚本的执行方式
    • 更新了 create-mako 包的构建和发布脚本
  • CLI 改进

    • 重新设计了命令行界面
    • 简化了项目创建流程
    • 引入新的交互式提示系统
  • 模板调整

    • 移除了 .gitignore 文件中的 .swc 忽略项

Copy link
Contributor

coderabbitai bot commented Jan 13, 2025

概述

遍历

此次更改主要涉及 create-mako 包的重构,包括更新依赖项、修改脚本和重新设计命令行界面。主要变化包括移除旧的依赖,添加新的开发依赖,更新构建和发布脚本,以及使用新的命令行交互工具重写 CLI 实现。

变更

文件 变更摘要
package.json 添加 build:create-mako 脚本,修改 release:create-mako 脚本
packages/create-mako/bin/create-mako.js 添加引入 ../dist/cli 模块
packages/create-mako/package.json 移除旧依赖,添加新依赖,更新脚本
packages/create-mako/src/cli.ts 重写命令行界面,使用新的交互工具
packages/create-mako/src/create.ts 新增项目创建逻辑
scripts/release-create-mako.ts 删除发布脚本

诗歌

🐰 兔子的发布秘籍
依赖换新装,脚本焕容颜
CLI 重构飞,模板更轻巧
创建项目,如风般潇洒
兔子微笑,代码飞翔!🚀

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Walkthrough

This pull request refactors the create-mako package by updating its build and release scripts, restructuring the CLI implementation, and modifying dependencies. The changes aim to streamline the project creation process and improve maintainability.

Changes

Files Summary
package.json Updated build and release scripts for create-mako.
packages/create-mako/bin/create-mako.js Adjusted CLI entry point.
packages/create-mako/src/cli.ts, packages/create-mako/src/create.ts Refactored CLI logic and project creation process.
pnpm-lock.yaml Updated dependencies and versions.
scripts/release-create-mako.ts Removed obsolete release script.
packages/create-mako/templates/minimal/*, packages/create-mako/templates/umi/_gitignore Minor template adjustments.
🪧 Tips For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me.

);
const args = selectedPackageManager === 'yarn' ? [] : ['install'];
try {
await execa(selectedPackageManager, args, {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The execa function is defined but not imported from any module. This could lead to a runtime error if execa is not available in the current scope. Consider importing execa from the appropriate module or replacing it with a suitable alternative.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (2)
packages/create-mako/src/cli.ts (1)

39-50: 更新帮助信息以包含对 bun 的支持

帮助信息中未列出 bun 作为可选的包管理器,但在代码中支持 bun。应更新帮助信息以反映所有支持的包管理器。

修复如下:

     --template, -t    Specify a template for the project
     --npm-client, -n  Specify the npm client to use (pnpm, yarn, npm)
+    --npm-client, -n  Specify the npm client to use (pnpm, yarn, npm, bun)

  Examples:
    create-mako                          Create a new project
packages/create-mako/src/create.ts (1)

51-51: 删除多余的 console.log('prompting'); 语句

第 51 行的 console.log('prompting'); 似乎是调试代码,建议删除以保持代码简洁。

修复如下:

          console.log('prompting');
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4bb698d and 01d93ca.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • package.json (2 hunks)
  • packages/create-mako/bin/create-mako.js (1 hunks)
  • packages/create-mako/package.json (2 hunks)
  • packages/create-mako/src/cli.ts (1 hunks)
  • packages/create-mako/src/create.ts (1 hunks)
  • packages/create-mako/templates/umi/_gitignore (0 hunks)
  • scripts/release-create-mako.ts (0 hunks)
💤 Files with no reviewable changes (2)
  • packages/create-mako/templates/umi/_gitignore
  • scripts/release-create-mako.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/create-mako/bin/create-mako.js
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: stable - i686-pc-windows-msvc - node@20
  • GitHub Check: stable - x86_64-pc-windows-msvc - node@20
  • GitHub Check: stable - aarch64-unknown-linux-musl - node@20
  • GitHub Check: stable - aarch64-unknown-linux-gnu - node@20
  • GitHub Check: Clippy
  • GitHub Check: stable - x86_64-unknown-linux-musl - node@20
  • GitHub Check: Mako Build (macos-latest)
  • GitHub Check: stable - x86_64-unknown-linux-gnu - node@20
  • GitHub Check: Mako Build (ubuntu-latest)
  • GitHub Check: stable - aarch64-apple-darwin - node@20
  • GitHub Check: Code Coverage
  • GitHub Check: Cargo Test
  • GitHub Check: stable - x86_64-apple-darwin - node@20
🔇 Additional comments (2)
package.json (2)

9-9: 新增构建脚本符合项目规范!

新增的 build:create-mako 脚本与项目中其他构建脚本保持一致的模式,使用 pnpm 工作空间过滤功能来构建特定包。


21-21: 优化发布流程的改动很棒!

release:create-mako 从自定义发布脚本改为使用 pnpm 工作空间命令是个很好的改进:

  • 简化了发布流程
  • 与其他包的发布命令(如 release:mako)保持一致
  • 充分利用了 pnpm 工作空间的特性

Comment on lines +9 to +16
const argv = yargsParser(process.argv.slice(2), {
alias: {
version: ['v'],
help: ['h'],
template: ['t'],
},
boolean: ['version', 'help'],
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

缺少对 --npm-client 参数的解析

当前的 yargsParser 配置中,没有解析 --npm-client-n 参数,导致 argv.packageManager 始终为 undefined,无法正确传递给 create 函数。

建议在 alias 中添加对 packageManager 参数的映射,修复如下:

  const argv = yargsParser(process.argv.slice(2), {
    alias: {
      version: ['v'],
      help: ['h'],
      template: ['t'],
+     packageManager: ['npm-client', 'n'],
    },
    boolean: ['version', 'help'],
  });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const argv = yargsParser(process.argv.slice(2), {
alias: {
version: ['v'],
help: ['h'],
template: ['t'],
},
boolean: ['version', 'help'],
});
const argv = yargsParser(process.argv.slice(2), {
alias: {
version: ['v'],
help: ['h'],
template: ['t'],
packageManager: ['npm-client', 'n'],
},
boolean: ['version', 'help'],
});

Comment on lines +64 to +65
.catch((err) => {
p.cancel(`Create failed, ${err.message}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

使用 p.cancel 处理错误可能不合适

p.cancel 通常用于用户取消操作。这里在捕获错误时使用 p.cancel,可能不符合预期。建议使用 p.outrop.error 来显示错误信息。

根据 @umijs/clack-prompt 的实际 API,修改如下:

      .catch((err) => {
-       p.cancel(`Create failed, ${err.message}`);
+       p.error(`Create failed, ${err.message}`);
        process.exit(1);
      });

或:

      .catch((err) => {
-       p.cancel(`Create failed, ${err.message}`);
+       p.outro(`Create failed, ${err.message}`);
        process.exit(1);
      });

请根据 @umijs/clack-prompt 的实际方法选择合适的替代方案。

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +161 to +166
child.stdout?.on('data', (data) => {
options.onData(data);
});
child.stderr?.on('data', (data) => {
options.onData(data);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

确保子进程输出的数据被正确处理为字符串

在处理子进程输出时,data 可能是 Buffer 对象,需要在调用 options.onData 之前转换为字符串,否则可能导致输出显示异常或错误。

修复如下:

      child.stdout?.on('data', (data) => {
-       options.onData(data);
+       options.onData(data.toString());
      });
      child.stderr?.on('data', (data) => {
-       options.onData(data);
+       options.onData(data.toString());
      });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
child.stdout?.on('data', (data) => {
options.onData(data);
});
child.stderr?.on('data', (data) => {
options.onData(data);
});
child.stdout?.on('data', (data) => {
options.onData(data.toString());
});
child.stderr?.on('data', (data) => {
options.onData(data.toString());
});

Comment on lines +28 to +29
"build": "utools bundle --patch-dirname",
"release": "utools release"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

缺少 utools 作为开发依赖

scripts 中使用了 utools,但未在 devDependencies 中声明,可能导致构建或发布过程中的错误。

建议在 devDependencies 中添加 utools

  "devDependencies": {
    "tsx": "^4.19.2",
    "typescript": "^5.6.3",
+   "utools": "^适当的版本号"
  },

请根据项目要求填写 utools 的正确版本号。

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +10 to +16
"@umijs/clack-prompt": "^0.0.3",
"@umijs/tools": "^0.1.3",
"gradient-string": "^3.0.0",
"picocolors": "^1.1.1",
"tsx": "^4.19.2",
"typescript": "^5.6.3",
"yargs-parser": "^21.1.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

将运行时依赖从 devDependencies 移动到 dependencies

在代码中使用的包(如 @umijs/clack-promptgradient-stringpicocolorsyargs-parser)是运行时依赖,应放在 dependencies 中。如果它们仅存在于 devDependencies,当用户安装该包时,这些依赖不会被安装,导致运行时错误。

修复如下:

  "devDependencies": {
-   "@umijs/clack-prompt": "^0.0.3",
-   "@umijs/tools": "^0.1.3",
-   "gradient-string": "^3.0.0",
-   "picocolors": "^1.1.1",
    "tsx": "^4.19.2",
    "typescript": "^5.6.3",
-   "yargs-parser": "^21.1.1"
  },
+ "dependencies": {
+   "@umijs/clack-prompt": "^0.0.3",
+   "gradient-string": "^3.0.0",
+   "picocolors": "^1.1.1",
+   "yargs-parser": "^21.1.1"
+ },

Committable suggestion skipped: line range outside the PR's diff.

Copy link

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.81%. Comparing base (4bb698d) to head (01d93ca).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1751   +/-   ##
=======================================
  Coverage   54.81%   54.81%           
=======================================
  Files         180      180           
  Lines       18081    18081           
=======================================
  Hits         9911     9911           
  Misses       8170     8170           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sorrycc sorrycc merged commit 75ee67b into master Jan 13, 2025
23 checks passed
@sorrycc sorrycc deleted the sorrycc-5kko branch January 13, 2025 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant