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!: v2 #8

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

feat!: v2 #8

wants to merge 11 commits into from

Conversation

kuritkaj
Copy link
Owner

@kuritkaj kuritkaj commented Aug 18, 2023

Summary by CodeRabbit

New Features:

  • Added a new command "GenerateStage" for generating sources.
  • Introduced new modules for file operations and finding files matching specified patterns.
  • Implemented a generic plugin system with GenericPlugin class.
  • Added a new GitPlugin class for handling Git-related tasks.

Refactor:

  • Updated import paths across multiple files.
  • Replaced string stage names with WorkflowStageName enum.
  • Simplified file existence checks and copying with new Files module functions.
  • Improved code readability by reordering imports and updating function signatures.

kuritkaj and others added 10 commits April 21, 2023 19:05
# Conflicts:
#	package-lock.json
#	package.json
#	src/commands/build/index.ts
#	src/commands/dev/index.ts
#	src/commands/format/index.ts
#	src/commands/lint/index.ts
#	src/commands/preview/index.ts
#	src/commands/release/index.ts
#	src/context/PresetWorkflowProvider.ts
#	src/context/StageRunner.ts
#	src/context/context.ts
#	src/flow/WorkflowPresetRepository.ts
#	src/flow/WorkflowPresetRunner.ts
#	src/flow/WorkflowStage.ts
#	src/lib/workflow/WorkflowStages.ts
#	src/presets/default/HandleConfig.ts
#	src/presets/presets.ts
#	src/presets/release/index.ts
#	src/presets/rome/RomeBase.ts
#	src/presets/ts/ts.ts
#	src/task/FSTasks.ts
#	src/task/ProgramRunner.ts
@coderabbitai
Copy link

coderabbitai bot commented Aug 18, 2023

Walkthrough

The project has been updated with new commands and enhancements, particularly focusing on the CLI tool's usability. A GenerateStage command has been introduced, and several files have been adjusted to work with the new WorkflowStageName enum. The codebase has been refactored for better organization, with import statements being cleaned up and method signatures updated for consistency. Additionally, the handling of .gitignore has been improved within the configuration context.

Changes

File Pattern Change Summary
README.md Added new CLI commands and usage examples.
bin/dev.js Modified comments.
src/commands/.../index.ts Reordered imports; updated import paths for WorkflowStageName.
src/command/BaseCommand.ts
src/commands/generate/index.ts
src/flow/WorkflowPresetRunner.ts
src/flow/WorkflowPresetRepository.ts
src/flow/WorkflowStages.ts
src/kplugin/KPlugin.ts
New imports; method signature changes to use WorkflowStageName; added GenerateStage command and KPlugin class.
src/context/... Added ignoreFile property; new getConfigAsync() function for .gitignore processing.
src/.../WorkflowStage.ts Interface implementation change from StageAction to Action.
src/lib/...
src/plugins/...
src/presets/...
src/task/...
templates/vite/...
New modules and classes; method modifications; import clean-up.

🐇✨
In the burrow of the code, changes abound,
Commands anew, and refactors found.
Gitignore dances, imports align,
A CLI tool refined, by paws so fine. 🌟🎩

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

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.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 83cfedc and bfd551d commits.
Files ignored due to filter (5)
  • package-lock.json
  • package.json
  • rome.json
  • templates/rome/rome.json
  • templates/vite/tsconfig.json
Files selected for processing (49)
  • README.md (3 hunks)
  • bin/dev.js (1 hunks)
  • src/command/BaseCommand.ts (2 hunks)
  • src/commands/build/index.ts (1 hunks)
  • src/commands/dev/index.ts (1 hunks)
  • src/commands/format/index.ts (1 hunks)
  • src/commands/generate/index.ts (1 hunks)
  • src/commands/lint/index.ts (1 hunks)
  • src/commands/preview/index.ts (1 hunks)
  • src/commands/release/index.ts (1 hunks)
  • src/context/ConfigProvider.ts (2 hunks)
  • src/context/ContextProvider.ts (2 hunks)
  • src/context/PresetWorkflowProvider.ts (1 hunks)
  • src/context/StageRunner.ts (2 hunks)
  • src/context/context.ts (2 hunks)
  • src/flow/WorkflowPresetRepository.ts (1 hunks)
  • src/flow/WorkflowPresetRunner.ts (4 hunks)
  • src/flow/WorkflowStage.ts (1 hunks)
  • src/flow/WorkflowStages.ts (1 hunks)
  • src/kplugin/KPlugin.ts (1 hunks)
  • src/lib/flow/Action.ts (1 hunks)
  • src/lib/flow/ActionGroup.ts (1 hunks)
  • src/lib/fs/Files.ts (1 hunks)
  • src/lib/fs/Location.ts (3 hunks)
  • src/lib/fs/finder/Finder.ts (1 hunks)
  • src/lib/fs/finder/IgnoreFinderFilter.ts (1 hunks)
  • src/lib/plugin/Plugin.ts (1 hunks)
  • src/lib/workflow/WorkflowStages.ts (1 hunks)
  • src/lib/workflow/stage/StageAction.ts (1 hunks)
  • src/lib/workflow/stage/StagePreset.ts (1 hunks)
  • src/plugins/git/GitPlugin.ts (1 hunks)
  • src/plugins/git/HandleConfig.ts (1 hunks)
  • src/presets/default/HandleConfig.ts (1 hunks)
  • src/presets/default/defaultPreset.ts (1 hunks)
  • src/presets/presets.ts (1 hunks)
  • src/presets/release/Release.ts (1 hunks)
  • src/presets/release/ReleaseInit.ts (1 hunks)
  • src/presets/release/index.ts (1 hunks)
  • src/presets/rome/RomeBase.ts (2 hunks)
  • src/presets/rome/RomeInit.ts (1 hunks)
  • src/presets/rome/RomeLint.ts (1 hunks)
  • src/presets/rome/index.ts (1 hunks)
  • src/presets/ts/ViteBase.ts (2 hunks)
  • src/presets/ts/ViteInit.ts (1 hunks)
  • src/presets/ts/ts.ts (1 hunks)
  • src/task/FSTasks.ts (2 hunks)
  • src/task/ProgramRunner.ts (3 hunks)
  • templates/vite/vite.ts.js (1 hunks)
  • templates/vite/vite.ts.lib.js (1 hunks)
