cocos2d-cli 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cocos-cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- /**
2
+ /**
3
3
  * Cocos Creator CLI
4
4
  * Command-line tools for AI to read and manipulate Cocos Creator 2.4.x project scenes
5
5
  */
@@ -15,26 +15,30 @@ const commands = {
15
15
  'add-component': '../src/commands/add-component',
16
16
  'remove': '../src/commands/remove',
17
17
  delete: '../src/commands/delete',
18
- build: '../src/commands/build'
18
+ build: '../src/commands/build',
19
+ 'prefab-create': '../src/commands/prefab-create',
20
+ 'create-scene': '../src/commands/create-scene'
19
21
  };
20
22
 
21
23
  // 帮助信息
22
24
  function showHelp() {
23
25
  console.log(`
24
- Cocos Creator CLI - 场景操作工具集
26
+ Cocos Creator CLI - 场景/预制体操作工具集
25
27
 
26
28
  用法:
27
29
  cocos2.4 <command> [options]
28
30
 
29
31
  命令:
30
- tree <场景文件路径> 查看节点树
31
- get <场景文件路径> <节点> 获取节点信息
32
- set <场景文件路径> <节点> [选项] 修改节点属性
33
- add <场景文件路径> <父节点> <名称> 添加节点
34
- add-component <场景文件路径> <节点> <类型> 给节点添加组件
35
- remove <场景路径> <索引> 删除节点或组件
36
- delete <场景文件路径> <节点> 删除节点
37
- build <项目目录> 构建组件映射
32
+ tree <场景.fire | 预制体.prefab> 查看节点树(获取索引)
33
+ get <场景.fire | 预制体.prefab> <索引> 获取节点属性
34
+ set <场景.fire | 预制体.prefab> <索引> [选项] 修改节点属性
35
+ add <场景.fire | 预制体.prefab> <父索引> <名称> 添加节点
36
+ add-component <文件> <节点索引> <类型> 给节点添加组件
37
+ remove <文件> <索引> 删除节点或组件
38
+ delete <文件> <节点索引> 删除节点
39
+ build <项目目录> 构建组件映射
40
+ prefab-create <预制体路径> <根节点名称> 创建新预制体文件
41
+ create-scene <输出路径.fire> [场景名称] 从 stdin 创建场景文件
38
42
 
39
43
  选项:
40
44
  --name=<名称> 修改节点名称
@@ -50,19 +54,33 @@ Cocos Creator CLI - 场景操作工具集
50
54
  --rotation=<角度> 修改旋转角度
51
55
  --scaleX=<数值> 修改 X 缩放
52
56
  --scaleY=<数值> 修改 Y 缩放
53
- --type=sprite/label 添加节点时指定组件类型
54
- --at=<位置> 添加节点时指定插入位置
57
+ --type=sprite/label/button 添加节点时指定组件类型
58
+ --at=<索引> 添加节点时插入到子节点的指定位置(0=第一个)
59
+
60
+ create-scene 支持的组件类型:
61
+ sprite, label, button, layout, widget, camera, canvas, particle
62
+
63
+ create-scene 节点选项:
64
+ #width=100 设置宽度
65
+ #height=50 设置高度
66
+ #x=10 设置 X 坐标
67
+ #y=20 设置 Y 坐标
55
68
 
56
69
  示例:
57
70
  cocos2.4 tree assets/main.fire
58
- cocos2.4 get assets/main.fire Canvas
59
- cocos2.4 set assets/main.fire Canvas/Player --x=100 --y=200
60
- cocos2.4 add assets/main.fire Canvas NewSprite --type=sprite --x=100
61
- cocos2.4 add-component assets/main.fire Canvas/Player sprite
62
- cocos2.4 delete assets/main.fire OldNode
63
- cocos2.4 build ./my-project
64
-
65
- 版本: 1.0.2
71
+ cocos2.4 get assets/main.fire 5
72
+ cocos2.4 set assets/main.fire 8 --x=100 --y=200 --color=#ff0000
73
+ cocos2.4 add assets/main.fire 5 NewSprite --type=sprite --x=100
74
+ cocos2.4 prefab-create assets/MyPanel.prefab Panel
75
+
76
+ # 从树形结构创建场景
77
+ echo "Canvas (canvas)
78
+ ├─ TopBar (sprite, widget) #width=720 #height=80
79
+ │ ├─ ScoreLabel (label)
80
+ │ └─ GoldLabel (label)
81
+ └─ GameArea" | cocos2.4 create-scene assets/game.fire
82
+
83
+ 版本: 1.1.0
66
84
  `);
67
85
  }
68
86
 
