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

refactor: 完成创建package.json,同时处理了一些其他小改动: (#28) #39

Merged
merged 1 commit into from
Mar 16, 2024

Conversation

uaenaTzx
Copy link
Collaborator

@uaenaTzx uaenaTzx commented Mar 16, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[√] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

What is the new behavior?

  • 实现的流程创建 package.json
  • 创建 packageAPI 文件,设置 packageAPI 类专门用于管理 package.json 操作
  • 暂时注释了 覆盖文件 的操作(目前有bug),后续开 issue 处理
  • 尝试写了写 plugin-eslint ,后续开 issue 专门开发,目前仅仅作为一个模板

Does this PR introduce a breaking change?

[√] Yes
[ ] No

架构升级的部分功能实现

Other information

Summary by CodeRabbit

以下是这些拉取请求的简洁发布说明:

  • packages/@plugin/plugin-eslint/index.ts:

    • 重构:添加了一个buildToolConfigs对象和一个pluginEslint函数,用于处理不同构建工具的配置。
    • Bug修复:注释掉了覆盖文件的操作,并计划在后续处理相关bug时再开issue。
  • packages/core/src/index.ts:

    • 重构:删除了createApp函数的调用,添加了一个console.log(pluginOptions, plugin)语句,并对代码进行了格式化调整。
  • packages/core/src/utils/createAppTest.ts:

    • 重构:创建了package.json文件,并使用PackageAPI类来管理package.json的操作。
    • Bug修复:注释了覆盖文件的操作,并计划在后续处理相关bug时再开issue。
  • packages/core/src/utils/packageAPI.ts:

    • 新功能:实现了一个名为packageAPI的类,用于创建、读取、更新和删除package.json文件。

请注意,这些发布说明侧重于对最终用户可见的功能,并省略了代码级别的细节。

Copy link

github-actions bot commented Mar 16, 2024

Image description CodeRabbit

Walkthrough

这次的代码改动主要包括以下几个方面的重构:

  • packages/@plugin/plugin-eslint/index.ts:添加了一个buildToolConfigs对象,用于存储不同构建工具的配置函数;添加了一个pluginEslint函数,根据传入的构建工具类型选择相应的配置函数进行处理;注释掉了覆盖文件的操作,并计划在后续开issue处理相关bug;尝试编写了一个plugin-eslint作为模板。
  • packages/core/src/index.ts:删除了createApp函数的调用;添加了console.log(pluginOptions, plugin)语句;对代码进行了格式化调整。
  • packages/core/src/utils/createAppTest.ts:创建了package.json文件,并使用PackageAPI类来管理package.json的操作;注释了覆盖文件的操作,并计划在后续处理相关bug时再开issue;尝试编写了plugin-eslint,但目前仅作为一个模板。
  • packages/core/src/utils/packageAPI.ts:实现了一个名为packageAPI的类,具有创建、读取、更新和删除package.json文件的功能。

Changes

文件 摘要
packages/@plugin/plugin-eslint/index.ts 进行了较小的重构,添加了buildToolConfigs对象和pluginEslint函数。
packages/core/src/index.ts 删除了createApp函数的调用,添加了console.log语句,进行了格式化调整。
packages/core/src/utils/createAppTest.ts 创建了package.json文件,使用PackageAPI类管理操作,并尝试编写了模板。
packages/core/src/utils/packageAPI.ts 实现了packageAPI类,具有对package.json文件的创建、读取、更新和删除功能。

"代码重构如春风拂面,揭示问题如阳光明媚。小兔子欢快地跳跃,庆祝改动的美丽。🌼🐇"


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 26e9aa1 and d78e5ed commits.
Files selected (4)
  • packages/@plugin/plugin-eslint/index.ts (1)
  • packages/core/src/index.ts (1)
  • packages/core/src/utils/createAppTest.ts (4)
  • packages/core/src/utils/packageAPI.ts (1)
Files not reviewed due to errors (2)
  • packages/core/src/index.ts (no response)
  • packages/core/src/utils/packageAPI.ts (no response)
Files skipped from review due to trivial changes (1)
  • packages/@plugin/plugin-eslint/index.ts
Review comments generated (5)
  • Review: 5
  • LGTM: 0

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines 8 to 10
import { projectSelect } from "./select";
import isGitInstalled from "./checkGitInstallation";
// import { createPackageJson } from "./createFile";

Choose a reason for hiding this comment

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

Image description CodeRabbit

这里注释掉了removeDirectory的调用,但是没有提供替代的代码。请确认是否有意为之。

Comment on lines 4 to 14
import { confirm } from "@clack/prompts";
import chalk from "chalk";

import { removeDirectory } from "./fileController";
// import { removeDirectory } from "./fileController";
import { projectSelect } from "./select";
import isGitInstalled from "./checkGitInstallation";
// import { createPackageJson } from "./createFile";
import PackageAPI from "./packageAPI";
import { createFiles } from "./createFiles";
import { type Preset, getFilesForProject, getNpmForPackage } from "./preset";
import createSuccessInfo from "./createSuccessInfo";

Choose a reason for hiding this comment

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

Image description CodeRabbit

Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [22-23]

这里创建了一个Preset对象,但是没有使用它。请确认是否有意为之。

Comment on lines +40 to 42
console.log(shouldContinue);

execSync(`mkdir ${rootDirectory}`);

Choose a reason for hiding this comment

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

Image description CodeRabbit

这里使用了execSync来执行命令mkdir,但是没有处理可能的异常情况。建议添加错误处理逻辑。

Comment on lines 46 to +67
const preset: Preset = await projectSelect();

console.log(rootDirectory);
// 创建package.json
await createFiles(rootDirectory, {
"package.json": "{}", // todo:具体内容待重构
console.log(chalk.blue(`\n📄 Generating package.json...`));
const packageContent = {
name: projectName,
version: "0.1.0",
private: true,
devDependencies: {},
};
// 遍历 preset.plugins,插入依赖
Object.keys(preset.plugins).forEach((dep) => {
console.log("dep:", dep);
// todo: 更多的处理依据 preset.plugins[dep] 后续的变化而插入
let { version } = preset.plugins[dep];
if (!version) {
version = "latest";
}
packageContent.devDependencies[dep] = version;
});
const packageJson = new PackageAPI(rootDirectory);
await packageJson.createPackageJson(packageContent);

Choose a reason for hiding this comment

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

Image description CodeRabbit

在这个代码块中,创建了一个packageContent对象,并将其传递给PackageAPI类的createPackageJson方法。然而,在新的代码中,没有展示如何使用PackageAPI类的实例。请提供相关的代码以确保createPackageJson方法被正确调用。

Comment on lines +79 to +82
Object.keys(packageContent.devDependencies).forEach(async (dep) => {
console.log(dep, "installed");
// 进入仓库
// await execSync(`npm install ${plugin}`)
// await execSync(`npm install ${dep}`)

Choose a reason for hiding this comment

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

Image description CodeRabbit

在这个代码块中,遍历了packageContent.devDependencies对象的键,并打印了每个键。然而,在新的代码中,没有展示如何安装依赖项。请提供相关的代码以确保依赖项被正确安装。

102:
这里打印了生成README.md文件的消息,但是没有展示具体的文件内容和创建过程。请提供相关的代码以确保README.md文件被正确创建。

以上是对packages/core/src/utils/createAppTest.ts文件的代码审查。请注意,这些评论仅针对代码质量和潜在问题,不包括其他方面的细节。

@xun082 xun082 self-requested a review March 16, 2024 14:19
@uaenaTzx uaenaTzx merged commit 9d31105 into refactor/template-upgrades Mar 16, 2024
1 check passed
@uaenaTzx uaenaTzx deleted the refactor/upgrades-package branch March 16, 2024 14:23
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