-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathmain.js
44 lines (40 loc) · 1.25 KB
/
main.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
const { showDialogY } = require("./dialog.js");
const { mapScreen } = require("./nodeMapper.js");
const { findArtboardInParent } = require("./scenegraphUtils.js");
const { saveText, saveTexts } = require("./textWriter.js");
const saveScreen = () => {
const { selection } = require("scenegraph");
let artboards = findArtboards(selection.items);
let length = artboards.length
if( length == 0 ){
showDialogY("Please select any node");
return;
}else if( length == 1 ){
let screenData = mapScreen(artboards[0]);
saveText(artboards[0].name + ".xda", JSON.stringify(screenData, null , "\t"));
}else{
let fileInfos = artboards.map( a => {
let screenData = mapScreen(a);
return {
"name" : a.name + ".xda",
"text" : JSON.stringify(screenData, null , "\t")
}
});
saveTexts(fileInfos);
}
}
const findArtboards = (nodes) => {
let rtn = []
nodes.forEach(x => {
let artboard = findArtboardInParent(x);
if(artboard != null && rtn.every(y => y.guid != artboard.guid)){
rtn.push(artboard);
}
});
return rtn;
}
module.exports = {
commands: {
"exportXda": saveScreen
}
};