Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon Test: Improve messages and post install script handling #29036

Merged
merged 18 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions code/addons/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@
"@storybook/csf": "^0.1.11"
},
"devDependencies": {
"@types/semver": "^7",
"@vitest/browser": "^2.0.0",
"boxen": "^8.0.1",
"find-up": "^7.0.0",
"semver": "^7.6.3",
"tinyrainbow": "^1.2.0",
"ts-dedent": "^2.2.0",
"vitest": "^2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion code/addons/test/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"targets": {
"build": {}
}
}
}
34 changes: 34 additions & 0 deletions code/addons/test/src/postinstall-logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { colors, logger } from 'storybook/internal/node-logger';

import boxen, { type Options } from 'boxen';

const fancy =
process.platform !== 'win32' || process.env.CI || process.env.TERM === 'xterm-256color';
Comment on lines +5 to +6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a more descriptive variable name than 'fancy', such as 'useFancyCharacters' or 'useUnicodeSymbols'


export const step = colors.gray('›');
export const info = colors.blue(fancy ? 'ℹ' : 'i');
export const success = colors.green(fancy ? '✔' : '√');
export const warning = colors.orange(fancy ? '⚠' : '‼');
export const error = colors.red(fancy ? '✖' : '×');

const baseOptions: Options = {
borderStyle: 'round',
padding: 1,
};

export const print = (message: string, options: Options) => {
logger.line(1);
logger.plain(boxen(message, { ...baseOptions, ...options }));
};

export const printInfo = (title: string, message: string, options?: Options) =>
print(message, { borderColor: 'blue', title, ...options });

export const printWarning = (title: string, message: string, options?: Options) =>
print(message, { borderColor: 'yellow', title, ...options });

export const printError = (title: string, message: string, options?: Options) =>
print(message, { borderColor: 'red', title, ...options });

export const printSuccess = (title: string, message: string, options?: Options) =>
print(message, { borderColor: 'green', title, ...options });
Comment on lines +24 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: These functions are very similar. Consider using a single function with an enum parameter for the message type to reduce code duplication

Loading