/* eslint-disable import/no-dynamic-require, no-console */
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();

@@ -470,68 +470,19 @@
 heck
-Commit() %7B%0A  const %7B current, files %7D = await git.status();%0A
+Version() %7B
 %0A  c
@@ -770,24 +770,68 @@
 cess();%0A  %7D%0A
+%7D%0A%0Aasync function checkBranch(%7B current %7D) %7B
 %0A  if (curre
@@ -942,16 +942,58 @@
 ();%0A  %7D%0A
+%7D%0A%0Aasync function checkCommit(%7B files %7D) %7B
 %0A  if (f
@@ -1221,16 +1221,49 @@
 ();%0A  %7D%0A
+%7D%0A%0Aasync function checkRemote() %7B
 %0A  const
@@ -1493,23 +1493,197 @@
 %0A  %7D%0A%7D%0A%0A
-checkCommit
+async function checkAll() %7B%0A  const status = await git.status();%0A%0A  await checkVersion();%0A%0A  await checkBranch(status);%0A%0A  await checkCommit(status);%0A%0A  await checkRemote();%0A%7D%0A%0AcheckAll
 ();%0A

update script (#16204)