index.js 780 B

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