You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.3 KiB

  1. // Generated by CoffeeScript 1.6.2
  2. var balUtil, pathUtil,
  3. __hasProp = {}.hasOwnProperty,
  4. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  5. balUtil = require('bal-util');
  6. pathUtil = require('path');
  7. module.exports = function(BasePlugin) {
  8. var GhpagesPlugin, _ref;
  9. return GhpagesPlugin = (function(_super) {
  10. __extends(GhpagesPlugin, _super);
  11. function GhpagesPlugin() {
  12. _ref = GhpagesPlugin.__super__.constructor.apply(this, arguments);
  13. return _ref;
  14. }
  15. GhpagesPlugin.prototype.name = 'ghpages';
  16. GhpagesPlugin.prototype.config = {
  17. deployBranch: 'gh-pages',
  18. environment: 'static'
  19. };
  20. GhpagesPlugin.prototype.consoleSetup = function(opts) {
  21. var commander, config, consoleInterface, docpad, me;
  22. consoleInterface = opts.consoleInterface, commander = opts.commander;
  23. me = this;
  24. config = this.config;
  25. docpad = this.docpad;
  26. docpad.setInstanceConfig({
  27. env: config.environment
  28. });
  29. commander.command('deploy-ghpages').description("deploys your " + config.environment + " website to the " + config.deployBranch + " branch").action(consoleInterface.wrapAction(function(next) {
  30. var outGitPath, outPath;
  31. docpad.log('info', 'Deployment to GitHub Pages starting...');
  32. outPath = docpad.config.outPath;
  33. outGitPath = pathUtil.join(outPath, '.git');
  34. return balUtil.rmdirDeep(outGitPath, function(err) {
  35. if (err) {
  36. return next(err);
  37. }
  38. return docpad.action('generate', {
  39. env: config.environment
  40. }, function(err) {
  41. if (err) {
  42. return next(err);
  43. }
  44. return balUtil.spawnCommand('git', ['config', 'remote.origin.url'], function(err, stdout, stderr) {
  45. var remoteRepoUrl;
  46. if (err) {
  47. return next(err);
  48. }
  49. remoteRepoUrl = stdout.replace(/\n/, "");
  50. return balUtil.spawnCommand('git', ['log', '--oneline'], function(err, stdout, stderr) {
  51. var gitCommands, lastCommit;
  52. if (err) {
  53. return next(err);
  54. }
  55. lastCommit = stdout.split('\n')[0];
  56. gitCommands = [['init'], ['add', '.'], ['commit', '-m', lastCommit], ['push', '--force', remoteRepoUrl, "master:" + config.deployBranch]];
  57. return balUtil.spawnCommands('git', gitCommands, {
  58. cwd: outPath,
  59. output: true
  60. }, function(err, stdout, stderr) {
  61. if (err) {
  62. return next(err);
  63. }
  64. return balUtil.rmdirDeep(outGitPath, function(err) {
  65. if (err) {
  66. return next(err);
  67. }
  68. docpad.log('info', 'Deployment to GitHub Pages completed successfully');
  69. return next();
  70. });
  71. });
  72. });
  73. });
  74. });
  75. });
  76. }));
  77. return this;
  78. };
  79. return GhpagesPlugin;
  80. })(BasePlugin);
  81. };