
Research
/Security News
OpenAPI React Query Codegen Compromised in Mini Shai-Hulud npm Supply Chain Attack
Ten malicious OpenAPI React Query Codegen versions were published to npm in the Mini Shai-Hulud attack, all with valid provenance.
cocos2d-cli
Advanced tools
Command-line tools for AI to read and manipulate Cocos Creator 2.4.x project scenes
Cocos Creator 2.4.x 场景 / 预制体命令行工具。
它可以直接操作 .fire 和 .prefab 文件,也支持从简化 JSON 生成场景、预制体,以及通过截图方式快速预览 UI 结构。
适用场景:
screenshot命令依赖playwright。
全局安装:
npm install -g cocos2d-cli
或在项目中直接使用:
npx cocos2d-cli --help
查看帮助:
cocos2d-cli --help
查看节点树:
cocos2d-cli tree assets/main.fire
cocos2d-cli tree assets/panel.prefab
从 JSON 预览并生成预制体:
cocos2d-cli screenshot panel.json -o ./screenshots --width 750 --height 1334
cocos2d-cli create-prefab panel.json assets/Panel.prefab
查看场景或预制体的节点树。
cocos2d-cli tree <scene.fire | prefab.prefab>
示例:
cocos2d-cli tree assets/main.fire
获取节点属性,或获取节点上某个组件的属性。
cocos2d-cli get <文件> <节点路径> [属性名 | 组件类型]
说明:
示例:
cocos2d-cli get assets/main.fire Canvas
cocos2d-cli get assets/main.fire Canvas/MidNode x
cocos2d-cli get assets/main.fire Canvas/Label Label
修改节点属性。
cocos2d-cli set <文件> <节点路径> <属性名> <值>
当前支持的常用节点属性:
nameactivexywidthheightanchorXanchorYopacityscaleXscaleYrotation示例:
cocos2d-cli set assets/main.fire Canvas/MidNode x 100
cocos2d-cli set assets/main.fire Canvas/MidNode width 200
cocos2d-cli set assets/main.fire Canvas/MidNode active false
修改节点上某个组件的属性。
cocos2d-cli set-component <文件> <节点路径> <组件类型> <属性名> <值>
示例:
cocos2d-cli set-component assets/main.fire Canvas/Label Label string "Hello"
cocos2d-cli set-component assets/main.fire Canvas/Label Label fontSize 32
cocos2d-cli set-component assets/main.fire Canvas/Sprite Sprite sizeMode 0
不同组件是否支持修改,取决于该组件类是否实现了
setProp。
在指定父节点下添加新节点。
cocos2d-cli add <文件> <父节点路径> <节点名称> [选项]
支持选项:
--x=<数值>--y=<数值>--width=<数值>--height=<数值>--scaleX=<数值>--scaleY=<数值>--rotation=<角度>--active=true|false--type=sprite|label|button--string=<文本>(配合 --type=label)--fontSize=<数值>(配合 --type=label)示例:
cocos2d-cli add assets/main.fire Canvas NewSprite --type=sprite --x=100 --y=50 --width=120 --height=120
cocos2d-cli add assets/main.fire Canvas Title --type=label --string=Hello --fontSize=32
删除指定节点。
cocos2d-cli remove <文件> <节点路径>
示例:
cocos2d-cli remove assets/main.fire Canvas/MidNode
不能删除根节点。
给节点添加组件。
cocos2d-cli add-component <文件> <节点路径> <组件类型>
当前命令中支持的组件类型:
canvaswidgetspritelabelbuttoncamera示例:
cocos2d-cli add-component assets/main.fire Canvas/NewNode sprite
cocos2d-cli add-component assets/main.fire Canvas/Main Camera camera
删除节点上的组件。
cocos2d-cli remove-component <文件> <节点路径> <组件类型>
示例:
cocos2d-cli remove-component assets/main.fire Canvas/NewNode sprite
创建预制体。
cocos2d-cli create-prefab [JSON文件路径] <输出路径.prefab>
行为说明:
.meta 文件示例:
cocos2d-cli create-prefab assets/NewNode.prefab
cocos2d-cli create-prefab panel.json assets/Panel.prefab
创建场景。
cocos2d-cli create-scene [JSON文件路径] <输出路径.fire>
行为说明:
Canvas 和 Main Camerasettings/project.json,会读取设计分辨率.meta 文件示例:
cocos2d-cli create-scene assets/Main.fire
cocos2d-cli create-scene scene.json assets/Scene.fire
扫描 Cocos Creator 项目的 library/imports,构建脚本哈希到类名的映射文件,用于更好地识别自定义脚本组件。
cocos2d-cli build <项目目录>
示例:
cocos2d-cli build D:/my-cocos-project
输出文件默认写到:
cocos2d-cli/data/script_map.json
将 JSON 渲染为页面并截图。
cocos2d-cli screenshot <json文件> [选项]
支持选项:
-o, --output <目录> 输出目录,默认当前目录--width <数值> 视口宽度,默认 750--height <数值> 视口高度,默认 1334--full-page 全页截图(默认)--no-full-page 仅视口截图--debug-bounds 叠加节点边界和名称--timeout <毫秒> 默认 30000--wait <毫秒> 默认 1000示例:
cocos2d-cli screenshot data.json
cocos2d-cli screenshot data.json -o ./screenshots
cocos2d-cli screenshot data.json --width 1080 --height 1920
cocos2d-cli screenshot data.json --debug-bounds
-o/--output是输出目录,不是输出图片文件名。
节点路径使用 / 分隔:
Canvas
Canvas/MidNode
Canvas/GameScene/NodeA
如果路径首段和根节点同名,工具会自动兼容。
{
"name": "Panel",
"width": 400,
"height": 300,
"x": 0,
"y": 0,
"anchorX": 0.5,
"anchorY": 0.5,
"color": "#336699",
"opacity": 255,
"components": [
"sprite",
{ "type": "label", "string": "Hello", "fontSize": 28, "horizontalAlign": "center" }
],
"children": [
{
"name": "Btn",
"width": 200,
"height": 60,
"components": ["sprite", "button"]
}
]
}
namex, ywidth, heightanchorX, anchorYscaleX, scaleYrotationopacityactivecolorcomponentschildrencanvaswidgetspritelabelbuttoncamerarichTextlabel:
{
"type": "label",
"string": "文本内容",
"fontSize": 28,
"lineHeight": 40,
"horizontalAlign": "left",
"verticalAlign": "center",
"color": "#ffffff"
}
richText:
{
"type": "richText",
"string": "普通<color=#ff0000>红色</color>文字<br/>第二行",
"fontSize": 28,
"lineHeight": 40,
"maxWidth": 600,
"horizontalAlign": "left"
}
widget:
{
"type": "widget",
"isAlignLeft": true,
"isAlignRight": true,
"isAlignTop": true,
"isAlignBottom": true,
"left": 0,
"right": 0,
"top": 0,
"bottom": 0
}
Cocos 默认锚点在节点中心:
anchorX = 0.5anchorY = 0.5因此 x / y 通常是相对父节点中心点的偏移。
对于左对齐 / 右对齐文本,更推荐:
anchorX: 0 + horizontalAlign: "left"anchorX: 1 + horizontalAlign: "right"示例:
{
"name": "Amount",
"anchorX": 1,
"x": 330,
"width": 300,
"components": [
{ "type": "label", "string": "¥40.00", "horizontalAlign": "right" }
]
}
screenshot 的输出参数是目录,不是图片路径set-component 是否可修改,取决于组件类是否实现 setPropcreate-scene 不传 JSON 时,会创建默认场景(含 Canvas 和 Main Camera)create-prefab / create-scene 会自动写入 .meta 文件build 生成的脚本映射会写入项目内的 data/script_map.jsonbin/cocos2d-cli.js # CLI 入口
src/commands/ # 各命令实现
src/lib/ # 场景/节点/组件处理逻辑
data/script_map.json # 脚本组件映射
MIT
FAQs
Command-line tools for AI to read and manipulate Cocos Creator 2.4.x project scenes
The npm package cocos2d-cli receives a total of 4 weekly downloads. As such, cocos2d-cli popularity was classified as not popular.
We found that cocos2d-cli demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Research
/Security News
Ten malicious OpenAPI React Query Codegen versions were published to npm in the Mini Shai-Hulud attack, all with valid provenance.

Security News
Socket joins more than 100 technology, cybersecurity, and financial organizations calling for a global surge in cyber defense.

Product
Enterprise security teams can now detect malware, credential theft, suspicious network activity, and risky updates across Microsoft Edge extensions.