forked from ember-cli-deploy/ember-cli-deploy-revision-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (69 loc) · 2.15 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
'use strict';
var RSVP = require('rsvp');
var DeployPluginBase = require('ember-cli-deploy-plugin');
module.exports = {
name: 'ember-cli-deploy-revision-data',
createDeployPlugin: function(options) {
var DeployPlugin = DeployPluginBase.extend({
name: options.name,
defaultConfig: {
type: 'file-hash',
separator: '+',
filePattern: 'index.html',
versionFile: 'package.json',
distDir: function(context) {
return context.distDir;
},
distFiles: function(context) {
return context.distFiles;
},
rootDir: function(context) {
return context.project.root;
},
scm: function(/* context */) {
return require('./lib/scm-data-generators')['git'];
}
},
prepare: function(/*context*/) {
var self = this;
var promises = {
data: this._getData(),
scm: this._getScmData()
};
return RSVP.hash(promises)
.then(function(results) {
var data = results.data;
data.scm = results.scm;
self.log('generated revision data for revision: `' + data.revisionKey + '`', { verbose: true });
return data;
})
.then(function(data) {
return { revisionData: data };
})
.catch(this._errorMessage.bind(this));
},
_getData: function() {
var type = this.readConfig('type');
this.log('creating revision data using `' + type + '`', { verbose: true });
var DataGenerator = require('./lib/data-generators')[type];
return new DataGenerator({
plugin: this
}).generate();
},
_getScmData: function() {
var ScmDataGenerator = this.readConfig('scm');
if (ScmDataGenerator) {
var path = this.readConfig('rootDir');
return new ScmDataGenerator(path).generate();
} else {
return RSVP.resolve();
}
},
_errorMessage: function(error) {
this.log(error, { color: 'red' });
return RSVP.reject(error);
}
});
return new DeployPlugin();
}
};