postinstall.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* eslint-disable max-len -- for better formatting */
  2. var env = process.env;
  3. var ADBLOCK = is(env.ADBLOCK);
  4. var COLOR = is(env.npm_config_color);
  5. var DISABLE_OPENCOLLECTIVE = is(env.DISABLE_OPENCOLLECTIVE);
  6. var SILENT = ['silent', 'error', 'warn'].indexOf(env.npm_config_loglevel) !== -1;
  7. var OPEN_SOURCE_CONTRIBUTOR = is(env.OPEN_SOURCE_CONTRIBUTOR);
  8. // you could add a PR with an env variable for your CI detection
  9. var CI = [
  10. 'BUILD_NUMBER',
  11. 'CI',
  12. 'CONTINUOUS_INTEGRATION',
  13. 'DRONE',
  14. 'RUN_ID'
  15. ].some(function (it) { return is(env[it]); });
  16. var BANNER = '\u001b[35m\u001b[1mLove Swiper? Support Vladimir\'s work by donating or pledging: \u001B[0m\n' +
  17. '\u001b[22m\u001b[39m\u001b[32m> On Patreon https://patreon.com/swiperjs \u001B[0m\n' +
  18. '\u001b[22m\u001b[39m\u001b[32m> On Open Collective https://opencollective.com/swiper';
  19. function is(it) {
  20. return !!it && it !== '0' && it !== 'false';
  21. }
  22. function isBannerRequired() {
  23. return !(ADBLOCK || CI || DISABLE_OPENCOLLECTIVE || SILENT || OPEN_SOURCE_CONTRIBUTOR);
  24. }
  25. function showBanner() {
  26. // eslint-disable-next-line no-console,no-control-regex -- output
  27. console.log(COLOR ? BANNER : BANNER.replace(/\u001B\[\d+m/g, ''));
  28. }
  29. if (isBannerRequired()) showBanner();