index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Gather initial information
  2. var isCI = false
  3. var debug = false
  4. var tty = false
  5. var nodeENV = 'development'
  6. var browser = typeof window !== 'undefined'
  7. var platform = ''
  8. var minimal = false
  9. // Boolean helper
  10. function toBoolean(val) {
  11. return (!val || val === 'false') ? false : true
  12. }
  13. // Process dependent
  14. if (typeof process !== 'undefined') {
  15. // Platform
  16. if (process.platform) {
  17. platform = String(process.platform)
  18. }
  19. // TTY
  20. if (process.stdout) {
  21. tty = toBoolean(process.stdout.isTTY)
  22. }
  23. // Is CI
  24. isCI = Boolean(require('ci-info').isCI)
  25. // Env dependent
  26. if (process.env) {
  27. // NODE_ENV
  28. if (process.env.NODE_ENV) {
  29. nodeENV = process.env.NODE_ENV
  30. }
  31. // DEBUG
  32. debug = toBoolean(process.env.DEBUG)
  33. // MINIMAL
  34. minimal = toBoolean(process.env.MINIMAL)
  35. }
  36. }
  37. // Construct env object
  38. var env = {
  39. browser: browser,
  40. test: nodeENV === 'test',
  41. dev: nodeENV === 'development' || nodeENV === 'dev',
  42. production: nodeENV === 'production',
  43. debug: debug,
  44. ci: isCI,
  45. tty: tty,
  46. minimal: undefined,
  47. minimalCLI: undefined,
  48. windows: /^win/i.test(platform),
  49. darwin: /^darwin/i.test(platform),
  50. linux: /^linux/i.test(platform),
  51. }
  52. // Compute minimal
  53. env.minimal = minimal || env.ci || env.test || !env.tty
  54. env.minimalCLI = env.minimal
  55. // Export env
  56. module.exports = Object.freeze(env)