forked from treyhunner/ember-deploy-ssh-index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (66 loc) · 2.45 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 DeployPluginBase = require('ember-cli-deploy-plugin');
var path = require('path');
module.exports = {
name: 'ember-cli-deploy-ssh-index',
createDeployPlugin: function(options) {
var SSHAdapter = require('./lib/ssh-adapter');
var DeployPlugin = DeployPluginBase.extend({
name: options.name,
defaultConfig: {
revisionKey: function(context) {
return context.commandOptions.revision ||
(context.revisionData && context.revisionData.revisionKey);
},
keyPrefix: function(context) {
return context.project.name();
},
filePattern: 'index.html',
distDir: function(context) {
return context.distDir;
},
didDeployMessage: function(context) {
var revisionKey, activatedRevisionKey;
if (context.revisionData) {
revisionKey = context.revisionData.revisionKey;
activatedRevisionKey = context.revisionData.activatedRevisionKey;
}
if (revisionKey && !activatedRevisionKey) {
return 'Deployed but did not activate revision ' + revisionKey +
'. To activate, run: ember deploy:activate ' +
context.deployTarget + ' --revision=' + revisionKey + '\n';
}
},
},
requiredConfig: ['host', 'username', 'remoteDir'],
upload: function(/* context */) {
var sshAdapter = new SSHAdapter({ plugin: this });
var distDir = this.readConfig('distDir');
var filePattern = this.readConfig('filePattern');
var filePath = path.join(distDir, filePattern);
var buffer = require('fs').readFileSync(filePath);
return sshAdapter.upload(buffer);
},
didDeploy: function(/* context */){
var didDeployMessage = this.readConfig('didDeployMessage');
if (didDeployMessage) {
this.log(didDeployMessage);
}
},
activate: function(/* context */) {
var sshAdapter = new SSHAdapter({ plugin: this });
var revisionKey = this.readConfig('revisionKey');
return sshAdapter.activate(revisionKey);
},
fetchRevisions: function(context) {
var sshAdapter = new SSHAdapter({ plugin: this });
return sshAdapter.fetchRevisions()
.then(function(revisions) {
context.revisions = revisions;
});
}
});
return new DeployPlugin();
}
};