Files skipped from review due to trivial changes (34)
  • README.md
  • bin/dev.js
  • src/command/BaseCommand.ts
  • src/commands/dev/index.ts
  • src/commands/generate/index.ts
  • src/commands/lint/index.ts
  • src/commands/preview/index.ts
  • src/commands/release/index.ts
  • src/context/ContextProvider.ts
  • src/context/PresetWorkflowProvider.ts
  • src/context/context.ts
  • src/flow/WorkflowStage.ts
  • src/flow/WorkflowStages.ts
  • src/lib/flow/Action.ts
  • src/lib/fs/Files.ts
  • src/lib/fs/Location.ts
  • src/lib/fs/finder/IgnoreFinderFilter.ts
  • src/lib/workflow/WorkflowStages.ts
  • src/lib/workflow/stage/StageAction.ts
  • src/lib/workflow/stage/StagePreset.ts
  • src/plugins/git/GitPlugin.ts
  • src/presets/default/defaultPreset.ts
  • src/presets/presets.ts
  • src/presets/release/Release.ts
  • src/presets/release/index.ts
  • src/presets/rome/RomeBase.ts
  • src/presets/rome/RomeInit.ts
  • src/presets/rome/RomeLint.ts
  • src/presets/rome/index.ts
  • src/presets/ts/ViteBase.ts
  • src/presets/ts/ViteInit.ts
  • src/presets/ts/ts.ts
  • templates/vite/vite.ts.js
  • templates/vite/vite.ts.lib.js
Review comments generated (8)
  • Actionable : 8
  • LGTM (Skipped): 5
  • Noise Suppression (Skipped): 20

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Tag the bot with @coderabbitai in any review comment to ask it questions. The bot will not respond unless explicitly tagged.
  • A review comment is a comment on a diff or a file and not a comment on the PR itself.
  • You can use the mouse to select multiple lines of code to provide exact context to the bot.

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 +58 to +81
async getConfigAsync(): Promise<KtoolsConfig> {
const gitIgnoreFilePath = this.context.project.ignoreFile.relativePath;

const fs = new Files();
const gitIgnoreFile = await fs.readIfExists(".gitignore");

const filters = [];

if (gitIgnoreFile) {
filters.push(new IgnoreFinderFilter(gitIgnoreFile));
}

const finder = new Finder({
filters,
});

const files = await finder.findMatching(["**/*.*?js", "**/*.ts"]);

// console.log(this.context.project.ignoreFile.relativePath);
// console.log(files);
console.log(files.map(getFirstDirectory));

return this.getConfig();
}
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

This new getConfigAsync method reads a .gitignore file, finds all JavaScript and TypeScript files that are not ignored, and logs the first directory of each file. However, it doesn't seem to use this information for any purpose other than logging. It might be better to return this information or use it in some way. Also, the method ends by returning the result of this.getConfig(), which is a synchronous method. This could potentially block the event loop if the config loading operation is heavy. Consider making getConfig() asynchronous as well, or at least ensure that it won't block the event loop.

-    return this.getConfig();
+    return await this.getConfigAsync();

Comment on lines +1 to +16
import { WorkflowStage } from "../../flow/WorkflowStage.js";
import { TaskList } from "../../lib/task/Task.js";
import { Context } from "../../context/context.js";

export class HandleConfig extends WorkflowStage {
run(): TaskList {
const { context } = Context;

return [
Context.fs.copyConfigWhenMissing(
context.tools.config.filePath.absolutePath,
context.tools.config.fileName,
),
];
}
}
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

