UNPKG

1.24 kBJavaScriptView Raw
1/**
2 * Create Plugin Directory.
3 *
4 * @param {string} blockName The block name.
5 * @return {promise} promise resolved.
6 */
7
8'use strict';
9
10const chalk = require( 'chalk' );
11const shell = require( 'shelljs' );
12const clearConsole = require( './consoleClear' );
13const directoryExists = require( 'directory-exists' );
14
15module.exports = blockName => {
16 // Check if the plugin dir is already presnet.
17 const dirAlreadyExist = directoryExists.sync( `./${ blockName }` );
18
19 // If exists then exit.
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 // Where user is at the moment.
45 shell.exec( `mkdir -p ${ blockName }`, () => {
46 resolve( true );
47 } );
48 } );
49 }
50};