1234567891011121314151617181920212223242526272829
  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. }