The HandleConfig class extends WorkflowStage and overrides the run() method. It uses the Context.fs.copyConfigWhenMissing function to copy a configuration file if it's missing. However, there is no error handling in case the copying fails due to reasons such as lack of permissions or disk space. Consider adding error handling to this operation.

    return [
      Context.fs.copyConfigWhenMissing(
        context.tools.config.filePath.absolutePath,
        context.tools.config.fileName,
      ).catch(error => {
        console.error(`Failed to copy config file: ${error}`);
        throw error;
      }),
    ];

Comment on lines +27 to +30
constructor({ cwd, filters }: FinderOptions = defaultOptions) {
this.cwd = cwd;
this.filters = filters || [];
}
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

The constructor is using default parameters correctly. However, if the filters parameter is not provided, it will be set to an empty array. This could potentially overwrite any existing filters on the instance. If this is not the intended behavior, consider changing the logic here.

-    this.filters = filters || [];
+    this.filters = filters ?? this.filters;

Comment on lines +7 to +8
const configFile = Context.context.tools.config.fileName;
return [Context.fs.copyConfigWhenMissing(configFile, configFile)];
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

The logic for copying the configuration file when it's missing has been simplified. However, the check for the project path existence has been removed. If this check is still necessary, consider adding it back.

- return [Context.fs.copyConfigWhenMissing(configFile, configFile)];
+ return [
+   Context.fs.projectPathExists(configFile),
+   Context.fs.copyConfigWhenMissing(configFile, configFile)
+ ];

Comment on lines 9 to +15
projectPathExists(path: string): Task<{ projectConfigExists: boolean }> {
const file = this.context.project.rootPath.join(path).relativePath;

return {
title: `[FS] File exist ${file}`,
task: async (ctx, task) => {
ctx.projectConfigExists = !!(await jetpack.existsAsync(file));
ctx.projectConfigExists = !!(await this.files.exists(file));
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

The projectPathExists method has been refactored to use the Files class for file operations instead of directly using the fs-jetpack library. This change improves modularity and makes the code easier to test, as the Files class can be mocked during testing.

- ctx.projectConfigExists = !!(await jetpack.existsAsync(file));
+ ctx.projectConfigExists = !!(await this.files.exists(file));

Comment on lines +31 to 32
await this.files.copyFile(localFile, projectFile);
task.title = `[FS] New config created ${projectFile}`;
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

The copyFile method from the Files class is used here to copy a file. This is an improvement over the previous implementation which used the fs-jetpack library directly. The task title is updated after the operation, providing more accurate feedback.

- await jetpack.copyAsync(localFile, projectFile);
+ await this.files.copyFile(localFile, projectFile);

Comment on lines +46 to +47
await this.files.moveFile(originalFile, destinationFile);
task.title = `[FS] Config moved ${destinationFile}`;
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

The moveFile method from the Files class is used here to move a file. This is an improvement over the previous implementation which used the fs-jetpack library directly. The task title is updated after the operation, providing more accurate feedback.

- await jetpack.moveAsync(originalFile, destinationFile);
+ await this.files.moveFile(originalFile, destinationFile);

Comment on lines 1 to +5
import { execa } from "execa";
import { NpmProvider } from "../context/NpmProvider.js";
import { TaskRunner } from "../lib/task/TaskRunner.js";
import path from "node:path";
import { Task, TaskContext } from "../lib/task/Task.js";
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

The import statements are not ordered correctly. It's a good practice to order the imports in a certain way for better readability and maintainability. Usually, we start with third-party libraries, then internal modules. Also, it's common to sort them alphabetically.

- import { execa } from "execa";
- import { NpmProvider } from "../context/NpmProvider.js";
- import { TaskRunner } from "../lib/task/TaskRunner.js";
- import path from "node:path";
- import { Task, TaskContext } from "../lib/task/Task.js";
+ import { execa } from "execa";
+ import path from "node:path";
+ import { NpmProvider } from "../context/NpmProvider.js";
+ import { Task, TaskContext } from "../lib/task/Task.js";
+ import { TaskRunner } from "../lib/task/TaskRunner.js";

Watermelon AI Summary

This pull request focuses on overhauling components for the second major version (v2) of the application. It includes a mix of updates such as introducing new features like a generic plugin system and a GitPlugin, streamlining existing operations with refactoring, increasing readability, and improving configuration resolutions. Dependency updates and adjustments that improve the overall codebase also play a critical part. Conflicts from merging branches are resolved to maintain code cohesiveness.

GitHub PRs

ktools is an open repo and Watermelon will serve it for free.
🍉🫶

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between bfd551d and 361956a.
Files selected for processing (1)
  • bin/dev.js (2 hunks)
Additional comments: 2
bin/dev.js (2)
  • 11-11: The updated comment clarifies the purpose of the code block. Ensure that the comment accurately reflects the code's functionality and intent.

  • 21-21: The updated comment adds personality to the code. While this is not an issue, ensure that such comments maintain professionalism and clarity in the codebase.

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