-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(opencollective prompt): add prompt in postinstall script
- Loading branch information
Showing
4 changed files
with
63 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,6 @@ yarn.lock | |
|
||
# source maps of docs | ||
docs/**/*.map | ||
|
||
# open collective badge | ||
.lastocprint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const child_process = require("child_process"); | ||
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) { | ||
if (process.stdout.isTTY && process.platform === "darwin") { | ||
return emoji; | ||
} else { | ||
return ""; | ||
} | ||
} | ||
|
||
function print(str = "", color = "dim") { | ||
const terminalCols = process.platform === "win32" ? 80 : parseInt(child_process.execSync("tput cols").toString()); | ||
// eslint-disable-next-line no-control-regex | ||
const ansiEscapeSeq = /\u001b\[[0-9]{1,2}m/g; | ||
const strLength = str.replace(ansiEscapeSeq, "").length; | ||
const leftPaddingLength = Math.floor((terminalCols - strLength) / 2); | ||
const leftPadding = " ".repeat(leftPaddingLength); | ||
str = chalk[color](str); | ||
console.log(leftPadding, str); | ||
} | ||
|
||
function printBadge() { | ||
console.log("\n"); | ||
print(`${chalk.bold("Thanks for using")} ${chalk.bold.blue("Webpack!")}`); | ||
print(`Please consider donating to our ${chalk.bold.blue("Open Collective")}`); | ||
print("to help us maintain this package."); | ||
console.log("\n\n"); | ||
print(`${emoji("👉")} ${chalk.bold.yellow(" Donate:")} ${chalk.reset.underline.yellow("https://opencollective.com/webpack/donate")}`); | ||
console.log("\n"); | ||
} | ||
|
||
|
||
const now = new Date(); | ||
if (now.getDay() == 1 ) { | ||
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); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters