chore: move upload script to template
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
- [x] 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
- [x] Other... Please describe:
Background and solution
- 将同步物料的脚本移动到用户工程以及模板中。(通过 cli 模板可以直接得到 script)
- 使用 FormData API 替代手动构造 multipart/form-data 请求体;增强错误处理和日志输出;增强功能详细说明
- 将
updateTempmlate中的assert语法改为with(Node.js v22 assert 语法已经被废弃)
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
Other information
Summary by CodeRabbit
-
New Features
- Added a material upload command to sync component bundles with the backend.
- Added colored, timestamped logging for clearer progress and error messages.
-
Chores
- Added dev dependencies for environment/config and file handling.
- Switched the upload task to use the monorepo-aware command invocation.
- Replaced the legacy upload implementation with an updated template-backed workflow.
Walkthrough
Adds Logger utilities and new uploadMaterials scripts in designer-demo and template paths, updates root package.json script to use pnpm filter, adds devDependencies (dotenv, fs-extra, picocolors) to the template, removes a legacy root upload script, and changes a JSON import assertion to with { type: 'json' }.
Changes
| Cohort / File(s) | Summary |
|---|---|
Logger Utilities designer-demo/scripts/logger.mjs, packages/engine-cli/template/designer/scripts/logger.mjs |
New Logger class modules providing timestamped, command-prefixed logging with runtime color detection and emoji fallbacks; exports default Logger with methods info, warn, error, success. |
Upload Materials Scripts designer-demo/scripts/uploadMaterials.mjs, packages/engine-cli/template/designer/scripts/uploadMaterials.mjs |
New standalone scripts that load env/.env.local to obtain backend_url, read public/mock/bundle.json, POST the bundle as multipart/form-data to /material-center/api/component/bundle/create, log progress/results, and exit non-zero on failure. |
Designer Package Configs designer-demo/package.json, packages/engine-cli/template/designer/package.json |
Added uploadMaterials script; template package.json also adds devDependencies: dotenv, fs-extra, and picocolors. Template script value: "node ./scripts/uploadMaterials.mjs". |
Root Orchestration package.json |
Updated root scripts.uploadMaterials from "node scripts/uploadMaterials.mjs" to "pnpm --filter designer-demo uploadMaterials" to invoke the demo package task via pnpm filter. |
Removed Root Script scripts/uploadMaterials.mjs |
Deleted legacy root-level upload script that previously performed bundle upload with manual multipart construction and fetch. |
Import Assertion Update scripts/updateTemplate.mjs |
Changed JSON import assertion from assert { type: 'json' } to with { type: 'json' }. |
Misc / Dump bash.exe.stackdump |
Added a stack dump file containing a textual stack trace. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant PNPM as pnpm
participant Script as uploadMaterials.mjs
participant FS as FileSystem
participant Logger as Logger
participant Backend as BackendAPI
User->>PNPM: run uploadMaterials (pnpm --filter designer-demo)
PNPM->>Script: invoke script
Script->>FS: read env/.env.local
Script->>Logger: info "env loaded"
Script->>FS: read public/mock/bundle.json
Script->>Logger: info "bundle loaded"
Script->>Logger: info "starting upload"
Script->>Backend: POST /material-center/api/component/bundle/create (multipart/form-data)
alt Success (2xx & success:true)
Backend-->>Script: 200 + JSON { success:true, inserted/updated }
Script->>Logger: success "upload complete"
else Failure (non-OK or success:false)
Backend-->>Script: error / JSON { success:false, message }
Script->>Logger: warn/error "upload failed"
end
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
- Review focus:
- env file loading and
backend_urlvalidation - multipart/FormData construction and correct Content-Type handling
- consistency between template and demo script implementations
- Logger initColors dynamic import and color/emoji fallback behavior
- env file loading and
Poem
🐇 I hopped through code with nimble paws,
Colors bright and logs with tiny claws,
Bundles read and POSTs took flight,
PNPM called and things went right —
I twitched my nose and cheered in bytes.
Pre-merge checks and finishing touches
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title 'chore: move upload script to template' accurately reflects the main objective of the changeset, which moves the uploadMaterials script from the root scripts directory to both the designer-demo and engine-cli template directories. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✨ Finishing touches
- [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.