Skip to content

Commit b96ad56

Browse files
committedMar 12, 2019
feat(opencollective prompt): remove .lastocprint file from fs
1 parent 790d27a commit b96ad56

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed
 

‎.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,3 @@ yarn.lock
3737

3838
# source maps of docs
3939
docs/**/*.map
40-
41-
# open collective badge
42-
.lastocprint

‎bin/cli.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
(function() {
99
// wrap in IIFE to be able to use return
10-
1110
const importLocal = require("import-local");
1211
// Prefer the local installation of webpack-cli
1312
if (importLocal(__filename)) {
@@ -473,7 +472,19 @@ For more information, see https://webpack.js.org/api/cli/.`);
473472
const statsString = stats.toString(outputOptions);
474473
const delimiter = outputOptions.buildDelimiter ? `${outputOptions.buildDelimiter}\n` : "";
475474
if (statsString) stdout.write(`${statsString}\n${delimiter}`);
476-
require("./opencollective");
475+
476+
477+
const now = new Date();
478+
const MONDAY = 2;
479+
const SIX_DAYS = 518400000;
480+
if (now.getDay() === MONDAY) {
481+
const statSync = require("fs").statSync;
482+
const lastPrint = statSync(__dirname + "/opencollective.js").atime;
483+
const lastPrintTS = new Date(lastPrint).getTime();
484+
if (now.getTime() - lastPrintTS > SIX_DAYS) {
485+
require("./opencollective");
486+
}
487+
}
477488
}
478489
if (!options.watch && stats.hasErrors()) {
479490
process.exitCode = 2;

‎bin/opencollective.js

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
const chalk = require("chalk");
2-
const fs = require("fs");
3-
const path = require("path");
42

53
// Only show emoji on OSx (Windows shell doesn't like them that much ¯\_(ツ)_/¯ )
64
function emoji(emoji) {
@@ -32,16 +30,4 @@ function printBadge() {
3230
console.log("\n");
3331
}
3432

35-
36-
const now = new Date();
37-
const MONDAY = 1;
38-
if (now.getDay() === MONDAY) {
39-
const lastPrintFile = path.resolve(__dirname, "../.lastocprint");
40-
fs.readFile(lastPrintFile, "utf8", (err, lastPrint = 0) => {
41-
if (err && err.code !== "ENOENT") return;
42-
if (now - lastPrint > 6 * 24 * 60 * 60 * 1000) {
43-
printBadge();
44-
fs.writeFileSync(lastPrintFile, now);
45-
}
46-
});
47-
}
33+
printBadge();

0 commit comments

Comments
 (0)