Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Dec 13, 2021
1 parent 8f66031 commit 603908d
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 37 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ examples/angular-cli/addon-jest.testresults.json
!/**/.yarn/plugins
!/**/.yarn/sdks
!/**/.yarn/versions
/**/.pnp.*
/**/.pnp.*
examples/*/*-stats.json
examples/*/*-stats-*.json
2 changes: 1 addition & 1 deletion lib/addons/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface Parameters {
[key: string]: any;
}

export type StoryContext = StoryContextForFramework<AnyFramework>;
export type StoryContext = StoryContextForFramework;
export type StoryContextUpdate = Partial<StoryContext>;

type ReturnTypeFramework<ReturnType> = { component: any; storyResult: ReturnType };
Expand Down
6 changes: 3 additions & 3 deletions lib/client-api/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
Addon,
StoryId,
StoryName,
Expand All @@ -13,8 +13,8 @@ import {
LoaderFunction,
StoryContext,
} from '@storybook/addons';
import { AnyFramework, StoryIdentifier, ProjectAnnotations } from '@storybook/csf';
import { StoryStore, HooksContext, RenderContext } from '@storybook/store';
import type { AnyFramework, StoryIdentifier, ProjectAnnotations } from '@storybook/csf';
import type { StoryStore, HooksContext, RenderContext } from '@storybook/store';

