From 4a9fc915d18f306dff08b08ab902610c7ccc2ee6 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Sat, 29 Oct 2022 20:56:14 +0800 Subject: [PATCH 1/9] CSF plugin: Turn story comments into docs desciptions --- code/lib/csf-tools/package.json | 1 - code/lib/csf-tools/src/CsfFile.ts | 3 + code/lib/csf-tools/src/enrichCsf.test.ts | 116 +++++++++++++++++++++++ code/lib/csf-tools/src/enrichCsf.ts | 55 +++++++++-- 4 files changed, 166 insertions(+), 9 deletions(-) diff --git a/code/lib/csf-tools/package.json b/code/lib/csf-tools/package.json index a27688c6b75d..77c7862f08a7 100644 --- a/code/lib/csf-tools/package.json +++ b/code/lib/csf-tools/package.json @@ -51,7 +51,6 @@ "devDependencies": { "@babel/generator": "^7.12.11", "@babel/parser": "^7.12.11", - "@babel/template": "^7.12.11", "@babel/traverse": "^7.12.11", "@types/fs-extra": "^9.0.6", "js-yaml": "^3.14.1", diff --git a/code/lib/csf-tools/src/CsfFile.ts b/code/lib/csf-tools/src/CsfFile.ts index 458713ea0d41..af2ff4365d0f 100644 --- a/code/lib/csf-tools/src/CsfFile.ts +++ b/code/lib/csf-tools/src/CsfFile.ts @@ -156,6 +156,8 @@ export class CsfFile { _storyExports: Record = {}; + _storyStatements: Record = {}; + _storyAnnotations: Record> = {}; _templates: Record = {}; @@ -283,6 +285,7 @@ export class CsfFile { return; } self._storyExports[exportName] = decl; + self._storyStatements[exportName] = node; let name = storyNameFromExport(exportName); if (self._storyAnnotations[exportName]) { logger.warn( diff --git a/code/lib/csf-tools/src/enrichCsf.test.ts b/code/lib/csf-tools/src/enrichCsf.test.ts index f2e7988f9453..07b89aab3d0b 100644 --- a/code/lib/csf-tools/src/enrichCsf.test.ts +++ b/code/lib/csf-tools/src/enrichCsf.test.ts @@ -125,6 +125,122 @@ describe('enrichCsf', () => { `); }); }); + + describe('descriptions', () => { + it('skips inline comments', () => { + expect( + enrich(dedent` + export default { + title: 'Button', + } + // The most basic button + export const Basic = () =>