sf-sketch-rpc
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -6,2 +6,7 @@ Object.defineProperty(exports, "__esModule", { | ||
var _templateObject = _taggedTemplateLiteral([''], ['']), | ||
_templateObject2 = _taggedTemplateLiteral(['\n(function (bundlePath, bundleId) {\n var commandDescriptors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];\n\n\n // Embedded Utils.\n var _isBoxedObject = function _isBoxedObject(obj) {\n return toString.call(obj) == \'[object MOBoxedObject]\';\n };\n\n var _isArray = function _isArray(obj) {\n return Array.isArray(obj);\n };\n\n var _each = function _each(collection) {\n var iteratee = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};\n\n if (_isBoxedObject(collection) && collection.className() == \'NSArray\') {\n var count = collection.count();\n for (var i = 0; i < count; i++) {\n iteratee(collection.objectAtIndex(i), i);\n }\n } else if (_isArray(collection)) {\n for (var _i = 0; _i < collection.length; _i++) {\n iteratee(collection[_i], _i);\n }\n }\n };\n\n var _ = {\n isBoxedObject: _isBoxedObject,\n isArray: _isArray,\n each: _each\n };\n\n // Bootstrapper logic.\n var appController = NSApp.delegate();\n var pluginsManager = appController.pluginManager();\n\n var allRunningCommands = pluginsManager.runningCommands().allValues();\n _.each(allRunningCommands, function (command) {\n if (command.pluginBundle().identifier() == bundleId) {\n print(\'Tearing down sessions for command: \' + command.identifier());\n command.tearDownSession();\n }\n });\n\n pluginsManager.cleanupFinishedCommands();\n\n var plugins = pluginsManager.plugins();\n\n var url = NSURL.fileURLWithPath(bundlePath);\n var bundle = MSPluginBundle.pluginBundleWithURL(url);\n\n var findPluginsMenu = function findPluginsMenu() {\n var mainMenu = NSApp.mainMenu();\n var pluginsMenuItem = mainMenu.itemWithTitle(\'Plugins\');\n\n var menu = pluginsMenuItem.submenu();\n return menu;\n };\n\n var pls = NSMutableDictionary.dictionaryWithDictionary(plugins);\n pls[bundle.identifier()] = bundle;\n pluginsManager.plugins = NSDictionary.dictionaryWithDictionary(pls);\n\n // Inserting menu item.\n var menu = findPluginsMenu();\n\n var customMenu = NSMenu.alloc().init();\n pluginsManager.addCommands_toMenu_fromDescription_selector(bundle.commands(), customMenu, bundle.menuDescription(), NSSelectorFromString(\'runPlugin:\'));\n\n var menuItem = NSMenuItem.alloc().init();\n menuItem.title = bundle.name() + " (dev)";\n menuItem.submenu = customMenu;\n\n menu.insertItem_atIndex(menuItem, 0);\n menu.insertItem_atIndex(NSMenuItem.separatorItem(), 1);\n\n // Execute commands\n _.each(commandDescriptors, function (descriptor) {\n var command = bundle.commands()[descriptor.identifier];\n\n var context = MSDocument.currentDocument().pluginContext();\n var cmdContext = command.fullContextFromContext_url(context, bundle.url());\n cmdContext.remoteContext = descriptor.context;\n command.run_manager(cmdContext, pluginsManager);\n });\n})("<<\'{{{pluginBundlePath}}}\'>>", "<<\'{{{bundleID}}}\'>>", "<<{{{commandDescriptors}}}>>");\n'], ['\n(function (bundlePath, bundleId) {\n var commandDescriptors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];\n\n\n // Embedded Utils.\n var _isBoxedObject = function _isBoxedObject(obj) {\n return toString.call(obj) == \'[object MOBoxedObject]\';\n };\n\n var _isArray = function _isArray(obj) {\n return Array.isArray(obj);\n };\n\n var _each = function _each(collection) {\n var iteratee = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};\n\n if (_isBoxedObject(collection) && collection.className() == \'NSArray\') {\n var count = collection.count();\n for (var i = 0; i < count; i++) {\n iteratee(collection.objectAtIndex(i), i);\n }\n } else if (_isArray(collection)) {\n for (var _i = 0; _i < collection.length; _i++) {\n iteratee(collection[_i], _i);\n }\n }\n };\n\n var _ = {\n isBoxedObject: _isBoxedObject,\n isArray: _isArray,\n each: _each\n };\n\n // Bootstrapper logic.\n var appController = NSApp.delegate();\n var pluginsManager = appController.pluginManager();\n\n var allRunningCommands = pluginsManager.runningCommands().allValues();\n _.each(allRunningCommands, function (command) {\n if (command.pluginBundle().identifier() == bundleId) {\n print(\'Tearing down sessions for command: \' + command.identifier());\n command.tearDownSession();\n }\n });\n\n pluginsManager.cleanupFinishedCommands();\n\n var plugins = pluginsManager.plugins();\n\n var url = NSURL.fileURLWithPath(bundlePath);\n var bundle = MSPluginBundle.pluginBundleWithURL(url);\n\n var findPluginsMenu = function findPluginsMenu() {\n var mainMenu = NSApp.mainMenu();\n var pluginsMenuItem = mainMenu.itemWithTitle(\'Plugins\');\n\n var menu = pluginsMenuItem.submenu();\n return menu;\n };\n\n var pls = NSMutableDictionary.dictionaryWithDictionary(plugins);\n pls[bundle.identifier()] = bundle;\n pluginsManager.plugins = NSDictionary.dictionaryWithDictionary(pls);\n\n // Inserting menu item.\n var menu = findPluginsMenu();\n\n var customMenu = NSMenu.alloc().init();\n pluginsManager.addCommands_toMenu_fromDescription_selector(bundle.commands(), customMenu, bundle.menuDescription(), NSSelectorFromString(\'runPlugin:\'));\n\n var menuItem = NSMenuItem.alloc().init();\n menuItem.title = bundle.name() + " (dev)";\n menuItem.submenu = customMenu;\n\n menu.insertItem_atIndex(menuItem, 0);\n menu.insertItem_atIndex(NSMenuItem.separatorItem(), 1);\n\n // Execute commands\n _.each(commandDescriptors, function (descriptor) {\n var command = bundle.commands()[descriptor.identifier];\n\n var context = MSDocument.currentDocument().pluginContext();\n var cmdContext = command.fullContextFromContext_url(context, bundle.url());\n cmdContext.remoteContext = descriptor.context;\n command.run_manager(cmdContext, pluginsManager);\n });\n})("<<\'{{{pluginBundlePath}}}\'>>", "<<\'{{{bundleID}}}\'>>", "<<{{{commandDescriptors}}}>>");\n']), | ||
_templateObject3 = _taggedTemplateLiteral(['\nconst app = COScript.app(\'{{{appName}}}\');\napp.delegate().runPluginScript_name("<<\'{{{script}}}\'>>","<<\'FusionLauncher\'>>");\n'], ['\nconst app = COScript.app(\'{{{appName}}}\');\napp.delegate().runPluginScript_name("<<\'{{{script}}}\'>>","<<\'FusionLauncher\'>>");\n']), | ||
_templateObject4 = _taggedTemplateLiteral(['\n(function(options){\n const appController = NSApp.delegate();\n const pluginsManager = appController.pluginManager();\n\n const allRunningCommands = pluginsManager.runningCommands().allValues();\n _.each(allRunningCommands,(command) => {\n if (command.pluginBundle().identifier() == bundleId) {\n print(\'Tearing down sessions for command: \' + command.identifier());\n command.tearDownSession();\n }\n });\n\n pluginsManager.cleanupFinishedCommands();\n\n const plugins = pluginsManager.plugins();\n\n const url = NSURL.fileURLWithPath(bundlePath);\n const bundle = MSPluginBundle.pluginBundleWithURL(url);\n const pls = NSMutableDictionary.dictionaryWithDictionary(plugins);\n pls[bundle.identifier()] = bundle;\n pluginsManager.plugins = NSDictionary.dictionaryWithDictionary(pls);\n\n})("<<{{{options}}}\'>>")\n'], ['\n(function(options){\n const appController = NSApp.delegate();\n const pluginsManager = appController.pluginManager();\n\n const allRunningCommands = pluginsManager.runningCommands().allValues();\n _.each(allRunningCommands,(command) => {\n if (command.pluginBundle().identifier() == bundleId) {\n print(\'Tearing down sessions for command: \' + command.identifier());\n command.tearDownSession();\n }\n });\n\n pluginsManager.cleanupFinishedCommands();\n\n const plugins = pluginsManager.plugins();\n\n const url = NSURL.fileURLWithPath(bundlePath);\n const bundle = MSPluginBundle.pluginBundleWithURL(url);\n const pls = NSMutableDictionary.dictionaryWithDictionary(plugins);\n pls[bundle.identifier()] = bundle;\n pluginsManager.plugins = NSDictionary.dictionaryWithDictionary(pls);\n\n})("<<{{{options}}}\'>>")\n']); | ||
var _lodash = require('lodash'); | ||
@@ -29,4 +34,21 @@ | ||
function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } | ||
/* | ||
const readTemplateNamed = (name) => { | ||
let script = fs.readFileSync(path.join(path.resolve(__dirname,'templates'),`${name}.js`),'utf8'); | ||
return _.replace(_.replace(script,/"<</g,''),/>>"/g,''); | ||
}; | ||
*/ | ||
var templates = {}; | ||
templates['bootstrap-plugin-instance'] = ''(_templateObject2)(_templateObject); | ||
templates['coscript-executor'] = ''(_templateObject3)(_templateObject); | ||
templates['plugin-command-executor'] = ''(_templateObject4)(_templateObject); | ||
var readTemplateNamed = function readTemplateNamed(name) { | ||
var script = _fs2['default'].readFileSync(_path2['default'].join(_path2['default'].resolve(__dirname, 'templates'), String(name) + '.js'), 'utf8'); | ||
var script = templates[name]; | ||
return _lodash2['default'].replace(_lodash2['default'].replace(script, /"<</g, ''), />>"/g, ''); | ||
@@ -33,0 +55,0 @@ }; |
{ | ||
"name": "sf-sketch-rpc", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "RPC module based on `coscript` cli for running scripts in Sketch runtime on node.js platform", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -8,2 +8,3 @@ | ||
/* | ||
const readTemplateNamed = (name) => { | ||
@@ -13,3 +14,133 @@ let script = fs.readFileSync(path.join(path.resolve(__dirname,'templates'),`${name}.js`),'utf8'); | ||
}; | ||
*/ | ||
const templates = {}; | ||
templates['bootstrap-plugin-instance'] = ``` | ||
(function (bundlePath, bundleId) { | ||
var commandDescriptors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
// Embedded Utils. | ||
var _isBoxedObject = function _isBoxedObject(obj) { | ||
return toString.call(obj) == '[object MOBoxedObject]'; | ||
}; | ||
var _isArray = function _isArray(obj) { | ||
return Array.isArray(obj); | ||
}; | ||
var _each = function _each(collection) { | ||
var iteratee = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {}; | ||
if (_isBoxedObject(collection) && collection.className() == 'NSArray') { | ||
var count = collection.count(); | ||
for (var i = 0; i < count; i++) { | ||
iteratee(collection.objectAtIndex(i), i); | ||
} | ||
} else if (_isArray(collection)) { | ||
for (var _i = 0; _i < collection.length; _i++) { | ||
iteratee(collection[_i], _i); | ||
} | ||
} | ||
}; | ||
var _ = { | ||
isBoxedObject: _isBoxedObject, | ||
isArray: _isArray, | ||
each: _each | ||
}; | ||
// Bootstrapper logic. | ||
var appController = NSApp.delegate(); | ||
var pluginsManager = appController.pluginManager(); | ||
var allRunningCommands = pluginsManager.runningCommands().allValues(); | ||
_.each(allRunningCommands, function (command) { | ||
if (command.pluginBundle().identifier() == bundleId) { | ||
print('Tearing down sessions for command: ' + command.identifier()); | ||
command.tearDownSession(); | ||
} | ||
}); | ||
pluginsManager.cleanupFinishedCommands(); | ||
var plugins = pluginsManager.plugins(); | ||
var url = NSURL.fileURLWithPath(bundlePath); | ||
var bundle = MSPluginBundle.pluginBundleWithURL(url); | ||
var findPluginsMenu = function findPluginsMenu() { | ||
var mainMenu = NSApp.mainMenu(); | ||
var pluginsMenuItem = mainMenu.itemWithTitle('Plugins'); | ||
var menu = pluginsMenuItem.submenu(); | ||
return menu; | ||
}; | ||
var pls = NSMutableDictionary.dictionaryWithDictionary(plugins); | ||
pls[bundle.identifier()] = bundle; | ||
pluginsManager.plugins = NSDictionary.dictionaryWithDictionary(pls); | ||
// Inserting menu item. | ||
var menu = findPluginsMenu(); | ||
var customMenu = NSMenu.alloc().init(); | ||
pluginsManager.addCommands_toMenu_fromDescription_selector(bundle.commands(), customMenu, bundle.menuDescription(), NSSelectorFromString('runPlugin:')); | ||
var menuItem = NSMenuItem.alloc().init(); | ||
menuItem.title = bundle.name() + " (dev)"; | ||
menuItem.submenu = customMenu; | ||
menu.insertItem_atIndex(menuItem, 0); | ||
menu.insertItem_atIndex(NSMenuItem.separatorItem(), 1); | ||
// Execute commands | ||
_.each(commandDescriptors, function (descriptor) { | ||
var command = bundle.commands()[descriptor.identifier]; | ||
var context = MSDocument.currentDocument().pluginContext(); | ||
var cmdContext = command.fullContextFromContext_url(context, bundle.url()); | ||
cmdContext.remoteContext = descriptor.context; | ||
command.run_manager(cmdContext, pluginsManager); | ||
}); | ||
})("<<'{{{pluginBundlePath}}}'>>", "<<'{{{bundleID}}}'>>", "<<{{{commandDescriptors}}}>>"); | ||
```; | ||
templates['coscript-executor'] = ``` | ||
const app = COScript.app('{{{appName}}}'); | ||
app.delegate().runPluginScript_name("<<'{{{script}}}'>>","<<'FusionLauncher'>>"); | ||
```; | ||
templates['plugin-command-executor'] = ``` | ||
(function(options){ | ||
const appController = NSApp.delegate(); | ||
const pluginsManager = appController.pluginManager(); | ||
const allRunningCommands = pluginsManager.runningCommands().allValues(); | ||
_.each(allRunningCommands,(command) => { | ||
if (command.pluginBundle().identifier() == bundleId) { | ||
print('Tearing down sessions for command: ' + command.identifier()); | ||
command.tearDownSession(); | ||
} | ||
}); | ||
pluginsManager.cleanupFinishedCommands(); | ||
const plugins = pluginsManager.plugins(); | ||
const url = NSURL.fileURLWithPath(bundlePath); | ||
const bundle = MSPluginBundle.pluginBundleWithURL(url); | ||
const pls = NSMutableDictionary.dictionaryWithDictionary(plugins); | ||
pls[bundle.identifier()] = bundle; | ||
pluginsManager.plugins = NSDictionary.dictionaryWithDictionary(pls); | ||
})("<<{{{options}}}'>>") | ||
```; | ||
const readTemplateNamed = (name) => { | ||
let script = templates[name]; | ||
return _.replace(_.replace(script,/"<</g,''),/>>"/g,''); | ||
}; | ||
export const buildScript = (scriptName,appName,params) => { | ||
@@ -16,0 +147,0 @@ let targetScript = readTemplateNamed(scriptName); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41894
657
6