Skip to content
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

Typescript: Migrate @storybook/mithril #8320

Merged
merged 5 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/mithril/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"standalone.js"
],
"main": "dist/client/index.js",
"types": "dist/client/index.d.ts",
"bin": {
"build-storybook": "./bin/build.js",
"start-storybook": "./bin/index.js",
Expand All @@ -31,14 +32,17 @@
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@babel/core": "^7.6.2",
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@storybook/addons": "5.3.0-alpha.15",
"@storybook/core": "5.3.0-alpha.15",
"core-js": "^3.0.1",
"global": "^4.3.2",
"regenerator-runtime": "^0.13.3",
"ts-dedent": "^1.1.0"
},
"devDependencies": {
"@types/mithril": "^2.0.0",
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
"mithril": "^1.1.6"
},
"peerDependencies": {
Expand Down
File renamed without changes.
21 changes: 0 additions & 21 deletions app/mithril/src/client/preview/index.js

This file was deleted.

34 changes: 34 additions & 0 deletions app/mithril/src/client/preview/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { start } from '@storybook/core/client';

import './globals';
import { ClientStoryApi, Loadable } from '@storybook/addons';
import render from './render';

import { IStorybookSection, StoryFnMithrilReturnType } from './types';

const { configure: coreConfigure, clientApi, forceReRender } = start(render);

const framework = 'mithril';

interface ClientApi extends ClientStoryApi<StoryFnMithrilReturnType> {
setAddon(addon: any): void;
configure(loader: Loadable, module: NodeModule): void;
getStorybook(): IStorybookSection[];
clearDecorators(): void;
forceReRender(): void;
raw: () => any; // todo add type
}

export const storiesOf: ClientApi['storiesOf'] = (kind, m) =>
(clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({ framework });

export const configure: ClientApi['configure'] = (...args) => coreConfigure(...args, framework);

export const { setAddon } = clientApi;
export const { addDecorator } = clientApi;
export const { addParameters } = clientApi;
export const { clearDecorators } = clientApi;
export const { getStorybook } = clientApi;
export const { raw } = clientApi;

export { forceReRender };
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { document } from 'global';
import m from 'mithril';
import dedent from 'ts-dedent';

import { RenderMainArgs } from './types';

const rootEl = document.getElementById('root');

export default function renderMain({
Expand All @@ -12,8 +14,7 @@ export default function renderMain({
selectedStory,
showMain,
showError,
// forceRender,
}) {
}: RenderMainArgs) {
const element = storyFn();

if (!element) {
Expand Down
28 changes: 28 additions & 0 deletions app/mithril/src/client/preview/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import m from 'mithril';

export interface IStorybookStory {
name: string;
render: () => any;
}

export interface IStorybookSection {
kind: string;
stories: IStorybookStory[];
}

export type StoryFnMithrilReturnType = m.Component<unknown>;

export interface ShowErrorArgs {
title: string;
description: string;
}

export interface RenderMainArgs {
storyFn: () => StoryFnMithrilReturnType;
selectedKind: string;
selectedStory: string;
showMain: () => void;
showError: (args: ShowErrorArgs) => void;
showException: (err: Error) => void;
forceRender: boolean;
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export function babelDefault(config) {
import { TransformOptions } from '@babel/core';

export function babelDefault(config: TransformOptions) {
return {
...config,
plugins: [...config.plugins, require.resolve('@babel/plugin-transform-react-jsx')],
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions app/mithril/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare module '@storybook/core/*';
declare module 'global';
15 changes: 15 additions & 0 deletions app/mithril/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"types": ["webpack-env"],
"resolveJsonModule": true
},
"include": [
"src/**/*",
"package.json"
],
"exclude": [
"src/**/*.test.*"
]
}
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
semver "^5.4.1"
source-map "^0.5.0"

"@babel/core@^7.0.0", "@babel/core@^7.1.0", "@babel/core@^7.1.6", "@babel/core@^7.2.2", "@babel/core@^7.3.3", "@babel/core@^7.3.4", "@babel/core@^7.4.3", "@babel/core@^7.4.5":
"@babel/core@^7.0.0", "@babel/core@^7.1.0", "@babel/core@^7.1.6", "@babel/core@^7.2.2", "@babel/core@^7.3.3", "@babel/core@^7.3.4", "@babel/core@^7.4.3", "@babel/core@^7.4.5", "@babel/core@^7.6.2":
version "7.6.2"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.6.2.tgz#069a776e8d5e9eefff76236bc8845566bd31dd91"
integrity sha512-l8zto/fuoZIbncm+01p8zPSDZu/VuuJhAfA7d/AbzM09WR7iVhavvfNDYCNpo1VvLk6E6xgAoP9P+/EMJHuRkQ==
Expand Down Expand Up @@ -3836,6 +3836,11 @@
resolved "https://registry.yarnpkg.com/@types/mithril/-/mithril-1.1.17.tgz#1a5dde2a653ef6011cd36ef70eefe6bac0cb92e4"
integrity sha512-U/wwKZT8hjstY2Q470bLMGVh/fjT2+SgBMzIILn0Z4nmgzzG6j+n18UOAxQ63aI8vXIOkQsbkAdbESt8+jIQdQ==

"@types/mithril@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/mithril/-/mithril-2.0.0.tgz#f9a9e523264af6dc8c2027029bcd400a459739bb"
integrity sha512-Bjjs5a7xc6eC207ZE1tR7ssnMoF8d3VVcupmzbhFaP2nM4G1Jpm1oqrvAiu+ys0OLKYUQjxNALUerHDPHbuwfA==

"@types/node@*", "@types/node@^12.7.9":
version "12.7.10"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.10.tgz#942c128c37b5d780aff5441fd457cd7ffdc18b36"
Expand Down