react-native-navigation的迁移库

release.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. execSync(`rm -f package-lock.json`);
  43. const npmrcPath = p.resolve(`${__dirname}/.npmrc`);
  44. execSync(`cp -rf ${npmrcPath} .`);
  45. }
  46. function tagAndPublish(newVersion) {
  47. console.log(`new version is: ${newVersion}`);
  48. execSync(`npm version ${newVersion} -m "v${newVersion} [ci skip]"`);
  49. execSync(`npm publish --tag latest`);
  50. execSyncSilently(`git push deploy --tags`);
  51. }
  52. function run() {
  53. if (!validateEnv()) {
  54. return;
  55. }
  56. setupGit();
  57. copyNpmRc();
  58. tagAndPublish(calcNewVersion());
  59. }
  60. run();