Skip to content

Commit

Permalink
newsync
Browse files Browse the repository at this point in the history
  • Loading branch information
bugluo committed Jan 21, 2019
1 parent 1f6b989 commit b075bce
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 24 deletions.
6 changes: 2 additions & 4 deletions WeSketch.sketchplugin/Contents/Sketch/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
{"key":"zhCN","name":"简体中文(zhCN)"},
{"key":"zhTW","name":"繁體中文(zhTW)"}
],
"UIKIT": [{"title":"WeUI","url":"http:https://tmtdemo.qq.com/sketch/weui.sketch"},
{"title":"AndroidDesign","url":"http:https://tmtdemo.qq.com/sketch/android.sketch"},
{"title":"iOSDesign","url":"http:https://tmtdemo.qq.com/sketch/iOS.sketch"}
"UIKIT": [{"title":"WeChat UI Kit","url":"https://team.weui.io/double/WeChat.sketch"}
],
"COLOR": [{"title":"WeUI","url":"http:https://tmtdemo.qq.com/wechatcolor.json"
"COLOR": [{"title":"WeUI","url":""
}]
}
5 changes: 2 additions & 3 deletions WeSketch.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Miaow",
"author": "Tencent WeChat",
"version": "1.4.4",
"version": "1.4.5",
"identifier": "cn.wechat",
"description": "A set of plugins for Sketch include drawing links & marks, UI Kit & Color sync, font & text replacing",
"icon": "minicon.png",
Expand Down Expand Up @@ -132,7 +132,6 @@
"script" : "iconQ.js",
"icon": "../Resources/icons/icon.png",
"shortcut": "",
"istool":"true",
"handler" : "iconQRun"
},
{
Expand Down Expand Up @@ -183,7 +182,7 @@
{
"name" : "Sync UI Kit",
"identifier" : "syncuikit",
"script" : "syncUIkit.js",
"script" : "newSyncUIkit.js",
"icon": "../Resources/icons/syncui.png",
"shortcut": "",
"istool":"true",
Expand Down
280 changes: 280 additions & 0 deletions WeSketch.sketchplugin/Contents/Sketch/newSyncUikit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
var that = this;
function __skpm_run (key, context) {
that.context = context;

var exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {

module.exports = require("sketch/dom");

/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";


Object.defineProperty(exports, "__esModule", {
value: true
});
var UI = __webpack_require__(2);
var sketchDom = __webpack_require__(0);
var Library = __webpack_require__(0).Library;

var pageLayers = [];
var selectedArtboard = void 0;
var previewOnline = void 0;

// exportTo
var syncUIKit = function syncUIKit(context, fileType, fileMarkup) {

// var _ = function (context) {
// var i18nKey = "com.sketchplugins.wechat.i18n";
// var lang = NSUserDefaults.standardUserDefaults().objectForKey(i18nKey);
// if (lang == undefined) {
// var macOSVersion = NSDictionary.dictionaryWithContentsOfFile("/System/Library/CoreServices/SystemVersion.plist").objectForKey("ProductVersion") + "";
// lang = NSUserDefaults.standardUserDefaults().objectForKey("AppleLanguages").objectAtIndex(0);
// lang = (macOSVersion >= "10.12") ? lang.split("-").slice(0, -1).join("-") : lang;
// if (lang.indexOf('zh') > -1) {
// lang = 'zhCN';
// } else {
// lang = 'enUS';
// }
// NSUserDefaults.standardUserDefaults().setObject_forKey(lang, i18nKey);
// }
// if (encodeURIComponent(lang.toString()).length != 4) {
// lang = 'enUS';
// NSUserDefaults.standardUserDefaults().setObject_forKey(lang, i18nKey);
// }

// function get_(json, context) {
// var manifestPath = context.plugin.url().URLByAppendingPathComponent("Contents").URLByAppendingPathComponent("Sketch").URLByAppendingPathComponent("i18n").URLByAppendingPathComponent(json + ".json").path();
// var jsonData = NSData.dataWithContentsOfFile(manifestPath);
// jsonData = NSString.alloc().initWithData_encoding(jsonData,NSUTF8StringEncoding);
// return JSON.parse(jsonData);
// }
// var i18Content = {};
// i18Content = get_(lang, context);

// return i18Content;
// };

// const i18 = _(context).syncUIkit;

// context.document.showMessage(i18.m1);

var uiKitUrlKey = "com.sketchplugins.wechat.newuikiturl";
var colorUrlKey = "com.sketchplugins.wechat.colorurl";

var document = sketchDom.fromNative(context.document);
var page = document.selectedPage;
pageLayers = page.layers;

var getConfig = function getConfig(json, content) {
var manifestPath = context.plugin.url().URLByAppendingPathComponent("Contents").URLByAppendingPathComponent("Sketch").URLByAppendingPathComponent(json + ".json").path();
return NSJSONSerialization.JSONObjectWithData_options_error(NSData.dataWithContentsOfFile(manifestPath), NSJSONReadingMutableContainers, nil);
};

function networkRequest(args) {
var task = NSTask.alloc().init();
task.setLaunchPath("/usr/bin/curl");
task.setArguments(args);
var outputPipe = NSPipe.pipe();
task.setStandardOutput(outputPipe);
task.launch();
var responseData = outputPipe.fileHandleForReading().readDataToEndOfFile();
return responseData;
}

var getUIKIT = function getUIKIT(content) {
var List = NSUserDefaults.standardUserDefaults().objectForKey(uiKitUrlKey) || getConfig('config', context).UIKIT;
return List;
};
var uikitList = getUIKIT(context);

function createRadioButtons(options, selected, format, x, y) {
var rows = options.length,
columns = 1,
matrixWidth = 300,
cellWidth = matrixWidth,
x = x ? x : 0,
y = y ? y : 0;

if (format && format != 0) {
rows = options.length / 2;
columns = 2;
matrixWidth = 300;
cellWidth = matrixWidth / columns;
}

var buttonCell = NSButtonCell.alloc().init();

buttonCell.setButtonType(NSRadioButton);

var matrix = NSMatrix.alloc().initWithFrame_mode_prototype_numberOfRows_numberOfColumns(NSMakeRect(x, y, matrixWidth, rows * 20), NSRadioModeMatrix, buttonCell, rows, columns);

matrix.setCellSize(NSMakeSize(cellWidth, 20));

options.forEach(function (option, i) {
matrix.cells().objectAtIndex(i).setTitle(option);
matrix.cells().objectAtIndex(i).setTag(i);
});

matrix.selectCellAtRow_column(selected, 0);

return matrix;
}

var runExportModal = function runExportModal() {
var exportModal = COSAlertWindow["new"]();
var iconImage = NSImage.alloc().initByReferencingFile(context.plugin.urlForResourceNamed("icon.png").path());
if (iconImage) {
exportModal.setIcon(iconImage);
}
exportModal.setMessageText("\u8BF7\u9009\u62E9\u8981\u5BFC\u5165\u7684 Library");
exportModal.addButtonWithTitle("确认");
exportModal.addButtonWithTitle("取消");

var viewWidth = 300;
var viewHeight = 20 * uikitList.length;
var view = NSView.alloc().initWithFrame(NSMakeRect(0, 0, viewWidth, viewHeight));
exportModal.addAccessoryView(view);

var scaleOptionsMatrix;
var ButtonList = [];

uikitList.forEach(function (uikiti) {
if (uikiti.title != '' && uikiti.url != '') {
var key = uikiti.title;
ButtonList.push(key);
}
});

scaleOptionsMatrix = createRadioButtons(ButtonList, ButtonList[0]);

var checkboxPreview = NSButton.alloc().initWithFrame(NSMakeRect(0, 20, viewWidth, 22));

view.addSubview(scaleOptionsMatrix);

var resultExportModal = exportModal.runModal();
if (resultExportModal != "1000") {
return;
} else {
var uikit = scaleOptionsMatrix.selectedCell();
context.document.showMessage(uikit);

var index = uikit.tag();
context.document.showMessage(index);

var data = networkRequest([uikitList[index].url]);
var save = NSSavePanel.savePanel();
var databasePath = (save.URL().path() + '.sketch').replace('Untitled', 'WeChat');
data = NSData.alloc().initWithData(data);
data.writeToFile_atomically(databasePath, true);

var library = Library.getLibraryForDocumentAtPath(databasePath);

context.document.showMessage('导入成功,请在 Symbol 中使用您的 Library');
}
};

var parseContent = async function parseContent(pageLayers, artboard, directoryPath, file) {
var content = await getParsedContent(pageLayers, artboard, directoryPath, fileType);
await saveContentToFile(directoryPath, file, content);
UI.alert("Export complete.", "\uD83C\uDF89\uD83C\uDF89 " + String(artboard) + " was successfully exported to " + String(fileMarkup) + ".");
return content;
};

// save content to file
var saveContentToFile = function saveContentToFile(path, file, content) {
fs.writeFileSync("" + String(path) + String(file), content, "utf8");
};

runExportModal();
};

exports["default"] = syncUIKit;

/***/ }),
/* 2 */
/***/ (function(module, exports) {

module.exports = require("sketch/ui");

/***/ })
/******/ ]);
if (key === 'default' && typeof exports === 'function') {
exports(context);
} else {
exports[key](context);
}
}
that['onRun'] = __skpm_run.bind(this, 'default')
var newSyncUikit = __skpm_run.bind(this, 'default')
4 changes: 2 additions & 2 deletions WeSketch.sketchplugin/Contents/Sketch/syncSetting.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import "common.js";
var uiKitUrlKey = "com.sketchplugins.wechat.uikiturl";
var colorUrlKey = "com.sketchplugins.wechat.colorurl";
var uiKitUrlKey = "com.sketchplugins.wechat.newuikiturl";
var colorUrlKey = "com.sketchplugins.wechat.newcolorurl";

var onRun = function (context) {

Expand Down
4 changes: 2 additions & 2 deletions WeSketch.sketchplugin/Contents/Sketch/syncUIkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function syncUIkit(context) {
var i18 = _(context).syncUIkit;
var scaleOptionsMatrix;
var scaleOptionsMatrix2;
var uiKitUrlKey = "com.sketchplugins.wechat.uikiturl";
var colorUrlKey = "com.sketchplugins.wechat.colorurl";
var uiKitUrlKey = "com.sketchplugins.wechat.newuikiturl";
var colorUrlKey = "com.sketchplugins.wechat.newcolorurl";

function chooseKit(context) {
var settingsWindow = dialog(context);
Expand Down
Loading

0 comments on commit b075bce

Please sign in to comment.