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