This repository has been archived by the owner on Oct 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.js
59 lines (48 loc) · 1.46 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function getFileContents(path) {
return NSString.stringWithContentsOfFile_encoding_error(path, NSUTF8StringEncoding, nil)
}
function getCurrentPath() {
return NSProcessInfo.processInfo().arguments()[0].stringByDeletingLastPathComponent();
}
function splitLines(str) {
return str.match(/[^\r\n]+/g)
}
function getMergedObject() {
var obj = {},
i = 0,
il = arguments.length,
key;
for (; i < il; i++) {
for (key in arguments[i]) {
if (arguments[i].hasOwnProperty(key)) {
obj[key] = arguments[i][key];
}
}
}
return obj;
};
function main() {
var appIdentifier = 'com.bohemiancoding.sketch3';
var pluginSession = "SketchPlugin-" + Date.now();
print("Running...");
var origPluginCode = getFileContents('bundle.js');
origPluginCode = origPluginCode.replace(/%CURRENT_PATH%/, getCurrentPath());
// Find the Sketch application
sketch = COScript.applicationForIdentifier(appIdentifier)
if (!sketch) {
throw Error("Cannot find Sketch for " + appIdentifier)
}
// Parse the output and see what we get
var pluginCode;
var log;
print('Exporting...')
pluginCode = origPluginCode.replace(/%TYPE%/, 'export');
log = sketch.delegate().runPluginScript_name(pluginCode, pluginSession);
print(log)
print('Importing...')
pluginCode = origPluginCode.replace(/%TYPE%/, 'import');
sketch.delegate().openTemplateAtPath(null);
log = sketch.delegate().runPluginScript_name(pluginCode, pluginSession);
print(log)
}
main()