index.js 666 B

12345678910111213141516171819202122232425262728
  1. 'use strict'
  2. function inCommand (cmd) {
  3. try {
  4. var npm_config_argv = JSON.parse(process.env['npm_config_argv'])
  5. } catch (e) {
  6. return false
  7. }
  8. if (typeof npm_config_argv !== 'object') process.exit(1)
  9. if (!npm_config_argv.cooked) process.exit(1)
  10. if (!npm_config_argv.cooked instanceof Array) process.exit(1)
  11. var V
  12. while ((V = npm_config_argv.cooked.shift()) !== undefined) {
  13. if (/^-/.test(V)) continue
  14. if (cmd.test(V)) return true
  15. return false
  16. }
  17. return false
  18. }
  19. exports.inPublish = function () {
  20. return inCommand(/^pu(b(l(i(sh?)?)?)?)?$/)
  21. }
  22. exports.inInstall = function () {
  23. return inCommand(/^i(n(s(t(a(ll?)?)?)?)?)?$/)
  24. }