Skip to content

Commit

Permalink
Fix CSF Plugin for Angular
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Dec 4, 2023
1 parent e206035 commit cdb5079
Show file tree
Hide file tree
Showing 3 changed files with 318 additions and 108 deletions.
12 changes: 7 additions & 5 deletions code/lib/csf-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ const logger = console;
export const unplugin = createUnplugin<CsfPluginOptions>((options) => {
return {
name: 'unplugin-csf',
enforce: 'pre',
loadInclude(id) {
transformInclude(id) {
return STORIES_REGEX.test(id);
},
async load(fname) {
const code = await fs.readFile(fname, 'utf-8');
async transform(code, id) {
const sourceCode = await fs.readFile(id, 'utf-8');
try {
const csf = loadCsf(code, { makeTitle: (userTitle) => userTitle || 'default' }).parse();
enrichCsf(csf, options);
const csfSource = loadCsf(sourceCode, {
makeTitle: (userTitle) => userTitle || 'default',
}).parse();
enrichCsf(csf, csfSource, options);
return formatCsf(csf, { sourceMaps: true });
} catch (err: any) {
// This can be called on legacy storiesOf files, so just ignore
Expand Down
Loading

0 comments on commit cdb5079

Please sign in to comment.