Merge pull request #11057 from storybookjs/fix/autorefs

FIX auto refs when there are no specified refs
This commit is contained in:
Norbert de Langen 2020-06-11 15:03:56 +02:00 committed by GitHub
commit eebad1a883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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`)));
}