1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | const chalk = require( 'chalk' );
|
11 | const shell = require( 'shelljs' );
|
12 | const clearConsole = require( './consoleClear' );
|
13 | const directoryExists = require( 'directory-exists' );
|
14 |
|
15 | module.exports = blockName => {
|
16 |
|
17 | const dirAlreadyExist = directoryExists.sync( `./${ blockName }` );
|
18 |
|
19 |
|
20 | if ( dirAlreadyExist ) {
|
21 | clearConsole();
|
22 | console.log(
|
23 | '\n❌ ',
|
24 | chalk.black.bgRed(
|
25 | ` A directory with this name already exists: ${ blockName } \n`
|
26 | )
|
27 | );
|
28 |
|
29 | console.log(
|
30 | ` ${ chalk.dim(
|
31 | 'Please move or delete it (maybe make a copy for backup) and run this command again.'
|
32 | ) }`
|
33 | );
|
34 | console.log(
|
35 | ` ${ chalk.dim( 'Or provide a different name for your block.' ) }`
|
36 | );
|
37 | console.log( chalk.dim( '\nFor example: \n' ) );
|
38 | console.log(
|
39 | ` ${ chalk.dim( 'create-guten-block' ) } ${ chalk.green( 'new-block-name' ) }\n`
|
40 | );
|
41 | process.exit( 1 );
|
42 | } else {
|
43 | return new Promise( resolve => {
|
44 |
|
45 | shell.exec( `mkdir -p ${ blockName }`, () => {
|
46 | resolve( true );
|
47 | } );
|
48 | } );
|
49 | }
|
50 | };
|