Skip to content

Commit

Permalink
Create block: Add check for minimum system requirements (#20398)
Browse files Browse the repository at this point in the history
* Create block: Add check for minimum system requirements
Added error message when minimum system requirements not met. Corrected the minimum `npm` version required to align with `@wordpress/scripts` package used internally.

* Update CHANGELOG.md
  • Loading branch information
gziolo authored Feb 24, 2020
1 parent bef4179 commit 1e26a8f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions packages/create-block/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Master

### Bug Fixes

- Added error message when minimum system requirements not met ([#20398](https://github.com/WordPress/gutenberg/pull/20398/)).
- Corrected the minimum `npm` version required to align with `@wordpress/scripts` package used internally ([#20398](https://github.com/WordPress/gutenberg/pull/20398/)).

## 0.8.0 (2020-02-21)

### New Features
Expand Down
2 changes: 1 addition & 1 deletion packages/create-block/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ You just need to provide the `slug` which is the target location for scaffolded
$ npm start
```

_(requires `node` version `10.0.0` or above, and `npm` version `6.1.0` or above)_
_(requires `node` version `10.0.0` or above, and `npm` version `6.9.0` or above)_

You don’t need to install or configure tools like [webpack](https://webpack.js.org), [Babel](https://babeljs.io) or [ESLint](https://eslint.org) yourself. They are preconfigured and hidden so that you can focus on the code.

Expand Down
37 changes: 25 additions & 12 deletions packages/create-block/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/**
* External dependencies
*/
const { command } = require( 'execa' );
const program = require( 'commander' );
const inquirer = require( 'inquirer' );
const { startCase } = require( 'lodash' );
const { join } = require( 'path' );

/**
* Internal dependencies
Expand All @@ -14,6 +16,19 @@ const { version } = require( '../package.json' );
const scaffold = require( './scaffold' );
const { getDefaultValues, getPrompts } = require( './templates' );

async function checkSystemRequirements() {
try {
await command( 'check-node-version --package', {
cwd: join( __dirname, '..' ),
} );
} catch ( error ) {
log.error( 'Minimum system requirements not met!' );
log.error( error.stderr );
log.info( error.stdout );
process.exit( error.exitCode );
}
}

const commandName = `wp-create-block`;
program
.name( commandName )
Expand All @@ -31,6 +46,7 @@ program
'esnext'
)
.action( async ( slug, { template } ) => {
await checkSystemRequirements();
try {
const defaultValues = getDefaultValues( template );
if ( slug ) {
Expand All @@ -50,21 +66,18 @@ program
}
} catch ( error ) {
if ( error instanceof CLIError ) {
log.info( '' );
log.error( error.message );
process.exit( 1 );
} else {
throw error;
}
}
} );

program.on( '--help', function() {
log.info( '' );
log.info( 'Examples:' );
log.info( ` $ ${ commandName }` );
log.info( ` $ ${ commandName } todo-list` );
log.info( ` $ ${ commandName } --template es5 todo-list` );
} );

program.parse( process.argv );
} )
.on( '--help', function() {
log.info( '' );
log.info( 'Examples:' );
log.info( ` $ ${ commandName }` );
log.info( ` $ ${ commandName } todo-list` );
log.info( ` $ ${ commandName } --template es5 todo-list` );
} )
.parse( process.argv );
4 changes: 2 additions & 2 deletions packages/create-block/lib/templates.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
const CliError = require( './cli-error' );
const CLIError = require( './cli-error' );
const prompts = require( './prompts' );

const namespace = 'create-block';
Expand Down Expand Up @@ -60,7 +60,7 @@ const templates = {

const getTemplate = ( templateName ) => {
if ( ! templates[ templateName ] ) {
throw new CliError(
throw new CLIError(
`Invalid template type name. Allowed values: ${ Object.keys(
templates
).join( ', ' ) }.`
Expand Down
5 changes: 3 additions & 2 deletions packages/create-block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"url": "https://github.com/WordPress/gutenberg/issues"
},
"engines": {
"node": ">=10.0",
"npm": ">=6.1"
"node": ">=10",
"npm": ">=6.9"
},
"files": [
"lib"
Expand All @@ -31,6 +31,7 @@
},
"dependencies": {
"chalk": "^2.4.2",
"check-node-version": "^3.1.1",
"commander": "^4.1.0",
"execa": "^4.0.0",
"inquirer": "^7.0.3",
Expand Down

0 comments on commit 1e26a8f

Please sign in to comment.