fix: clean code.

This commit is contained in:
Yadong Zhang 2023-02-13 07:02:37 +00:00
parent c2a344c7d7
commit 6e122495d8
4 changed files with 17 additions and 27 deletions

View File

@ -23,8 +23,6 @@ import {
resolveAddonName,
} from '@storybook/core-common';
import isEqual from 'lodash/isEqual.js';
import { outputStats } from './utils/output-stats';
import {
copyAllStaticFiles,
@ -35,7 +33,6 @@ import { extractStoriesJson, convertToIndexV3 } from './utils/stories-json';
import { extractStorybookMetadata } from './utils/metadata';
import { StoryIndexGenerator } from './utils/StoryIndexGenerator';
import { summarizeIndex } from './utils/summarizeIndex';
import { defaultStaticDirs } from './presets/common-preset';
export type BuildStaticStandaloneOptions = CLIOptions &
LoadOptions &
@ -117,7 +114,7 @@ export async function buildStaticStandalone(options: BuildStaticStandaloneOption
features,
};
if (staticDirs && options.staticDir && !isEqual(staticDirs, defaultStaticDirs)) {
if (staticDirs && options.staticDir) {
throw new Error(dedent`
Conflict when trying to read staticDirs:
* Storybook's configuration option: 'staticDirs'
@ -133,17 +130,13 @@ export async function buildStaticStandalone(options: BuildStaticStandaloneOption
await managerBuilder.build({ startTime: process.hrtime(), options: fullOptions });
if (staticDirs && !isEqual(staticDirs, defaultStaticDirs)) {
if (staticDirs) {
effects.push(
copyAllStaticFilesRelativeToMain(staticDirs, options.outputDir, options.configDir)
);
} else if (options.staticDir) {
}
if (options.staticDir) {
effects.push(copyAllStaticFiles(options.staticDir, options.outputDir));
} else {
throw new Error(dedent`
Error when trying to read staticDirs, recommend to use
* Storybook's configuration option: 'staticDirs' in the main configuration file.
`);
}
const coreServerPublicDir = join(

View File

@ -16,19 +16,13 @@ import type {
PresetPropertyFn,
} from '@storybook/types';
import { loadCsf } from '@storybook/csf-tools';
import { dirname, join } from 'path';
import { join } from 'path';
import { dedent } from 'ts-dedent';
import { parseStaticDir } from '../utils/server-statics';
import { defaultStaticDirs } from '../utils/constants';
const defaultFavicon = require.resolve('@storybook/core-server/public/favicon.svg');
export const defaultStaticDirs = [
{
from: join(dirname(require.resolve('@storybook/manager/package.json')), 'static'),
to: '/sb-common-assets',
},
];
export const staticDirs: PresetPropertyFn<'staticDirs'> = async (values = []) => [
...defaultStaticDirs,
...values,

View File

@ -1 +1,10 @@
import { dirname, join } from 'path';
export const DEBOUNCE = 100;
export const defaultStaticDirs = [
{
from: join(dirname(require.resolve('@storybook/manager/package.json')), 'static'),
to: '/sb-common-assets',
},
];

View File

@ -4,18 +4,12 @@ import { getDirectoryFromWorkingDir } from '@storybook/core-common';
import chalk from 'chalk';
import express from 'express';
import { pathExists } from 'fs-extra';
import path, { dirname, join } from 'path';
import path from 'path';
import favicon from 'serve-favicon';
import isEqual from 'lodash/isEqual.js';
import { dedent } from 'ts-dedent';
const defaultStaticDirs = [
{
from: join(dirname(require.resolve('@storybook/manager/package.json')), 'static'),
to: '/sb-common-assets',
},
];
import { defaultStaticDirs } from './constants';
export async function useStatics(router: any, options: Options) {
const staticDirs = await options.presets.apply<StorybookConfig['staticDirs']>('staticDirs');