2023-04-28 21:49:55 +08:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
import chalk from 'chalk';
|
|
|
|
import fetch from 'isomorphic-fetch';
|
|
|
|
import type { StatusResult } from 'simple-git';
|
|
|
|
import simpleGit from 'simple-git';
|
|
|
|
import localPackage from '../package.json';
|
|
|
|
|
|
|
|
const { version } = localPackage;
|
2019-04-17 18:07:34 +08:00
|
|
|
|
|
|
|
const cwd = process.cwd();
|
|
|
|
const git = simpleGit(cwd);
|
|
|
|
|
|
|
|
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() {
|
2022-11-14 11:37:30 +08:00
|
|
|
try {
|
2023-05-12 14:53:47 +08:00
|
|
|
const { versions } = await fetch('http://registry.npmjs.org/antd').then((res: Response) =>
|
2023-04-28 21:49:55 +08:00
|
|
|
res.json(),
|
|
|
|
);
|
2022-11-14 11:37:30 +08:00
|
|
|
if (version in versions) {
|
|
|
|
console.log(chalk.yellow('😈 Current version already exists. Forget update package.json?'));
|
|
|
|
console.log(chalk.cyan(' => Current:'), version);
|
|
|
|
exitProcess();
|
|
|
|
}
|
2023-04-28 21:49:55 +08:00
|
|
|
} catch {
|
2022-11-14 11:37:30 +08:00
|
|
|
console.log(chalk.red('🚨 Check version failed. Skip...'));
|
2019-04-17 18:07:34 +08:00
|
|
|
}
|
2019-04-21 14:34:14 +08:00
|
|
|
}
|
2019-04-17 18:07:34 +08:00
|
|
|
|
2023-04-28 21:49:55 +08:00
|
|
|
async function checkBranch({ current }: StatusResult) {
|
2022-11-08 10:37:00 +08:00
|
|
|
if (
|
|
|
|
version.includes('-alpha.') ||
|
|
|
|
version.includes('-beta.') ||
|
|
|
|
version.includes('-rc.') ||
|
|
|
|
version.includes('-experimental.')
|
|
|
|
) {
|
2021-05-24 16:24:00 +08:00
|
|
|
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
|
|
|
|
2023-04-28 21:49:55 +08:00
|
|
|
async function checkCommit({ files }: StatusResult) {
|
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() {
|
2022-11-14 11:44:34 +08:00
|
|
|
try {
|
|
|
|
const { remote } = await git.fetch('origin', 'master');
|
2023-07-11 23:36:34 +08:00
|
|
|
console.log(chalk.blue('⛳ Checking origin master with `git fetch origin master`'));
|
2023-04-28 21:49:55 +08:00
|
|
|
if (!remote?.includes('ant-design/ant-design')) {
|
2023-07-11 23:36:34 +08:00
|
|
|
console.log(chalk.blue('⛳ Checking locally with `git config --get remote.origin.url`'));
|
|
|
|
const { value } = await git.getConfig('remote.origin.url');
|
|
|
|
if (!value?.includes('ant-design/ant-design')) {
|
|
|
|
console.log(
|
|
|
|
chalk.yellow('🧐 Your remote origin is not ant-design/ant-design, did you fork it?'),
|
|
|
|
);
|
|
|
|
exitProcess();
|
|
|
|
}
|
2022-11-14 11:44:34 +08:00
|
|
|
}
|
2023-04-28 21:49:55 +08:00
|
|
|
} catch {
|
2022-11-14 11:44:34 +08:00
|
|
|
console.log(chalk.red('🚨 Check remote failed. Skip...'));
|
2019-04-17 18:07:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|