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(material): add material package #537

Open
wants to merge 1 commit into
base: refactor/develop
Choose a base branch
from

Conversation

chilingling
Copy link
Member

@chilingling chilingling commented Jun 4, 2024

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

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
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Added comprehensive documentation for using TinyEngine's official materials.
    • Introduced functionality for building material assets, including validation, bundling, and serving.
    • Added configuration schemas for various components (ElButton, ElInput, TinyButton, TinyInput, Input) detailing properties, events, and slots.
  • Chores

    • Updated package.json for @opentiny/tiny-engine-materials with new scripts and dependencies.

Copy link

coderabbitai bot commented Jun 4, 2024

Walkthrough

The recent updates introduce a comprehensive setup for TinyEngine's materials package, including new configuration schemas for various components, a build script for material assets, and updates to the package configuration. The changes enhance the framework's ability to validate, build, and serve component libraries, facilitating a more modular and customizable development experience.

Changes

Files/Paths Change Summaries
packages/materials/README.md Added instructions on using TinyEngine's official materials, including building and adding custom materials.
packages/materials/buildMaterials.mjs Introduced functionality for building material assets, including validation, generation, and serving.
packages/materials/package.json Updated to include scripts for testing, serving, building, and configuration details for publishing.
.../src/ElementPlus/ElButton.json Introduced configuration schema for the ElButton component with various properties and configurations.
.../src/ElementPlus/ElInput.json Introduced configuration schema for the ElInput component with properties, events, and slots.
.../src/TinyVue/TinyButton.json Introduced configuration for the TinyButton component with properties and event handling for onClick.
.../src/TinyVue/TinyInput.json Introduced configuration for the TinyInput component with properties, events, slots, and configuration.
.../src/html/Input.json Introduced configuration for an HTML input component with properties, events, and configuration options.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant Developer
    participant CLI
    participant BuildScript
    participant Server
    Developer->>CLI: Run build command
    CLI->>BuildScript: Initialize build
    BuildScript->>BuildScript: Validate components
    BuildScript->>BuildScript: Generate component bundles
    BuildScript->>BuildScript: Build components from JSON files
    BuildScript->>Server: Serve material assets
    Server->>Developer: Material assets ready
Loading

Poem

In the land of code so bright,
TinyEngine takes its flight.
Building buttons, inputs too,
With schemas fresh and scripts anew.
Components dance in structured form,
A rabbit's dream in digital norm. 🐇


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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ec2c752 and f43f9dd.

Files selected for processing (8)
  • packages/materials/README.md (1 hunks)
  • packages/materials/buildMaterials.mjs (1 hunks)
  • packages/materials/package.json (1 hunks)
  • packages/materials/src/ElementPlus/ElButton.json (1 hunks)
  • packages/materials/src/ElementPlus/ElInput.json (1 hunks)
  • packages/materials/src/TinyVue/TinyButton.json (1 hunks)
  • packages/materials/src/TinyVue/TinyInput.json (1 hunks)
  • packages/materials/src/html/Input.json (1 hunks)
Files skipped from review due to trivial changes (5)
  • packages/materials/package.json
  • packages/materials/src/ElementPlus/ElButton.json
  • packages/materials/src/TinyVue/TinyButton.json
  • packages/materials/src/TinyVue/TinyInput.json
  • packages/materials/src/html/Input.json
Additional context used
Markdownlint
packages/materials/README.md

12-12: null (MD032, blanks-around-lists)
Lists should be surrounded by blank lines


33-33: null (MD034, no-bare-urls)
Bare URL used

Additional comments not posted (4)
packages/materials/buildMaterials.mjs (3)

24-42: Ensure all required fields are checked in validateComponent.

This function correctly checks for missing required fields and logs appropriate errors. Good use of array operations for validation.


118-154: Ensure error handling in buildComponents is robust.

Good use of try-catch for error handling. Consider adding more specific error messages or handling different types of exceptions if applicable.


156-190: Review the implementation of the serve function.

The function sets up a watcher and a static server correctly. Good use of asynchronous programming and logging.

