deploy.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * React Starter Kit (https://www.reactstarterkit.com/)
  3. *
  4. * Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
  5. *
  6. * This source code is licensed under the MIT license found in the
  7. * LICENSE.txt file in the root directory of this source tree.
  8. */
  9. import GitRepo from 'git-repository';
  10. import run from './run';
  11. import fetch from './lib/fetch';
  12. // TODO: Update deployment URL
  13. // For more information visit http://gitolite.com/deploy.html
  14. const getRemote = (slot) => ({
  15. name: slot || 'production',
  16. url: `https://example${slot ? `-${slot}` : ''}.scm.azurewebsites.net:443/example.git`,
  17. website: `http://example${slot ? `-${slot}` : ''}.azurewebsites.net`,
  18. });
  19. /**
  20. * Deploy the contents of the `/build` folder to a remote
  21. * server via Git. Example: `npm run deploy -- production`
  22. */
  23. async function deploy() {
  24. // By default deploy to the staging deployment slot
  25. const remote = getRemote(process.argv.includes('--production') ? null : 'staging');
  26. // Initialize a new Git repository inside the `/build` folder
  27. // if it doesn't exist yet
  28. const repo = await GitRepo.open('build', { init: true });
  29. await repo.setRemote(remote.name, remote.url);
  30. // Fetch the remote repository if it exists
  31. if ((await repo.hasRef(remote.url, 'master'))) {
  32. await repo.fetch(remote.name);
  33. await repo.reset(`${remote.name}/master`, { hard: true });
  34. await repo.clean({ force: true });
  35. }
  36. // Build the project in RELEASE mode which
  37. // generates optimized and minimized bundles
  38. process.argv.push('--release');
  39. await run(require('./build'));
  40. // Push the contents of the build folder to the remote server via Git
  41. await repo.add('--all .');
  42. await repo.commit('Update');
  43. await repo.push(remote.name, 'master');
  44. // Check if the site was successfully deployed
  45. const response = await fetch(remote.website);
  46. console.log(`${remote.website} -> ${response.statusCode}`);
  47. }
  48. export default deploy;