bin.js 915 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env node
  2. const pkg = require('./package.json')
  3. const { enableAndSave, disableAndSave } = require('./index')
  4. const usage = `Usage
  5. $ pinst
  6. Options
  7. --enable, -e Enable postinstall hook
  8. --disable, -d Disable postinstall hook
  9. --silent, -s
  10. Examples
  11. $ pinst --enable`
  12. function run(args) {
  13. // Silent
  14. const silent = args.includes('--silent') || args.includes('-s')
  15. // Enable
  16. if (args.includes('--enable') || args.includes('-e')) {
  17. if (!silent) console.log('pinst enable')
  18. return enableAndSave()
  19. }
  20. // Disable
  21. if (args.includes('--disable') || args.includes('-d')) {
  22. if (!silent) console.log('pinst disable')
  23. return disableAndSave()
  24. }
  25. // Version
  26. if (args.includes('--version') || args.includes('-v')) {
  27. return console.log(pkg.version)
  28. }
  29. // No known flag provided
  30. console.log(usage)
  31. process.exit(1)
  32. }
  33. const [, , ...args] = process.argv
  34. run(args)