Skip to content

Commit

Permalink
feat(opencollective prompt): remove .lastocprint file from fs
Browse files Browse the repository at this point in the history
  • Loading branch information
misterdev committed Mar 12, 2019
1 parent 790d27a commit b96ad56
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,3 @@ yarn.lock

# source maps of docs
docs/**/*.map

# open collective badge
.lastocprint
15 changes: 13 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

(function() {
// wrap in IIFE to be able to use return

const importLocal = require("import-local");
// Prefer the local installation of webpack-cli
if (importLocal(__filename)) {
Expand Down Expand Up @@ -473,7 +472,19 @@ For more information, see https://webpack.js.org/api/cli/.`);
const statsString = stats.toString(outputOptions);
const delimiter = outputOptions.buildDelimiter ? `${outputOptions.buildDelimiter}\n` : "";
if (statsString) stdout.write(`${statsString}\n${delimiter}`);
require("./opencollective");


const now = new Date();
const MONDAY = 2;
const SIX_DAYS = 518400000;
if (now.getDay() === MONDAY) {
const statSync = require("fs").statSync;
const lastPrint = statSync(__dirname + "/opencollective.js").atime;
const lastPrintTS = new Date(lastPrint).getTime();
if (now.getTime() - lastPrintTS > SIX_DAYS) {
require("./opencollective");
}
}
}
if (!options.watch && stats.hasErrors()) {
process.exitCode = 2;
Expand Down
16 changes: 1 addition & 15 deletions bin/opencollective.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const chalk = require("chalk");
const fs = require("fs");
const path = require("path");

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


const now = new Date();
const MONDAY = 1;
if (now.getDay() === MONDAY) {
const lastPrintFile = path.resolve(__dirname, "../.lastocprint");
fs.readFile(lastPrintFile, "utf8", (err, lastPrint = 0) => {
if (err && err.code !== "ENOENT") return;
if (now - lastPrint > 6 * 24 * 60 * 60 * 1000) {
printBadge();
fs.writeFileSync(lastPrintFile, now);
}
});
}
printBadge();

0 comments on commit b96ad56

Please sign in to comment.