Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Block: Added prompt to continue when minimum system requirements not met #42151

Merged
merged 4 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/create-block/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Enhancement

- Added prompt to continue when minimum system requirements not met ([#42151](https://github.com/WordPress/gutenberg/pull/42151)).
t-hamano marked this conversation as resolved.
Show resolved Hide resolved

## 3.3.0 (2022-06-01)

### Enhancement
Expand Down
33 changes: 29 additions & 4 deletions packages/create-block/lib/check-system-requirements.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/**
* External dependencies
*/
const inquirer = require( 'inquirer' );
const checkSync = require( 'check-node-version' );
const tools = require( 'check-node-version/tools' );
const { forEach } = require( 'lodash' );
const { promisify } = require( 'util' );

Expand All @@ -14,20 +16,43 @@ const check = promisify( checkSync );

async function checkSystemRequirements( engines ) {
const result = await check( engines );

if ( ! result.isSatisfied ) {
log.error( 'Minimum system requirements not met!' );
log.info( '' );

forEach( result.versions, ( { isSatisfied, wanted }, name ) => {
if ( ! isSatisfied ) {
log.error(
`Error: Wanted ${ name } version ${ wanted.raw } (${ wanted.range })`
);
log.info(
check.PROGRAMS[ name ].getInstallInstructions( wanted.raw )
);
}
} );
process.exit( 1 );

log.info( '' );

const { yesContinue } = await inquirer.prompt( [
{
type: 'confirm',
name: 'yesContinue',
message: 'Are you sure you want to continue anyway?',
default: false,
},
] );

if ( ! yesContinue ) {
log.error( 'Cancelled.' );
log.info( '' );

forEach( result.versions, ( { isSatisfied, wanted }, name ) => {
if ( ! isSatisfied ) {
log.info(
tools[ name ].getInstallInstructions( wanted.raw )
);
}
} );
process.exit( 1 );
}
}
}

Expand Down