Skip to content

Commit

Permalink
Merge pull request #22906 from storybookjs/shilman/22896-server-add-yml
Browse files Browse the repository at this point in the history
Server: Fix .stories.yml support
  • Loading branch information
shilman committed Jun 4, 2023
1 parent 8213fd2 commit d62b23c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
1 change: 0 additions & 1 deletion code/lib/cli/src/sandbox-templates.ts
Expand Up @@ -469,7 +469,6 @@ const internalTemplates = {
builder: '@storybook/builder-webpack5',
},
isInternal: true,
inDevelopment: true,
},
// 'internal/pnp': {
// ...baseTemplates['cra/default-ts'],
Expand Down
5 changes: 4 additions & 1 deletion code/presets/server-webpack/src/index.ts
Expand Up @@ -16,7 +16,10 @@ export const webpack: StorybookConfig['webpack'] = (config) => {
test: /\.stories\.ya?ml/,
use: [
require.resolve('@storybook/preset-server-webpack/dist/loader'),
require.resolve('yaml-loader'),
{
loader: require.resolve('yaml-loader'),
options: { asJSON: true },
},
],
},
];
Expand Down
3 changes: 2 additions & 1 deletion code/presets/server-webpack/src/loader.ts
Expand Up @@ -5,7 +5,8 @@ export default (content: string) => {
const after = compileCsfModule(JSON.parse(content));
return after;
} catch (e) {
//
// for debugging
console.log(content, e);
}
return content;
};
3 changes: 2 additions & 1 deletion code/renderers/server/package.json
Expand Up @@ -60,7 +60,8 @@
"@storybook/types": "7.0.18",
"@types/fs-extra": "^11.0.1",
"fs-extra": "^11.1.0",
"ts-dedent": "^2.0.0"
"ts-dedent": "^2.0.0",
"yaml": "^2.3.1"
},
"devDependencies": {
"typescript": "~4.9.3"
Expand Down
11 changes: 7 additions & 4 deletions code/renderers/server/src/preset.ts
@@ -1,11 +1,14 @@
import fs from 'fs-extra';
import yaml from 'yaml';
import { toId } from '@storybook/csf';
import type { StaticMeta } from '@storybook/csf-tools';
import type { IndexerOptions, IndexedStory, StoryIndexer } from '@storybook/types';

export const storyIndexers = (indexers: StoryIndexer[] | null) => {
const jsonIndexer = async (fileName: string, opts: IndexerOptions) => {
const json = await fs.readJson(fileName, 'utf-8');
const serverIndexer = async (fileName: string, opts: IndexerOptions) => {
const json = fileName.endsWith('.json')
? await fs.readJson(fileName, 'utf-8')
: yaml.parse((await fs.readFile(fileName, 'utf-8')).toString());
const meta: StaticMeta = {
title: json.title,
};
Expand All @@ -25,8 +28,8 @@ export const storyIndexers = (indexers: StoryIndexer[] | null) => {
};
return [
{
test: /(stories|story)\.json$/,
indexer: jsonIndexer,
test: /(stories|story)\.(json|ya?ml)$/,
indexer: serverIndexer,
},
...(indexers || []),
];
Expand Down
9 changes: 5 additions & 4 deletions code/yarn.lock
Expand Up @@ -7005,6 +7005,7 @@ __metadata:
fs-extra: ^11.1.0
ts-dedent: ^2.0.0
typescript: ~4.9.3
yaml: ^2.3.1
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -31859,10 +31860,10 @@ __metadata:
languageName: node
linkType: hard

"yaml@npm:^2.0.0":
version: 2.2.1
resolution: "yaml@npm:2.2.1"
checksum: 12f3a73f2d28970d146184b1425d32a63f65e9f4840eeab09155a4d23a15be8401ac7a3a09b6626895ccf853c1b9069450957c0ad82cfe591369aaa58d1593d6
"yaml@npm:^2.0.0, yaml@npm:^2.3.1":
version: 2.3.1
resolution: "yaml@npm:2.3.1"
checksum: ed4c21a907fb1cd60a25177612fa46d95064a144623d269199817908475fe85bef20fb17406e3bdc175351b6488056a6f84beb7836e8c262646546a0220188e3
languageName: node
linkType: hard

Expand Down

0 comments on commit d62b23c

Please sign in to comment.