-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
76 lines (62 loc) · 2.12 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
/* jshint node: true */
'use strict';
var Promise = require('rsvp').Promise;
var DeployPluginBase = require('ember-cli-deploy-plugin');
var cpr = require('cpr');
var SilentError = require('silent-error');
module.exports = {
name: 'ember-cli-deploy-cp',
createDeployPlugin: function(options) {
var DeployPlugin = DeployPluginBase.extend({
name: options.name,
defaultConfig: {
distDir: function(context) {
return context.distDir;
},
deleteFirst: false,
overwrite: true,
confirm: true,
filePattern: undefined,
didDeployMessage: function(context){
var revisionKey = context.revisionData && context.revisionData.revisionKey;
if (revisionKey) {
return "Copied revision " + revisionKey + ".";
}
},
},
requiredConfig: ['destDir'],
configure: function(/* context */) {
this.log('validating config');
['distDir', 'deleteFirst', 'overwrite', 'confirm', 'didDeployMessage', 'filePattern'].forEach(this.applyDefaultConfigProperty.bind(this));
this.log('config ok');
},
upload: function(/* context */) {
var distDir = this.readConfig('distDir');
var destDir = this.readConfig('destDir');
var options = {
deleteFirst: this.readConfig('deleteFirst'),
overwrite: this.readConfig('overwrite'),
confirm: this.readConfig('confirm')
};
if(this.readConfig('filePattern') !== undefined) {
options.filter = this.readConfig('filePattern');
}
return new Promise(function(resolve, reject) {
cpr(distDir, destDir, options, function(err, files) {
if(err) {
return reject(new SilentError('Could not copy files' + err));
}
resolve();
});
});
},
didDeploy: function(/* context */){
var didDeployMessage = this.readConfig('didDeployMessage');
if (didDeployMessage) {
this.log(didDeployMessage);
}
}
});
return new DeployPlugin();
}
};