Skip to content

Commit 19f5aea

Browse files
author
David Brody
authored
Merge pull request #20 from dbrody/master
Initial 1.0.0 of ContentSync Platform
2 parents d81e17b + 7bcd8a4 commit 19f5aea

File tree

9 files changed

+224
-264
lines changed

9 files changed

+224
-264
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// Works with:
3+
// ./coscript <thisfile>
4+
//
5+
try {
6+
var sketchApp = COScript.app("Sketch")
7+
var plugins = sketchApp.delegate().pluginManager().plugins()
8+
var plugin = plugins["com.github.contentsync.sketchcontentsync"]
9+
var commands = plugin.commands();
10+
var command = commands["appopen_contentsync"];
11+
sketchApp.delegate().runPluginCommand_fromMenu(command, false);
12+
} catch(e){
13+
log("ContentSync appcall Error:")
14+
log(e);
15+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@import './lib/MasterSymbolMapper.js';
2+
@import './lib/TextLayerUpdater.js';
3+
@import './lib/ContentSyncStateStore.js';
4+
5+
var onRun = function(context) {
6+
var doc = context.document;
7+
var contentsyncFile = doc.fileURL().path() + ".contentsync"
8+
var fileContentsJsonString = [[NSString alloc]initWithContentsOfFile:contentsyncFile encoding:NSUTF8StringEncoding error:nil];
9+
var data = [fileContentsJsonString dataUsingEncoding:NSUTF8StringEncoding];
10+
var json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
11+
12+
// MasterSymbol mapping for symbol handling
13+
var stateStore = new ContentSyncStateStore();
14+
// Store symbol map
15+
stateStore.set('symbolmap', (new MasterSymbolMapper()).generate(doc).map());
16+
// Store selected version
17+
var selectedVersion = json["selection"]["versionName"]
18+
stateStore.version(selectedVersion);
19+
// Store data
20+
stateStore.set('synckeys', json["data"]["versions"]);
21+
22+
var textUpdater = new TextLayerUpdater(doc)
23+
textUpdater.update(stateStore);
24+
delete textUpdater;
25+
26+
doc.showMessage('Content Sync Completed - Version: ' + selectedVersion);
27+
};

Contents/Sketch/contentsync.google.js

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
@import './lib/MacOSAppCommunicator.js';
3+
4+
var onRun = function(context) {
5+
var commands = {
6+
sketch_file:true,
7+
import: true,
8+
export: false
9+
};
10+
var comm = new MacOSAppCommunicator(context);
11+
comm.sendJSONCommands(commands);
12+
};

Contents/Sketch/helpers/GoogleSyncHelpers.js

Lines changed: 0 additions & 165 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
@import './lib/Utils.js'
2+
3+
var kPluginName = "ContentSync",
4+
kPluginDomain = "com.syncify.ContentSync"
5+
6+
var MacOSAppCommunicator = function(context){
7+
var self = this;
8+
self.context = context;
9+
10+
// List of paths where the ContentSync.app may be
11+
// Multiple items is useful for development.
12+
self.appPaths = [
13+
"~/Library/Developer/Xcode/DerivedData/ContentSync-aczvmrxkkrbszrftgltjcizttdxl/Build/Products/Debug/ContentSync.app",
14+
"/Applications/ContentSync.app"
15+
];
16+
17+
self.sendJSONCommands = function(params) {
18+
if(!self.context.document || !self.context.document.fileURL()){
19+
Utils.showDialog("Could not launch plugin. Please save this file first.")
20+
return;
21+
};
22+
var sketchFilePath = self.context.document.fileURL().path();
23+
var
24+
sp = self.context.scriptPath,
25+
uniqueID = [[NSUUID UUID] UUIDString],
26+
tempFolderPath = Utils.getTempFolderPath("temp-commands/"+uniqueID),
27+
jsonPath = sketchFilePath + ".contentsync",
28+
bundlePath = [[NSBundle mainBundle] bundlePath],
29+
appName = [[NSFileManager defaultManager] displayNameAtPath: bundlePath],
30+
d = [NSMutableDictionary new],
31+
val;
32+
33+
for (var key in params) {
34+
val = params[key]
35+
[d setValue:val forKey:key]
36+
}
37+
[d setValue:[sketchFilePath lastPathComponent] forKey:"sketchfilename"]
38+
[d setValue:sketchFilePath forKey:"sketchfilepath"]
39+
[d setValue:kPluginDomain forKey:"pluginDomain"]
40+
41+
var jData = [NSJSONSerialization dataWithJSONObject:d options:0 error:nil];
42+
var jsonString = [[NSString alloc] initWithData:jData encoding:NSUTF8StringEncoding]
43+
44+
Utils.writeTextToFile(jsonString, jsonPath)
45+
46+
// Try each path until one succeeds
47+
for(var i = 0; i < self.appPaths.length; i++){
48+
var appPath = self.appPaths[i];
49+
var path = [NSString stringWithFormat:@"%@", appPath];
50+
appPath = path.expandTilde();
51+
52+
if([[NSWorkspace sharedWorkspace] openFile:jsonPath withApplication:appPath]]) {
53+
// Able to launch with path
54+
log("Found at path: " + appPath);
55+
return true;
56+
}
57+
}
58+
Utils.showDialog("Could not launch plugin. Please make sure you have ContentSync.app installed.")
59+
}
60+
};

0 commit comments

Comments
 (0)