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) {
  15. throw new Error(`releasing is only available from CI`);
  16. }
  17. if (!process.env.JENKINS_MASTER) {
  18. console.log(`not publishing on a different build`);
  19. return false;
  20. }
  21. return true;
  22. }
  23. function setupGit() {
  24. execSyncSilently(`git config --global push.default simple`);
  25. execSyncSilently(`git config --global user.email "${process.env.GIT_EMAIL}"`);
  26. execSyncSilently(`git config --global user.name "${process.env.GIT_USER}"`);
  27. const remoteUrl = new RegExp(`https?://(\\S+)`).exec(execSyncRead(`git remote -v`))[1];
  28. execSyncSilently(`git remote add deploy "https://${process.env.GIT_USER}:${process.env.GIT_TOKEN}@${remoteUrl}"`);
  29. execSync(`git checkout master`);
  30. }
  31. function calcNewVersion() {
  32. const latestVersion = execSyncRead(`npm view ${process.env.npm_package_name}@latest version`);
  33. console.log(`latest version is: ${latestVersion}`);
  34. console.log(`package version is: ${process.env.npm_package_version}`);
  35. if (semver.gt(process.env.npm_package_version, latestVersion)) {
  36. return semver.inc(process.env.npm_package_version, 'patch');
  37. } else {
  38. return semver.inc(latestVersion, 'patch');
  39. }
  40. }
  41. function copyNpmRc() {
  42. const npmrcPath = p.resolve(`${__dirname}/.npmrc`);
  43. execSync(`cp -rf ${npmrcPath} .`);
  44. }
  45. function tagAndPublish(newVersion) {
  46. console.log(`new version is: ${newVersion}`);
  47. execSync(`npm version ${newVersion} -m "v${newVersion} [ci skip]"`);
  48. execSync(`npm publish --tag latest`);
  49. execSyncSilently(`git push deploy --tags`);
  50. }
  51. function run() {
  52. if (!validateEnv()) {
  53. return;
  54. }
  55. setupGit();
  56. copyNpmRc();
  57. tagAndPublish(calcNewVersion());
  58. }
  59. run();