UNPKG

1.87 kBJavaScriptView Raw
1/* eslint-disable max-len */
2var fs = require('fs');
3var os = require('os');
4var path = require('path');
5var env = process.env;
6
7var ADBLOCK = is(env.ADBLOCK);
8var CI = is(env.CI);
9var COLOR = is(env.npm_config_color);
10var DISABLE_OPENCOLLECTIVE = is(env.DISABLE_OPENCOLLECTIVE);
11var SILENT = ['silent', 'error', 'warn'].indexOf(env.npm_config_loglevel) !== -1;
12var MINUTE = 60 * 1000;
13
14var BANNER = '\u001B[96mThank you for using core-js (\u001B[94m https://github.com/zloirock/core-js \u001B[96m) for polyfilling JavaScript standard library!\u001B[0m\n\n' +
15 '\u001B[96mThe project needs your help! Please consider supporting of core-js on Open Collective or Patreon: \u001B[0m\n' +
16 '\u001B[96m>\u001B[94m https://opencollective.com/core-js \u001B[0m\n' +
17 '\u001B[96m>\u001B[94m https://www.patreon.com/zloirock \u001B[0m\n\n' +
18 '\u001B[96mAlso, the author of core-js (\u001B[94m https://github.com/zloirock \u001B[96m) is looking for a good job -)\u001B[0m\n';
19
20function is(it) {
21 return !!it && it !== '0' && it !== 'false';
22}
23
24function isBannerRequired() {
25 if (ADBLOCK || CI || DISABLE_OPENCOLLECTIVE || SILENT) return false;
26 var file = path.join(os.tmpdir(), 'core-js-banners');
27 var banners = [];
28 try {
29 var DELTA = Date.now() - fs.statSync(file).mtime;
30 if (DELTA >= 0 && DELTA < MINUTE * 3) {
31 banners = JSON.parse(fs.readFileSync(file, 'utf8'));
32 if (banners.indexOf(BANNER) !== -1) return false;
33 }
34 } catch (error) {
35 banners = [];
36 }
37 try {
38 banners.push(BANNER);
39 fs.writeFileSync(file, JSON.stringify(banners), 'utf8');
40 } catch (error) { /* empty */ }
41 return true;
42}
43
44function showBanner() {
45 // eslint-disable-next-line no-console,no-control-regex
46 console.log(COLOR ? BANNER : BANNER.replace(/\u001B\[\d+m/g, ''));
47}
48
49if (isBannerRequired()) showBanner();