Skip to content

Commit dd9d528

Browse files
committedMar 11, 2019
feat(opencollective prompt): add prompt in postinstall script
1 parent 6aec4c3 commit dd9d528

File tree

4 files changed

+63
-19
lines changed

4 files changed

+63
-19
lines changed
 

‎.gitignore

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

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

‎bin/cli.js

+1
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ For more information, see https://webpack.js.org/api/cli/.`);
473473
const statsString = stats.toString(outputOptions);
474474
const delimiter = outputOptions.buildDelimiter ? `${outputOptions.buildDelimiter}\n` : "";
475475
if (statsString) stdout.write(`${statsString}\n${delimiter}`);
476+
require("./opencollective");
476477
}
477478
if (!options.watch && stats.hasErrors()) {
478479
process.exitCode = 2;

‎bin/opencollective.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const child_process = require("child_process");
2+
const chalk = require("chalk");
3+
const fs = require("fs");
4+
const path = require("path");
5+
6+
// Only show emoji on OSx (Windows shell doesn't like them that much ¯\_(ツ)_/¯ )
7+
function emoji(emoji) {
8+
if (process.stdout.isTTY && process.platform === "darwin") {
9+
return emoji;
10+
} else {
11+
return "";
12+
}
13+
}
14+
15+
function print(str = "", color = "dim") {
16+
const terminalCols = process.platform === "win32" ? 80 : parseInt(child_process.execSync("tput cols").toString());
17+
// eslint-disable-next-line no-control-regex
18+
const ansiEscapeSeq = /\u001b\[[0-9]{1,2}m/g;
19+
const strLength = str.replace(ansiEscapeSeq, "").length;
20+
const leftPaddingLength = Math.floor((terminalCols - strLength) / 2);
21+
const leftPadding = " ".repeat(leftPaddingLength);
22+
str = chalk[color](str);
23+
console.log(leftPadding, str);
24+
}
25+
26+
function printBadge() {
27+
console.log("\n");
28+
print(`${chalk.bold("Thanks for using")} ${chalk.bold.blue("Webpack!")}`);
29+
print(`Please consider donating to our ${chalk.bold.blue("Open Collective")}`);
30+
print("to help us maintain this package.");
31+
console.log("\n\n");
32+
print(`${emoji("👉")} ${chalk.bold.yellow(" Donate:")} ${chalk.reset.underline.yellow("https://opencollective.com/webpack/donate")}`);
33+
console.log("\n");
34+
}
35+
36+
37+
const now = new Date();
38+
if (now.getDay() == 1 ) {
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+
}

‎package.json

+12-19
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"format": "prettier-eslint ./bin/*.js ./test/**/*.js ./packages/**/*.js --write",
3737
"lint:codeOnly": "eslint \"{bin}/**/!(__testfixtures__)/*.js\" \"{bin}/**.js\"",
3838
"lint": "eslint \"./bin/*.js\" \"./test/**/*.js\" \"packages/**/!(node_modules)/*.test.js\"",
39+
"postinstall": "node ./bin/opencollective.js",
3940
"pretest": "npm run build && npm run lint && npm run tslint",
4041
"reportCoverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json --disable=gcov",
4142
"test": "nyc jest --maxWorkers=4 --reporters=default --reporters=jest-junit",
@@ -62,10 +63,6 @@
6263
]
6364
},
6465
"jest": {
65-
"testPathIgnorePatterns": [
66-
"^.+\\.(ts)?$",
67-
"/node_modules/"
68-
],
6966
"testEnvironment": "node",
7067
"collectCoverage": true,
7168
"coverageReporters": [
@@ -120,44 +117,40 @@
120117
"loader-utils": "^1.1.0",
121118
"supports-color": "^5.5.0",
122119
"v8-compile-cache": "^2.0.2",
123-
"yargs": "^12.0.5"
120+
"yargs": "^12.0.4"
124121
},
125122
"peerDependencies": {
126123
"webpack": "4.x.x"
127124
},
128125
"devDependencies": {
129-
"@babel/preset-env": "^7.3.4",
130-
"@babel/register": "^7.0.0",
131126
"@commitlint/cli": "^7.2.1",
132127
"@commitlint/config-lerna-scopes": "^7.2.1",
133-
"@commitlint/prompt-cli": "^7.5.0",
128+
"@commitlint/prompt-cli": "^7.2.1",
134129
"@commitlint/travis-cli": "^7.2.1",
135-
"@types/jest": "^23.3.14",
130+
"@types/jest": "^23.3.9",
136131
"@types/node": "^10.12.9",
137132
"babel-preset-env": "^1.7.0",
138-
"babel-preset-jest": "^24.3.0",
139133
"bundlesize": "^0.17.0",
140134
"codecov": "^3.1.0",
141-
"commitizen": "^3.0.7",
135+
"commitizen": "^3.0.4",
142136
"commitlint-config-cz": "^0.10.1",
143137
"conventional-changelog-cli": "^2.0.11",
144138
"cz-customizable": "^5.3.0",
145139
"eslint": "^5.9.0",
146140
"eslint-plugin-node": "^8.0.0",
147-
"esm": "^3.2.14",
148141
"execa": "^1.0.0",
149142
"husky": "^1.1.4",
150-
"jest": "^24.3.1",
151-
"jest-cli": "^24.3.1",
152-
"jest-junit": "^6.3.0",
153-
"lerna": "^3.13.1",
143+
"jest": "^23.6.0",
144+
"jest-cli": "^23.6.0",
145+
"jest-junit": "^5.0.0",
146+
"lerna": "^3.10.7",
154147
"lint-staged": "7.x.x",
155-
"nyc": "^13.3.0",
148+
"nyc": "^13.1.0",
156149
"prettier-eslint-cli": "^4.7.1",
157150
"readable-stream": "^3.0.6",
158151
"rimraf": "^2.6.2",
159152
"schema-utils": "^1.0.0",
160-
"ts-jest": "^23.10.5",
153+
"ts-jest": "^23.10.4",
161154
"ts-node": "^7.0.1",
162155
"tslint": "^5.11.0",
163156
"typedoc": "^0.13.0",
@@ -170,4 +163,4 @@
170163
"type": "opencollective",
171164
"url": "https://opencollective.com/webpack"
172165
}
173-
}
166+
}

0 commit comments

Comments
 (0)
Please sign in to comment.