woocommerce/plugins/woocommerce-blocks/bin/hook-docs/actions/index.js

67 lines
1.5 KiB
JavaScript

'use strict';
/* eslint no-console: 0 */
/**
* External dependencies
*/
const chalk = require( 'chalk' );
/**
* Internal dependencies
*/
const {
params,
exceptions,
returns,
example,
related,
} = require( '../format-hook-doc' );
const {
createDocs,
generateHookName,
generateIntroduction,
sectionWithHeading,
contentWithHeading,
generateToc,
} = require( '../utilities' );
const generate = ( hooks ) => {
console.log( chalk.blue( 'Generating Action Docs...' ) );
const jsonDocs = [
{ html: '<!-- DO NOT UPDATE THIS DOC DIRECTLY -->' },
{
html:
'<!-- Use `npm run build:docs` to automatically build hook documentation -->',
},
{ h1: 'Actions' },
{ h2: 'Table of Contents' },
...generateToc( hooks ),
{ hr: '' },
...hooks.map( ( hook ) => {
const hookDocs = hook.doc || [];
return [
...generateHookName( hook ),
...generateIntroduction( hook ),
...contentWithHeading(
hook.doc.long_description_html,
'Description'
),
...sectionWithHeading( params( hookDocs ), 'Parameters' ),
...sectionWithHeading( exceptions( hookDocs ), 'Exceptions' ),
...sectionWithHeading( returns( hookDocs ), 'Returns' ),
...sectionWithHeading( example( hookDocs ), 'Example' ),
...sectionWithHeading( related( hookDocs ), 'Related' ),
{ h3: `Source` },
{ p: `File: [${ hook.file }](../src/${ hook.file })` },
{ hr: '' },
].filter( Boolean );
} ),
];
createDocs( 'docs/extensibility/actions.md', jsonDocs );
console.log( chalk.green( 'Done!' ) );
};
module.exports = { generate };