mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 07:21:17 +08:00
Merge pull request #11057 from storybookjs/fix/autorefs
FIX auto refs when there are no specified refs
This commit is contained in:
commit
eebad1a883
@ -36,6 +36,8 @@ const getAutoRefs = async (options) => {
|
||||
return list.filter(Boolean);
|
||||
};
|
||||
|
||||
const stripTrailingSlash = (url) => url.replace(/\/$/, '');
|
||||
|
||||
const toTitle = (input) => {
|
||||
const result = input
|
||||
.replace(/[A-Z]/g, (f) => ` ${f}`)
|
||||
@ -51,18 +53,22 @@ async function getManagerWebpackConfig(options, presets) {
|
||||
const babelOptions = await presets.apply('babel', {}, { ...options, typescriptOptions });
|
||||
|
||||
const autoRefs = await getAutoRefs(options);
|
||||
const refs = await presets.apply('refs', undefined, options);
|
||||
const definedRefs = await presets.apply('refs', undefined, options);
|
||||
const entries = await presets.apply('managerEntries', [], options);
|
||||
|
||||
if (refs) {
|
||||
const refs = {};
|
||||
|
||||
if (autoRefs && autoRefs.length) {
|
||||
autoRefs.forEach(({ id, url, title }) => {
|
||||
refs[id] = {
|
||||
id,
|
||||
url,
|
||||
url: stripTrailingSlash(url),
|
||||
title,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
if (definedRefs) {
|
||||
Object.entries(refs).forEach(([key, value]) => {
|
||||
const url = typeof value === 'string' ? value : value.url;
|
||||
const title = typeof value === 'string' ? toTitle(key) : value.title || toTitle(value.key);
|
||||
@ -70,10 +76,11 @@ async function getManagerWebpackConfig(options, presets) {
|
||||
refs[key] = {
|
||||
id: key,
|
||||
title,
|
||||
url,
|
||||
url: stripTrailingSlash(url),
|
||||
};
|
||||
});
|
||||
|
||||
}
|
||||
if (autoRefs || definedRefs) {
|
||||
entries.push(path.resolve(path.join(options.configDir, `generated-refs.js`)));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user