diff --git a/bin/hook-reference/data.js b/bin/hook-reference/data.js index 462b87dbba..2db756fa81 100644 --- a/bin/hook-reference/data.js +++ b/bin/hook-reference/data.js @@ -1,4 +1,4 @@ -const fsPromises = require( 'fs' ).promises; +const { readFile } = require( 'fs/promises' ); const exec = require( 'await-exec' ); const { parse } = require( 'comment-parser/lib' ); @@ -25,12 +25,12 @@ const addSourceFiles = async ( hooks, fileName ) => { }; const prepareHooks = async ( fileName ) => { - const data = await fsPromises - .readFile( fileName, 'utf-8' ) - .catch( ( err ) => console.error( 'Failed to read file', err ) ); + const data = await readFile( fileName, 'utf-8' ).catch( ( err ) => + console.error( 'Failed to read file', err ) + ); - const parsed = parse( data ); - const rawHooks = getHooks( parsed ); + const parsedData = parse( data ); + const rawHooks = getHooks( parsedData ); return await addSourceFiles( rawHooks, fileName ); }; diff --git a/bin/hook-reference/data.json b/bin/hook-reference/data.json new file mode 100644 index 0000000000..4c9a9848a5 --- /dev/null +++ b/bin/hook-reference/data.json @@ -0,0 +1,8 @@ +[ + { + "description": "List of homepage stats enabled by default", + "sourceFile": "https://github.com/woocommerce/woocommerce-admin/blob/b49e316cda779b925a8de9dbc54c3e293b0a8086//Users/paulsealock/vagrant-local/www/tangaroa/public_html/wp-content/plugins/woocommerce-admin/client/homescreen/stats-overview/defaults.js#L5-L16", + "name": "woocommerce_admin_homepage_default_stats", + "example": "addFilter( 'woocommerce_admin_homepage_default_stats', 'plugin-domain', ( defaultStats ) => defaultStats.filter( ( stat ) => stat !== 'jetpack/stats/views' ) );" + } +] \ No newline at end of file diff --git a/bin/hook-reference/index.js b/bin/hook-reference/index.js index 1864f98ed6..2869a59b7c 100644 --- a/bin/hook-reference/index.js +++ b/bin/hook-reference/index.js @@ -1,9 +1,7 @@ -const createData = require( './data' ); -const { promisify } = require( 'util' ); -const { resolve } = require( 'path' ); const fs = require( 'fs' ); -const readdir = promisify( fs.readdir ); -const stat = promisify( fs.stat ); +const { stat, readdir, writeFile } = require( 'fs/promises' ); +const { resolve } = require( 'path' ); +const createData = require( './data' ); async function getFiles( dir ) { const subdirs = await readdir( dir ); @@ -16,9 +14,10 @@ async function getFiles( dir ) { return files.reduce( ( a, f ) => a.concat( f ), [] ); } -const writeJSONFile = ( data ) => { - // Make JSON File here - console.log( data ); +const writeJSONFile = async ( data ) => { + const fileName = 'bin/hook-reference/data.json'; + const stringifiedData = JSON.stringify( data, null, 4 ); + await writeFile( fileName, stringifiedData ); }; getFiles( 'client' )