Skip to content

Commit

Permalink
chore: refactor the update notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
tatomyr committed Jan 31, 2024
1 parent 3c7ff52 commit 20bfafd
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions packages/cli/src/utils/update-version-notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,27 @@ const renderUpdateBanner = (current: string, latest: string) => {
const maxLength = Math.max(...messageLines.map((line) => cleanColors(line).length));

const border = yellow('═'.repeat(maxLength + SPACE_TO_BORDER));

const banner = `
${yellow('╔' + border + '╗')}
${yellow('║' + ' '.repeat(maxLength + SPACE_TO_BORDER) + '║')}
${messageLines
.map((line, index) => {
return getLineWithPadding(maxLength, line, index);
})
.join('\n')}
${yellow('║' + ' '.repeat(maxLength + SPACE_TO_BORDER) + '║')}
${yellow('╚' + border + '╝')}
`;

const extraSpaces = ' '.repeat(SPACE_TO_BORDER);

const banner = [
'',
extraSpaces + yellow('╔' + border + '╗'),
extraSpaces + yellow('║' + ' '.repeat(maxLength + SPACE_TO_BORDER) + '║'),
messageLines.map(getLineWithPadding(maxLength, extraSpaces)).join('\n'),
extraSpaces + yellow('║' + ' '.repeat(maxLength + SPACE_TO_BORDER) + '║'),
extraSpaces + yellow('╚' + border + '╝'),
'',
'',
].join('\n');
process.stderr.write(banner);
};

const getLineWithPadding = (maxLength: number, line: string, index: number): string => {
const padding = ' '.repeat(maxLength - cleanColors(line).length);
const extraSpaces = index !== 0 ? ' '.repeat(SPACE_TO_BORDER) : '';
return `${extraSpaces}${yellow('║')} ${line}${padding} ${yellow('║')}`;
};
const getLineWithPadding =
(maxLength: number, extraSpaces: string) =>
(line: string): string => {
const padding = ' '.repeat(maxLength - cleanColors(line).length);
return `${extraSpaces}${yellow('║')} ${line}${padding} ${yellow('║')}`;
};

const isNeedToBeCached = (): boolean => {
try {
Expand Down

0 comments on commit 20bfafd

Please sign in to comment.