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

Release v1.7.0 #532

Merged
merged 19 commits into from
Dec 22, 2024
Merged

Release v1.7.0 #532

merged 19 commits into from
Dec 22, 2024

Conversation

skyclouds2001
Copy link
Owner

@skyclouds2001 skyclouds2001 commented Dec 22, 2024

Summary

How did you test this change?

Summary by CodeRabbit

  • 新功能

    • 新增 npm-release 作业到 GitHub Actions 工作流。
    • 更新 CLI 工具的使用说明,简化了项目生成命令。
    • 引入新的初始化命令 npx @sky-fly/template init
    • 支持异步文件操作,改善文件处理性能。
  • 修复

    • 允许在没有暂存文件的情况下执行 lint-staged。
  • 文档

    • 更新了 CHANGELOG.md,记录了版本 1.7.0 的变更。
    • 更新了 README.md,提供了更清晰的 CLI 选项说明。
  • 版本更新

    • 将软件包版本更新至 1.7.0。

Copy link

coderabbitai bot commented Dec 22, 2024

演练

这个拉取请求包含了多个文件的更改,主要涉及 CLI 模板项目的版本升级到 1.7.0。更改包括更新 GitHub Actions 工作流以添加 npm-release 作业、修改 Husky 预提交钩子以允许空提交、更新 README 文档以简化 CLI 使用说明、重构文件系统操作为异步模式、更新依赖引擎版本要求,以及调整模板管理的结构。

变更

文件 变更摘要
.github/workflows/release.yml 新增 npm-release 作业,用于发布 npm 包
.husky/pre-commit 修改 lint-staged 命令,添加 --allow-empty 标志
CHANGELOG.md 更新版本信息至 1.7.0,包含多个小改动和补丁
README.md 更新 CLI 使用说明和安装命令
index.js 更改模块导入为 ES 模块
package.json 版本升级到 1.7.0,更新引擎版本,修改 bin 命令
src/fs.ts 迁移到异步文件系统操作
src/index.ts 重构目录操作逻辑
src/template.ts 将模板定义从接口转换为类
src/rewrite.ts 增加异步文件操作,重构项目信息覆盖逻辑
src/package.ts 更新 PackageManager 类的文档注释
jsconfig.json 删除文件
rollup-template-sky 更新子项目提交引用
vite-react-template-sky 更新子项目提交引用
vite-vue-template-sky 更新子项目提交引用

可能相关的 PR

  • Release v1.6.0 #518:修改 GitHub Actions 发布工作流,涉及 .github/workflows/release.yml 文件的更新。

诗歌

🐰 模板兔子的代码舞蹈
异步操作,轻盈跳跃
版本升级,命令简化
CLI 工具焕然一新
兔子微笑,代码飞翔 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


🪧 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.

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.

@skyclouds2001 skyclouds2001 self-assigned this Dec 22, 2024
@skyclouds2001 skyclouds2001 added the enhancement New feature or request label Dec 22, 2024
@skyclouds2001 skyclouds2001 added this to the development milestone Dec 22, 2024
@skyclouds2001 skyclouds2001 marked this pull request as ready for review December 22, 2024 07:43
Copy link

@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: 7

🧹 Nitpick comments (17)
src/fs.ts (4)

19-20: 检查空目录的实现很合理
当前异步实现可在读取目录失败时抛出异常,建议在调用方或函数内部添加错误处理,以免在读取权限受限或目录不存在等场景下导致未捕获的错误。


44-44: 文档注释可再补充“忽略”机制
建议在注释里说明该函数会跳过 IGNORE_COPY 中配置的文件或目录,帮助调用者直观理解忽略的范围。


48-61: 在遍历复制时应添加错误处理
若遇到无法读取的文件或目录,会导致函数抛出异常。可在复制过程对异常进行捕获,以防止一次文件错误导致整体复制流程中断。


64-64: 复制文件成功后可考虑增加日志或提示
在执行大规模复制操作时,适当打印日志可帮助快速定位错误文件。根据项目需要,可添加 debug 日志或错误提示。

src/rewrite.ts (4)

6-16: OVERRIDE_FILE 的键值定义可做进一步维护
目前 OVERRIDE_FILE 中的路径较多,后期若再扩展,维护成本会提升。建议考虑更灵活的配置或注释说明,以便后续增删文件时不易出错。


58-62: 覆盖写入 package.json 成功后可考虑添加日志
成功写入后增加提示信息,便于开发者确认是否已完成修改。


64-117: 处理 OVERRIDE_FILE 时的 Promise.allSettled 容错性不错
当前逻辑能并行处理各文件操作并捕获错误。若存在部分成功、部分失败的情况,可在后续增加一处对所有 rejected 结果的汇总日志,方便一次性查看错误详情。


120-135: 重写 .all-contributorsrc 的逻辑建议考虑判空
在解析到 contributors 时,将其置为空数组符合需求;但若调用方需要保留原有贡献者信息,可在此处提供一个条件选项或提示,让使用者自行决定是否清空列表。

src/index.ts (3)

8-8: 导入多个异步函数时,需注意错误处理流程
clearDir、copyDirOrFile、isEmptyDir 皆为异步函数,应在调用链中确保对可能异常的情形进行捕获或处理,以避免后续逻辑被意外中断。


125-127: 捕获异常后立即新建目录的方式可进一步解释
若抛出异常有多种原因(权限不足、磁盘问题等),在此简单新建目录可能无法解决问题。可在代码注释中说明逻辑原因或加更具体的错误判别。


134-134: 复制模板后可打印相关信息
当前操作可能比较耗时,建议在成功复制后适当提示用户,以防止在等待过程出现误解。

src/template.ts (1)

32-32: 建议优化类型安全性

当前的模板名称验证可以利用 TypeScript 的类型系统来增强类型安全性。

建议修改验证函数的实现:

