Skip to content

Commit

Permalink
Core Data: Add docgen auto-documentation for actions, selectors (#15200)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Apr 26, 2019
1 parent 20582e5 commit fe43fd7
Show file tree
Hide file tree
Showing 2 changed files with 404 additions and 16 deletions.
42 changes: 28 additions & 14 deletions bin/update-readmes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

const path = require( 'path' );
const { join } = require( 'path' );
const { promisify } = require( 'util' );
const spawn = promisify( require( 'child_process' ).spawn );

Expand All @@ -13,6 +13,10 @@ const packages = [
'block-serialization-default-parser',
'blocks',
'compose',
[ 'core-data', {
'Autogenerated actions': 'src/actions.js',
'Autogenerated selectors': 'src/selectors.js',
} ],
'data',
'date',
'deprecated',
Expand All @@ -35,20 +39,30 @@ const packages = [
'wordcount',
];

Promise.all( packages.map( async ( packageName ) => {
const { status, stderr } = await spawn(
path.join( __dirname, '..', 'node_modules', '.bin', 'docgen' ),
[
`packages/${ packageName }/src/index.js`,
`--output packages/${ packageName }/README.md`,
'--to-token',
'--ignore "/unstable|experimental/i"',
],
{ shell: true },
);
if ( status !== 0 ) {
throw stderr.toString();
Promise.all( packages.map( ( entry ) => {
if ( ! Array.isArray( entry ) ) {
entry = [ entry, { 'Autogenerated API docs': 'src/index.js' } ];
}

const [ packageName, targets ] = entry;

return Promise.all( Object.entries( targets ).map( async ( [ token, path ] ) => {
const { status, stderr } = await spawn(
join( __dirname, '..', 'node_modules', '.bin', 'docgen' ),
[
join( 'packages', packageName, path ),
`--output packages/${ packageName }/README.md`,
'--to-token',
`--use-token "${ token }"`,
'--ignore "/unstable|experimental/i"',
],
{ shell: true },
);

if ( status !== 0 ) {
throw stderr.toString();
}
} ) );
} ) ).catch( ( error ) => {
process.stderr.write( `${ error }\n` );
process.exit( 1 );
Expand Down
Loading

0 comments on commit fe43fd7

Please sign in to comment.