Skip to content

Commit

Permalink
Make the SDK work with plugins made with Webpack (#385)
Browse files Browse the repository at this point in the history
* make pluginTester compatible with webpack plugins

* Add exress standalone server

* Fix broken plugins/ path

* indexOf can be 0, fix operator to include it
  • Loading branch information
AlexKvazos authored and ahabeb committed Oct 27, 2017
1 parent c73fa6d commit 0f69325
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 17 deletions.
189 changes: 189 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"devDependencies": {
"body-parser": "1.11.0",
"chai": "^3.3.0",
"express": "4.0.0",
"express": "^4.0.0",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1",
"gulp-uglify": "^3.0.0",
Expand Down
6 changes: 4 additions & 2 deletions pluginTester/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ $app.config(['$routeProvider', '$sceDelegateProvider', function ($routeProvider,
// Allow same origin resource loads.
'self',
// Allow loading from our assets domain. Notice the difference between * and **.
window.siteConfig.endPoints.pluginHost + '/**'
window.siteConfig.endPoints.pluginHost + '/**',
// Allow webpack plugins
'http://127.0.0.1:8080/**'
]);

}]);
Expand All @@ -38,4 +40,4 @@ $app.run(function () {
if (user) {
window.currentUser = JSON.parse(user);
}
});
});
66 changes: 62 additions & 4 deletions pluginTester/pages/controllers/shellCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,57 @@ $app.controller('shellCtrl', ['$rootScope', '$scope', '$routeParams', '$sce', '$
postMaster.widgetPluginAPI.history.pop(breadcrumb);
};

$scope.loadWebpackFrames = function(config) {
var root = 'http://127.0.0.1:' + config.webpack;
$scope.widgetSrc = root + '/widget/index.html?fid=widget';

if (config.widget && config.widget.service) {
serviceFrame = document.createElement('iframe');
serviceFrame.sandbox="allow-scripts allow-forms allow-same-origin";
serviceFrame.id='service';
serviceFrame.style.display='none';
serviceFrame.src = root + '/widget/' + config.widget.service + "?fid=service";
document.body.appendChild(serviceFrame);
}

if (config.control.settings.enabled) {
$scope.currentControl = $scope.settingsSrc = root + '/control/settings/index.html?fid=controlSettings';
}

if (config.control.design.enabled) {
$scope.currentControl = $scope.designSrc = root + '/control/design/index.html?fid=controlDesign';
}

if (config.control.content.enabled) {
$scope.currentControl = $scope.contentSrc = root + '/control/content/index.html?fid=controlContent';
}

$scope.pluginControlIframeVisible = true;

if(config.control.customTabs && config.control.customTabs.length) {
for(var i = 0 ; i < config.control.customTabs.length; i++) {
var tab = config.control.customTabs[i];
if(tab && tab.url) {
if(tab.url.indexOf('//') != 0 && tab.url.indexOf('http://') != 0 && tab.url.indexOf('https://') != 0) {
var root = 'http://127.0.0.1:8080/control/';
// strip leading '/' if any
var customTabUrl = tab.url.indexOf("/") == 0 ? tab.url.substr(1) : tab.url;
tab.controlUrl = $sce.trustAsResourceUrl(root + customTabUrl);
} else {
tab.secureUrl = $sce.trustAsResourceUrl(tab.url);
}
}
}
$scope.customTabs = config.control.customTabs;
}

if (!$scope.$$phase)
$scope.$apply();
}

window.serviceFrame;
$scope.loadFrames = function (pluginFolder, config) {
var root = '../plugins/';
var root = '../plugins/';
$scope.widgetSrc = root + pluginFolder + '/widget/index.html?fid=widget';

if (config.widget && config.widget.service) {
Expand Down Expand Up @@ -100,7 +147,10 @@ $app.controller('shellCtrl', ['$rootScope', '$scope', '$routeParams', '$sce', '$
var pluginFolder = $routeParams.pluginFolder;
if (!pluginFolder) pluginFolder = window.appContext.currentPlugin.pluginPath;

$scope.currentControl = '../plugins/' + pluginFolder + '/control/' + section + '/index.html?fid=control';
$scope.currentControl = $scope.pluginConfig.webpack
? 'http://127.0.0.1:8080/control/' + section + '/index.html?fid=control'
: '../plugins/' + pluginFolder + '/control/' + section + '/index.html?fid=control';

var element = document.querySelector('.active');
if (element)element.className = '';
e.target.className = 'active';
Expand Down Expand Up @@ -166,10 +216,18 @@ $app.controller('shellCtrl', ['$rootScope', '$scope', '$routeParams', '$sce', '$
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
config = JSON.parse(xmlhttp.responseText);
$scope.loadFrames(pluginFolder, config);
$scope.pluginConfig = config;

if (config.webpack) {
console.log('== LOADING WEBPACK PLUGIN ==');
$scope.loadWebpackFrames(config);
} else {
$scope.loadFrames(pluginFolder, config);
}

$scope.navToValue = $scope.pluginFolder = pluginFolder;
keepTrackOfRecentPlugins(pluginFolder);

var hideEmulator = (config.widget && typeof config.widget.enabled != 'undefined') ? !config.widget.enabled : false;

displayEmulator(hideEmulator);
Expand Down
20 changes: 10 additions & 10 deletions scripts/buildfire.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ var buildfire = {
if (callback) callback(err, result);
});
}
/// ref:
/// ref:
, insert: function (obj, tag, userToken, checkDuplicate, callback) {

var userTokenType = typeof (userToken);
Expand Down Expand Up @@ -904,7 +904,7 @@ var buildfire = {
callback(err, result);
});
}
/// ref:
/// ref:
, bulkInsert: function (arrayObj, tag, userToken, callback) {

if (arrayObj.constructor !== Array) {
Expand Down Expand Up @@ -933,7 +933,7 @@ var buildfire = {
callback(err, result);
});
}
///
///
, update: function (id, obj, tag, userToken, callback) {
var userTokenType = typeof (userToken);
if (userTokenType == "undefined")
Expand Down Expand Up @@ -980,7 +980,7 @@ var buildfire = {
if (callback) callback(err, result);
});
}
/// ref
/// ref
, delete: function (id, tag, userToken, callback) {

var userTokenType = typeof (userToken);
Expand All @@ -1004,7 +1004,7 @@ var buildfire = {
if (callback) callback(err, result);
});
}
///
///
, search: function (options, tag, callback) {

var tagType = typeof (tag);
Expand All @@ -1024,21 +1024,21 @@ var buildfire = {
callback(err, result);
});
}
/// ref:
/// ref:
, onUpdate: function (callback, allowMultipleHandlers) {
return buildfire.eventManager.add('userDataOnUpdate', callback, allowMultipleHandlers);
}
, triggerOnUpdate: function (obj) {
buildfire.eventManager.trigger('userDataOnUpdate', obj);
}
/// ref:
/// ref:
, onRefresh: function (callback, allowMultipleHandlers) {
return buildfire.eventManager.add('userDataOnRefresh', callback, allowMultipleHandlers);
}
, triggerOnRefresh: function (obj) {
buildfire.eventManager.trigger('userDataOnRefresh', obj);
}
/// ref:
/// ref:
, disableRefresh: function () {
var p = new Packet(null, "userData.disableRefresh");
buildfire._sendPacket(p);
Expand Down Expand Up @@ -1434,7 +1434,7 @@ var buildfire = {

if (options.width == 'full') options.width = window.innerWidth;
if (options.height == 'full') options.height = window.innerHeight;

var localURL = buildfire.imageLib.local.toLocalPath(url);
if (localURL) {
var img = new Image();
Expand Down Expand Up @@ -1475,7 +1475,7 @@ var buildfire = {
dim.height *= ratio;
options.width *= ratio;
options.height *= ratio;

canvas.width = options.width;
canvas.height = options.height;
ctx.drawImage(img, offset.x, offset.y, dim.width, dim.height);
Expand Down
Loading

0 comments on commit 0f69325

Please sign in to comment.