react-native-navigation的迁移库

release.js 2.1KB

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