-export function isValidTemplateName(name: string): boolean {
-  return Object.values(Template).some((template) => template.name === name.toLowerCase())
+export function isValidTemplateName(name: string): name is TemplateName {
+  return name.toLowerCase() in Template
}
src/package.ts (1)

2-4: 建议优化包管理器的类型定义

与 Template 类似,PackageManager 类也可以重构为更简洁的常量对象或枚举类型。

建议采用以下方案重构代码:

-export class PackageManager {
-  static readonly PNPM = 'pnpm'
-  static readonly YARN = 'yarn'
-  static readonly NPM = 'npm'
-}
+export const PackageManager = {
+  PNPM: 'pnpm',
+  YARN: 'yarn',
+  NPM: 'npm',
+} as const
+
+export type PackageManagerType = typeof PackageManager[keyof typeof PackageManager]
README.md (3)

7-10: 安装说明需要补充更多细节

建议在全局安装说明中添加以下内容:

  1. 说明需要的 Node.js 最低版本 (>=20.0.0)
  2. 提供其他包管理器的安装命令 (yarn, pnpm)
 First install the package as a global dependency:

 ```sh
 npm i @sky-fly/template -g
+
+# 或使用 yarn
+yarn global add @sky-fly/template
+
+# 或使用 pnpm
+pnpm add -g @sky-fly/template

+> 注意:需要 Node.js >= 20.0.0


---

`19-22`: **npx 命令说明需要优化**

当前的描述不够清晰,建议重写以提高可读性。

```diff
-Also directly use npx tool to generate a project without globally install it is available:
+Alternatively, you can use npx to generate a project without global installation:

39-42: CLI 选项表格需要补充说明

建议为模板类型和包管理器选项添加默认值说明。

 | Name                     | Default | Type                                 | Description                                            |
 | ------------------------ | ------- | ------------------------------------ | ------------------------------------------------------ |
-| _--template_ _-t_        | -       | `'vite-vue'\|'vite-react'\|'rollup'` | decide the template the project is intended to use     |
-| _--package-manager_ _-p_ | -       | `'npm'\|'yarn'\|'pnpm'`              | decide the package manager the project is going to use |
+| _--template_ _-t_        | vite-vue| `'vite-vue'\|'vite-react'\|'rollup'` | decide the template the project is intended to use     |
+| _--package-manager_ _-p_ | npm     | `'npm'\|'yarn'\|'pnpm'`              | decide the package manager the project is going to use |
CHANGELOG.md (1)

29-29: 引擎限制更新的描述不够具体

建议在更新说明中明确指出具体的版本要求变更。

-- [`3543a0f`](https://github.com/skyclouds2001/template-sky/commit/3543a0f00a16beb52eefe2e33dad92e305a9ce58) Thanks [@skyclouds2001](https://github.com/skyclouds2001)! - build: update engine limit
+- [`3543a0f`](https://github.com/skyclouds2001/template-sky/commit/3543a0f00a16beb52eefe2e33dad92e305a9ce58) Thanks [@skyclouds2001](https://github.com/skyclouds2001)! - build: update minimum required Node.js version to 20.0.0
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c352f3 and 55d9540.

📒 Files selected for processing (15)
  • .github/workflows/release.yml (1 hunks)
  • .husky/pre-commit (1 hunks)
  • CHANGELOG.md (1 hunks)
  • README.md (1 hunks)
  • index.js (1 hunks)
  • jsconfig.json (0 hunks)
  • package.json (2 hunks)
  • rollup-template-sky (1 hunks)
  • src/fs.ts (3 hunks)
  • src/index.ts (3 hunks)
  • src/package.ts (1 hunks)
  • src/rewrite.ts (3 hunks)
  • src/template.ts (1 hunks)
  • vite-react-template-sky (1 hunks)
  • vite-vue-template-sky (1 hunks)
💤 Files with no reviewable changes (1)
  • jsconfig.json
✅ Files skipped from review due to trivial changes (4)
  • rollup-template-sky
  • vite-react-template-sky
  • index.js
  • vite-vue-template-sky
🧰 Additional context used
🪛 Biome (1.9.4)
src/template.ts

[error] 6-24: Avoid classes that contain only static members.

Prefer using simple functions instead of classes with only static members.

(lint/complexity/noStaticOnlyClass)

🪛 LanguageTool
README.md

[uncategorized] ~18-~18: A comma may be missing after the conjunctive/linking adverb ‘Also’.
Context: ... a project: sh create-template Also directly use npx tool to generate a pro...

(SENT_START_CONJUNCTIVE_LINKING_ADVERB_COMMA)

🔇 Additional comments (8)
src/fs.ts (1)

29-37: 清空目录逻辑需注意符号链接与权限问题
在使用递归删除目录时,若存在符号链接或权限不足的文件,可能抛出异常。可考虑在此函数内部进行更详细的错误处理,或在调用方做更全面的防护。

src/rewrite.ts (2)

1-1: 统一使用异步 I/O 接口的做法很好
从 node:fs/promises 切换后,请确保在出错时能捕获事件并在控制台或日志里输出,避免在管道中断时难以排查。


30-34: 读取并解析 package.json 时应注意操作的有效性
若文件读取失败或 JSON 格式有误,则此处会抛出异常;可以在调用层或本函数内捕获并提示用户文件损坏或丢失。

src/index.ts (4)

1-1: 保持风格一致并使用异步 API
将原本同步或旧式回调的文件操作统一切换到 fs/promises,风格一致,代码更易维护。


11-11: 导入 Template 的方式更新需保持与内部实现一致
确保 Template 内部属性或静态方法未发生冲突;在后续版本若 Template 扩展,可同步更新此处 choices 生成逻辑。


68-68: 模板选择方式简洁明了
使用 map 生成新数组再赋值给 prompts 的 choices,这里逻辑清晰、可维护性高。


131-131: templateDir 的计算路径要注意兼容性
在多种操作系统或可能存在符号链接的情况,url.fileURLToPath 配合相对路径可能存在兼容性问题。建议在做完 resolve 后,使用 fs.stat 检测一下有效性。

.husky/pre-commit (1)

1-1: 允许空提交时依旧执行 lint-staged
此改动能让开发者在没有更改代码的情况下也执行预提交校验逻辑,这对统一流程和防止疏漏有一定帮助。

src/index.ts Show resolved Hide resolved
src/template.ts Outdated Show resolved Hide resolved
.github/workflows/release.yml Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
Copy link

@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: 0

🧹 Nitpick comments (2)
README.md (2)

7-10: 安装说明需要补充包管理器选项

建议在全局安装说明中添加其他包管理器的命令示例,因为项目支持 npm、yarn 和 pnpm。

建议添加如下内容:

 npm i @sky-fly/template -g
+# 或
+yarn global add @sky-fly/template
+# 或
+pnpm add -g @sky-fly/template

19-19: 建议改进句子结构

为提高可读性,建议在 "Also" 后添加逗号。

-Also directly use npx tool to generate a project without globally install it is available:
+Also, directly use npx tool to generate a project without globally installing it:
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 55d9540 and 3ee9eac.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • src/template.ts (1 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~18-~18: A comma may be missing after the conjunctive/linking adverb ‘Also’.
Context: ... generate a project: sh create Also directly use npx tool to generate a pro...

(SENT_START_CONJUNCTIVE_LINKING_ADVERB_COMMA)

🔇 Additional comments (3)
src/template.ts (2)

32-32: 验证逻辑优化得当!

使用 Object.values 遍历模板对象并进行不区分大小写的比较是个很好的实现。这样可以提供更好的用户体验,同时保持代码的简洁性。


6-24: 代码重构符合最佳实践!

将静态类重构为常量对象是个很好的改进,使代码更加简洁和易于维护。注意到 rollup 模板的颜色从 blue 改为了 magenta,这个改动可能会影响到用户体验。

✅ Verification successful

颜色变更是安全的修改

根据代码分析,颜色定义仅在 Template 对象内部使用,没有其他地方引用或依赖特定的颜色值。将 rollup 模板的颜色从 blue 改为 magenta 是一个安全的修改,不会影响到其他代码的功能。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查颜色变更是否在其他地方被引用或依赖

# 搜索可能依赖于特定颜色值的代码
rg -l "kleur\.blue.*rollup|rollup.*kleur\.blue"

Length of output: 49


Script:

#!/bin/bash
# 搜索所有引用了 Template 对象的文件
rg -l "Template\."

# 搜索所有使用了 kleur 颜色的地方
rg "kleur\.(blue|magenta|green)" -A 2 -B 2

Length of output: 595

README.md (1)

39-42: CLI 选项文档更新准确!

模板选项和包管理器选项的文档更新准确反映了代码中的可用选项,表格格式清晰易读。

Copy link

@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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ee9eac and aae8a02.

📒 Files selected for processing (1)
  • src/index.ts (3 hunks)
🔇 Additional comments (3)
src/index.ts (3)

1-1: 导入声明的更改符合最佳实践!

  • 使用 node:fs/promises 替代 node:fs 更好地支持异步操作
  • ./fs 导入的函数名称更清晰地表达了其用途
  • 新增的模板相关导入优化了代码组织结构

Also applies to: 8-8, 11-11


68-71: 模板处理逻辑优化得当!

使用 Object.values(Template) 替代原有的 templates 数组:

  • 提供了更好的类型安全性
  • 集中了模板的管理
  • 使用 color 方法使模板名称展示更友好

100-127: 建议优化目录处理逻辑

当前的目录处理逻辑可以进一步改进:

  1. 建议区分"完全清空"与"仅覆盖"的场景
  2. 可以提供选项让用户选择:
    • 完全清空目录
    • 仅覆盖冲突文件
    • 保留特定文件/文件夹

src/index.ts Show resolved Hide resolved
@skyclouds2001 skyclouds2001 deleted the dev branch December 22, 2024 08:07
@skyclouds2001 skyclouds2001 restored the dev branch December 22, 2024 08:07
@skyclouds2001 skyclouds2001 reopened this Dec 22, 2024
@skyclouds2001 skyclouds2001 merged commit 0b09f18 into master Dec 22, 2024
15 checks passed
@skyclouds2001 skyclouds2001 deleted the dev branch December 22, 2024 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant