Skip to content

Commit

Permalink
fix: accomodate for storybook no title
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jun 6, 2020
1 parent e27f047 commit da26a05
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/instrument/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"find-cache-dir": "^3.3.1",
"gray-matter": "^4.0.2",
"hosted-git-info": "^3.0.4",
"js-string-escape": "^1.0.1",
"prettier": "^1.19.1",
"read-package-json": "^2.1.1",
"resolve": "^1.15.1",
Expand Down
12 changes: 12 additions & 0 deletions core/instrument/src/babel/mdx-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import camelCase from 'camelcase';
import { File } from '@babel/types';
import traverse from '@babel/traverse';
import { extractFunctionParameters } from './extract-function-parameters';
import jsStringEscape from 'js-string-escape';
import { followStoryImport } from './follow-imports';
import { extractAttributes } from './extract-attributes';
import { sourceLocation } from '../misc/source-location';
Expand Down Expand Up @@ -78,6 +79,17 @@ export const extractMDXStories = (props: any) => (
exports: {},
packages: {},
};
if (props) {
store.exports.default = {
story: Object.keys(props).reduce((acc: object, key: string) => {
const prop = props[key];
return {
...acc,
[key]: typeof prop === 'string' ? `"${jsStringEscape(prop)}"` : prop,
};
}, {}),
};
}
const { transformMDX } = _options.mdx;
traverse(ast as any, {
JSXElement: (path: any) => {
Expand Down
8 changes: 4 additions & 4 deletions core/instrument/src/misc/mdx-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export const extractStoryExports = (exports?: MDXExportTypes): string => {
const exportNames = Object.keys(exports);
if (exportNames.length) {
let defaultExportCode = '';
if (exports.default && exports.default.story) {
if (exports.default) {
const expCode = mdxPropertiesExport(exports.default);
if (expCode) {
defaultExportCode = `export default { ${expCode}, MDXPage: () => <MDXContent /> };`;
}
defaultExportCode = `export default { ${
expCode ? `${expCode},` : ''
} MDXPage: () => <MDXContent /> };`;
}

let storiesExports: string[] = [];
Expand Down
1 change: 1 addition & 0 deletions core/instrument/src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ declare module 'read-package-json';
declare module '@hutson/parse-repository-url';
declare module 'hosted-git-info';
declare module '@mdx-js/mdx';
declare module 'js-string-escape';
6 changes: 5 additions & 1 deletion core/loader/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const store: LoadingStore = {
};

export const reserveStories = (filePaths: string[]) => {
filePaths.forEach(filePath => store.stores.push({ filePath }));
if (store.stores.length === 0) {
filePaths.forEach(filePath => store.stores.push({ filePath }));
}
};
export const addStoriesDoc = (filePath: string, added: LoadingDocStore) => {
const { components, packages, stories, doc } = added;
Expand All @@ -45,5 +47,7 @@ export const addStoriesDoc = (filePath: string, added: LoadingDocStore) => {
if (storeStore) {
storeStore.stories = stories;
storeStore.doc = doc;
} else {
store.stores.push({ filePath, stories, doc });
}
};
1 change: 0 additions & 1 deletion integrations/gatsby-theme-stories/src/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ exports.createPages = async (
: await compile(config);
if (store) {
const { basePath = '' } = store.config?.options || {};
console.log('basePath', basePath);
const template = require.resolve(`../src/templates/StoryPage.tsx`);
store.stores.forEach(s => {
const doc = s.doc;
Expand Down

0 comments on commit da26a05

Please sign in to comment.