deploy.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. // TODO: Update deployment URL
  8. const remote = {
  9. name: 'github',
  10. url: 'https://github.com/{user}/{repo}.git',
  11. branch: 'gh-pages',
  12. };
  13. /**
  14. * Deploy the contents of the `/build` folder to GitHub Pages.
  15. */
  16. export default async () => {
  17. // Initialize a new Git repository inside the `/build` folder
  18. // if it doesn't exist yet
  19. const repo = await GitRepo.open('build', { init: true });
  20. await repo.setRemote(remote.name, remote.url);
  21. // Fetch the remote repository if it exists
  22. if ((await repo.hasRef(remote.url, remote.branch))) {
  23. await repo.fetch(remote.name);
  24. await repo.reset(`${remote.name}/${remote.branch}`, { hard: true });
  25. await repo.clean({ force: true });
  26. }
  27. // Build the project in RELEASE mode which
  28. // generates optimized and minimized bundles
  29. process.argv.push('release');
  30. await require('./build')();
  31. // Push the contents of the build folder to the remote server via Git
  32. await repo.add('--all .');
  33. await repo.commit('Update ' + new Date().toISOString());
  34. await repo.push(remote.name, remote.branch);
  35. };