react-native-navigation的迁移库

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