Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
psealock committed Feb 28, 2021
1 parent b49e316 commit c414d9e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
12 changes: 6 additions & 6 deletions bin/hook-reference/data.js
Original file line number Diff line number Diff line change
@@ -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' );

Expand All @@ -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 );
};

Expand Down
8 changes: 8 additions & 0 deletions bin/hook-reference/data.json
Original file line number Diff line number Diff line change
@@ -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' ) );"
}
]
15 changes: 7 additions & 8 deletions bin/hook-reference/index.js
Original file line number Diff line number Diff line change
@@ -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 );
Expand All @@ -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' )
Expand Down

0 comments on commit c414d9e

Please sign in to comment.