test commit
This commit is contained in:
parent
4e17dacd51
commit
5ae2a74320
4 changed files with 88 additions and 44 deletions
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -627,6 +627,11 @@
|
|||
"integrity": "sha1-Zws6+8VS4LVd9rd4DKdGFfI60cs=",
|
||||
"dev": true
|
||||
},
|
||||
"wp-prettier": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-2.0.5.tgz",
|
||||
"integrity": "sha512-5GCgdeevIXwR3cW4Qj5XWC5MO1iSCz8+IPn0mMw6awAt/PBiey8yyO7MhePRsaMqghJAhg6Q3QLYWSnUHWkG6A=="
|
||||
},
|
||||
"wrap-ansi": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"description": "Automattic public themes",
|
||||
"author": "automattic",
|
||||
"license": "GPL-2.0",
|
||||
"prettier": "@wordpress/prettier-config",
|
||||
"prettier": "@wordpress/prettier-config",
|
||||
"scripts": {
|
||||
"sandbox:clean": "./sandbox.sh clean",
|
||||
"sandbox:push": "./sandbox.sh push",
|
||||
|
@ -22,5 +22,8 @@
|
|||
"hooks": {
|
||||
"pre-commit": "node pre-commit-hook.js"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"wp-prettier": "^2.0.5"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,14 +34,18 @@ function parseGitDiffToPathArray( command ) {
|
|||
return execSync( command, { encoding: 'utf8' } )
|
||||
.split( '\n' )
|
||||
.map( ( name ) => name.trim() )
|
||||
.filter( ( name ) => /(?:\.json|\.[jt]sx?|\.scss|\.php)$/.test( name ) );
|
||||
.filter( ( name ) =>
|
||||
/(?:\.json|\.[jt]sx?|\.scss|\.php)$/.test( name )
|
||||
);
|
||||
}
|
||||
|
||||
function getPathForCommand( command ) {
|
||||
const composerBinDir = path.join( __dirname, 'vendor', 'bin' );
|
||||
let path_to_command;
|
||||
try {
|
||||
path_to_command = execSync( 'command -v ' + command, { encoding: 'utf8' } );
|
||||
path_to_command = execSync( 'command -v ' + command, {
|
||||
encoding: 'utf8',
|
||||
} );
|
||||
} catch ( e ) {
|
||||
path_to_command = path.join( composerBinDir, command );
|
||||
}
|
||||
|
@ -77,8 +81,8 @@ function linterFailure() {
|
|||
console.log(
|
||||
chalk.red( 'COMMIT ABORTED:' ),
|
||||
'The linter reported some problems. ' +
|
||||
'If you are aware of them and it is OK, ' +
|
||||
'repeat the commit command with --no-verify to avoid this check.'
|
||||
'If you are aware of them and it is OK, ' +
|
||||
'repeat the commit command with --no-verify to avoid this check.'
|
||||
);
|
||||
process.exit( 1 );
|
||||
}
|
||||
|
@ -89,27 +93,32 @@ const phpcs = phpcsInstalled();
|
|||
// determine if PHPCBF is available
|
||||
const phpcbf = phpcbfInstalled();
|
||||
|
||||
// grab a list of all the files staged to commit
|
||||
const files = parseGitDiffToPathArray( 'git diff --cached --name-only --diff-filter=ACM' ).filter( ( file ) => file.endsWith( '.php' ) );
|
||||
// grab a list of all the php files staged to commit
|
||||
const phpFiles = parseGitDiffToPathArray(
|
||||
'git diff --cached --name-only --diff-filter=ACM'
|
||||
).filter( ( file ) => file.endsWith( '.php' ) );
|
||||
|
||||
if ( files.length ) {
|
||||
phpcbfResult = spawnSync( phpcbfPath,
|
||||
[ ...files ],
|
||||
{
|
||||
shell: true,
|
||||
stdio: 'inherit',
|
||||
}
|
||||
);
|
||||
if ( phpFiles.length ) {
|
||||
phpcbfResult = spawnSync( phpcbfPath, [ ...phpFiles ], {
|
||||
shell: true,
|
||||
stdio: 'inherit',
|
||||
} );
|
||||
|
||||
if ( phpcbfResult && phpcbfResult.status ) {
|
||||
execSync( `git add ${ files.join( ' ' ) }` );
|
||||
console.log( chalk.yellow( 'PHPCS issues detected and automatically fixed via PHPCBF.' ) );
|
||||
execSync( `git add ${ phpFiles.join( ' ' ) }` );
|
||||
console.log(
|
||||
chalk.yellow(
|
||||
'PHPCS issues detected and automatically fixed via PHPCBF.'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( phpcs ) {
|
||||
const lintResult = spawnSync(
|
||||
`PHPCS=${ quotedPath( phpcsPath ) } ${ quotedPath( phpcsChangedPath ) }`,
|
||||
[ '--git', ...files ],
|
||||
`PHPCS=${ quotedPath( phpcsPath ) } ${ quotedPath(
|
||||
phpcsChangedPath
|
||||
) }`,
|
||||
[ '--git', ...phpFiles ],
|
||||
{
|
||||
shell: true,
|
||||
stdio: 'inherit',
|
||||
|
@ -121,3 +130,20 @@ if ( files.length ) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// grab a list of all the js files staged to commit
|
||||
const jsFiles = parseGitDiffToPathArray(
|
||||
'git diff --cached --name-only --diff-filter=ACM'
|
||||
).filter( ( file ) => file.endsWith( '.js' ) );
|
||||
|
||||
if ( jsFiles.length ) {
|
||||
jsFiles.forEach( ( file ) =>
|
||||
console.log( `Prettier formatting staged file: ${ file }` )
|
||||
);
|
||||
execSync(
|
||||
`./node_modules/.bin/prettier --ignore-path .eslintignore --write ${ jsFiles.join(
|
||||
' '
|
||||
) }`
|
||||
);
|
||||
execSync( `git add ${ jsFiles.join( ' ' ) }` );
|
||||
}
|
||||
|
|
|
@ -3,59 +3,69 @@
|
|||
*
|
||||
* Required to open and close the mobile navigation.
|
||||
*/
|
||||
( function() {
|
||||
|
||||
( function () {
|
||||
/**
|
||||
* Menu Toggle Behaviors
|
||||
*
|
||||
* @param {Element} element
|
||||
*/
|
||||
var navMenu = function ( id ){
|
||||
var wrapper = document.body; // this is the element to which a CSS class is added when a mobile nav menu is open
|
||||
var openButton = document.getElementById( id + '-open-menu' );
|
||||
var closeButton = document.getElementById( id + '-close-menu' );
|
||||
var navMenu = function ( id ) {
|
||||
var wrapper = document.body; // this is the element to which a CSS class is added when a mobile nav menu is open
|
||||
var openButton = document.getElementById( id + '-open-menu' );
|
||||
var closeButton = document.getElementById( id + '-close-menu' );
|
||||
|
||||
if ( openButton && closeButton ){
|
||||
openButton.onclick = function() {
|
||||
if ( openButton && closeButton ) {
|
||||
openButton.onclick = function () {
|
||||
wrapper.classList.add( id + '-navigation-open' );
|
||||
wrapper.classList.add( 'lock-scrolling' );
|
||||
closeButton.focus();
|
||||
}
|
||||
};
|
||||
|
||||
closeButton.onclick = function() {
|
||||
closeButton.onclick = function () {
|
||||
wrapper.classList.remove( id + '-navigation-open' );
|
||||
wrapper.classList.remove( 'lock-scrolling' );
|
||||
openButton.focus();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Trap keyboard navigation in the menu modal.
|
||||
* Adapted from TwentyTwenty
|
||||
*/
|
||||
document.addEventListener( 'keydown', function( event ) {
|
||||
if ( ! wrapper.classList.contains( id + '-navigation-open' ) ){
|
||||
document.addEventListener( 'keydown', function ( event ) {
|
||||
if ( ! wrapper.classList.contains( id + '-navigation-open' ) ) {
|
||||
return;
|
||||
}
|
||||
var modal, elements, selectors, lastEl, firstEl, activeEl, tabKey, shiftKey, escKey;
|
||||
}
|
||||
var modal,
|
||||
elements,
|
||||
selectors,
|
||||
lastEl,
|
||||
firstEl,
|
||||
activeEl,
|
||||
tabKey,
|
||||
shiftKey,
|
||||
escKey;
|
||||
|
||||
modal = document.querySelector( '.' + id + '-navigation' );
|
||||
selectors = "input, a, button";
|
||||
selectors = 'input, a, button';
|
||||
elements = modal.querySelectorAll( selectors );
|
||||
elements = Array.prototype.slice.call( elements );
|
||||
elements = elements.filter( function( el ) {
|
||||
elements = elements.filter( function ( el ) {
|
||||
return ! el.classList.contains( 'woocommerce-cart-link' ); // ignore this element because it's hidden on mobile
|
||||
});
|
||||
} );
|
||||
tabKey = event.keyCode === 9;
|
||||
shiftKey = event.shiftKey;
|
||||
escKey = event.keyCode === 27;
|
||||
activeEl = document.activeElement;
|
||||
lastEl = elements[ elements.length - 1 ];
|
||||
firstEl = elements[0];
|
||||
firstEl = elements[ 0 ];
|
||||
|
||||
if ( escKey ) {
|
||||
event.preventDefault();
|
||||
wrapper.classList.remove( id + '-navigation-open', 'lock-scrolling' );
|
||||
wrapper.classList.remove(
|
||||
id + '-navigation-open',
|
||||
'lock-scrolling'
|
||||
);
|
||||
openButton.focus();
|
||||
}
|
||||
|
||||
|
@ -73,11 +83,11 @@
|
|||
if ( tabKey && firstEl === lastEl ) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
||||
window.addEventListener( 'load', function() {
|
||||
window.addEventListener( 'load', function () {
|
||||
new navMenu( 'primary' );
|
||||
new navMenu( 'woo' );
|
||||
});
|
||||
} )();
|
||||
} );
|
||||
} )();
|
||||
|
|
Loading…
Reference in a new issue