-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathApplyUpdates.js
More file actions
88 lines (75 loc) · 2.7 KB
/
ApplyUpdates.js
File metadata and controls
88 lines (75 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*globals define*/
/*eslint-env node, browser*/
define([
'plugin/ImportLibrary/ImportLibrary/ImportLibrary',
'deepforge/updates/Updates',
'text!./metadata.json',
'underscore',
], function (
PluginBase,
Updates,
pluginMetadata,
_,
) {
'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 {updates=[]} = config;
if (!updates.length) {
this.result.setSuccess(true);
return callback(null, this.result);
}
// Apply each of the updates
const [migrations, libUpdates] = _.partition(
updates,
update => update.type === Updates.MIGRATION
);
for (let i = 0, len = migrations.length; i < len; i++) {
const update = migrations[i];
this.logger.info(`Applying update: ${update.name} to ${this.projectId}`);
await update.apply(this.core, this.rootNode, this.META);
}
for (let i = libUpdates.length; i--;) {
const libraryInfo = libUpdates[i].info;
await this.importLibrary(libraryInfo);
}
// Save the project
const updateNames = updates.map(update => update.name);
await this.save(`Applied project updates: ${updateNames.join(',')}`);
this.result.setSuccess(true);
callback(null, this.result);
};
return ApplyUpdates;
});