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 authored Jun 4, 2023
2 parents e0d42d6 + 32962ae commit f9a6c78
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
1 change: 0 additions & 1 deletion code/lib/cli/src/sandbox-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"@storybook/types": "7.1.0-alpha.26",
"@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
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7499,6 +7499,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 @@ -32376,7 +32377,7 @@ __metadata:
languageName: node
linkType: hard

"yaml@npm:^2.0.0":
"yaml@npm:^2.0.0, yaml@npm:^2.3.1":
version: 2.3.1
resolution: "yaml@npm:2.3.1"
checksum: ed4c21a907fb1cd60a25177612fa46d95064a144623d269199817908475fe85bef20fb17406e3bdc175351b6488056a6f84beb7836e8c262646546a0220188e3
Expand Down

0 comments on commit f9a6c78

Please sign in to comment.