From 46f53919090ae3e00256c91ba9c18a3b1ed8c496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Maisse?= Date: Sun, 13 Dec 2020 21:24:45 +0100 Subject: [PATCH] refactor(marko): migrate to TS --- app/marko/src/client/{index.js => index.ts} | 0 .../src/client/preview/{globals.js => globals.ts} | 0 .../src/client/preview/{index.js => index.ts} | 5 +++-- .../src/client/preview/{render.js => render.ts} | 15 +++++++++++---- app/marko/src/server/{build.js => build.ts} | 0 ...-preset-marko.js => framework-preset-marko.ts} | 4 +++- app/marko/src/server/{index.js => index.ts} | 0 app/marko/src/server/{options.js => options.ts} | 0 app/marko/src/typings.d.ts | 2 ++ app/marko/tsconfig.json | 7 +++++++ 10 files changed, 26 insertions(+), 7 deletions(-) rename app/marko/src/client/{index.js => index.ts} (100%) rename app/marko/src/client/preview/{globals.js => globals.ts} (100%) rename app/marko/src/client/preview/{index.js => index.ts} (65%) rename app/marko/src/client/preview/{render.js => render.ts} (80%) rename app/marko/src/server/{build.js => build.ts} (100%) rename app/marko/src/server/{framework-preset-marko.js => framework-preset-marko.ts} (79%) rename app/marko/src/server/{index.js => index.ts} (100%) rename app/marko/src/server/{options.js => options.ts} (100%) create mode 100644 app/marko/src/typings.d.ts create mode 100644 app/marko/tsconfig.json diff --git a/app/marko/src/client/index.js b/app/marko/src/client/index.ts similarity index 100% rename from app/marko/src/client/index.js rename to app/marko/src/client/index.ts diff --git a/app/marko/src/client/preview/globals.js b/app/marko/src/client/preview/globals.ts similarity index 100% rename from app/marko/src/client/preview/globals.js rename to app/marko/src/client/preview/globals.ts diff --git a/app/marko/src/client/preview/index.js b/app/marko/src/client/preview/index.ts similarity index 65% rename from app/marko/src/client/preview/index.js rename to app/marko/src/client/preview/index.ts index 7635388ae4e5..ea2cf3e60afc 100644 --- a/app/marko/src/client/preview/index.js +++ b/app/marko/src/client/preview/index.ts @@ -15,7 +15,8 @@ export const { } = clientApi; const framework = 'marko'; -export const storiesOf = (...args) => clientApi.storiesOf(...args).addParameters({ framework }); -export const configure = (...args) => coreConfigure(framework, ...args); +export const storiesOf = (...args: any) => + clientApi.storiesOf(...args).addParameters({ framework }); +export const configure = (...args: any) => coreConfigure(framework, ...args); export { forceReRender }; diff --git a/app/marko/src/client/preview/render.js b/app/marko/src/client/preview/render.ts similarity index 80% rename from app/marko/src/client/preview/render.js rename to app/marko/src/client/preview/render.ts index f314429c8384..681e20fcc4f8 100644 --- a/app/marko/src/client/preview/render.js +++ b/app/marko/src/client/preview/render.ts @@ -4,9 +4,9 @@ import dedent from 'ts-dedent'; import { logger } from '@storybook/client-logger'; const rootEl = document.getElementById('root'); -let activeComponent = null; // currently loaded marko component. -let activeTemplate = null; // template for the currently loaded component. -let activeStoryFn = null; // used to determine if we've switched stories. +let activeComponent: any = null; // currently loaded marko component. +let activeTemplate: any = null; // template for the currently loaded component. +let activeStoryFn: any = null; // used to determine if we've switched stories. export default function renderMain({ storyFn, @@ -15,7 +15,14 @@ export default function renderMain({ showMain, showError, parameters, - // forceRender, +}: // forceRender, +{ + storyFn: Function; + kind: string; + name: string; + showMain: () => any; + showError: (input: { title: string; description: string }) => void; + parameters: any; }) { const isSameStory = activeStoryFn === storyFn; const config = storyFn(); diff --git a/app/marko/src/server/build.js b/app/marko/src/server/build.ts similarity index 100% rename from app/marko/src/server/build.js rename to app/marko/src/server/build.ts diff --git a/app/marko/src/server/framework-preset-marko.js b/app/marko/src/server/framework-preset-marko.ts similarity index 79% rename from app/marko/src/server/framework-preset-marko.js rename to app/marko/src/server/framework-preset-marko.ts index 5c5d74a7b644..df9c611b587e 100644 --- a/app/marko/src/server/framework-preset-marko.js +++ b/app/marko/src/server/framework-preset-marko.ts @@ -1,4 +1,6 @@ -export function webpack(config) { +import { Configuration } from 'webpack'; + +export function webpack(config: Configuration) { return { ...config, module: { diff --git a/app/marko/src/server/index.js b/app/marko/src/server/index.ts similarity index 100% rename from app/marko/src/server/index.js rename to app/marko/src/server/index.ts diff --git a/app/marko/src/server/options.js b/app/marko/src/server/options.ts similarity index 100% rename from app/marko/src/server/options.js rename to app/marko/src/server/options.ts diff --git a/app/marko/src/typings.d.ts b/app/marko/src/typings.d.ts new file mode 100644 index 000000000000..6288cba4b09a --- /dev/null +++ b/app/marko/src/typings.d.ts @@ -0,0 +1,2 @@ +declare module '@storybook/core/*'; +declare module 'global'; diff --git a/app/marko/tsconfig.json b/app/marko/tsconfig.json new file mode 100644 index 000000000000..0f41123e444a --- /dev/null +++ b/app/marko/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "types": ["webpack-env"] + } +}