diff --git a/bin/hook-reference/document.js b/bin/hook-reference/data.js similarity index 80% rename from bin/hook-reference/document.js rename to bin/hook-reference/data.js index a6543cd4ee6..462b87dbba4 100644 --- a/bin/hook-reference/document.js +++ b/bin/hook-reference/data.js @@ -34,7 +34,7 @@ const prepareHooks = async ( fileName ) => { return await addSourceFiles( rawHooks, fileName ); }; -const makeDocObject = async ( fileName ) => { +const makeDocObjects = async ( fileName ) => { const hooks = await prepareHooks( fileName ); return hooks.map( ( { description, tags, sourceFile } ) => { const example = tags.find( ( tag ) => tag.tag === 'example' ); @@ -48,18 +48,13 @@ const makeDocObject = async ( fileName ) => { } ); }; -const makeJSONFile = async ( docObjects ) => { - // Make JSON File here - console.log( docObjects ); -}; - -const makeDocument = async ( fileNames ) => { - const docObjects = await Promise.all( - fileNames.map( async ( f ) => { - return await makeDocObject( f ); +const createData = async ( fileNames ) => { + const data = await Promise.all( + fileNames.map( async ( fileName ) => { + return await makeDocObjects( fileName ); } ) ); - makeJSONFile( docObjects.flat() ); + return data.flat(); }; -module.exports = makeDocument; +module.exports = createData; diff --git a/bin/hook-reference/index.js b/bin/hook-reference/index.js index 795c3b51f4c..1864f98ed6c 100644 --- a/bin/hook-reference/index.js +++ b/bin/hook-reference/index.js @@ -1,4 +1,4 @@ -const makeDocument = require( './document' ); +const createData = require( './data' ); const { promisify } = require( 'util' ); const { resolve } = require( 'path' ); const fs = require( 'fs' ); @@ -16,6 +16,12 @@ async function getFiles( dir ) { return files.reduce( ( a, f ) => a.concat( f ), [] ); } +const writeJSONFile = ( data ) => { + // Make JSON File here + console.log( data ); +}; + getFiles( 'client' ) - .then( ( fileNames ) => makeDocument( fileNames ) ) + .then( ( fileNames ) => createData( fileNames ) ) + .then( ( data ) => writeJSONFile( data ) ) .catch( ( e ) => console.error( e ) );