1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | 'use strict';
|
8 |
|
9 | const chalk = require( 'chalk' );
|
10 | const commander = require( 'commander' );
|
11 | const maybeEnvInfo = require( './envInfo' );
|
12 | const noBlockName = require( './noBlockName' );
|
13 | const packageJson = require( '../package.json' );
|
14 |
|
15 |
|
16 | module.exports = () => {
|
17 |
|
18 | let blockName;
|
19 |
|
20 | const program = new commander.Command( packageJson.name )
|
21 | .arguments( '<block-name>' )
|
22 | .usage( `${ chalk.green( '<block-name>' ) }` )
|
23 | .action( name => {
|
24 | blockName = name;
|
25 | } )
|
26 | .allowUnknownOption()
|
27 | .on( '--help', () => {
|
28 | console.log( `\n Only ${ chalk.green( '<block-name>' ) } is required.\n` );
|
29 | } )
|
30 | .option( '-d, --debug', 'Prints envinfo for debugging' )
|
31 | .description(
|
32 | `CGB ${ chalk.dim(
|
33 | '(create-guten-block)'
|
34 | ) } is a Zero-Config #OCJS for builing WordPress Gutenberg Blocks.`
|
35 | )
|
36 | .version( packageJson.version, '-v, --version' )
|
37 | .parse( process.argv );
|
38 |
|
39 |
|
40 | if ( typeof blockName === 'undefined' ) {
|
41 |
|
42 | maybeEnvInfo( program );
|
43 |
|
44 |
|
45 | noBlockName();
|
46 | }
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | const formatBlockName = blockName
|
52 | .toLowerCase()
|
53 | .split( ' ' )
|
54 | .join( '-' );
|
55 |
|
56 | return formatBlockName;
|
57 | };
|