react-native-navigation的迁移库

release.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const shellUtils = require('shell-utils');
  2. const p = require('path');
  3. const semver = require('semver');
  4. function validateEnv() {
  5. if (!process.env.CI || !process.env.TRAVIS) {
  6. throw new Error(`releasing is only available from Travis CI`);
  7. }
  8. if (process.env.TRAVIS_BRANCH !== 'master') {
  9. console.log(`not publishing on branch ${process.env.TRAVIS_BRANCH}`);
  10. return false;
  11. }
  12. if (process.env.TRAVIS_PULL_REQUEST !== 'false') {
  13. console.log(`not publishing as triggered by pull request ${process.env.TRAVIS_PULL_REQUEST}`);
  14. return false;
  15. }
  16. return true;
  17. }
  18. function setupGit() {
  19. shellUtils.exec.execSyncSilent(`git config --global push.default simple`);
  20. shellUtils.exec.execSyncSilent(`git config --global user.email "${process.env.GIT_EMAIL}"`);
  21. shellUtils.exec.execSyncSilent(`git config --global user.name "${process.env.GIT_USER}"`);
  22. const remoteUrl = new RegExp(`https?://(\\S+)`).exec(shellUtils.exec.execSyncRead(`git remote -v`))[1];
  23. shellUtils.exec.execSyncSilent(`git remote add deploy "https://${process.env.GIT_USER}:${process.env.GIT_TOKEN}@${remoteUrl}"`);
  24. shellUtils.exec.execSync(`git checkout master`);
  25. }
  26. function calcNewVersion() {
  27. const nextTaggedVersion = shellUtils.exec.execSyncRead(`npm view ${process.env.npm_package_name}@next version`);
  28. console.log(`next tagged version is: ${nextTaggedVersion}`);
  29. return semver.inc(nextTaggedVersion, 'prerelease');
  30. }
  31. function copyNpmRc() {
  32. const npmrcPath = p.resolve(`${__dirname}/.npmrc`);
  33. shellUtils.exec.execSync(`cp -rf ${npmrcPath} .`);
  34. }
  35. function tagAndPublish(newVersion) {
  36. console.log(`new version is: ${newVersion}`);
  37. shellUtils.exec.execSync(`npm version ${newVersion} -m "v${newVersion} [ci skip]"`);
  38. shellUtils.exec.execSyncSilent(`git push deploy --tags`);
  39. shellUtils.exec.execSync(`npm publish --tag next`);
  40. }
  41. function run() {
  42. if (!validateEnv()) {
  43. return;
  44. }
  45. setupGit();
  46. copyNpmRc();
  47. tagAndPublish(calcNewVersion());
  48. }
  49. run();