@@ -0,0 +1,72 @@
1
+ [
2
+ {
3
+ "__type__": "cc.Prefab",
4
+ "_name": "",
5
+ "_objFlags": 0,
6
+ "_native": "",
7
+ "data": {
8
+ "__id__": 1
9
+ },
10
+ "optimizationPolicy": 0,
11
+ "asyncLoadAssets": false,
12
+ "readonly": false
13
+ },
14
+ {
15
+ "__type__": "cc.Node",
16
+ "_name": "RootNode",
17
+ "_objFlags": 0,
18
+ "_parent": null,
19
+ "_children": [],
20
+ "_active": true,
21
+ "_components": [],
22
+ "_prefab": {
23
+ "__id__": 2
24
+ },
25
+ "_opacity": 255,
26
+ "_color": {
27
+ "__type__": "cc.Color",
28
+ "r": 255,
29
+ "g": 255,
30
+ "b": 255,
31
+ "a": 255
32
+ },
33
+ "_contentSize": {
34
+ "__type__": "cc.Size",
35
+ "width": 0,
36
+ "height": 0
37
+ },
38
+ "_anchorPoint": {
39
+ "__type__": "cc.Vec2",
40
+ "x": 0.5,
41
+ "y": 0.5
42
+ },
43
+ "_trs": {
44
+ "__type__": "TypedArray",
45
+ "ctor": "Float64Array",
46
+ "array": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1]
47
+ },
48
+ "_eulerAngles": {
49
+ "__type__": "cc.Vec3",
50
+ "x": 0,
51
+ "y": 0,
52
+ "z": 0
53
+ },
54
+ "_skewX": 0,
55
+ "_skewY": 0,
56
+ "_is3DNode": false,
57
+ "_groupIndex": 0,
58
+ "groupIndex": 0,
59
+ "_id": ""
60
+ },
61
+ {
62
+ "__type__": "cc.PrefabInfo",
63
+ "root": {
64
+ "__id__": 1
65
+ },
66
+ "asset": {
67
+ "__id__": 0
68
+ },
69
+ "fileId": "",
70
+ "sync": false
71
+ }
72
+ ]
@@ -0,0 +1,241 @@
1
+ [
2
+ {
3
+ "__type__": "cc.SceneAsset",
4
+ "_name": "",
5
+ "_objFlags": 0,
6
+ "_native": "",
7
+ "scene": {
8
+ "__id__": 1
9
+ }
10
+ },
11
+ {
12
+ "__type__": "cc.Scene",
13
+ "_objFlags": 0,
14
+ "_parent": null,
15
+ "_children": [
16
+ {
17
+ "__id__": 2
18
+ }
19
+ ],
20
+ "_active": true,
21
+ "_components": [],
22
+ "_prefab": null,
23
+ "_opacity": 255,
24
+ "_color": {
25
+ "__type__": "cc.Color",
26
+ "r": 255,
27
+ "g": 255,
28
+ "b": 255,
29
+ "a": 255
30
+ },
31
+ "_contentSize": {
32
+ "__type__": "cc.Size",
33
+ "width": 0,
34
+ "height": 0
35
+ },
36
+ "_anchorPoint": {
37
+ "__type__": "cc.Vec2",
38
+ "x": 0,
39
+ "y": 0
40
+ },
41
+ "_trs": {
42
+ "__type__": "TypedArray",
43
+ "ctor": "Float64Array",
44
+ "array": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1]
45
+ },
46
+ "_is3DNode": true,
47
+ "_groupIndex": 0,
48
+ "groupIndex": 0,
49
+ "autoReleaseAssets": false,
50
+ "_id": ""
51
+ },
52
+ {
53
+ "__type__": "cc.Node",
54
+ "_name": "Canvas",
55
+ "_objFlags": 0,
56
+ "_parent": {
57
+ "__id__": 1
58
+ },
59
+ "_children": [
60
+ {
61
+ "__id__": 3
62
+ }
63
+ ],
64
+ "_active": true,
65
+ "_components": [
66
+ {
67
+ "__id__": 5
68
+ },
69
+ {
70
+ "__id__": 6
71
+ }
72
+ ],
73
+ "_prefab": null,
74
+ "_opacity": 255,
75
+ "_color": {
76
+ "__type__": "cc.Color",
77
+ "r": 255,
78
+ "g": 255,
79
+ "b": 255,
80
+ "a": 255
81
+ },
82
+ "_contentSize": {
83
+ "__type__": "cc.Size",
84
+ "width": 960,
85
+ "height": 640
86
+ },
87
+ "_anchorPoint": {
88
+ "__type__": "cc.Vec2",
89
+ "x": 0.5,
90
+ "y": 0.5
91
+ },
92
+ "_trs": {
93
+ "__type__": "TypedArray",
94
+ "ctor": "Float64Array",
95
+ "array": [480, 320, 0, 0, 0, 0, 1, 1, 1, 1]
96
+ },
97
+ "_eulerAngles": {
98
+ "__type__": "cc.Vec3",
99
+ "x": 0,
100
+ "y": 0,
101
+ "z": 0
102
+ },
103
+ "_skewX": 0,
104
+ "_skewY": 0,
105
+ "_is3DNode": false,
106
+ "_groupIndex": 0,
107
+ "groupIndex": 0,
108
+ "_id": ""
109
+ },
110
+ {
111
+ "__type__": "cc.Node",
112
+ "_name": "Main Camera",
113
+ "_objFlags": 0,
114
+ "_parent": {
115
+ "__id__": 2
116
+ },
117
+ "_children": [],
118
+ "_active": true,
119
+ "_components": [
120
+ {
121
+ "__id__": 4
122
+ }
123
+ ],
124
+ "_prefab": null,
125
+ "_opacity": 255,
126
+ "_color": {
127
+ "__type__": "cc.Color",
128
+ "r": 255,
129
+ "g": 255,
130
+ "b": 255,
131
+ "a": 255
132
+ },
133
+ "_contentSize": {
134
+ "__type__": "cc.Size",
135
+ "width": 0,
136
+ "height": 0
137
+ },
138
+ "_anchorPoint": {
139
+ "__type__": "cc.Vec2",
140
+ "x": 0.5,
141
+ "y": 0.5
142
+ },
143
+ "_trs": {
144
+ "__type__": "TypedArray",
145
+ "ctor": "Float64Array",
146
+ "array": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1]
147
+ },
148
+ "_eulerAngles": {
149
+ "__type__": "cc.Vec3",
150
+ "x": 0,
151
+ "y": 0,
152
+ "z": 0
153
+ },
154
+ "_skewX": 0,
155
+ "_skewY": 0,
156
+ "_is3DNode": false,
157
+ "_groupIndex": 0,
158
+ "groupIndex": 0,
159
+ "_id": ""
160
+ },
161
+ {
162
+ "__type__": "cc.Camera",
163
+ "_name": "",
164
+ "_objFlags": 0,
165
+ "node": {
166
+ "__id__": 3
167
+ },
168
+ "_enabled": true,
169
+ "_cullingMask": 4294967295,
170
+ "_clearFlags": 7,
171
+ "_backgroundColor": {
172
+ "__type__": "cc.Color",
173
+ "r": 0,
174
+ "g": 0,
175
+ "b": 0,
176
+ "a": 255
177
+ },
178
+ "_depth": -1,
179
+ "_zoomRatio": 1,
180
+ "_targetTexture": null,
181
+ "_fov": 60,
182
+ "_orthoSize": 10,
183
+ "_nearClip": 1,
184
+ "_farClip": 4096,
185
+ "_ortho": true,
186
+ "_rect": {
187
+ "__type__": "cc.Rect",
188
+ "x": 0,
189
+ "y": 0,
190
+ "width": 1,
191
+ "height": 1
192
+ },
193
+ "_renderStages": 1,
194
+ "_alignWithScreen": true,
195
+ "_id": ""
196
+ },
197
+ {
198
+ "__type__": "cc.Canvas",
199
+ "_name": "",
200
+ "_objFlags": 0,
201
+ "node": {
202
+ "__id__": 2
203
+ },
204
+ "_enabled": true,
205
+ "_designResolution": {
206
+ "__type__": "cc.Size",
207
+ "width": 960,
208
+ "height": 640
209
+ },
210
+ "_fitWidth": false,
211
+ "_fitHeight": true,
212
+ "_id": ""
213
+ },
214
+ {
215
+ "__type__": "cc.Widget",
216
+ "_name": "",
217
+ "_objFlags": 0,
218
+ "node": {
219
+ "__id__": 2
220
+ },
221
+ "_enabled": true,
222
+ "alignMode": 1,
223
+ "_target": null,
224
+ "_alignFlags": 45,
225
+ "_left": 0,
226
+ "_right": 0,
227
+ "_top": 0,
228
+ "_bottom": 0,
229
+ "_verticalCenter": 0,
230
+ "_horizontalCenter": 0,
231
+ "_isAbsLeft": true,
232
+ "_isAbsRight": true,
233
+ "_isAbsTop": true,
234
+ "_isAbsBottom": true,
235
+ "_isAbsHorizontalCenter": true,
236
+ "_isAbsVerticalCenter": true,
237
+ "_originalWidth": 0,
238
+ "_originalHeight": 0,
239
+ "_id": ""
240
+ }
241
+ ]
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
- "name": "cocos2d-cli",
3
- "version": "1.0.4",
2
+ "name": "cocos2d-cli",
3
+ "version": "1.1.0",
4
4
  "description": "Command-line tools for AI to read and manipulate Cocos Creator 2.4.x project scenes",
5
- "main": "src/lib/index.js",
5
+ "main": "bin/cocos-cli.js",
6
6
  "bin": {
7
7
  "cocos2d-cli": "./bin/cocos-cli.js"
8
8
  },
@@ -12,9 +12,7 @@
12
12
  "data"
13
13
  ],
14
14
  "scripts": {
15
- "test": "bash test/run.sh",
16
- "test:structure": "node test/verify_structure.js",
17
- "test:cli": "bash test/run.sh"
15
+ "test": "echo \"No tests specified\" && exit 1"
18
16
  },
19
17
  "keywords": [
20
18
  "cocos",