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: suport definePage #183

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

Conversation

CrazyZhang3
Copy link
Contributor

@CrazyZhang3 CrazyZhang3 commented Aug 26, 2024

Description 描述

feat: suport definePage
支持definePage定义路由信息

Summary by CodeRabbit

  • New Features

    • Enhanced documentation for routing data management, including a new section on defining routing data.
    • Introduced definePage function for flexible page metadata handling.
    • Added a new Vue component example utilizing the definePage function.
  • Bug Fixes

    • Improved logic for parsing and handling Single File Components (SFCs) to enhance reliability.
  • Documentation

    • Updated README to clarify usage and structure of routing data and macros.
  • Chores

    • Added new dependencies to improve tooling and TypeScript support.

Copy link

coderabbitai bot commented Aug 26, 2024

Walkthrough

The changes include significant updates to documentation, the addition of new dependencies, and enhancements to the PageContext class. Key modifications involve restructuring routing data management, improving metadata parsing, and introducing a new definePage function for flexible page definitions. These updates aim to enhance the framework's capabilities and improve the developer experience.

Changes

Files Change Summary
README.md Updated documentation on routing data, added section on definePage, clarified <route> usage.
packages/core/package.json Added new dependencies: @babel/generator, @babel/types, @vue-macros/common, and type definitions.
packages/core/src/constant.ts Introduced constant MACRO_DEFINE_PAGE with value 'definePage'.
packages/core/src/context.ts Enhanced PageContext class for file reading and metadata handling; simplified methods.
packages/core/src/customBlock.ts Modified getRouteSfcBlock to accept SFCDescriptor instead of file path.
packages/core/src/definePage.ts Introduced file for parsing SFCs with macros; added findMacroWithImports, readPageOptionsFromMacro, and findMacro functions.
packages/core/src/index.ts Enhanced VitePluginUniPages to parse SFCs and handle macros.
packages/core/src/types.ts Added new function definePage for flexible page metadata handling.
packages/core/src/utils.ts Updated functions to use SFCDescriptor and refined caching and change detection logic.
packages/playground/src/pages/test-define-page.vue Implemented a new Vue component using definePage with TypeScript.
test/parser.spec.ts Updated tests to reflect changes in SFC handling, including parsing and reading file content.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant VitePluginUniPages
    participant SFCParser
    participant MacroHandler

    User->>VitePluginUniPages: Define SFC
    VitePluginUniPages->>SFCParser: Parse SFC
    SFCParser->>MacroHandler: Find macros
    MacroHandler-->>VitePluginUniPages: Return macro data
    VitePluginUniPages-->>User: Processed SFC
Loading

🐇 In the meadow, changes bloom,
New routes and macros, dispelling gloom.
With definePage, we hop and play,
Crafting pages in a joyful way.
So let’s celebrate, with a cheer,
For every change brings us near! 🌼


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

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e7b3213 and fa71a29.

Files selected for processing (11)
  • README.md (1 hunks)
  • packages/core/package.json (2 hunks)
  • packages/core/src/constant.ts (1 hunks)
  • packages/core/src/context.ts (5 hunks)
  • packages/core/src/customBlock.ts (2 hunks)
  • packages/core/src/definePage.ts (1 hunks)
  • packages/core/src/index.ts (3 hunks)
  • packages/core/src/types.ts (1 hunks)
  • packages/core/src/utils.ts (2 hunks)
  • packages/playground/src/pages/test-define-page.vue (1 hunks)
  • test/parser.spec.ts (3 hunks)
Files skipped from review due to trivial changes (1)
  • packages/core/src/constant.ts
Additional comments not posted (20)
packages/playground/src/pages/test-define-page.vue (2)

14-16: LGTM!

The template section is correctly implemented.

The code changes are approved.


1-10: LGTM! But verify the usage of definePage.

The script setup section is correctly implemented. However, ensure that the definePage function is used correctly and that the properties are valid.

The code changes are approved.

Run the following script to verify the usage of definePage:

Verification successful

Usage of definePage is correct.

The definePage function is used to define route data at compile time, as described in the documentation. The current implementation in test-define-page.vue aligns with the intended usage. No issues found.

  • Reference: README.md explains the compile-time usage of definePage.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `definePage`.

# Test: Search for the function definition. Expect: Only occurrences of the correct usage.
rg --type ts -A 5 $'definePage'

Length of output: 1452


Script:

#!/bin/bash
# Description: Search for additional references or documentation for `definePage`.

# Search for any documentation or comments related to `definePage`.
rg 'definePage' --type md -A 5

# Search for any additional references to `definePage` in the codebase.
rg 'definePage' --type ts -A 5

Length of output: 1831

test/parser.spec.ts (3)

2-4: LGTM!

The import statement has been correctly updated to include parseSFC.

The code changes are approved.


13-15: LGTM!

The test case is correctly implemented. The addition of parseSFC enhances the flexibility and correctness of the SFC handling.

The code changes are approved.


37-39: LGTM!

The test case is correctly implemented. The addition of parseSFC enhances the flexibility and correctness of the SFC handling.

The code changes are approved.

packages/core/package.json (4)

58-58: LGTM!

The addition of @babel/generator is appropriate for facilitating code generation within the Babel ecosystem.

The code changes are approved.


59-59: LGTM!

The addition of @babel/types is appropriate for facilitating code manipulation within the Babel ecosystem.

The code changes are approved.


61-61: LGTM!

The addition of @vue-macros/common is appropriate for enhancing the handling of Vue macros.

The code changes are approved.


76-76: LGTM!

The addition of @types/babel__generator is appropriate for improving TypeScript support for the Babel generator.

The code changes are approved.

packages/core/src/customBlock.ts (1)

74-75: LGTM!

The function changes improve efficiency by eliminating the need to read and parse the file content. The function now directly accesses the customBlocks property, which simplifies the logic.

The code changes are approved.

packages/core/src/definePage.ts (1)

85-87: LGTM!

The function is well-implemented and reuses the findMacroWithImports function.

The code changes are approved.

packages/core/src/utils.ts (3)

64-73: LGTM! But verify the function usage in the codebase.

The function is correctly implemented. However, ensure that all function calls to parseData match the new signature.

The code changes are approved.

Run the following script to verify the function usage:

Verification successful

Function usage verified successfully.

The parseData function is used correctly with the updated signature in the following files:

  • packages/core/src/utils.ts
  • packages/core/src/context.ts

All instances match the new function signature with three parameters. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `parseData` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type js -A 5 $'parseData'

Length of output: 29


Script:

#!/bin/bash
# Description: Verify all function calls to `parseData` across the entire codebase, including TypeScript files.

# Test: Search for the function usage in all relevant files.
rg --type-add 'ts:*.{ts,tsx}' --type ts -A 5 $'parseData'

Length of output: 1882


82-87: LGTM! But verify the function usage in the codebase.

The function is correctly implemented. However, ensure that all function calls to hasChanged match the new signature.

The code changes are approved.

Run the following script to verify the function usage:

Verification successful

Function hasChanged is used correctly with the new signature.

The function hasChanged is correctly implemented and used in the codebase with the updated parameters. No issues were found with its usage.

  • Verified in packages/core/src/context.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `hasChanged` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type js -A 5 $'hasChanged'

Length of output: 30


Script:

#!/bin/bash
# Search for the definition of the `hasChanged` function to ensure it's correctly identified.
ast-grep --lang typescript --pattern 'function hasChanged($_, $_, $_) { $$$ }'

# Search for all occurrences of `hasChanged` to verify its usage in the codebase.
rg 'hasChanged' -A 5

Length of output: 2483


76-79: LGTM! But verify the function usage in the codebase.

The function is correctly implemented. However, ensure that all function calls to setCache match the new signature.

The code changes are approved.

Run the following script to verify the function usage:

README.md (1)

57-70: LGTM!

The documentation changes are correctly implemented and improve the clarity and structure of the content.

The code changes are approved.

packages/core/src/index.ts (1)

96-101: LGTM! But verify the function usage in the codebase.

The function is correctly implemented. However, ensure that the new functionality related to parseSFC and findMacro is used correctly.

The code changes are approved.

Run the following script to verify the function usage:

Verification successful

Function usage verified successfully. The functions parseSFC and findMacro are correctly used across the codebase. No issues were found with their integration.

  • parseSFC is used in packages/core/src/index.ts, packages/core/src/context.ts, and test/parser.spec.ts.
  • findMacro is used in packages/core/src/index.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `parseSFC` and `findMacro` in the codebase.

# Test: Search for the function usage. Expect: Only occurrences of the new functionality.
rg --type js -A 5 $'parseSFC'
rg --type js -A 5 $'findMacro'

Length of output: 58


Script:

#!/bin/bash
# Search for the definitions of `parseSFC` and `findMacro` to understand their implementations.
ast-grep --lang typescript --pattern 'function parseSFC($_) { $$$ }'
ast-grep --lang typescript --pattern 'function findMacro($_) { $$$ }'

# Search for the usage of `parseSFC` and `findMacro` in TypeScript files.
rg --type ts -A 5 'parseSFC'
rg --type ts -A 5 'findMacro'

Length of output: 5432

packages/core/src/context.ts (4)

3-3: LGTM!

The new imports are necessary for the new functionality.

The code changes are approved.

Also applies to: 19-19


234-234: LGTM!

The method simplifies the code by removing an unnecessary intermediate variable.

The code changes are approved.


267-269: LGTM!

The method enhances the change detection mechanism by considering the content of the SFC.

The code changes are approved.


176-179: LGTM! But verify error handling in parseSFC and parseData.

The method correctly integrates file reading and metadata processing. Ensure that parseSFC and parseData handle errors gracefully.

The code changes are approved.

Run the following script to verify error handling in parseSFC and parseData:

packages/core/src/definePage.ts Outdated Show resolved Hide resolved
packages/core/src/definePage.ts Show resolved Hide resolved
Comment on lines +144 to +147
export function definePage(_options: Partial<
PageMetaDatum
>) {
}
Copy link

Choose a reason for hiding this comment

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

Implement the function to handle page metadata.

The function is a placeholder and does not perform any operations. It should be implemented to handle page metadata.

Apply this diff to implement the function:

 export function definePage(_options: Partial<
   PageMetaDatum
 >) {
+  // Implement the function to handle page metadata
+  // Example implementation:
+  const pageMeta: PageMetaDatum = {
+    path: _options.path || '',
+    type: _options.type,
+    style: _options.style,
+    needLogin: _options.needLogin,
+    ..._options,
+  }
+  return pageMeta
 }

Committable suggestion was skipped due to low confidence.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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 fa71a29 and 13465ef.

Files selected for processing (1)
  • packages/core/src/definePage.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/definePage.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant