react-native-navigation的迁移库

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