diff --git a/package.json b/package.json index 18c2718d4a19e7..f065d16bc9a34b 100644 --- a/package.json +++ b/package.json @@ -230,6 +230,7 @@ "fixtures:generate": "cross-env GENERATE_MISSING_FIXTURES=y npm run test-unit", "fixtures:regenerate": "npm run fixtures:clean && npm run fixtures:generate", "format": "wp-scripts format", + "format-js": "wp-scripts format-js", "format-php": "wp-env run composer run-script format", "lint": "concurrently \"npm run lint-lockfile\" \"npm run lint-js\" \"npm run lint-pkg-json\" \"npm run lint-css\"", "lint-js": "wp-scripts lint-js", diff --git a/packages/scripts/scripts/format-js.js b/packages/scripts/scripts/format-js.js new file mode 100644 index 00000000000000..06dd2cbcb8b9d7 --- /dev/null +++ b/packages/scripts/scripts/format-js.js @@ -0,0 +1,36 @@ +/** + * External dependencies + */ +const chalk = require( 'chalk' ); + +/** + * Internal dependencies + */ +const { getNodeArgsFromCLI, spawnScript } = require( '../utils' ); + +const { scriptArgs, nodeArgs } = getNodeArgsFromCLI(); + +const keypress = async () => { + process.stdin.setRawMode( true ); + return new Promise( ( resolve ) => + process.stdin.once( 'data', () => { + process.stdin.setRawMode( false ); + resolve(); + } ) + ); +}; + +( async () => { + const message = + `Please note that the ${ chalk.red( + 'format-js' + ) } script has been renamed to ${ chalk.green( 'format' ) }.\n` + + "If you're calling it from any of your own scripts, please update them accordingly.\n" + + 'Press any key to continiue.'; + + // eslint-disable-next-line no-console + console.log( message ); + + await keypress(); + spawnScript( 'format', scriptArgs, nodeArgs ); +} )();