UNPKG

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