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

Scripts: Fix naming conventions for function containing CLI keyword #16091

Merged
merged 1 commit into from
Jun 14, 2019
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: 2 additions & 2 deletions packages/scripts/bin/wp-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* Internal dependencies
*/
const { getCliArgs, spawnScript } = require( '../utils' );
const { getArgsFromCLI, spawnScript } = require( '../utils' );

const [ scriptName, ...nodesArgs ] = getCliArgs();
const [ scriptName, ...nodesArgs ] = getArgsFromCLI();

spawnScript( scriptName, nodesArgs );
14 changes: 7 additions & 7 deletions packages/scripts/scripts/check-engines.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ const { sync: resolveBin } = require( 'resolve-bin' );
* Internal dependencies
*/
const {
getCliArgs,
hasCliArg,
getArgsFromCLI,
hasArgInCLI,
} = require( '../utils' );

const args = getCliArgs();
const args = getArgsFromCLI();

const hasConfig = hasCliArg( '--package' ) ||
hasCliArg( '--node' ) ||
hasCliArg( '--npm' ) ||
hasCliArg( '--yarn' );
const hasConfig = hasArgInCLI( '--package' ) ||
hasArgInCLI( '--node' ) ||
hasArgInCLI( '--npm' ) ||
hasArgInCLI( '--yarn' );
const config = ! hasConfig ?
[
'--node', '>=10.0.0',
Expand Down
12 changes: 6 additions & 6 deletions packages/scripts/scripts/check-licenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const chalk = require( 'chalk' );
/**
* Internal dependencies
*/
const { getCliArg, hasCliArg } = require( '../utils' );
const { getArgFromCLI, hasArgInCLI } = require( '../utils' );

/*
* WARNING: Changes to this file may inadvertently cause us to distribute code that
Expand All @@ -22,11 +22,11 @@ const { getCliArg, hasCliArg } = require( '../utils' );

const ERROR = chalk.reset.inverse.bold.red( ' ERROR ' );

const prod = hasCliArg( '--prod' ) || hasCliArg( '--production' );
const dev = hasCliArg( '--dev' ) || hasCliArg( '--development' );
const gpl2 = hasCliArg( '--gpl2' );
const ignored = hasCliArg( '--ignore' ) ?
getCliArg( '--ignore' )
const prod = hasArgInCLI( '--prod' ) || hasArgInCLI( '--production' );
const dev = hasArgInCLI( '--dev' ) || hasArgInCLI( '--development' );
const gpl2 = hasArgInCLI( '--gpl2' );
const ignored = hasArgInCLI( '--ignore' ) ?
getArgFromCLI( '--ignore' )
// "--ignore=a, b" -> "[ 'a', ' b' ]"
.split( ',' )
// "[ 'a', ' b' ]" -> "[ 'a', 'b' ]"
Expand Down
16 changes: 8 additions & 8 deletions packages/scripts/scripts/lint-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ const { sync: resolveBin } = require( 'resolve-bin' );
*/
const {
fromConfigRoot,
getCliArgs,
hasCliArg,
hasFileInCliArgs,
getArgsFromCLI,
hasArgInCLI,
hasFileArgInCLI,
hasPackageProp,
hasProjectFile,
} = require( '../utils' );

const args = getCliArgs();
const args = getArgsFromCLI();

const defaultFilesArgs = hasFileInCliArgs() ? [] : [ '.' ];
const defaultFilesArgs = hasFileArgInCLI() ? [] : [ '.' ];

// See: https://eslint.org/docs/user-guide/configuring#using-configuration-files-1.
const hasLintConfig = hasCliArg( '-c' ) ||
hasCliArg( '--config' ) ||
const hasLintConfig = hasArgInCLI( '-c' ) ||
hasArgInCLI( '--config' ) ||
hasProjectFile( '.eslintrc.js' ) ||
hasProjectFile( '.eslintrc.yaml' ) ||
hasProjectFile( '.eslintrc.yml' ) ||
Expand All @@ -38,7 +38,7 @@ const defaultConfigArgs = ! hasLintConfig ?
[];

// See: https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories.
const hasIgnoredFiles = hasCliArg( '--ignore-path' ) ||
const hasIgnoredFiles = hasArgInCLI( '--ignore-path' ) ||
hasProjectFile( '.eslintignore' );

const defaultIgnoreArgs = ! hasIgnoredFiles ?
Expand Down
16 changes: 8 additions & 8 deletions packages/scripts/scripts/lint-pkg-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ const { sync: resolveBin } = require( 'resolve-bin' );
*/
const {
fromConfigRoot,
getCliArgs,
hasCliArg,
hasFileInCliArgs,
getArgsFromCLI,
hasArgInCLI,
hasFileArgInCLI,
hasProjectFile,
hasPackageProp,
} = require( '../utils' );

const args = getCliArgs();
const args = getArgsFromCLI();

const defaultFilesArgs = hasFileInCliArgs() ? [] : [ '.' ];
const defaultFilesArgs = hasFileArgInCLI() ? [] : [ '.' ];

// See: https://github.com/tclindner/npm-package-json-lint/wiki/configuration#configuration.
const hasLintConfig = hasCliArg( '-c' ) ||
hasCliArg( '--configFile' ) ||
const hasLintConfig = hasArgInCLI( '-c' ) ||
hasArgInCLI( '--configFile' ) ||
hasProjectFile( '.npmpackagejsonlintrc.json' ) ||
hasProjectFile( 'npmpackagejsonlint.config.js' ) ||
hasPackageProp( 'npmPackageJsonLintConfig' );
Expand All @@ -32,7 +32,7 @@ const defaultConfigArgs = ! hasLintConfig ?
[];

// See: https://github.com/tclindner/npm-package-json-lint/#cli-commands-and-configuration.
const hasIgnoredFiles = hasCliArg( '--ignorePath' ) ||
const hasIgnoredFiles = hasArgInCLI( '--ignorePath' ) ||
hasProjectFile( '.npmpackagejsonlintignore' );

const defaultIgnoreArgs = ! hasIgnoredFiles ?
Expand Down
14 changes: 7 additions & 7 deletions packages/scripts/scripts/lint-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ const { sync: resolveBin } = require( 'resolve-bin' );
*/
const {
fromConfigRoot,
getCliArgs,
hasCliArg,
hasFileInCliArgs,
getArgsFromCLI,
hasArgInCLI,
hasFileArgInCLI,
hasProjectFile,
hasPackageProp,
} = require( '../utils' );

const args = getCliArgs();
const args = getArgsFromCLI();

const defaultFilesArgs = hasFileInCliArgs() ? [] : [ '**/*.{css,scss}' ];
const defaultFilesArgs = hasFileArgInCLI() ? [] : [ '**/*.{css,scss}' ];

// See: https://github.com/stylelint/stylelint/blob/master/docs/user-guide/configuration.md#loading-the-configuration-object.
const hasLintConfig = hasCliArg( '--config' ) ||
const hasLintConfig = hasArgInCLI( '--config' ) ||
hasProjectFile( '.stylelintrc' ) ||
hasProjectFile( '.stylelintrc.js' ) ||
hasProjectFile( '.stylelintrc.json' ) ||
Expand All @@ -35,7 +35,7 @@ const defaultConfigArgs = ! hasLintConfig ?
[];

// See: https://github.com/stylelint/stylelint/blob/master/docs/user-guide/configuration.md#stylelintignore.
const hasIgnoredFiles = hasCliArg( '--ignore-path' ) ||
const hasIgnoredFiles = hasArgInCLI( '--ignore-path' ) ||
hasProjectFile( '.stylelintignore' );

const defaultIgnoreArgs = ! hasIgnoredFiles ?
Expand Down
20 changes: 10 additions & 10 deletions packages/scripts/scripts/test-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const jest = require( 'jest' );
*/
const {
fromConfigRoot,
getCliArg,
getCliArgs,
hasCliArg,
getArgFromCLI,
getArgsFromCLI,
hasArgInCLI,
hasProjectFile,
hasJestConfig,
} = require( '../utils' );
Expand All @@ -37,15 +37,15 @@ const config = ! hasJestConfig() ?
[ '--config', JSON.stringify( require( fromConfigRoot( 'jest-e2e.config.js' ) ) ) ] :
[];

const hasRunInBand = hasCliArg( '--runInBand' ) ||
hasCliArg( '-i' );
const hasRunInBand = hasArgInCLI( '--runInBand' ) ||
hasArgInCLI( '-i' );
const runInBand = ! hasRunInBand ?
[ '--runInBand' ] :
[];

if ( hasCliArg( '--puppeteer-interactive' ) ) {
if ( hasArgInCLI( '--puppeteer-interactive' ) ) {
process.env.PUPPETEER_HEADLESS = 'false';
process.env.PUPPETEER_SLOWMO = getCliArg( '--puppeteer-slowmo' ) || 80;
process.env.PUPPETEER_SLOWMO = getArgFromCLI( '--puppeteer-slowmo' ) || 80;
}

const configsMapping = {
Expand All @@ -55,11 +55,11 @@ const configsMapping = {
};

Object.entries( configsMapping ).forEach( ( [ envKey, argName ] ) => {
if ( hasCliArg( argName ) ) {
process.env[ envKey ] = getCliArg( argName );
if ( hasArgInCLI( argName ) ) {
process.env[ envKey ] = getArgFromCLI( argName );
}
} );

const cleanUpPrefixes = [ '--puppeteer-', '--wordpress-' ];

jest.run( [ ...config, ...runInBand, ...getCliArgs( cleanUpPrefixes ) ] );
jest.run( [ ...config, ...runInBand, ...getArgsFromCLI( cleanUpPrefixes ) ] );
4 changes: 2 additions & 2 deletions packages/scripts/scripts/test-unit-jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ const jest = require( 'jest' );
*/
const {
fromConfigRoot,
getCliArgs,
getArgsFromCLI,
hasJestConfig,
} = require( '../utils' );

const config = ! hasJestConfig() ?
[ '--config', JSON.stringify( require( fromConfigRoot( 'jest-unit.config.js' ) ) ) ] :
[];

jest.run( [ ...config, ...getCliArgs() ] );
jest.run( [ ...config, ...getArgsFromCLI() ] );
18 changes: 9 additions & 9 deletions packages/scripts/utils/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ const {
} = require( './file' );
const {
exit,
getCliArgs,
getArgsFromCLI,
} = require( './process' );

const getCliArg = ( arg ) => {
for ( const cliArg of getCliArgs() ) {
const getArgFromCLI = ( arg ) => {
for ( const cliArg of getArgsFromCLI() ) {
const [ name, value ] = cliArg.split( '=' );
if ( name === arg ) {
return value || null;
}
}
};

const hasCliArg = ( arg ) => getCliArg( arg ) !== undefined;
const hasArgInCLI = ( arg ) => getArgFromCLI( arg ) !== undefined;

const hasFileInCliArgs = () => minimist( getCliArgs() )._.length > 0;
const hasFileArgInCLI = () => minimist( getArgsFromCLI() )._.length > 0;

const handleSignal = ( signal ) => {
if ( signal === 'SIGKILL' ) {
Expand Down Expand Up @@ -81,9 +81,9 @@ const spawnScript = ( scriptName, args = [] ) => {
};

module.exports = {
getCliArg,
getCliArgs,
hasCliArg,
hasFileInCliArgs,
getArgFromCLI,
getArgsFromCLI,
hasArgInCLI,
hasFileArgInCLI,
spawnScript,
};
10 changes: 5 additions & 5 deletions packages/scripts/utils/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
const { hasCliArg, getCliArgs } = require( './cli' );
const { hasArgInCLI, getArgsFromCLI } = require( './cli' );
const { fromConfigRoot, hasProjectFile } = require( './file' );
const { hasPackageProp } = require( './package' );

Expand All @@ -12,18 +12,18 @@ const hasBabelConfig = () =>
hasPackageProp( 'babel' );

const hasJestConfig = () =>
hasCliArg( '-c' ) ||
hasCliArg( '--config' ) ||
hasArgInCLI( '-c' ) ||
hasArgInCLI( '--config' ) ||
hasProjectFile( 'jest.config.js' ) ||
hasProjectFile( 'jest.config.json' ) ||
hasPackageProp( 'jest' );

const hasWebpackConfig = () => hasCliArg( '--config' ) ||
const hasWebpackConfig = () => hasArgInCLI( '--config' ) ||
hasProjectFile( 'webpack.config.js' ) ||
hasProjectFile( 'webpack.config.babel.js' );

const getWebpackArgs = ( additionalArgs = [] ) => {
const webpackArgs = getCliArgs();
const webpackArgs = getArgsFromCLI();
if ( ! hasWebpackConfig() ) {
webpackArgs.push( '--config', fromConfigRoot( 'webpack.config.js' ) );
}
Expand Down
16 changes: 8 additions & 8 deletions packages/scripts/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* Internal dependencies
*/
const {
getCliArg,
getCliArgs,
hasCliArg,
hasFileInCliArgs,
getArgFromCLI,
getArgsFromCLI,
hasArgInCLI,
hasFileArgInCLI,
spawnScript,
} = require( './cli' );
const {
Expand All @@ -27,12 +27,12 @@ const {
module.exports = {
camelCaseDash,
fromConfigRoot,
getCliArg,
getCliArgs,
getArgFromCLI,
getArgsFromCLI,
getWebpackArgs,
hasBabelConfig,
hasCliArg,
hasFileInCliArgs,
hasArgInCLI,
hasFileArgInCLI,
hasJestConfig,
hasPackageProp,
hasProjectFile,
Expand Down
4 changes: 2 additions & 2 deletions packages/scripts/utils/process.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const getCliArgs = ( excludePrefixes ) => {
const getArgsFromCLI = ( excludePrefixes ) => {
const args = process.argv.slice( 2 );
if ( excludePrefixes ) {
return args.filter( ( arg ) => {
Expand All @@ -10,6 +10,6 @@ const getCliArgs = ( excludePrefixes ) => {

module.exports = {
exit: process.exit,
getCliArgs,
getArgsFromCLI,
getCurrentWorkingDirectory: process.cwd,
};
Loading