-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pre-commit hook for handbook data docs
- Loading branch information
Showing
4 changed files
with
76 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Node dependencies. | ||
*/ | ||
const chalk = require( 'chalk' ); | ||
const execSync = require( 'child_process' ).execSync; | ||
|
||
/** | ||
* Local dependencies. | ||
*/ | ||
const getPackages = require( './packages' ); | ||
|
||
const getUnstagedFiles = () => execSync( 'git diff --name-only', { encoding: 'utf8' } ).split( '\n' ).filter( ( element ) => '' !== element ); | ||
|
||
const readmeFiles = getPackages().map( ( [ packageName ] ) => `docs/designers-developers/developers/data/data-${ packageName.replace( '/', '-' ) }.md` ); | ||
const unstagedFiles = getUnstagedFiles(); | ||
|
||
const unstagedReadmes = []; | ||
unstagedFiles.forEach( ( element ) => { | ||
if ( readmeFiles.includes( element ) ) { | ||
unstagedReadmes.push( element ); | ||
} | ||
} ); | ||
|
||
let exitCode = 0; | ||
if ( unstagedReadmes.length > 0 ) { | ||
exitCode = 1; | ||
process.stdout.write( chalk.red( | ||
'\n', | ||
'Some API docs may be out of date:', | ||
unstagedReadmes.toString(), | ||
'Either stage them or continue with --no-verify.', | ||
'\n' | ||
) ); | ||
} | ||
|
||
process.exit( exitCode ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const packages = [ | ||
[ 'core', { | ||
'Autogenerated actions': 'packages/core-data/src/actions.js', | ||
'Autogenerated selectors': 'packages/core-data/src/selectors.js', | ||
} ], | ||
'core/annotations', | ||
'core/blocks', | ||
'core/block-editor', | ||
'core/editor', | ||
'core/edit-post', | ||
'core/notices', | ||
'core/nux', | ||
'core/viewport', | ||
]; | ||
|
||
module.exports = function() { | ||
return packages.map( ( entry ) => { | ||
if ( ! Array.isArray( entry ) ) { | ||
entry = [ entry, { | ||
'Autogenerated actions': `packages/${ entry.replace( 'core/', '' ) }/src/store/actions.js`, | ||
'Autogenerated selectors': `packages/${ entry.replace( 'core/', '' ) }/src/store/selectors.js`, | ||
} ]; | ||
} | ||
return entry; | ||
} ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters