-
Notifications
You must be signed in to change notification settings - Fork 1
/
manager.js
49 lines (46 loc) · 1.83 KB
/
manager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var exec = require('child_process').exec
var dom
var cmdStr = 'ibtool ./View.xib --objects --connections --hierarchy'
///path/to/xibOrStroyborad
exec(cmdStr, {
encoding: 'utf8',
timeout: 0,
maxBuffer: 5000 * 1024, // 默认 200 * 1024
killSignal: 'SIGTERM'
}, function (err, stdout, stderr) {
if (err) {
console.log(cmdStr + ' error:' + stderr + "|||||| err:" + err)
} else {
var plist = require('plist').parse(stdout)
var PlistCenterModule = require("./plistData")
var plistCenter = new PlistCenterModule.PlistCenter(plist)
var ViewModule = require("./view")
var ControllerModule = require("./controller")
var ConstraintModule = require("./constraint")
var hierarchys = plist["com.apple.ibtool.document.hierarchy"]
let objects = plist["com.apple.ibtool.document.objects"]
if (cmdStr.indexOf("storyboard") != -1) {
//是storyboard
//想要生成层次,hierarchys是最合适的遍历格式
for (var i = 0; i < hierarchys.length; i++) {
var hierarch = hierarchys[i]
//最上层应该是controller
let id_lu = hierarch["object-id"]
let type = plistCenter.getTypeOf(id_lu)
if (type == plistCenter.ObjectType.Controller) {
let control = new ControllerModule.Controller(id_lu, plistCenter)
console.log(control.description)
}
}
} else {
//是xib
for (key in objects) {
let type = plistCenter.getTypeOf(key)
if (type == plistCenter.ObjectType.View) {
let control = new ViewModule.View(key, plistCenter)
console.log(control.description)
}
}
}
}
})