chore: add pre-publish commit check (#16134)

* add prepublish check

* update check logic

* add version check
This commit is contained in:
zombieJ 2019-04-17 18:07:34 +08:00 committed by GitHub
parent 21c0ba5bbd
commit 3a11402042
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 2 deletions

View File

@ -116,7 +116,7 @@
"bisheng-plugin-description": "^0.1.4",
"bisheng-plugin-react": "^1.0.0",
"bisheng-plugin-toc": "^0.4.4",
"chalk": "^2.4.1",
"chalk": "^2.4.2",
"commander": "^2.18.0",
"cross-env": "^5.2.0",
"css-split-webpack-plugin": "^0.2.6",
@ -149,6 +149,7 @@
"lz-string": "^1.4.4",
"majo": "^0.7.1",
"mockdate": "^2.0.2",
"node-fetch": "^2.3.0",
"pre-commit": "^1.2.2",
"preact": "^8.3.1",
"preact-compat": "^3.18.4",
@ -183,6 +184,7 @@
"reqwest": "^2.0.5",
"rimraf": "^2.6.2",
"scrollama": "^2.0.0",
"simple-git": "^1.110.0",
"stylelint": "^10.0.0",
"stylelint-config-prettier": "^5.0.0",
"stylelint-config-rational-order": "^0.1.0",
@ -198,6 +200,7 @@
"test": "jest --config .jest.js --no-cache",
"test-node": "jest --config .jest.node.js --no-cache",
"test-all": "./scripts/test-all.sh",
"check-commit": "node ./scripts/check-commit.js",
"lint": "npm run lint:ts && npm run lint:es && npm run lint:demo && npm run lint:style && npm run lint:deps",
"lint:deps": "antd-tools run deps-lint",
"lint:ts": "npm run tsc && antd-tools run ts-lint",
@ -222,7 +225,7 @@
"deploy:china-mirror": "git checkout gh-pages && git pull origin gh-pages && git push git@gitee.com:ant-design/ant-design.git gh-pages",
"pub": "antd-tools run pub",
"prepublish": "antd-tools run guard",
"pre-publish": "npm run test-all",
"pre-publish": "npm run check-commit && npm run test-all",
"authors": "git log --format='%aN <%aE>' | sort -u | grep -v 'users.noreply.github.com' | grep -v 'gitter.im' | grep -v '.local>' | grep -v 'alibaba-inc.com' | grep -v 'alipay.com' | grep -v 'taobao.com' > AUTHORS.txt",
"lint-staged": "lint-staged",
"lint-staged:ts": "tsc && node node_modules/tslint/bin/tslint",

47
scripts/check-commit.js Executable file
View File

@ -0,0 +1,47 @@
/* eslint-disable import/no-dynamic-require */
const chalk = require('chalk');
const path = require('path');
const fetch = require('node-fetch');
const simpleGit = require('simple-git/promise');
const cwd = process.cwd();
const git = simpleGit(cwd);
const { version } = require(path.resolve(cwd, 'package.json'));
function exitProcess(code = 1) {
console.log(''); // Keep an empty line here to make looks good~
process.exit(code);
}
async function checkCommit() {
const { current, files } = await git.status();
const { versions } = await fetch('http://registry.npmjs.org/antd').then(res => res.json());
if (version in versions) {
console.log(chalk.yellow('😈 Current version already exists. Forget update package.json?'));
console.log(chalk.cyan(' => Current:'), version);
exitProcess();
}
if (current !== 'master') {
console.log(chalk.yellow('🤔 You are not in the master branch!'));
exitProcess();
}
if (files.length) {
console.log(chalk.yellow('🙄 You forgot something to commit.'));
files.forEach(({ path: filePath, working_dir: mark }) => {
console.log(' -', chalk.red(mark), filePath);
});
exitProcess();
}
const { remote } = await git.fetch('origin', 'master');
if (remote.indexOf('ant-design/ant-design') === -1 || true) {
console.log(chalk.yellow('😓 Your remote origin is not ant-design. Do you fork it?'));
exitProcess();
}
}
checkCommit();