From dd9d5285c19a2857e18033468b7420ede392f6e9 Mon Sep 17 00:00:00 2001 From: "devid.farinelli@gmail.com" Date: Mon, 11 Mar 2019 16:56:53 +0100 Subject: [PATCH 01/10] feat(opencollective prompt): add prompt in postinstall script --- .gitignore | 3 +++ bin/cli.js | 1 + bin/opencollective.js | 47 +++++++++++++++++++++++++++++++++++++++++++ package.json | 31 +++++++++++----------------- 4 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 bin/opencollective.js diff --git a/.gitignore b/.gitignore index ef696edb785..f84c225c2ba 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,6 @@ yarn.lock # source maps of docs docs/**/*.map + +# open collective badge +.lastocprint diff --git a/bin/cli.js b/bin/cli.js index b0dc2649d2d..bd2f3602565 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -473,6 +473,7 @@ 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"); } if (!options.watch && stats.hasErrors()) { process.exitCode = 2; diff --git a/bin/opencollective.js b/bin/opencollective.js new file mode 100644 index 00000000000..cb9f08f80d7 --- /dev/null +++ b/bin/opencollective.js @@ -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); + } + }); +} \ No newline at end of file diff --git a/package.json b/package.json index b9430b21ae3..14c7b1e2f58 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "format": "prettier-eslint ./bin/*.js ./test/**/*.js ./packages/**/*.js --write", "lint:codeOnly": "eslint \"{bin}/**/!(__testfixtures__)/*.js\" \"{bin}/**.js\"", "lint": "eslint \"./bin/*.js\" \"./test/**/*.js\" \"packages/**/!(node_modules)/*.test.js\"", + "postinstall": "node ./bin/opencollective.js", "pretest": "npm run build && npm run lint && npm run tslint", "reportCoverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json --disable=gcov", "test": "nyc jest --maxWorkers=4 --reporters=default --reporters=jest-junit", @@ -62,10 +63,6 @@ ] }, "jest": { - "testPathIgnorePatterns": [ - "^.+\\.(ts)?$", - "/node_modules/" - ], "testEnvironment": "node", "collectCoverage": true, "coverageReporters": [ @@ -120,44 +117,40 @@ "loader-utils": "^1.1.0", "supports-color": "^5.5.0", "v8-compile-cache": "^2.0.2", - "yargs": "^12.0.5" + "yargs": "^12.0.4" }, "peerDependencies": { "webpack": "4.x.x" }, "devDependencies": { - "@babel/preset-env": "^7.3.4", - "@babel/register": "^7.0.0", "@commitlint/cli": "^7.2.1", "@commitlint/config-lerna-scopes": "^7.2.1", - "@commitlint/prompt-cli": "^7.5.0", + "@commitlint/prompt-cli": "^7.2.1", "@commitlint/travis-cli": "^7.2.1", - "@types/jest": "^23.3.14", + "@types/jest": "^23.3.9", "@types/node": "^10.12.9", "babel-preset-env": "^1.7.0", - "babel-preset-jest": "^24.3.0", "bundlesize": "^0.17.0", "codecov": "^3.1.0", - "commitizen": "^3.0.7", + "commitizen": "^3.0.4", "commitlint-config-cz": "^0.10.1", "conventional-changelog-cli": "^2.0.11", "cz-customizable": "^5.3.0", "eslint": "^5.9.0", "eslint-plugin-node": "^8.0.0", - "esm": "^3.2.14", "execa": "^1.0.0", "husky": "^1.1.4", - "jest": "^24.3.1", - "jest-cli": "^24.3.1", - "jest-junit": "^6.3.0", - "lerna": "^3.13.1", + "jest": "^23.6.0", + "jest-cli": "^23.6.0", + "jest-junit": "^5.0.0", + "lerna": "^3.10.7", "lint-staged": "7.x.x", - "nyc": "^13.3.0", + "nyc": "^13.1.0", "prettier-eslint-cli": "^4.7.1", "readable-stream": "^3.0.6", "rimraf": "^2.6.2", "schema-utils": "^1.0.0", - "ts-jest": "^23.10.5", + "ts-jest": "^23.10.4", "ts-node": "^7.0.1", "tslint": "^5.11.0", "typedoc": "^0.13.0", @@ -170,4 +163,4 @@ "type": "opencollective", "url": "https://opencollective.com/webpack" } -} +} \ No newline at end of file From f0807331481210d642bbdac4dabba01a52fa5807 Mon Sep 17 00:00:00 2001 From: "devid.farinelli@gmail.com" Date: Mon, 11 Mar 2019 17:22:25 +0100 Subject: [PATCH 02/10] feat(opencollective prompt): clear package.json modifications --- package.json | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 14c7b1e2f58..a5ca888edba 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,10 @@ ] }, "jest": { + "testPathIgnorePatterns": [ + "^.+\\.(ts)?$", + "/node_modules/" + ], "testEnvironment": "node", "collectCoverage": true, "coverageReporters": [ @@ -117,40 +121,44 @@ "loader-utils": "^1.1.0", "supports-color": "^5.5.0", "v8-compile-cache": "^2.0.2", - "yargs": "^12.0.4" + "yargs": "^12.0.5" }, "peerDependencies": { "webpack": "4.x.x" }, "devDependencies": { + "@babel/preset-env": "^7.3.4", + "@babel/register": "^7.0.0", "@commitlint/cli": "^7.2.1", "@commitlint/config-lerna-scopes": "^7.2.1", - "@commitlint/prompt-cli": "^7.2.1", + "@commitlint/prompt-cli": "^7.5.0", "@commitlint/travis-cli": "^7.2.1", - "@types/jest": "^23.3.9", + "@types/jest": "^23.3.14", "@types/node": "^10.12.9", "babel-preset-env": "^1.7.0", + "babel-preset-jest": "^24.3.0", "bundlesize": "^0.17.0", "codecov": "^3.1.0", - "commitizen": "^3.0.4", + "commitizen": "^3.0.7", "commitlint-config-cz": "^0.10.1", "conventional-changelog-cli": "^2.0.11", "cz-customizable": "^5.3.0", "eslint": "^5.9.0", "eslint-plugin-node": "^8.0.0", + "esm": "^3.2.14", "execa": "^1.0.0", "husky": "^1.1.4", - "jest": "^23.6.0", - "jest-cli": "^23.6.0", - "jest-junit": "^5.0.0", - "lerna": "^3.10.7", + "jest": "^24.3.1", + "jest-cli": "^24.3.1", + "jest-junit": "^6.3.0", + "lerna": "^3.13.1", "lint-staged": "7.x.x", - "nyc": "^13.1.0", + "nyc": "^13.3.0", "prettier-eslint-cli": "^4.7.1", "readable-stream": "^3.0.6", "rimraf": "^2.6.2", "schema-utils": "^1.0.0", - "ts-jest": "^23.10.4", + "ts-jest": "^23.10.5", "ts-node": "^7.0.1", "tslint": "^5.11.0", "typedoc": "^0.13.0", @@ -163,4 +171,4 @@ "type": "opencollective", "url": "https://opencollective.com/webpack" } -} \ No newline at end of file +} From ea906d8c0bffba815991563f9ea79be1c8f929dd Mon Sep 17 00:00:00 2001 From: "devid.farinelli@gmail.com" Date: Mon, 11 Mar 2019 17:38:48 +0100 Subject: [PATCH 03/10] feat(opencollective prompt): lint --- bin/opencollective.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/opencollective.js b/bin/opencollective.js index cb9f08f80d7..e619ba330f1 100644 --- a/bin/opencollective.js +++ b/bin/opencollective.js @@ -35,7 +35,7 @@ function printBadge() { const now = new Date(); -if (now.getDay() == 1 ) { +if (now.getDay() === 1) { const lastPrintFile = path.resolve(__dirname, "../.lastocprint"); fs.readFile(lastPrintFile, "utf8", (err, lastPrint = 0) => { if (err && err.code !== "ENOENT") return; @@ -44,4 +44,4 @@ if (now.getDay() == 1 ) { fs.writeFileSync(lastPrintFile, now); } }); -} \ No newline at end of file +} From ea0039acae8bb7c71e6db2ead495f65295c40f78 Mon Sep 17 00:00:00 2001 From: "devid.farinelli@gmail.com" Date: Mon, 11 Mar 2019 17:45:50 +0100 Subject: [PATCH 04/10] feat(opencollective prompt): fix azure ci --- bin/opencollective.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/opencollective.js b/bin/opencollective.js index e619ba330f1..2a6a3801e3a 100644 --- a/bin/opencollective.js +++ b/bin/opencollective.js @@ -13,7 +13,7 @@ function emoji(emoji) { } function print(str = "", color = "dim") { - const terminalCols = process.platform === "win32" ? 80 : parseInt(child_process.execSync("tput cols").toString()); + const terminalCols = process.platform === "win32" ? 80 : parseInt(child_process.execSync("tty -s && 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; From badc32d4781f6caaa7d7cc17220f18e959e7b3ca Mon Sep 17 00:00:00 2001 From: "devid.farinelli@gmail.com" Date: Mon, 11 Mar 2019 18:16:13 +0100 Subject: [PATCH 05/10] feat(opencollective prompt): set terminal cols to 80 --- bin/opencollective.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/opencollective.js b/bin/opencollective.js index 2a6a3801e3a..d11b2679ea1 100644 --- a/bin/opencollective.js +++ b/bin/opencollective.js @@ -1,4 +1,3 @@ -const child_process = require("child_process"); const chalk = require("chalk"); const fs = require("fs"); const path = require("path"); @@ -13,7 +12,7 @@ function emoji(emoji) { } function print(str = "", color = "dim") { - const terminalCols = process.platform === "win32" ? 80 : parseInt(child_process.execSync("tty -s && tput cols").toString()); + const terminalCols = 80; // eslint-disable-next-line no-control-regex const ansiEscapeSeq = /\u001b\[[0-9]{1,2}m/g; const strLength = str.replace(ansiEscapeSeq, "").length; From 790d27aa09cdbf17997929780d6afb9777a9542b Mon Sep 17 00:00:00 2001 From: "devid.farinelli@gmail.com" Date: Mon, 11 Mar 2019 20:41:18 +0100 Subject: [PATCH 06/10] feat(opencollective prompt): extract weekday to variable --- bin/opencollective.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/opencollective.js b/bin/opencollective.js index d11b2679ea1..c542a868a84 100644 --- a/bin/opencollective.js +++ b/bin/opencollective.js @@ -34,7 +34,8 @@ function printBadge() { const now = new Date(); -if (now.getDay() === 1) { +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; From b96ad56d943fcbfc7b6da60fd0711e513c141732 Mon Sep 17 00:00:00 2001 From: Devid Farinelli Date: Tue, 12 Mar 2019 12:20:01 +0100 Subject: [PATCH 07/10] feat(opencollective prompt): remove .lastocprint file from fs --- .gitignore | 3 --- bin/cli.js | 15 +++++++++++++-- bin/opencollective.js | 16 +--------------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index f84c225c2ba..ef696edb785 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,3 @@ yarn.lock # source maps of docs docs/**/*.map - -# open collective badge -.lastocprint diff --git a/bin/cli.js b/bin/cli.js index bd2f3602565..108aa3c6b55 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -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)) { @@ -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; diff --git a/bin/opencollective.js b/bin/opencollective.js index c542a868a84..a6266a25b4e 100644 --- a/bin/opencollective.js +++ b/bin/opencollective.js @@ -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) { @@ -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(); From c2351b1fcf6ebf4132a7590d34568fc64297fd6a Mon Sep 17 00:00:00 2001 From: Devid Farinelli Date: Tue, 12 Mar 2019 19:06:17 +0100 Subject: [PATCH 08/10] feat(opencollective prompt): fix typo --- bin/cli.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/cli.js b/bin/cli.js index 108aa3c6b55..9bb50482867 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -7,6 +7,7 @@ (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)) { @@ -475,7 +476,7 @@ For more information, see https://webpack.js.org/api/cli/.`); const now = new Date(); - const MONDAY = 2; + const MONDAY = 1; const SIX_DAYS = 518400000; if (now.getDay() === MONDAY) { const statSync = require("fs").statSync; From 3af73a87291abb94cf4b0f550a5f6dce7e48877f Mon Sep 17 00:00:00 2001 From: "devid.farinelli@gmail.com" Date: Wed, 13 Mar 2019 20:55:38 +0100 Subject: [PATCH 09/10] feat(opencollective prompt): work on windows setting atime by code --- bin/cli.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 9bb50482867..431009b4a1c 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -478,12 +478,15 @@ For more information, see https://webpack.js.org/api/cli/.`); const now = new Date(); const MONDAY = 1; const SIX_DAYS = 518400000; + const openCollectivePath = __dirname + "/opencollective.js"; if (now.getDay() === MONDAY) { - const statSync = require("fs").statSync; - const lastPrint = statSync(__dirname + "/opencollective.js").atime; + const { statSync, utimesSync } = require("fs"); + const lastPrint = statSync(openCollectivePath).atime; const lastPrintTS = new Date(lastPrint).getTime(); if (now.getTime() - lastPrintTS > SIX_DAYS) { - require("./opencollective"); + require(openCollectivePath); + // On windows we need to update the atime + utimesSync(openCollectivePath, now, now); } } } From 55992a45a302977ef5e5075e81cc127e9fafdf07 Mon Sep 17 00:00:00 2001 From: Devid Farinelli Date: Fri, 15 Mar 2019 20:26:05 +0100 Subject: [PATCH 10/10] docs(opencollective prompt): improve code clarity --- bin/cli.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 431009b4a1c..40cef49f4c9 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -474,18 +474,22 @@ For more information, see https://webpack.js.org/api/cli/.`); const delimiter = outputOptions.buildDelimiter ? `${outputOptions.buildDelimiter}\n` : ""; if (statsString) stdout.write(`${statsString}\n${delimiter}`); - - const now = new Date(); + /** + * Show a hint to donate to our Opencollective + * once a week, only on Monday + */ + const openCollectivePath = __dirname + "/opencollective.js"; const MONDAY = 1; const SIX_DAYS = 518400000; - const openCollectivePath = __dirname + "/opencollective.js"; + const now = new Date(); if (now.getDay() === MONDAY) { const { statSync, utimesSync } = require("fs"); const lastPrint = statSync(openCollectivePath).atime; const lastPrintTS = new Date(lastPrint).getTime(); - if (now.getTime() - lastPrintTS > SIX_DAYS) { + const timeSinceLastPrint = now.getTime() - lastPrintTS; + if (timeSinceLastPrint > SIX_DAYS) { require(openCollectivePath); - // On windows we need to update the atime + // On windows we need to manually update the atime utimesSync(openCollectivePath, now, now); } }