Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable plugins to be required without requirejs and passed to manager as "class" #59

Merged
merged 3 commits into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/client/pluginmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ define([

/**
* Run the plugin in the browser.
* @param {string} pluginId - id of plugin.
* @param {string|function} pluginIdOrClass - id or class for plugin.
* @param {object} context
* @param {object} context.managerConfig - where the plugin should execute.
* @param {ProjectInterface} context.managerConfig.project - project (e.g. client.getProjectObject()).
Expand All @@ -92,7 +92,7 @@ define([
* @param {object} [context.pluginConfig=%defaultForPlugin%] - specific configuration for the plugin.
* @param {function(err, PluginResult)} callback
*/
this.runBrowserPlugin = function (pluginId, context, callback) {
this.runBrowserPlugin = function (pluginIdOrClass, context, callback) {
var blobClient = new BlobClient({logger: logger.fork('BlobClient')}),
pluginManager = new PluginManagerBase(blobClient, null, mainLogger, gmeConfig);

Expand All @@ -105,12 +105,12 @@ define([

pluginManager.projectAccess = client.getProjectAccess();

pluginManager.executePlugin(pluginId, context.pluginConfig, context.managerConfig, callback);
pluginManager.executePlugin(pluginIdOrClass, context.pluginConfig, context.managerConfig, callback);
};

/**
* Run the plugin on the server inside a worker process.
* @param {string} pluginId - id of plugin.
* @param {string|function} pluginIdOrClass - id or class for plugin.
* @param {object} context
* @param {object} context.managerConfig - where the plugin should execute.
* @param {ProjectInterface|string} context.managerConfig.project - project or id of project.
Expand All @@ -122,8 +122,8 @@ define([
* @param {object} [context.pluginConfig=%defaultForPlugin%] - specific configuration for the plugin.
* @param {function} callback
*/
this.runServerPlugin = function (pluginId, context, callback) {

this.runServerPlugin = function (pluginIdOrClass, context, callback) {
var pluginId = typeof pluginIdOrClass === 'string' ? pluginIdOrClass : pluginIdOrClass.metadata.id;
if (context.managerConfig.project instanceof Project) {
context.managerConfig.project = context.managerConfig.project.projectId;
}
Expand Down
12 changes: 10 additions & 2 deletions src/common/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
/**
* STRING CONSTANT DEFINITIONS USED IN BOTH CLIENT AND SERVER JAVASCRIPT
* @author rkereskenyi / https://github.com/rkereskenyi
* @author pmeijer / https://github.com/pmeijer
*/

define(['common/core/constants', 'common/storage/constants'], function (CORE, STORAGE) {

(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['common/core/constants', 'common/storage/constants'], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('./core/constants'), require('./storage/constants'));
}
}(function (CORE, STORAGE) {
'use strict';
//return string constants
return {
Expand Down Expand Up @@ -110,4 +118,4 @@ define(['common/core/constants', 'common/storage/constants'], function (CORE, ST
}

};
});
}));
11 changes: 9 additions & 2 deletions src/common/core/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
/**
* @author kecso / https://github.com/kecso
*/
define([], function () {

(function (factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
}
}(function () {
'use strict';
//return string constants
return {
Expand Down Expand Up @@ -78,4 +85,4 @@ define([], function () {

OVERLAY_SHARD_INDICATOR: 'sharded'
};
});
}));
11 changes: 8 additions & 3 deletions src/common/storage/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@
* patch: [{op: 'add', path: '/atr/new', value: 'value'}]
* }
*/

define([], function () {
(function (factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
}
}(function () {
'use strict';

return {
Expand Down Expand Up @@ -140,4 +145,4 @@ define([], function () {
ADD_ON_NOTIFICATION: 'ADD_ON_NOTIFICATION',
CLIENT_STATE_NOTIFICATION: 'CLIENT_STATE_NOTIFICATION'
};
});
}));
10 changes: 8 additions & 2 deletions src/plugin/InterPluginResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
* @author pmeijer / https://github.com/meijer
*/

define(['plugin/PluginResultBase'], function (PluginResultBase) {
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['plugin/PluginResultBase'], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('./PluginResultBase'));
}
}(function (PluginResultBase) {
'use strict';

/**
Expand Down Expand Up @@ -46,4 +52,4 @@ define(['plugin/PluginResultBase'], function (PluginResultBase) {
};

return InterPluginResult;
});
}));
56 changes: 36 additions & 20 deletions src/plugin/PluginBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,41 @@
* @author pmeijer / https://github.com/pmeijer
*/

define([
'q',
'plugin/PluginConfig',
'plugin/PluginResultBase',
'plugin/PluginResult',
'plugin/InterPluginResult',
'plugin/PluginMessage',
'plugin/PluginNodeDescription',
'plugin/util',
'common/storage/constants'
], function (Q,
PluginConfig,
PluginResultBase,
PluginResult,
InterPluginResult,
PluginMessage,
PluginNodeDescription,
pluginUtil,
STORAGE_CONSTANTS) {
(function (factory) {
if (typeof define === 'function' && define.amd) {
define([
'q',
'plugin/PluginConfig',
'plugin/PluginResultBase',
'plugin/PluginResult',
'plugin/InterPluginResult',
'plugin/PluginMessage',
'plugin/PluginNodeDescription',
'plugin/util',
'common/storage/constants'
], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(
require('q'),
require('./PluginConfig'),
require('./PluginResultBase'),
require('./PluginResult'),
require('./InterPluginResult'),
require('./PluginMessage'),
require('./PluginNodeDescription'),
require('./util'),
require('../common/storage/constants')
);
}
}(function (Q,
PluginConfig,
PluginResultBase,
PluginResult,
InterPluginResult,
PluginMessage,
PluginNodeDescription,
pluginUtil,
STORAGE_CONSTANTS) {
'use strict';

/**
Expand Down Expand Up @@ -890,4 +906,4 @@ define([
//</editor-fold>

return PluginBase;
});
}));
10 changes: 8 additions & 2 deletions src/plugin/PluginConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
* @author lattmann / https://github.com/lattmann
*/

define([], function () {
(function (factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
}
}(function () {
'use strict';
/**
* Initializes a new instance of plugin configuration.
Expand Down Expand Up @@ -45,4 +51,4 @@ define([], function () {


return PluginConfig;
});
}));
10 changes: 8 additions & 2 deletions src/plugin/PluginManagerConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
*/


define([], function () {
(function (factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
}
}(function () {
'use strict';
/**
* Initializes a new instance of plugin manager configuration.
Expand Down Expand Up @@ -56,4 +62,4 @@ define([], function () {
};

return PluginManagerConfiguration;
});
}));
10 changes: 8 additions & 2 deletions src/plugin/PluginMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
*/


define(['plugin/PluginNodeDescription'], function (PluginNodeDescription) {
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['plugin/PluginNodeDescription'], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('./PluginNodeDescription'));
}
}(function (PluginNodeDescription) {
'use strict';

/**
Expand Down Expand Up @@ -60,4 +66,4 @@ define(['plugin/PluginNodeDescription'], function (PluginNodeDescription) {
};

return PluginMessage;
});
}));
10 changes: 8 additions & 2 deletions src/plugin/PluginNodeDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
*/


define([], function () {
(function (factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
}
}(function () {
'use strict';
/**
* Initializes a new instance of plugin node description object.
Expand Down Expand Up @@ -52,4 +58,4 @@ define([], function () {
};

return PluginNodeDescription;
});
}));
10 changes: 8 additions & 2 deletions src/plugin/PluginResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
* @author lattmann / https://github.com/lattmann
*/

define(['plugin/PluginMessage', 'plugin/PluginResultBase'], function (PluginMessage, PluginResultBase) {
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['plugin/PluginMessage', 'plugin/PluginResultBase'], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('./PluginMessage'), require('./PluginResultBase'));
}
}(function (PluginMessage, PluginResultBase) {
'use strict';

/**
Expand Down Expand Up @@ -188,4 +194,4 @@ define(['plugin/PluginMessage', 'plugin/PluginResultBase'], function (PluginMess
};

return PluginResult;
});
}));
10 changes: 8 additions & 2 deletions src/plugin/PluginResultBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
* @author pmeijer / https://github.com/meijer
*/

define([], function () {
(function (factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
}
}(function () {
'use strict';

/**
Expand Down Expand Up @@ -86,4 +92,4 @@ define([], function () {
};

return PluginResultBase;
});
}));
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@
* @module CorePlugins:MinimalWorkingExample
*/

define([
'plugin/PluginConfig',
'plugin/PluginBase',
'text!./metadata.json'
], function (PluginConfig, PluginBase, pluginMetadata) {

(function (factory) {
if (typeof define === 'function' && define.amd) {
define([
'plugin/PluginConfig',
'plugin/PluginBase',
'text!./metadata.json'
], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(
require('../../PluginConfig'),
require('../../PluginBase'),
require('./metadata.json')
);
}
}(function (PluginConfig, PluginBase, pluginMetadata) {
'use strict';

pluginMetadata = JSON.parse(pluginMetadata);
pluginMetadata = typeof pluginMetadata === 'string' ? JSON.parse(pluginMetadata) : pluginMetadata;

/**
* Initializes a new instance of MinimalWorkingExample.
Expand Down Expand Up @@ -98,4 +109,4 @@ define([
};

return MinimalWorkingExample;
});
}));
Loading