Skip to content

Commit

Permalink
Turn this into a loader
Browse files Browse the repository at this point in the history
So that it runs on code that still contains comments
  • Loading branch information
shilman committed Oct 30, 2022
1 parent 2c4c25d commit 87b2781
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions code/lib/csf-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { createUnplugin } from 'unplugin';
import fs from 'fs';
import { loadCsf, enrichCsf, formatCsf } from '@storybook/csf-tools';

export interface CsfPluginOptions {
source?: boolean;
description?: boolean;
}

const STORIES_REGEX = /\.(story|stories)\.[tj]sx?$/;

const logger = console;

export const unplugin = createUnplugin((options: CsfPluginOptions) => {
export const unplugin = createUnplugin<CsfPluginOptions>((options) => {
return {
name: 'unplugin-csf',
transformInclude(id) {
loadInclude(id) {
return STORIES_REGEX.test(id);
},
transform(code) {
load(fname) {
const code = fs.readFileSync(fname, 'utf-8');
try {
const csf = loadCsf(code, { makeTitle: (userTitle) => userTitle || 'default' }).parse();
enrichCsf(csf);
Expand Down

0 comments on commit 87b2781

Please sign in to comment.