react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*eslint-disable no-console*/
  2. const exec = require('shell-utils').exec;
  3. const p = require('path');
  4. const semver = require('semver');
  5. const fs = require('fs');
  6. const ONLY_ON_BRANCH = 'v2';
  7. const VERSION_TAG = 'alpha';
  8. const VERSION_INC = 'patch';
  9. function validateEnv() {
  10. if (!process.env.CI || !process.env.TRAVIS) {
  11. throw new Error(`releasing is only available from Travis CI`);
  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. if (process.env.TRAVIS_BRANCH !== ONLY_ON_BRANCH) {
  18. console.log(`not publishing on branch ${process.env.TRAVIS_BRANCH}`);
  19. return false;
  20. }
  21. return true;
  22. }
  23. function setupGit() {
  24. exec.execSyncSilent(`git config --global push.default simple`);
  25. exec.execSyncSilent(`git config --global user.email "${process.env.GIT_EMAIL}"`);
  26. exec.execSyncSilent(`git config --global user.name "${process.env.GIT_USER}"`);
  27. const remoteUrl = new RegExp(`https?://(\\S+)`).exec(exec.execSyncRead(`git remote -v`))[1];
  28. exec.execSyncSilent(`git remote add deploy "https://${process.env.GIT_USER}:${process.env.GIT_TOKEN}@${remoteUrl}"`);
  29. exec.execSync(`git checkout ${ONLY_ON_BRANCH}`);
  30. }
  31. function calcNewVersion() {
  32. const currentVersion = exec.execSyncRead(`npm view ${process.env.npm_package_name}@${VERSION_TAG} version`);
  33. console.log(`${VERSION_TAG} version: ${currentVersion}`);
  34. const packageVersion = process.env.npm_package_version;
  35. console.log(`package version: ${packageVersion}`);
  36. const greater = semver.gt(currentVersion, packageVersion) ? currentVersion : packageVersion;
  37. return semver.inc(greater, VERSION_INC);
  38. }
  39. function createNpmRc() {
  40. const content = `
  41. email=\${NPM_EMAIL}
  42. //registry.npmjs.org/:_authToken=\${NPM_TOKEN}
  43. `;
  44. fs.writeFileSync(`.npmrc`, content);
  45. }
  46. function tagAndPublish(newVersion) {
  47. console.log(`new version is: ${newVersion}`);
  48. exec.execSync(`npm version ${newVersion} -m "v${newVersion} [ci skip]"`);
  49. exec.execSyncSilent(`git push deploy --tags`);
  50. exec.execSync(`npm publish --tag ${VERSION_TAG}`);
  51. }
  52. function run() {
  53. if (!validateEnv()) {
  54. return;
  55. }
  56. setupGit();
  57. createNpmRc();
  58. tagAndPublish(calcNewVersion());
  59. }
  60. run();