Skip to content

Commit

Permalink
get tags from csf directly
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Nov 14, 2023
1 parent c8fdee3 commit cceb639
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/csf/transformCsf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,6 @@ const makeBeforeEach = (beforeEachPrefixer: FilePrefixer) => {
const makeArray = (templateResult: TemplateResult) =>
Array.isArray(templateResult) ? templateResult : [templateResult];

// copied from csf-tools, as it's not exported
function parseTags(prop: t.Node) {
if (!t.isArrayExpression(prop)) {
throw new Error('CSF: Expected tags array');
}

return prop.elements.map((e) => {
if (t.isStringLiteral(e)) return e.value;
throw new Error(`CSF: Expected tag to be string literal`);
}) as string[];
}

export const transformCsf = (
code: string,
{
Expand All @@ -128,7 +116,8 @@ export const transformCsf = (
if (annotations?.play) {
acc[key].play = annotations.play;
}
acc[key].tags = annotations.tags ? parseTags(annotations.tags) : csf.meta.tags || [];

acc[key].tags = csf._stories[key].tags || csf.meta.tags || [];
return acc;
}, {} as Record<string, { play?: t.Node; tags?: string[] }>);

Expand Down

0 comments on commit cceb639

Please sign in to comment.