Skip to content

Commit

Permalink
style(plugin): add initialization messages to console
Browse files Browse the repository at this point in the history
format messages show when plugin initialize
  • Loading branch information
samcyn committed Apr 10, 2024
1 parent 99aee75 commit a3842e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/plugin/src/on-plugin-init.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { GatsbyNode } from 'gatsby';
import { ERROR_CODES } from './constants';
import { wrapWithAsterisks } from './utils';

/**
* Use the onPluginInit API to set up things that should be run before the plugin is initialized.
Expand All @@ -10,7 +11,10 @@ import { ERROR_CODES } from './constants';
* @see https://www.gatsbyjs.com/docs/reference/config-files/node-api-helpers/#reporter
*/
export const onPluginInit: GatsbyNode['onPluginInit'] = ({ reporter }) => {
reporter.info('Ye! Hubspot Blog Plugin Initialized. Check ReadMe.MD file for documentations');
const info = `Hey, thanks for considering installing "gatsby-source-hubspot-node",
for documentation see https://github.com/samcyn/gatsby-source-hubspot-node`;

reporter.info(wrapWithAsterisks(info));
reporter.setErrorMap({
[ERROR_CODES.HubspotSourcing]: {
text: (context) => `${context.sourceMessage}: ${context.errorCode}`,
Expand Down
10 changes: 10 additions & 0 deletions packages/plugin/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,13 @@ export function createAssetNode(gatsbyApi: SourceNodesArgs, data: IPostImageInpu
*/
return id;
}

export function wrapWithAsterisks(message: string) {
function createAsteriskLine(length: number) {
return '*'.repeat(length);
}

const asteriskLine = createAsteriskLine(message.length / 2);

return `${asteriskLine}*\n\n* ${message} *\n\n${asteriskLine}******`;
}

0 comments on commit a3842e2

Please sign in to comment.