patch-release.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env node
  2. var fs = require('fs');
  3. var path = require('path');
  4. var childProcess = require('child_process');
  5. // Make sure we have required command line arguments.
  6. if (process.argv.length < 3) {
  7. var msg = '** Must supply a target package';
  8. process.stderr.write(msg);
  9. process.exit(1);
  10. }
  11. // Extract the desired package target.
  12. var target = process.argv[2];
  13. var packagePath = path.resolve(path.join('packages', target));
  14. if (!fs.existsSync(packagePath)) {
  15. console.log('Invalid package path', packagePath);
  16. process.exit(1);
  17. }
  18. /**
  19. * Run a command with terminal output.
  20. */
  21. function run(cmd, options) {
  22. options = options || {};
  23. options['stdio'] = [1,2,3];
  24. console.log('>', cmd);
  25. childProcess.execSync(cmd, options);
  26. }
  27. // Perform the patch operations.
  28. console.log('Patching', target, '...');
  29. run('npm run build:packages');
  30. run('npm version patch', { cwd: packagePath });
  31. run('npm publish', { cwd: packagePath});
  32. // Extract the new package info.
  33. var data = require(path.join(packagePath, 'package.json'));
  34. var name = data.name;
  35. var version = data.version;
  36. run('npm run update:dependency ' + name + ' ^' + version);
  37. run('git commit -a -m "Release ' + name + '@' + version + '"');
  38. run('git tag ' + name + '@' + version);
  39. console.log('\n\nFinished, make sure to push the commit and the tag.')