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 CI = is(env.CI);
|
9 | var COLOR = is(env.npm_config_color);
|
10 | var DISABLE_OPENCOLLECTIVE = is(env.DISABLE_OPENCOLLECTIVE);
|
11 | var SILENT = ['silent', 'error', 'warn'].indexOf(env.npm_config_loglevel) !== -1;
|
12 | var MINUTE = 60 * 1000;
|
13 |
|
14 | 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' +
|
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 |
|
20 | function is(it) {
|
21 | return !!it && it !== '0' && it !== 'false';
|
22 | }
|
23 |
|
24 | function 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) { }
|
41 | return true;
|
42 | }
|
43 |
|
44 | function showBanner() {
|
45 |
|
46 | console.log(COLOR ? BANNER : BANNER.replace(/\u001B\[\d+m/g, ''));
|
47 | }
|
48 |
|
49 | if (isBannerRequired()) showBanner();
|