-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate @storybook/html to Typescript #7338
Merged
ndelangen
merged 3 commits into
storybookjs:next
from
emilio-martinez:ts-migration/storybook-html
Jul 11, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* eslint-disable prefer-destructuring */ | ||
import { start } from '@storybook/core/client'; | ||
import { ClientStoryApi } from '@storybook/addons'; | ||
|
||
import './globals'; | ||
import render from './render'; | ||
import { StoryFnHtmlReturnType, IStorybookSection } from './types'; | ||
|
||
const framework = 'html'; | ||
|
||
interface ClientApi extends ClientStoryApi<StoryFnHtmlReturnType> { | ||
setAddon(addon: any): void; | ||
configure(loaders: () => void, module: NodeModule): void; | ||
getStorybook(): IStorybookSection[]; | ||
clearDecorators(): void; | ||
forceReRender(): void; | ||
raw: () => any; // todo add type | ||
load: (req: any, m: NodeModule, framework: string) => void; | ||
} | ||
|
||
const api = start(render); | ||
|
||
export const storiesOf: ClientApi['storiesOf'] = (kind, m) => { | ||
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({ | ||
framework, | ||
}); | ||
}; | ||
|
||
export const load: ClientApi['load'] = (...args) => api.load(...args, framework); | ||
export const addDecorator: ClientApi['addDecorator'] = api.clientApi.addDecorator; | ||
export const addParameters: ClientApi['addParameters'] = api.clientApi.addParameters; | ||
export const clearDecorators: ClientApi['clearDecorators'] = api.clientApi.clearDecorators; | ||
export const setAddon: ClientApi['setAddon'] = api.clientApi.setAddon; | ||
export const configure: ClientApi['configure'] = api.configApi.configure; | ||
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender; | ||
export const getStorybook: ClientApi['getStorybook'] = api.clientApi.getStorybook; | ||
export const raw: ClientApi['raw'] = api.clientApi.raw; |
4 changes: 2 additions & 2 deletions
4
app/html/src/client/preview/render.js → app/html/src/client/preview/render.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { StoryFn } from '@storybook/addons'; | ||
|
||
export type StoryFnHtmlReturnType = string | Node; | ||
|
||
export interface IStorybookStory { | ||
name: string; | ||
render: () => any; | ||
} | ||
|
||
export interface IStorybookSection { | ||
kind: string; | ||
stories: IStorybookStory[]; | ||
} | ||
|
||
export interface ShowErrorArgs { | ||
title: string; | ||
description: string; | ||
} | ||
|
||
export interface RenderMainArgs { | ||
storyFn: () => StoryFn<StoryFnHtmlReturnType>; | ||
selectedKind: string; | ||
selectedStory: string; | ||
showMain: () => void; | ||
showError: (args: ShowErrorArgs) => void; | ||
forceRender: boolean; | ||
} |
File renamed without changes.
5 changes: 4 additions & 1 deletion
5
app/html/src/server/framework-preset-html.js → app/html/src/server/framework-preset-html.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
3 changes: 2 additions & 1 deletion
3
app/html/src/server/options.js → app/html/src/server/options.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
declare module '@storybook/core/*'; | ||
declare module 'global'; | ||
|
||
// will be provided by the webpack define plugin | ||
declare var NODE_ENV: string | undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"types": ["webpack-env"] | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["src/__tests__/**/*"] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know well how this part of SB is working but maybe
webpack
should be apeerDependency
?@ndelangen can surely help us with this ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create a dependency on webpack for now, in monoconfig, I'll try an consolidate these types into a coherent whole.
When you add the dependency, be sure to add a wide version range.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should declare all the preset function types in
@storybook/core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, in this case
Configuration
is being picked up through@types/webpack
which is a devDependency at the root of the repo. Technically, there's no runtime use or type definitions coming fromwebpack
here.It would make sense to add
@types/webpack
as a devDependency here—I could match the version at the root of the repo to avoid any conflicts. Given the above, do you guys still feel I should addwebpack
as a dependency? Let me know your thoughts 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaetanmaisse @ndelangen let me know your thoughts on my last comment and I'll make the change :)