deploy.js 1.5 KB

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