export type {
SBType,
Expand Down
14 changes: 12 additions & 2 deletions lib/components/scripts/prebundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@ const { babel } = require('@rollup/plugin-babel');
const previewInputOptions = {
input: resolve(__dirname, '../src/index.ts'), // conditionally required
plugins: [
nodeResolve(),
nodeResolve({
browser: true,
preferBuiltins: true,
}),
commonjs(),
json(),
babel({ babelHelpers: 'bundled' }),
rollupTypescript(),
],
external: ['@storybook/addons', '@storybook/theming', 'react', 'react-dom', '@storybook/csf'],
external: [
'@storybook/addons',
'@storybook/csf',
'@storybook/theming',
'core-js',
'react-dom',
'react',
],
};

const previewOutputOptions = {
Expand Down
1 change: 1 addition & 0 deletions lib/components/src/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './IFrame';
export * from './Typeset';
export * from './ColorPalette';
export * from './IconGallery';
export * from './StorySkeleton';
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @param obj {*} object to get type
* @returns {*}
*/
function getObjectType(obj) {
function getObjectType(obj:any) {
if (
obj !== null &&
typeof obj === 'object' &&
Expand All @@ -21,7 +21,7 @@ function getObjectType(obj) {
* @param newValue {*} new value
* @returns {boolean} result
*/
function isComponentWillChange(oldValue, newValue) {
function isComponentWillChange(oldValue:any, newValue:any) {
const oldType = getObjectType(oldValue);
const newType = getObjectType(newValue);
return (oldType === 'Function' || newType === 'Function') && newType !== oldType;
Expand Down
10 changes: 8 additions & 2 deletions lib/core-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
],
"scripts": {
"prepare": "node ../../scripts/prepare.js",
"prebundle": "node ./scripts/prebundle.js"
"prebundle": "node ./scripts/prebundle.js",
"dtsbundle2": "node ./scripts/dtsbundle.js",
"dtsbundle": "dts-bundle-generator --no-banner -o ./bundle/index.d.ts ./src/index.ts"
},
"dependencies": {
"@storybook/addons": "6.5.0-alpha.1",
Expand Down Expand Up @@ -67,7 +69,11 @@
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.6",
"@rollup/plugin-typescript": "^8.3.0",
"rollup": "^2.60.2"
"dts-bundle-generator": "^6.2.0",
"rollup": "^2.60.2",
"rollup-plugin-dts": "^3.0.0",
"rollup-plugin-flat-dts": "^1.4.0",
"tsc-prog": "^2.2.1"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0",
Expand Down
12 changes: 12 additions & 0 deletions lib/core-client/scripts/dtsbundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const tsc = require('tsc-prog');

tsc.build({
basePath: __dirname,
configFilePath: '../tsconfig.json',
compilerOptions: {
declaration: true, // must be set
},
bundleDeclaration: {
entryPoint: 'index.d.ts', // relative to the OUTPUT directory ('dist' here)
},
});
15 changes: 14 additions & 1 deletion lib/core-client/scripts/prebundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,37 @@ const rollupTypescript = require('@rollup/plugin-typescript');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const json = require('@rollup/plugin-json');
// const flatDts = require('rollup-plugin-flat-dts');

// const { default: dts } = require('rollup-plugin-dts');

const previewInputOptions = {
input: resolve(__dirname, '../src/index.ts'), // conditionally required
plugins: [nodeResolve(), commonjs(), json(), rollupTypescript()],
plugins: [
nodeResolve({
browser: true,
preferBuiltins: true,
}),
commonjs(),
json(),
rollupTypescript() /* , dts() */,
],
external: [
'@storybook/addons',
'@storybook/components',
'@storybook/csf',
'@storybook/theming',
'react-dom',
'react',
'core-js',
],
};

const previewOutputOptions = {
dir: resolve(__dirname, '../bundle/preview'),

format: 'es', // required
// plugins: [flatDts()],
};

// see below for details on the options
Expand Down
3 changes: 3 additions & 0 deletions lib/core-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../typings.d.ts" />

export * from './preview';
export * from './preview/types';

Expand Down
2 changes: 1 addition & 1 deletion lib/core-client/src/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export default {
StoryStore,
};

export { start, toId, ClientApi, StoryStore };
export { start, toId, StoryStore };
3 changes: 3 additions & 0 deletions lib/core-client/src/preview/start.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../typings.d.ts" />

import global from 'global';
import deprecate from 'util-deprecate';
import { ClientApi } from '@storybook/client-api';
Expand Down
46 changes: 23 additions & 23 deletions lib/core-client/src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ declare module 'open';
declare module 'x-default-browser';
declare module '@storybook/ui';

declare module 'file-system-cache' {
export interface Options {
basePath?: string;
ns?: string | string[];
extension?: string;
}
// declare module 'file-system-cache' {
// export interface Options {
// basePath?: string;
// ns?: string | string[];
// extension?: string;
// }

export declare class FileSystemCache {
constructor(options: Options);
path(key: string): string;
fileExists(key: string): Promise<boolean>;
ensureBasePath(): Promise<void>;
get(key: string, defaultValue?: any): Promise<any | typeof defaultValue>;
getSync(key: string, defaultValue?: any): any | typeof defaultValue;
set(key: string, value: any): Promise<{ path: string }>;
setSync(key: string, value: any): this;
remove(key: string): Promise<void>;
clear(): Promise<void>;
save(): Promise<{ paths: string[] }>;
load(): Promise<{ files: Array<{ path: string; value: any }> }>;
}
// export declare class FileSystemCache {
// constructor(options: Options);
// path(key: string): string;
// fileExists(key: string): Promise<boolean>;
// ensureBasePath(): Promise<void>;
// get(key: string, defaultValue?: any): Promise<any | typeof defaultValue>;
// getSync(key: string, defaultValue?: any): any | typeof defaultValue;
// set(key: string, value: any): Promise<{ path: string }>;
// setSync(key: string, value: any): this;
// remove(key: string): Promise<void>;
// clear(): Promise<void>;
// save(): Promise<{ paths: string[] }>;
// load(): Promise<{ files: Array<{ path: string; value: any }> }>;
// }

function create(options: Options): FileSystemCache;
// function create(options: Options): FileSystemCache;

export = create;
}
// export = create;
// }
5 changes: 5 additions & 0 deletions scripts/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ function run() {
process.env.CI ? `--max-parallel=${maxConcurrentTasks}` : ''
}`
);
spawn(
`nx run-many --target=prebundle --all --parallel ${
process.env.CI ? `--max-parallel=${maxConcurrentTasks}` : ''
}`
);
},
order: 2,
}),
Expand Down
Loading

0 comments on commit 603908d

Please sign in to comment.