Skip to content

Conversation

zce
Copy link
Owner

@zce zce commented Jul 8, 2024

prepare

  • Type: (data: Result<Collections>, context: Context) => Promisable<void | false>

Data prepare hook, executed before write to file. You can apply additional processing to the output data, such as modify them, add missing data, handle relationships, or write them to files. return false to prevent the default output to a file if you wanted.

export default defineConfig({
  collections: { posts, tags },
  prepare: (data, context) => {
    // modify data
    data.posts.push({ ... })
    data.tags.push({ ... })

    // context
    const { config } = context
    // config is resolved from `velite.config.js` with default values

    // return false to prevent the default output to a file
  }
})

complete

  • Type: (data: Result<Collections>, context: Context) => Promisable<void>

Build success hook, executed after the build is complete. You can do anything after the build is complete, such as print some tips or deploy the output files.

close: #161

Summary by CodeRabbit

  • Documentation

    • Updated configuration documentation to include the new context parameter for prepare and complete functions.
  • New Features

    • Introduced a context parameter to the prepare and complete functions, allowing more context-aware operations within the build process.
  • Refactor

    • Modified internal functions to accept and utilize the new context parameter for enhanced configurability and functionality.

Copy link

coderabbitai bot commented Jul 8, 2024

Walkthrough

The changes introduce a context parameter to prepare and complete functions in the configuration and build files, allowing for more sophisticated context-related operations before and after the build process. These updates ensure the functions have the necessary context, such as configuration output, improving their utility for tasks like additional code generation.

Changes

Files Change Summary
docs/reference/... Updated prepare and complete function signatures to include context parameter
src/build.ts Modified resolve function and its calls to prepare and complete to include context
src/types.ts Added a Context type and updated UserConfig interface with context parameter in prepare and complete functions

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Config
    participant Build
    
    User->>Config: prepare(data, context)
    Config-->>Build: context with config
    Build-->>Config: complete(data, context)
Loading

Assessment against linked issues

Objective Addressed Explanation
prepare, complete events access to configuration output object (#161)

Poem

In fields of code where functions play,
Context joins in a new array.
Prepare and complete now have sight,
To config's depths, they take their flight.
With changes made, our paths align,
Code and context intertwine.
🌟 Cheers to progress, clear and bright!

Warning

Review ran into problems

Problems (1)
  • Git: Failed to clone repository. Please contact CodeRabbit support.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.
  • 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

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b34d6ea and 157c552.

Files selected for processing (3)
  • docs/reference/config.md (1 hunks)
  • src/build.ts (2 hunks)
  • src/types.ts (2 hunks)
Additional comments not posted (8)
docs/reference/config.md (3)

272-272: Correctly updated prepare hook type.

The type definition for the prepare hook has been correctly updated to include the context parameter.


276-291: Clear and comprehensive example for prepare hook.

The example usage of the prepare hook is clear and demonstrates how to modify data and access the context.


295-295: Correctly updated complete hook type.

The type definition for the complete hook has been correctly updated to include the context parameter.

src/types.ts (2)

201-209: Correctly added Context type.

The Context type has been correctly defined to include the config property.


265-272: Correctly updated prepare and complete functions in UserConfig interface.

The type definitions for the prepare and complete functions have been correctly updated to include the context parameter.

src/build.ts (3)

137-138: Correctly created context object.

The context object has been correctly created with the config property.


143-143: Correctly updated prepare function call.

The prepare function call has been correctly updated to include the context parameter.


160-160: Correctly updated complete function call.

The complete function call has been correctly updated to include the context parameter.

@zce zce merged commit 8eb6475 into main Jul 8, 2024
@zce zce deleted the hook-context branch July 8, 2024 02:01
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.

prepare, complete events access to configuration output object

1 participant