2019-04-20 23:38:02 +08:00
|
|
|
/* eslint-disable import/no-dynamic-require, no-console */
|
2019-04-17 18:07:34 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-04-21 14:34:14 +08:00
|
|
|
async function checkVersion() {
|
2019-04-17 18:07:34 +08:00
|
|
|
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();
|
|
|
|
}
|
2019-04-21 14:34:14 +08:00
|
|
|
}
|
2019-04-17 18:07:34 +08:00
|
|
|
|
2019-04-21 14:34:14 +08:00
|
|
|
async function checkBranch({ current }) {
|
2021-05-17 10:41:06 +08:00
|
|
|
if (version.includes('-alpha.')) {
|
|
|
|
console.log(chalk.cyan('😃 Alpha version. Skip branch check.'));
|
|
|
|
} else if (current !== 'master' && current !== '4.0-prepare') {
|
2019-04-17 18:07:34 +08:00
|
|
|
console.log(chalk.yellow('🤔 You are not in the master branch!'));
|
|
|
|
exitProcess();
|
|
|
|
}
|
2019-04-21 14:34:14 +08:00
|
|
|
}
|
2019-04-17 18:07:34 +08:00
|
|
|
|
2019-04-21 14:34:14 +08:00
|
|
|
async function checkCommit({ files }) {
|
2019-04-17 18:07:34 +08:00
|
|
|
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();
|
|
|
|
}
|
2019-04-21 14:34:14 +08:00
|
|
|
}
|
2019-04-17 18:07:34 +08:00
|
|
|
|
2019-04-21 14:34:14 +08:00
|
|
|
async function checkRemote() {
|
2019-04-17 18:07:34 +08:00
|
|
|
const { remote } = await git.fetch('origin', 'master');
|
2019-04-22 00:01:24 +08:00
|
|
|
if (remote.indexOf('ant-design/ant-design') === -1) {
|
2019-06-19 19:09:08 +08:00
|
|
|
console.log(
|
|
|
|
chalk.yellow('😓 Your remote origin is not ant-design/ant-design, did you fork it?'),
|
|
|
|
);
|
2019-04-17 18:07:34 +08:00
|
|
|
exitProcess();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-21 14:34:14 +08:00
|
|
|
async function checkAll() {
|
|
|
|
const status = await git.status();
|
|
|
|
|
|
|
|
await checkVersion();
|
|
|
|
|
|
|
|
await checkBranch(status);
|
|
|
|
|
|
|
|
await checkCommit(status);
|
|
|
|
|
|
|
|
await checkRemote();
|
|
|
|
}
|
|
|
|
|
|
|
|
checkAll();
|