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

Commit

Permalink
fancy logs
Browse files Browse the repository at this point in the history
  • Loading branch information
psealock committed Mar 17, 2021
1 parent 00faca7 commit 1b2c88a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
11 changes: 11 additions & 0 deletions bin/hook-reference/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { readFile } = require( 'fs' ).promises;
const exec = require( 'await-exec' );
const { parse } = require( 'comment-parser/lib' );
const { relative, resolve } = require( 'path' );
const chalk = require( 'chalk' );

const getHooks = ( parsedData ) =>
parsedData.filter( ( docBlock ) =>
Expand All @@ -15,11 +16,21 @@ const getSourceFile = ( file, commit, { source } ) => {
return `https://github.com/woocommerce/woocommerce-admin/blob/${ commit }/${ file }#L${ first }-L${ last }`;
};

const logProgress = ( fileName, { tags } ) => {
const hook = tags.find( ( tag ) => tag.tag === 'hook' );
console.log(
chalk.cyan( `${ hook.name } ` ) +
chalk.yellow( 'generated in ' ) +
chalk.yellow.underline( fileName )
);
};

const addSourceFiles = async ( hooks, fileName ) => {
const { stdout } = await exec( 'git log --pretty="format:%H" -1' );
const commit = stdout.trim();

return hooks.map( ( hook ) => {
logProgress( fileName, hook );
hook.sourceFile = getSourceFile( fileName, commit, hook );
return hook;
} );
Expand Down
2 changes: 1 addition & 1 deletion bin/hook-reference/data.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"description": "List of homepage stats enabled by default",
"sourceFile": "https://github.com/woocommerce/woocommerce-admin/blob/c93bd2b89650ee0050a155dee553c563ffc0a49f/client/homescreen/stats-overview/defaults.js#L5-L16",
"sourceFile": "https://github.com/woocommerce/woocommerce-admin/blob/ff1a3cb2f3857cfa759fb3c93cedfe630dbd5510/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' ) );"
}
Expand Down
11 changes: 11 additions & 0 deletions bin/hook-reference/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require( 'fs' );
const { stat, readdir, writeFile } = require( 'fs' ).promises;
const { resolve } = require( 'path' );
const createData = require( './data' );
const chalk = require( 'chalk' );

async function getFilePaths( dir ) {
const subdirs = await readdir( dir );
Expand All @@ -20,8 +21,18 @@ const writeJSONFile = async ( data ) => {
const fileName = 'bin/hook-reference/data.json';
const stringifiedData = JSON.stringify( data, null, 4 );
await writeFile( fileName, stringifiedData + '\n' );

console.log( '\n' );
console.log(
chalk.greenBright(
'A new Hook Reference data source has been created. See `/bin/hook-reference/data.json` and be sure to commit changes.'
)
);
};

console.log( chalk.green( 'Preparing Hook Reference data file' ) );
console.log( '\n' );

getFilePaths( 'client' )
.then( ( paths ) => createData( paths ) )
.then( ( data ) => writeJSONFile( data ) )
Expand Down

0 comments on commit 1b2c88a

Please sign in to comment.