mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-17 05:02:23 +08:00
Add metadata.hasChromatic
This commit is contained in:
parent
670f512793
commit
4cf693c66d
13
code/lib/telemetry/src/has-chromatic.test.ts
Normal file
13
code/lib/telemetry/src/has-chromatic.test.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { hasChromatic } from './has-chromatic';
|
||||
|
||||
it('works for dependencies', () => {
|
||||
expect(hasChromatic({ dependencies: { chromatic: '^6.11.4' } })).toBe(true);
|
||||
});
|
||||
|
||||
it('works for scripts', () => {
|
||||
expect(hasChromatic({ scripts: { chromatic: 'npx chromatic -t abc123' } })).toBe(true);
|
||||
});
|
||||
|
||||
it('fails otherwise', () => {
|
||||
expect(hasChromatic({})).toBe(false);
|
||||
});
|
16
code/lib/telemetry/src/has-chromatic.ts
Normal file
16
code/lib/telemetry/src/has-chromatic.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import type { PackageJson } from '@storybook/types';
|
||||
|
||||
export function hasChromatic(packageJson: PackageJson) {
|
||||
if (
|
||||
packageJson.dependencies?.chromatic ||
|
||||
packageJson.devDependencies?.chromatic ||
|
||||
packageJson.peerDependencies?.chromatic
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Chromatic isn't necessarily installed in dependencies, it can be run from npx
|
||||
return !!(
|
||||
packageJson.scripts && Object.values(packageJson.scripts).find((s) => s.match(/chromatic/))
|
||||
);
|
||||
}
|
@ -13,6 +13,7 @@ import { getActualPackageVersion, getActualPackageVersions } from './package-jso
|
||||
import { getMonorepoType } from './get-monorepo-type';
|
||||
import { cleanPaths } from './sanitize';
|
||||
import { getFrameworkInfo } from './get-framework-info';
|
||||
import { hasChromatic } from './has-chromatic';
|
||||
|
||||
export const metaFrameworks = {
|
||||
next: 'Next',
|
||||
@ -157,6 +158,7 @@ export const computeStorybookMetadata = async ({
|
||||
...frameworkInfo,
|
||||
storybookVersion,
|
||||
storybookVersionSpecifier: storybookInfo.version,
|
||||
hasChromatic: hasChromatic(packageJson),
|
||||
language,
|
||||
storybookPackages,
|
||||
addons,
|
||||
|
@ -49,6 +49,7 @@ export type StorybookMetadata = {
|
||||
hasStaticDirs?: boolean;
|
||||
hasCustomWebpack?: boolean;
|
||||
hasCustomBabel?: boolean;
|
||||
hasChromatic?: boolean;
|
||||
features?: StorybookConfig['features'];
|
||||
refCount?: number;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user