mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-05 06:21:15 +08:00
Telemetry: Measure version update check
This commit is contained in:
parent
298c9e9e66
commit
d10ab1f6af
@ -36,7 +36,7 @@ export async function buildDevStandalone(options: CLIOptions & LoadOptions & Bui
|
||||
getServerPort(options.port),
|
||||
versionUpdates
|
||||
? updateCheck(version)
|
||||
: Promise.resolve({ success: false, data: {}, time: Date.now() }),
|
||||
: Promise.resolve({ success: false, cached: false, data: {}, time: Date.now() }),
|
||||
releaseNotes
|
||||
? getReleaseNotesData(version, cache)
|
||||
: Promise.resolve(getReleaseNotesFailedState(version)),
|
||||
|
@ -1,7 +1,13 @@
|
||||
import express, { Router } from 'express';
|
||||
import compression from 'compression';
|
||||
|
||||
import type { CoreConfig, DocsOptions, Options, StorybookConfig } from '@storybook/types';
|
||||
import type {
|
||||
CoreConfig,
|
||||
DocsOptions,
|
||||
Options,
|
||||
StorybookConfig,
|
||||
VersionCheck,
|
||||
} from '@storybook/types';
|
||||
|
||||
import { normalizeStories, logConfig } from '@storybook/core-common';
|
||||
|
||||
@ -24,6 +30,12 @@ export const router: Router = new Router();
|
||||
|
||||
export const DEBOUNCE = 100;
|
||||
|
||||
const versionStatus = (versionCheck: VersionCheck) => {
|
||||
if (versionCheck.error) return 'error';
|
||||
if (versionCheck.cached) return 'cached';
|
||||
return 'success';
|
||||
};
|
||||
|
||||
export async function storybookDevServer(options: Options) {
|
||||
const startTime = process.hrtime();
|
||||
const app = express();
|
||||
@ -67,8 +79,10 @@ export async function storybookDevServer(options: Options) {
|
||||
if (!core?.disableTelemetry) {
|
||||
initializedStoryIndexGenerator.then(async (generator) => {
|
||||
const storyIndex = await generator?.getIndex();
|
||||
const { versionCheck, versionUpdates } = options;
|
||||
const payload = storyIndex
|
||||
? {
|
||||
versionStatus: versionUpdates ? versionStatus(versionCheck) : 'disabled',
|
||||
storyIndex: summarizeIndex(storyIndex),
|
||||
}
|
||||
: undefined;
|
||||
|
@ -22,13 +22,13 @@ export const updateCheck = async (version: string): Promise<VersionCheck> => {
|
||||
new Promise((res, rej) => global.setTimeout(rej, 1500)),
|
||||
]);
|
||||
const data = await fromFetch.json();
|
||||
result = { success: true, data, time };
|
||||
result = { success: true, cached: false, data, time };
|
||||
await cache.set('lastUpdateCheck', result);
|
||||
} else {
|
||||
result = fromCache;
|
||||
result = { ...fromCache, cached: true };
|
||||
}
|
||||
} catch (error) {
|
||||
result = { success: false, error, time };
|
||||
result = { success: false, cached: false, error, time };
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
@ -94,6 +94,7 @@ export interface Ref {
|
||||
|
||||
export interface VersionCheck {
|
||||
success: boolean;
|
||||
cached: boolean;
|
||||
data?: any;
|
||||
error?: any;
|
||||
time: number;
|
||||
|
Loading…
x
Reference in New Issue
Block a user