postversion.js 774 B

123456789101112131415161718192021222324252627282930313233
  1. import {exec} from 'child_process';
  2. import fs from 'fs';
  3. import path from 'path';
  4. /* eslint no-console: 0 */
  5. /**
  6. * Determines whether or not the project has the Bower setup by checking for
  7. * the presence of a bower.json file.
  8. *
  9. * @return {Boolean}
  10. */
  11. const hasBower = () => {
  12. try {
  13. fs.statSync(path.join(__dirname, '../bower.json'));
  14. return true;
  15. } catch (x) {
  16. return false;
  17. }
  18. };
  19. // If the project supports Bower, roll HEAD back one commit to avoid having
  20. // the tagged commit - with `dist/` - in the main history.
  21. if (hasBower()) {
  22. exec('git reset --hard HEAD~1', (err, stdout, stderr) => {
  23. if (err) {
  24. process.stdout.write(err.stack);
  25. process.exit(err.status || 1);
  26. } else {
  27. process.stdout.write(stdout);
  28. }
  29. });
  30. }