-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
94 lines (78 loc) · 3.02 KB
/
index.js
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
89
90
91
92
93
94
/* jshint node: true */
'use strict';
var DeployPluginBase = require('ember-cli-deploy-plugin');
var NavisDeploy = require('./lib/navis-deploy');
var path = require('path');
var RSVP = require('rsvp');
var minimatch = require('minimatch');
module.exports = {
name: 'ember-cli-deploy-navis',
createDeployPlugin: function(options) {
var DeployPlugin = DeployPluginBase.extend({
name: options.name,
defaultConfig: {
deployHost: 'http://api.navis.io',
uploadAssets: true,
filePattern: 'index.html',
assetPattern: '**/*.{js,css,png,gif,jpg,map,xml,txt,svg,eot,ttf,woff,woff2}',
navisDeploy: function() { return new NavisDeploy(this.pluginConfig); },
revisionKey: function(context) {
return context.commandOptions.revision || context['git-info']['commit'];
}
},
requiredConfig: ['appKey', 'userKey', 'userSecret'],
upload: function(context) {
return new RSVP.all([
this._uploadIndex(context),
this._uploadAssets(context)
]);
},
_uploadIndex: function(context) {
var navis = this.readConfig('navisDeploy');
var filePattern = this.readConfig('filePattern');
var revision = this.readConfig('revisionKey');
var filePath = path.join(context.distDir, filePattern);
this.log('Uploading `' + filePath + '`' + ' as `' + revision + '`');
return navis.uploadBuild(filePath, revision, context['git-info']);
},
_uploadAssets: function(context) {
if (!this.readConfig('uploadAssets')) { return RSVP.resolve(); }
var navis = this.readConfig('navisDeploy');
var assetPattern = this.readConfig('assetPattern');
var revision = this.readConfig('revisionKey');
this.log('Uploading assets');
var files = context.distFiles.
filter(minimatch.filter(assetPattern, {matchBase: true})).
map(function(file) {
return {
path: path.join(context.distDir, file),
file: file
}
}.bind(this));
return navis.uploadAssets(files, this);
},
activate: function() {
var navis = this.readConfig('navisDeploy');
var revision = this.readConfig('revisionKey');
this.log('Activating revision `' + revision + '`');
return navis.activate(revision);
},
fetchRevisions: function() {
var navis = this.readConfig('navisDeploy');
this.log('Fetching revisions from Navis');
return navis.list().then(function(data) {
// Format results for ember-cli-deploy
return {revisions: data.map(function(rev) {
return {
revision: rev.attributes.ref,
active: rev.attributes.active,
timestamp: rev.attributes['built-at'],
deployer: rev.attributes['build-by-name']
};
})};
});
}
});
return new DeployPlugin();
}
};