-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a pre-commit hook to check whether API docs are updated (#18820)
- Loading branch information
Showing
9 changed files
with
176 additions
and
99 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Node dependencies. | ||
*/ | ||
const { join } = require( 'path' ); | ||
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 ] ) => join( 'packages', packageName, 'README.md' ) ); | ||
const unstagedReadmes = getUnstagedFiles().filter( ( element ) => readmeFiles.includes( element ) ); | ||
|
||
if ( unstagedReadmes.length > 0 ) { | ||
process.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' | ||
) ); | ||
} |
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,44 @@ | ||
const packages = [ | ||
'a11y', | ||
'autop', | ||
'blob', | ||
'block-editor', | ||
'block-library', | ||
'block-serialization-default-parser', | ||
'blocks', | ||
'compose', | ||
[ 'core-data', { | ||
'Autogenerated actions': 'src/actions.js', | ||
'Autogenerated selectors': 'src/selectors.js', | ||
} ], | ||
'data', | ||
'data-controls', | ||
'date', | ||
'deprecated', | ||
'dom', | ||
'dom-ready', | ||
'e2e-test-utils', | ||
'edit-post', | ||
'element', | ||
'escape-html', | ||
'html-entities', | ||
'i18n', | ||
'keycodes', | ||
'plugins', | ||
'priority-queue', | ||
'redux-routine', | ||
'rich-text', | ||
'shortcode', | ||
'url', | ||
'viewport', | ||
'wordcount', | ||
]; | ||
|
||
module.exports = function() { | ||
return packages.map( ( entry ) => { | ||
if ( ! Array.isArray( entry ) ) { | ||
entry = [ entry, { 'Autogenerated API docs': 'src/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Node dependencies. | ||
*/ | ||
const { join } = require( 'path' ); | ||
const spawnSync = require( 'child_process' ).spawnSync; | ||
|
||
/** | ||
* Local dependencies. | ||
*/ | ||
const getPackages = require( './packages' ); | ||
|
||
getPackages().forEach( ( entry ) => { | ||
const [ packageName, targetFiles ] = entry; | ||
|
||
Object.entries( targetFiles ).forEach( ( [ token, path ] ) => { | ||
// Each target operates over the same file, so it needs to be processed synchronously, | ||
// as to make sure the processes don't overwrite each other. | ||
const { status, stderr } = spawnSync( | ||
join( __dirname, '..', '..', 'node_modules', '.bin', 'docgen' ).replace( / /g, '\\ ' ), | ||
[ | ||
join( 'packages', packageName, path ), | ||
`--output packages/${ packageName }/README.md`, | ||
'--to-token', | ||
`--use-token "${ token }"`, | ||
'--ignore "/unstable|experimental/i"', | ||
], | ||
{ shell: true }, | ||
); | ||
|
||
if ( status !== 0 ) { | ||
process.stderr.write( `${ packageName } ${ stderr.toString() }\n` ); | ||
process.exit( 1 ); | ||
} | ||
} ); | ||
} ); |
This file was deleted.
Oops, something went wrong.
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,27 @@ | ||
#!/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 unstagedReadmes = getUnstagedFiles().filter( ( element ) => readmeFiles.includes( element ) ); | ||
|
||
if ( unstagedReadmes.length > 0 ) { | ||
process.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' | ||
) ); | ||
} |
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