File tree Expand file tree Collapse file tree
packages/create-guten-block/app Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ const chalk = require( 'chalk' );
1010const commander = require ( 'commander' ) ;
1111const maybeEnvInfo = require ( './envInfo' ) ;
1212const noBlockName = require ( './noBlockName' ) ;
13+ const invalidBlockName = require ( './invalidBlockName' ) ;
1314const 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 - z 0 - 9 - ] / ;
59+ if ( ! blockNameRegex . test ( formatBlockName ) ) {
60+ invalidBlockName ( ) ;
61+ }
62+
5663 return formatBlockName ;
5764} ;
Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments