Skip to content

Commit

Permalink
Lodash: Remove completely from create-block package (#43362)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Aug 18, 2022
1 parent 0c14271 commit 37249ec
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 36 deletions.
1 change: 0 additions & 1 deletion package-lock.json

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

30 changes: 17 additions & 13 deletions packages/create-block/lib/check-system-requirements.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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 @@ -21,13 +20,15 @@ async function checkSystemRequirements( engines ) {
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 })`
);
Object.entries( result.versions ).forEach(
( [ name, { isSatisfied, wanted } ] ) => {
if ( ! isSatisfied ) {
log.error(
`Error: Wanted ${ name } version ${ wanted.raw } (${ wanted.range })`
);
}
}
} );
);

log.info( '' );
log.error( 'The program may not complete correctly if you continue.' );
Expand All @@ -46,13 +47,16 @@ async function checkSystemRequirements( engines ) {
log.error( 'Cancelled.' );
log.info( '' );

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

process.exit( 1 );
}
}
Expand Down
8 changes: 3 additions & 5 deletions packages/create-block/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
const inquirer = require( 'inquirer' );
const { capitalCase } = require( 'change-case' );
const program = require( 'commander' );
const { pickBy } = require( 'lodash' );

/**
* Internal dependencies
Expand Down Expand Up @@ -77,17 +76,16 @@ program
try {
const pluginTemplate = await getPluginTemplate( templateName );
const defaultValues = getDefaultValues( pluginTemplate );
const optionsValues = pickBy(
{
const optionsValues = Object.fromEntries(
Object.entries( {
plugin,
category,
description,
namespace,
title,
wpScripts,
wpEnv,
},
( value ) => value !== undefined
} ).filter( ( [ , value ] ) => value !== undefined )
);

if ( slug ) {
Expand Down
8 changes: 3 additions & 5 deletions packages/create-block/lib/init-block.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
const { omitBy } = require( 'lodash' );
const { dirname, join } = require( 'path' );
const makeDir = require( 'make-dir' );
const { writeFile } = require( 'fs' ).promises;
Expand Down Expand Up @@ -41,8 +40,8 @@ async function initBlockJSON( {
await writeFile(
outputFile,
JSON.stringify(
omitBy(
{
Object.fromEntries(
Object.entries( {
$schema,
apiVersion,
name: namespace + '/' + slug,
Expand All @@ -57,8 +56,7 @@ async function initBlockJSON( {
editorScript,
editorStyle,
style,
},
( value ) => ! value
} ).filter( ( [ , value ] ) => !! value )
),
null,
'\t'
Expand Down
8 changes: 3 additions & 5 deletions packages/create-block/lib/init-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
const { command } = require( 'execa' );
const { isEmpty, omitBy } = require( 'lodash' );
const npmPackageArg = require( 'npm-package-arg' );
const { join } = require( 'path' );
const writePkg = require( 'write-pkg' );
Expand Down Expand Up @@ -32,8 +31,8 @@ module.exports = async ( {

await writePkg(
cwd,
omitBy(
{
Object.fromEntries(
Object.entries( {
name: slug,
version,
description,
Expand All @@ -54,8 +53,7 @@ module.exports = async ( {
...( wpEnv && { env: 'wp-env' } ),
...customScripts,
},
},
isEmpty
} ).filter( ( [ , value ] ) => !! value )
)
);

Expand Down
7 changes: 1 addition & 6 deletions packages/create-block/lib/prompts.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
const { isEmpty } = require( 'lodash' );

/**
* Capitalizes the first letter in a string.
*
Expand Down Expand Up @@ -66,7 +61,7 @@ const dashicon = {
message:
'The dashicon to make it easier to identify your block (optional):',
validate( input ) {
if ( ! isEmpty( input ) && ! /^[a-z][a-z0-9\-]*$/.test( input ) ) {
if ( input.length && ! /^[a-z][a-z0-9\-]*$/.test( input ) ) {
return 'Invalid dashicon name specified. Visit https://developer.wordpress.org/resource/dashicons/ to discover available names.';
}

Expand Down
1 change: 0 additions & 1 deletion packages/create-block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"execa": "^4.0.2",
"fast-glob": "^3.2.7",
"inquirer": "^7.1.0",
"lodash": "^4.17.21",
"make-dir": "^3.0.0",
"mustache": "^4.0.0",
"npm-package-arg": "^8.1.5",
Expand Down

0 comments on commit 37249ec

Please sign in to comment.