react-native-navigation的迁移库

release.js 2.2KB

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