1 | 'use strict';
|
2 |
|
3 | const fs = require('fs-extra');
|
4 | const chalk = require('chalk');
|
5 | const validatePkgName = require('validate-npm-package-name');
|
6 |
|
7 |
|
8 | module.exports = {
|
9 | checkProjectName (projectName) {
|
10 | const valid = validatePkgName(projectName);
|
11 | if(!valid.validForNewPackages) {
|
12 | console.error(`Sorry, ${chalk.red(projectName)} is not a valid NPM project name`);
|
13 | console.log();
|
14 | if(valid.errors) {
|
15 | console.log('Error:');
|
16 | console.log(` ${chalk.yellow(valid.errors.join('; '))}`);
|
17 | console.log();
|
18 | }
|
19 | if(valid.warnings) {
|
20 | console.log('Warning:');
|
21 | console.log(` ${chalk.yellow(valid.warnings.join('; '))}`);
|
22 | console.log();
|
23 | }
|
24 | process.exit(1);
|
25 | }
|
26 |
|
27 | return true;
|
28 | },
|
29 |
|
30 | checkFileConflicts (appRoot) {
|
31 | const appFiles = [
|
32 | '.babelrc',
|
33 | '.eslintrc',
|
34 | '.gitignore',
|
35 | 'README.md',
|
36 | 'package.json',
|
37 | 'screenshot.png',
|
38 | 'src',
|
39 | 'webpack.config.js',
|
40 | ];
|
41 |
|
42 | const conflicts = fs.readdirSync(appRoot).filter(file => appFiles.includes(file));
|
43 | if(conflicts.length > 0) {
|
44 | console.log(`The directory ${chalk.green(appRoot)} contains files that could conflict:`);
|
45 | for (const file of conflicts) {
|
46 | console.log(` ${file}`);
|
47 | }
|
48 | console.log();
|
49 | console.log('Either try using a new directory name, or remove the files listed above.');
|
50 | process.exit(1);
|
51 | }
|
52 |
|
53 | return true;
|
54 | }
|
55 | };
|