This repository has been archived by the owner on Oct 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
61 lines (52 loc) · 1.97 KB
/
deploy.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
const {log} = require('./utils/log');
const transformOptions = require('./actions/transform-options');
const ensureLikeGhostInstance = require('./actions/ensure-like-ghost-instance');
const validateTheme = require('./actions/validate-theme');
const getToken = require('./actions/get-token');
const uploadTheme = require('./actions/upload-theme');
const activateTheme = require('./actions/activate-theme');
const destroyTokens = require('./actions/destroy-tokens');
module.exports = function deployGhostTheme(options) {
const tokens = {};
let opts;
/* Named ensureLikeGhostInstance because we're not doing a full on
* check, just making sure the API responds how we expect it to
*/
return transformOptions(options).then(options => {
opts = options;
log('Checking URL validity');
return ensureLikeGhostInstance(opts.url);
}).then(function actionValidate() {
if (opts.skipThemeValidation) {
return Promise.resolve();
}
log('Checking theme validity');
return validateTheme(opts.themePath);
}).then(function actionGet() {
if (opts.token) {
return Promise.resolve({accessToken: opts.token});
}
log('Retrieving access token');
return getToken(opts);
}).then(function actionUpload({accessToken, refreshToken}) {
tokens.access = accessToken;
tokens.refresh = refreshToken;
log('Uploading theme');
return uploadTheme(opts.url, accessToken, opts.themePath);
}).then(function actionActivate({data}) {
// Don't active the theme if we don't want to or it's already active
if (!opts.activateTheme || data.themes[0].active) {
return Promise.resolve();
}
log('Activating theme');
return activateTheme(opts.url, tokens.access, data.themes[0].name);
}).then(function actionDestroy() {
if (opts.token || !(tokens.access || tokens.refresh)) {
return Promise.resolve();
}
log('Destroying access tokens');
return destroyTokens(opts, tokens);
});
};
module.exports.DeployError = require('./utils/deploy-error');
module.exports.log = require('./utils/log');