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.

94 lines
3.5 KiB

  1. // Generated by CoffeeScript 1.6.3
  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 err, outGitPath, outPath;
  31. docpad.log('info', 'Deployment to GitHub Pages starting...');
  32. outPath = docpad.config.outPath;
  33. if (outPath === docpad.config.rootPath) {
  34. err = new Error("Your outPath configuration has been customised. Please remove the customisation in order to use the GitHub Pages plugin");
  35. return next(err);
  36. }
  37. outGitPath = pathUtil.join(outPath, '.git');
  38. return balUtil.rmdirDeep(outGitPath, function(err) {
  39. if (err) {
  40. return next(err);
  41. }
  42. return docpad.action('generate', {
  43. env: config.environment
  44. }, function(err) {
  45. if (err) {
  46. return next(err);
  47. }
  48. return balUtil.spawnCommand('git', ['config', 'remote.origin.url'], function(err, stdout, stderr) {
  49. var remoteRepoUrl;
  50. if (err) {
  51. return next(err);
  52. }
  53. remoteRepoUrl = stdout.replace(/\n/, "");
  54. return balUtil.spawnCommand('git', ['log', '--oneline'], function(err, stdout, stderr) {
  55. var gitCommands, lastCommit;
  56. if (err) {
  57. return next(err);
  58. }
  59. lastCommit = stdout.split('\n')[0];
  60. gitCommands = [['init'], ['add', '.'], ['commit', '-m', lastCommit], ['push', '--force', remoteRepoUrl, "master:" + config.deployBranch]];
  61. return balUtil.spawnCommands('git', gitCommands, {
  62. cwd: outPath,
  63. output: true
  64. }, function(err, stdout, stderr) {
  65. if (err) {
  66. return next(err);
  67. }
  68. return balUtil.rmdirDeep(outGitPath, function(err) {
  69. if (err) {
  70. return next(err);
  71. }
  72. docpad.log('info', 'Deployment to GitHub Pages completed successfully');
  73. return next();
  74. });
  75. });
  76. });
  77. });
  78. });
  79. });
  80. }));
  81. return this;
  82. };
  83. return GhpagesPlugin;
  84. })(BasePlugin);
  85. };