From 1b2c88a61639316de08593bcaac09b4b3e7d76de Mon Sep 17 00:00:00 2001 From: Paul Sealock Date: Mon, 15 Mar 2021 13:43:50 +1300 Subject: [PATCH] fancy logs --- bin/hook-reference/data.js | 11 +++++++++++ bin/hook-reference/data.json | 2 +- bin/hook-reference/index.js | 11 +++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/bin/hook-reference/data.js b/bin/hook-reference/data.js index 4deb3959cd8..a74ab934650 100644 --- a/bin/hook-reference/data.js +++ b/bin/hook-reference/data.js @@ -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 ) => @@ -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; } ); diff --git a/bin/hook-reference/data.json b/bin/hook-reference/data.json index f3c9549cd06..39c9262789a 100644 --- a/bin/hook-reference/data.json +++ b/bin/hook-reference/data.json @@ -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' ) );" } diff --git a/bin/hook-reference/index.js b/bin/hook-reference/index.js index 27847de811c..861c59e46cd 100644 --- a/bin/hook-reference/index.js +++ b/bin/hook-reference/index.js @@ -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 ); @@ -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 ) )