Repository navigation
Add a pre-commit hook to check whether API docs are updated #18820
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
Changes from 3 commits
f97e873
ba13296
14f3a3b
31378db
f4aa5ff
7790978
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #!/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 unstagedFiles = getUnstagedFiles(); | ||
|
|
||
| const unstagedReadmes = []; | ||
| unstagedFiles.forEach( ( element ) => { | ||
| if ( readmeFiles.includes( element ) ) { | ||
| unstagedReadmes.push( element ); | ||
| } | ||
| } ); | ||
|
oandregal marked this conversation as resolved.
Outdated
|
||
|
|
||
| let exitCode = 0; | ||
| if ( unstagedReadmes.length > 0 ) { | ||
| exitCode = 1; | ||
|
oandregal marked this conversation as resolved.
Outdated
|
||
| 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 ); | ||
| 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; | ||
| } ); | ||
| }; |
| 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.
| 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 ); |
| 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; | ||
| } ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,7 +120,7 @@ | |
| "fast-glob": "2.2.7", | ||
| "fbjs": "0.8.17", | ||
| "glob": "7.1.2", | ||
| "husky": "3.0.5", | ||
| "husky": "2.7.0", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was it intentional to downgrade? I would expect it would need corresponding changes to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to revert this. For context: when we updated husky from 0 to 3 we introduced a breaking change: the git version required to work with husky is I asked in core-editor about this change and it doesn't seem a widespread issue. Wasn't able to pin down easily the git versions that come with the supported OS for Windows and Mac to gauge how many could be affected. I guessed another way to look at it was that if people don't complain about hooks not executing for them, it's not an issue.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| "inquirer": "6.3.1", | ||
| "is-equal-shallow": "0.1.3", | ||
| "jest-junit": "6.4.0", | ||
|
|
@@ -171,7 +171,7 @@ | |
| "predev": "npm run check-engines", | ||
| "dev": "npm run build:packages && concurrently \"wp-scripts start\" \"npm run dev:packages\"", | ||
| "dev:packages": "node ./bin/packages/watch.js", | ||
| "docs:build": "node ./docs/tool/index.js && node ./bin/update-readmes.js", | ||
| "docs:build": "node ./docs/tool/index.js && node ./bin/api-docs/update-readmes.js", | ||
| "fixtures:clean": "rimraf \"packages/e2e-tests/fixtures/blocks/*.+(json|serialized.html)\"", | ||
| "fixtures:server-registered": "wp-scripts env docker-run php ./bin/get-server-blocks.php > test/integration/full-content/server-registered.json", | ||
| "fixtures:generate": "npm run fixtures:server-registered && cross-env GENERATE_MISSING_FIXTURES=y npm run test-unit", | ||
|
|
@@ -228,10 +228,12 @@ | |
| "wp-scripts lint-js" | ||
| ], | ||
| "{docs/{toc.json,tool/*.js},packages/{*/README.md,*/src/{actions,selectors}.js,components/src/*/**/README.md}}": [ | ||
| "node ./docs/tool/index.js" | ||
| "node ./docs/tool/index.js", | ||
| "node ./docs/tool/are-data-files-unstaged.js" | ||
| ], | ||
| "packages/**/*.js": [ | ||
| "node ./bin/update-readmes.js" | ||
| "node ./bin/api-docs/update-readmes.js", | ||
| "node ./bin/api-docs/are-readmes-unstaged.js" | ||
| ] | ||
| }, | ||
| "wp-env": { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.