packages/materials/src/ElementPlus/ElInput.json (1)

1-292: Review the schema definition for ElInput.

The JSON schema is well-structured and includes comprehensive details about the component, its properties, events, and slots. Good use of nested structures and data types.

```

解释:
1. 会持续监听 src 目录下文件变动,持续构建出来物料产物
Copy link

Choose a reason for hiding this comment

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

Add a blank line before the list for proper Markdown formatting.

+ 
解释:

Committable suggestion was skipped due to low confidence.

Tools
Markdownlint

12-12: null (MD032, blanks-around-lists)
Lists should be surrounded by blank lines


## 添加自己的物料

请先大致了解 TinyEngine 物料协议:https://opentiny.design/tiny-engine#/protocol
Copy link

Choose a reason for hiding this comment

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

Replace the bare URL with a Markdown link for better readability and to adhere to best practices.

- 请先大致了解 TinyEngine 物料协议:https://opentiny.design/tiny-engine#/protocol
+ 请先大致了解 TinyEngine 物料协议:[TinyEngine 物料协议](https://opentiny.design/tiny-engine#/protocol)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
请先大致了解 TinyEngine 物料协议:https://opentiny.design/tiny-engine#/protocol
请先大致了解 TinyEngine 物料协议:[TinyEngine 物料协议](https://opentiny.design/tiny-engine#/protocol)
Tools
Markdownlint

33-33: null (MD034, no-bare-urls)
Bare URL used

Comment on lines +44 to +106
const generateComponents = async (entry) => {
const files = await fg('*.json', { cwd: entry })
if (!files.length) {
// logger.warn('物料文件夹为空,请先执行`pnpm splitMaterials`命令拆分物料资产包')
return
}

const bundle = {
componentsMap: [],
components: [],
snippets: []
}

files.forEach((file) => {
const material = fsExtra.readJsonSync(path.resolve(entry, file), { throws: false })

if (!material) {
const fileFullPath = path.join(process.cwd(), file)

logger.error(`文件格式有误 (${fileFullPath})`)

return
}

const valid = validateComponent(file, material)

if (!valid) return

const { snippets: componentSnippets, category, ...componentInfo } = material

bundle.components.push(componentInfo)

const snippet = bundle.snippets.find((item) => item.group === category)

if (snippet) {
componentSnippets && snippet.children.push(componentSnippets[0])
} else if (category && componentInfo) {
bundle.snippets.push({
group: category,
children: componentSnippets || []
})
}

const npmInfo = componentInfo.npm
const { package: packageName = '', version = '', exportName = '' } = npmInfo

const mapItem = {
componentName: componentInfo.component,
package: packageName,
version,
exportName
}

if (typeof npmInfo.destructuring === 'boolean') {
mapItem.destructuring = componentInfo.npm.destructuring
}

if (npmInfo.package) {
bundle.componentsMap.push(mapItem)
}
})

return bundle
Copy link

Choose a reason for hiding this comment

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

Optimize the generateComponents function to handle empty directories more gracefully.

Consider logging a warning when the materials directory is empty, which could help in debugging.

-    // logger.warn('物料文件夹为空,请先执行`pnpm splitMaterials`命令拆分物料资产包')
+    logger.warn('物料文件夹为空,请先执行`pnpm splitMaterials`命令拆分物料资产包')
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const generateComponents = async (entry) => {
const files = await fg('*.json', { cwd: entry })
if (!files.length) {
// logger.warn('物料文件夹为空,请先执行`pnpm splitMaterials`命令拆分物料资产包')
return
}
const bundle = {
componentsMap: [],
components: [],
snippets: []
}
files.forEach((file) => {
const material = fsExtra.readJsonSync(path.resolve(entry, file), { throws: false })
if (!material) {
const fileFullPath = path.join(process.cwd(), file)
logger.error(`文件格式有误 (${fileFullPath})`)
return
}
const valid = validateComponent(file, material)
if (!valid) return
const { snippets: componentSnippets, category, ...componentInfo } = material
bundle.components.push(componentInfo)
const snippet = bundle.snippets.find((item) => item.group === category)
if (snippet) {
componentSnippets && snippet.children.push(componentSnippets[0])
} else if (category && componentInfo) {
bundle.snippets.push({
group: category,
children: componentSnippets || []
})
}
const npmInfo = componentInfo.npm
const { package: packageName = '', version = '', exportName = '' } = npmInfo
const mapItem = {
componentName: componentInfo.component,
package: packageName,
version,
exportName
}
if (typeof npmInfo.destructuring === 'boolean') {
mapItem.destructuring = componentInfo.npm.destructuring
}
if (npmInfo.package) {
bundle.componentsMap.push(mapItem)
}
})
return bundle
const generateComponents = async (entry) => {
const files = await fg('*.json', { cwd: entry })
if (!files.length) {
logger.warn('物料文件夹为空,请先执行`pnpm splitMaterials`命令拆分物料资产包')
return
}
const bundle = {
componentsMap: [],
components: [],
snippets: []
}
files.forEach((file) => {
const material = fsExtra.readJsonSync(path.resolve(entry, file), { throws: false })
if (!material) {
const fileFullPath = path.join(process.cwd(), file)
logger.error(`文件格式有误 (${fileFullPath})`)
return
}
const valid = validateComponent(file, material)
if (!valid) return
const { snippets: componentSnippets, category, ...componentInfo } = material
bundle.components.push(componentInfo)
const snippet = bundle.snippets.find((item) => item.group === category)
if (snippet) {
componentSnippets && snippet.children.push(componentSnippets[0])
} else if (category && componentInfo) {
bundle.snippets.push({
group: category,
children: componentSnippets || []
})
}
const npmInfo = componentInfo.npm
const { package: packageName = '', version = '', exportName = '' } = npmInfo
const mapItem = {
componentName: componentInfo.component,
package: packageName,
version,
exportName
}
if (typeof npmInfo.destructuring === 'boolean') {
mapItem.destructuring = componentInfo.npm.destructuring
}
if (npmInfo.package) {
bundle.componentsMap.push(mapItem)
}
})
return bundle

Comment on lines +202 to +219

function start() {
const commandsMap = {
serve: serve,
build: build,
'build:split': buildSplit
}

const command = process.argv.slice(2)

if (!commandsMap[command]) {
logger.error(`[@opentiny/tiny-engine-materials] 不支持${command}命令`)

return
}

commandsMap[command]()
}
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The start function in packages/materials/buildMaterials.mjs does include a basic validation check to ensure the command is in the commandsMap. However, it only checks if the command exists in the map and does not handle other potential issues such as invalid command formats or additional arguments.

  • Location in codebase:
    • packages/materials/buildMaterials.mjs (lines 202-219)

To improve the validation, consider adding more comprehensive checks, such as verifying the format of the command and handling unexpected additional arguments.

Analysis chain

Validate command input in start function.

Ensure that the command validation is comprehensive and covers all expected scenarios.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify command validation in the start function.

# Test: Search for command validation logic. Expect: Comprehensive validation logic.
rg --type javascript $'commandsMap[command]'

Length of output: 80



Script:

#!/bin/bash
# Description: Verify command validation in the start function.

# Test: Search for command validation logic. Expect: Comprehensive validation logic.
rg --type js $'commandsMap[command]'

Length of output: 37



Script:

#!/bin/bash
# Description: Locate the start function and review its implementation.

# Search for the start function definition in JavaScript files.
rg --type js 'function start'

Length of output: 31



Script:

#!/bin/bash
# Description: Locate the start function and review its implementation.

# Search for the start function definition in JavaScript and ES module files.
rg --type-add 'mjs:*.mjs' --type js --type mjs 'function start'

Length of output: 122



Script:

#!/bin/bash
# Description: Extract and display the start function implementation from buildMaterials.mjs.

# Extract the start function implementation.
rg --type-add 'mjs:*.mjs' --type mjs --context 10 'function start' packages/materials/buildMaterials.mjs

Length of output: 495

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.

None yet

1 participant