1 | 'use strict';
|
2 |
|
3 | const assignIn = require('lodash/assignIn');
|
4 | const clone = require('lodash/clone');
|
5 | const fs = require('hexo-fs');
|
6 | const chalk = require('chalk');
|
7 | const Promise = require('bluebird');
|
8 |
|
9 | function deployConsole(args) {
|
10 | let config = this.config.deploy;
|
11 | const deployers = this.extend.deployer.list();
|
12 | const self = this;
|
13 |
|
14 | if (!config) {
|
15 | let help = '';
|
16 |
|
17 | help += 'You should configure deployment settings in _config.yml first!\n\n';
|
18 | help += 'Available deployer plugins:\n';
|
19 | help += ` ${Object.keys(deployers).join(', ')}\n\n`;
|
20 | help += `For more help, you can check the online docs: ${chalk.underline('http://hexo.io/')}`;
|
21 |
|
22 | console.log(help);
|
23 | return;
|
24 | }
|
25 |
|
26 | return new Promise((resolve, reject) => {
|
27 | const generateArgs = clone(args);
|
28 | generateArgs.d = false;
|
29 | generateArgs.deploy = false;
|
30 |
|
31 | if (args.g || args.generate) {
|
32 | self.call('generate', args).then(resolve, reject);
|
33 | } else {
|
34 | fs.exists(self.public_dir, exist => {
|
35 | if (exist) return resolve();
|
36 | self.call('generate', args).then(resolve, reject);
|
37 | });
|
38 | }
|
39 | }).then(() => {
|
40 | self.emit('deployBefore');
|
41 |
|
42 | if (!Array.isArray(config)) config = [config];
|
43 | return config;
|
44 | }).each(item => {
|
45 | if (!item.type) return;
|
46 |
|
47 | const type = item.type;
|
48 |
|
49 | if (!deployers[type]) {
|
50 | self.log.error('Deployer not found: %s', chalk.magenta(type));
|
51 | return;
|
52 | }
|
53 |
|
54 | self.log.info('Deploying: %s', chalk.magenta(type));
|
55 |
|
56 | return deployers[type].call(self, assignIn({}, item, args)).then(() => {
|
57 | self.log.info('Deploy done: %s', chalk.magenta(type));
|
58 | });
|
59 | }).then(() => {
|
60 | self.emit('deployAfter');
|
61 | });
|
62 | }
|
63 |
|
64 | module.exports = deployConsole;
|