1 |
|
2 | var fs = require('fs');
|
3 | var os = require('os');
|
4 | var path = require('path');
|
5 | var env = process.env;
|
6 |
|
7 | var ADBLOCK = is(env.ADBLOCK);
|
8 | var COLOR = is(env.npm_config_color);
|
9 | var DISABLE_OPENCOLLECTIVE = is(env.DISABLE_OPENCOLLECTIVE);
|
10 | var SILENT = ['silent', 'error', 'warn'].indexOf(env.npm_config_loglevel) !== -1;
|
11 | var MINUTE = 60 * 1000;
|
12 |
|
13 |
|
14 | var CI = [
|
15 | 'BUILD_NUMBER',
|
16 | 'CI',
|
17 | 'CONTINUOUS_INTEGRATION',
|
18 | 'RUN_ID'
|
19 | ].some(function (it) { return is(env[it]); });
|
20 |
|
21 | 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' +
|
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 |
|
27 | function is(it) {
|
28 | return !!it && it !== '0' && it !== 'false';
|
29 | }
|
30 |
|
31 | function 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) { }
|
48 | return true;
|
49 | }
|
50 |
|
51 | function showBanner() {
|
52 |
|
53 | console.log(COLOR ? BANNER : BANNER.replace(/\u001B\[\d+m/g, ''));
|
54 | }
|
55 |
|
56 | if (isBannerRequired()) showBanner();
|