Skip to content
71 changes: 71 additions & 0 deletions src/common/updates/Updates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* globals define */
define([
'q'
], function(
Q
) {

const allUpdates = [
{
name: 'CustomUtilities',
isNeeded: function(core, rootNode) {
// Check the root directory for a MyUtilities node
return core.loadChildren(rootNode)
.then(children => {
const names = children.map(node => core.getAttribute(node, 'name'));
return !names.includes('MyUtilities');
});
},
apply: function(core, rootNode, META) {
// Create 'MyUtilities' node
const utils = core.createNode({
parent: rootNode,
base: META.FCO
});
core.setAttribute(utils, 'name', 'MyUtilities');

// Add 'MyUtilities' to the META
const META_ASPECT_SET_NAME = 'MetaAspectSet';
const META_SHEETS = 'MetaSheets';
const tabId = core.getRegistry(rootNode, META_SHEETS)
.find(desc => desc.order === 0)
.SetID;

core.addMember(rootNode, META_ASPECT_SET_NAME, utils);
core.addMember(rootNode, tabId, utils);

// Add 'Code' from 'pipelines' as a valid child
core.setChildMeta(utils, META['pipeline.Code']);

// Set the default visualizer to TabbedTextEditor
core.setRegistry(utils, 'validVisualizers', 'TabbedTextEditor');
}
}
];

const Updates = {};

Updates.getAvailableUpdates = function(core, rootNode) {
return Q.all(allUpdates.map(update => update.isNeeded(core, rootNode)))
.then(isNeeded => {
const updates = allUpdates.filter((update, i) => isNeeded[i]);
return updates;
});
};

Updates.getUpdates = function(names) {
if (names) {
return allUpdates.filter(update => names.includes(update.name));
}
return allUpdates;
};

Updates.getUpdate = function(name) {
return Updates.getUpdates([name])[0];
};

// Constants
Updates.MIGRATION = 'Migration';
Updates.SEED = 'SeedUpdate';
return Updates;
});
77 changes: 77 additions & 0 deletions src/plugins/ApplyUpdates/ApplyUpdates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*globals define*/
/*eslint-env node, browser*/

define([
'deepforge/updates/Updates',
'text!./metadata.json',
'plugin/PluginBase'
], function (
Updates,
pluginMetadata,
PluginBase
) {
'use strict';

pluginMetadata = JSON.parse(pluginMetadata);

/**
* Initializes a new instance of ApplyUpdates.
* @class
* @augments {PluginBase}
* @classdesc This class represents the plugin ApplyUpdates.
* @constructor
*/
var ApplyUpdates = function () {
// Call base class' constructor.
PluginBase.call(this);
this.pluginMetadata = pluginMetadata;
};

/**
* Metadata associated with the plugin. Contains id, name, version, description, icon, configStructue etc.
* This is also available at the instance at this.pluginMetadata.
* @type {object}
*/
ApplyUpdates.metadata = pluginMetadata;

// Prototypical inheritance from PluginBase.
ApplyUpdates.prototype = Object.create(PluginBase.prototype);
ApplyUpdates.prototype.constructor = ApplyUpdates;

/**
* Main function for the plugin to execute. This will perform the execution.
* Notes:
* - Always log with the provided logger.[error,warning,info,debug].
* - Do NOT put any user interaction logic UI, etc. inside this method.
* - callback always has to be called even if error happened.
*
* @param {function(string, plugin.PluginResult)} callback - the result callback
*/
ApplyUpdates.prototype.main = async function (callback) {
// Retrieve the updates to apply
const config = this.getCurrentConfig();
const updateNames = config.updates || [];

if (!updateNames.length) {
this.result.setSuccess(true);
return callback(null, this.result);
}

// Apply each of the updates
const updates = Updates.getUpdates(updateNames);

for (let i = 0, len = updates.length; i < len; i++) {
const update = updates[i];
this.logger.info(`Applying update: ${update.name} to ${this.projectId}`);
await update.apply(this.core, this.rootNode, this.META);
}

// Save the project
await this.save(`Applied project updates: ${updateNames.join(",")}`);

this.result.setSuccess(true);
callback(null, this.result);
};

return ApplyUpdates;
});
14 changes: 14 additions & 0 deletions src/plugins/ApplyUpdates/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "ApplyUpdates",
"name": "ApplyUpdates",
"version": "0.1.0",
"description": "",
"icon": {
"class": "glyphicon glyphicon-cog",
"src": ""
},
"disableServerSideExecution": false,
"disableBrowserSideExecution": false,
"writeAccessRequired": false,
"configStructure": []
}
178 changes: 0 additions & 178 deletions src/plugins/CheckLibraries/CheckLibraries.js

This file was deleted.

Loading