-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.js
74 lines (68 loc) · 2.17 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
"use strict";
var DeployPluginBase = require("ember-cli-deploy-plugin");
var path = require("path");
var git = require("./lib/git");
module.exports = {
name: "ember-cli-deploy-git",
createDeployPlugin: function(options) {
var DeployPlugin = DeployPluginBase.extend({
name: options.name,
configure: function(context) {
var pluginConfig = context.config[this.name] || {};
return getMyRepo(context)
.then(function(myRepo) {
var worktreePath =
pluginConfig.worktreePath || defaultWorktree(context);
return {
gitDeploy: {
myRepo: myRepo,
worktreePath: worktreePath,
destDir: path.resolve(worktreePath, pluginConfig.destDir || ""),
repo: pluginConfig.repo || myRepo,
branch: pluginConfig.branch || "gh-pages",
commitMessage: pluginConfig.commitMessage || "Deployed %@"
}
};
})
.catch(showStderr(context.ui));
},
prepare: function(context) {
var d = context.gitDeploy;
this.log("preparing git in " + d.worktreePath, { verbose: true });
return git
.prepareTree(d.worktreePath, d.myRepo, d.repo, d.branch)
.catch(showStderr(context.ui));
},
upload: function(context) {
var d = context.gitDeploy;
var distDir =
context.distDir || path.join(context.project.root, "dist");
return git
.replaceTree(d.destDir, distDir, d.commitMessage)
.then(function(didCommit) {
if (didCommit) {
return git.push(d.worktreePath, d.repo, d.branch);
} else {
console.log("Nothing to deploy");
}
})
.catch(showStderr(context.ui));
}
});
return new DeployPlugin();
}
};
function showStderr(ui) {
return function(err) {
if (err.stderr) {
ui.write(err.stderr);
}
throw err;
};
}
function getMyRepo(context) {
return git.origin(context.project.root);
}
function defaultWorktree(context) {
return path.join(context.project.root, "../deploy-" + context.project.name());
}