var fs = require('fs');
const path = require('path');
const paths = require('../config/paths');
const chalk = require('chalk');

const antdPath = path.resolve(paths.appPath, 'node_modules/antd')
const babelPluginImport = path.resolve(paths.appPath, 'node_modules/babel-plugin-import')
// const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
function checkRequiredFiles(files) {
  try {
    files.forEach(filePath => {
      fs.accessSync(filePath, fs.F_OK);
    });
    return true;
  } catch (err) {
    return false;
  }
}

const checkAntd = checkRequiredFiles([antdPath])
const checkBabelPluginImport = checkRequiredFiles([babelPluginImport])

function dealAntd({ position = null }) {
  // if use antd, push babel-plugin-import options
  if (checkRequiredFiles([antdPath])) {
    const babelPluginImport = [
      "import", {
        "libraryName": "antd",
        "style": "css" //`style: true` 会加载 less 文件
      }]
    position && position.push(babelPluginImport)
  }
  // if use antd , checkout if babel-plugin-import install
  if (checkAntd) {
    if (!checkBabelPluginImport) {
      console.log('')
      console.log(chalk.red('You are use antd, but we could not find a required node module.'));
      console.log(chalk.red('  Name: ') + chalk.cyan('babel-plugin-import'));
      console.log(chalk.red('  Please run npm i babel-plugin-import -D in your project\n'));
      process.exit(1)
    }
  }
}

paths.isPublish || console.log('\ncheckAntd\n', {
  antdPath,
  babelPluginImport,
  checkAntd,
  checkBabelPluginImport
})

module.exports = dealAntd

@@ -188,16 +188,95 @@
 /antd')%0A
+const antdMobilePath = path.resolve(paths.appPath, 'node_modules/antd-mobile')%0A
 const ba
@@ -668,16 +668,77 @@
 dPath%5D)%0A
+const checkAntdMobile = checkRequiredFiles(%5BantdMobilePath%5D)%0A
 const ch
@@ -908,33 +908,12 @@
 heck
-RequiredFiles(%5BantdPath%5D)
+Antd
 ) %7B%0A
@@ -1105,16 +1105,246 @@
 ort)%0A  %7D
+ else if (checkAntdMobile) %7B%0A    const babelPluginImport = %5B%0A      %22import%22, %7B%0A        %22libraryName%22: %22antd-mobile%22,%0A        %22style%22: %22css%22 //%60style: true%60 %E4%BC%9A%E5%8A%A0%E8%BD%BD less %E6%96%87%E4%BB%B6%0A      %7D%5D%0A    position && position.push(babelPluginImport)%0A  %7D%0A
 %0A  // if
@@ -1353,16 +1353,31 @@
 se antd 
+or antd-mobile 
 , checko
@@ -1417,32 +1417,51 @@
 %0A  if (checkAntd
+ %7C%7C checkAntdMobile
 ) %7B%0A    if (!che

update dealAntd