deploy.gh.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * React Static Boilerplate
  3. * https://github.com/koistya/react-static-boilerplate
  4. *
  5. * Copyright © 2015-2016 Konstantin Tarkus (@koistya)
  6. *
  7. * This source code is licensed under the MIT license found in the
  8. * LICENSE.txt file in the root directory of this source tree.
  9. */
  10. const GitRepo = require('git-repository');
  11. const task = require('./task');
  12. const remote = {
  13. name: 'github',
  14. url: 'https://github.com/{user}/{repo}.git',
  15. branch: 'gh-pages',
  16. };
  17. /**
  18. * Deploy the contents of the `/build` folder to GitHub Pages.
  19. */
  20. module.exports = task('deploy', () => new Promise((resolve, reject) => {
  21. // Initialize a new Git repository inside the `/build` folder
  22. // if it doesn't exist yet
  23. let p = GitRepo.open('build', { init: true });
  24. p = p.then(repo => {
  25. p = p.then(() => repo.setRemote(remote.name, remote.url));
  26. p = p.then(() => repo.hasRef(remote.url, remote.branch).then(exists => {
  27. if (exists) {
  28. p = p.then(() => repo.fetch(remote.name));
  29. p = p.then(() => repo.reset(`${remote.name}/${remote.branch}`, { hard: true }));
  30. p = p.then(() => repo.clean({ force: true }));
  31. }
  32. }));
  33. // Build the project in RELEASE mode which
  34. // generates optimized and minimized bundles
  35. process.argv.push('release');
  36. p = p.then(() => require('./build').default);
  37. // Push the contents of the build folder to the remote server via Git
  38. p = p.then(() => repo.add('--all .'));
  39. p = p.then(() => repo.commit(`Update ${new Date().toISOString()}`));
  40. p = p.then(() => repo.push(remote.name, `master:${remote.branch}`));
  41. resolve(p);
  42. });
  43. p.catch(reject);
  44. }));