Skip to content

Commit ec30256

Browse files
committed
2 parents ae07a3a + 5322279 commit ec30256

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

packages/create-guten-block/app/cli.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const chalk = require( 'chalk' );
1010
const commander = require( 'commander' );
1111
const maybeEnvInfo = require( './envInfo' );
1212
const noBlockName = require( './noBlockName' );
13+
const invalidBlockName = require( './invalidBlockName' );
1314
const packageJson = require( '../package.json' );
1415

1516
// Commander.js program.
@@ -53,5 +54,11 @@ module.exports = () => {
5354
.split( ' ' )
5455
.join( '-' );
5556

57+
// Check if block name is valid.
58+
const blockNameRegex = /^[a-z][a-z0-9-]/;
59+
if ( ! blockNameRegex.test( formatBlockName ) ) {
60+
invalidBlockName();
61+
}
62+
5663
return formatBlockName;
5764
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Handle if there's block name is not valid.
3+
*/
4+
5+
'use strict';
6+
7+
const chalk = require( 'chalk' );
8+
9+
module.exports = () => {
10+
// Stop if given block name is not valid.
11+
console.log(
12+
'\n❌ ',
13+
chalk.black.bgRed( ' Please provide a valid block name: \n' )
14+
);
15+
console.log(
16+
`${ chalk.dim(
17+
'⚠️ A block name can only contain lowercase alphanumeric characters and dashes.'
18+
) }`
19+
);
20+
console.log( `${ chalk.dim( '⚠️ A block name must begin with a letter.' ) }` );
21+
console.log();
22+
process.exit( 1 );
23+
};

0 commit comments

Comments
 (0)