Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix repeatedly showing postinstall to once a day #597

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/core-js/scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ var COLOR = is(env.npm_config_color);
var DISABLE_OPENCOLLECTIVE = is(env.DISABLE_OPENCOLLECTIVE);
var SILENT = !!~['silent', 'error', 'warn'].indexOf(env.npm_config_loglevel);

var tmpdir = require('os').tmpdir();
var fs = require('fs');

var minute = 60 * 1000;

var SEEN = false;
try {
var delta = Date.now() - fs.statSync(tmpdir + '/core-js-banner').mtime;
SEEN = delta < 5 * minute;
} catch (e) {}

function is(it) {
return !!it && it !== '0' && it !== 'false';
}
Expand All @@ -15,10 +26,14 @@ function log(it) {
console.log(COLOR ? it : it.replace(/\u001B\[\d+m/g, ''));
}

if (!ADBLOCK && !CI && !DISABLE_OPENCOLLECTIVE && !SILENT) {
if (!ADBLOCK && !CI && !DISABLE_OPENCOLLECTIVE && !SILENT && !SEEN) {
log('\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');
log('\u001B[96mThe project needs your help! Please consider supporting of core-js on Open Collective or Patreon: \u001B[0m');
log('\u001B[96m>\u001B[94m https://opencollective.com/core-js \u001B[0m');
log('\u001B[96m>\u001B[94m https://www.patreon.com/zloirock \u001B[0m\n');
log('\u001B[96mAlso, the author of core-js (\u001B[94m https://github.com/zloirock \u001B[96m) is looking for a good job -)\u001B[0m\n');

try {
fs.writeFileSync(tmpdir + '/core-js-banner', '');
} catch (e) {}
}