var fs = require("fs");
var chalk = require('chalk');
var path = require('path');
var existsSync = fs.existsSync;
var readdirSync = fs.readdirSync;
var rmdirSync = fs.rmdirSync;
var unlinkSync = fs.unlinkSync;
var statSync = fs.statSync;

function isCnFuc(language) {
	return language === "cn" ? true : false;
}

function emptyFs(path) {
	var files = [];
	var dir = [];
	if (existsSync(path)) {
		files = readdirSync(path);
		files.forEach(function(file, index) {
			var curPath = path + "/" + file;
			if (statSync(curPath).isDirectory()) {
				emptyFs(curPath);
			} else {
				unlinkSync(curPath);
			}
		});
		dir = readdirSync(path);
		dir.forEach(function(dirName, index) {
			rmdirSync(path + "/" + dirName);
		});
	}
}

/**
 * isSafeToCreateProjectIn function is created from `create-react-app`
 * which is on create-react-app/packages/create-react-app/createReactApp.js line 740 of version 2.0.4
 */
function isSafeToCreateProjectIn(root, name) {
	// These files should be allowed to remain on a failed install,
	// but then silently removed during the next create.
	const errorLogFilePatterns = [
		'npm-debug.log',
		'yarn-error.log',
		'yarn-debug.log',
	];

  const validFiles = [
    '.DS_Store',
    'Thumbs.db',
    '.git',
    '.gitignore',
    '.idea',
    'README.md',
    'LICENSE',
    'web.iml',
    '.hg',
    '.hgignore',
    '.hgcheck',
    '.npmignore',
    'mkdocs.yml',
    'docs',
    '.travis.yml',
    '.gitlab-ci.yml',
    '.gitattributes',
  ];
  console.log();

  const conflicts = fs
    .readdirSync(root)
    .filter(file => !validFiles.includes(file))
    // Don't treat log files from previous installation as conflicts
    .filter(
      file => !errorLogFilePatterns.some(pattern => file.indexOf(pattern) === 0)
    );

  if (conflicts.length > 0) {
    console.log(
      `The directory ${chalk.green(name)} contains files that could conflict:`
    );
    console.log();
    for (const file of conflicts) {
      console.log(`  ${file}`);
    }
    console.log();
    console.log(
      'Either try using a new directory name, or remove the files listed above.'
    );

    return false;
  }

  // Remove any remnant files from a previous installation
  const currentFiles = fs.readdirSync(path.join(root));
  currentFiles.forEach(file => {
    errorLogFilePatterns.forEach(errorLogFilePattern => {
      // This will catch `(npm-debug|yarn-error|yarn-debug).log*` files
      if (file.indexOf(errorLogFilePattern) === 0) {
        unlinkSync(path.join(root, file));
      }
    });
  });
  return true;
}

module.exports = {
	isCnFuc: isCnFuc,
	emptyFs: emptyFs,
	isSafeToCreateProjectIn: isSafeToCreateProjectIn
};

@@ -230,16 +230,80 @@
 tatSync;
+%0Avar validateProjectName = require('validate-npm-package-name');
 %0A%0Afuncti
@@ -2606,16 +2606,876 @@
 rue;%0A%7D%0A%0A
+// validate an app(project) name%0A// - Nameing Rules: https://www.npmjs.com/package/validate-npm-package-name#naming-rules%0A// - Referenced: https://github.com/facebook/create-react-app/blob/master/packages/create-react-app/createReactApp.js#L664%0Afunction checkAppName(appName) %7B%0A  const validationResult = validateProjectName(appName);%0A  if (!validationResult.validForNewPackages) %7B%0A    console.error(%0A      %60Could not create a project called $%7Bchalk.red(%0A        %60%22$%7BappName%7D%22%60%0A      )%7D because of npm naming restrictions: %60%0A    );%0A    printValidationResults(validationResult.errors);%0A    printValidationResults(validationResult.warnings);%0A    process.exit(1);%0A  %7D%0A%0A  function printValidationResults(results) %7B%0A    if (typeof results !== 'undefined') %7B%0A      results.forEach(error =%3E %7B%0A        console.error(chalk.red(%60  *  $%7Berror%7D%60));%0A      %7D);%0A    %7D%0A  %7D%0A%7D%0A%0A
 module.e
@@ -3523,17 +3523,18 @@
 mptyFs,%0A
-%09
+  
 isSafeTo
@@ -3573,12 +3573,42 @@
 rojectIn
+,%0A  checkAppName: checkAppName
 %0A%7D;%0A

add comment about reference and nameing rules