deploy.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * React Static Boilerplate
  3. * https://github.com/koistya/react-static-boilerplate
  4. * Copyright (c) Konstantin Tarkus (@koistya) | MIT license
  5. */
  6. import GitRepo from 'git-repository';
  7. import task from './lib/task';
  8. // TODO: Update deployment URL
  9. const remote = {
  10. name: 'github',
  11. url: 'https://github.com/{user}/{repo}.git',
  12. branch: 'gh-pages',
  13. };
  14. /**
  15. * Deploy the contents of the `/build` folder to GitHub Pages.
  16. */
  17. export default task(async function deploy() {
  18. // Initialize a new Git repository inside the `/build` folder
  19. // if it doesn't exist yet
  20. const repo = await GitRepo.open('build', { init: true });
  21. await repo.setRemote(remote.name, remote.url);
  22. // Fetch the remote repository if it exists
  23. if ((await repo.hasRef(remote.url, remote.branch))) {
  24. await repo.fetch(remote.name);
  25. await repo.reset(`${remote.name}/${remote.branch}`, { hard: true });
  26. await repo.clean({ force: true });
  27. }
  28. // Build the project in RELEASE mode which
  29. // generates optimized and minimized bundles
  30. process.argv.push('release');
  31. await require('./build')();
  32. // Push the contents of the build folder to the remote server via Git
  33. await repo.add('--all .');
  34. await repo.commit('Update ' + new Date().toISOString());
  35. await repo.push(remote.name, 'master:' + remote.branch);
  36. });