Skip to content

Commit

Permalink
Merge pull request #84 from storybookjs/norbert/to-esm-tsup
Browse files Browse the repository at this point in the history
upgrades & build using tsup
  • Loading branch information
ndelangen authored Jan 23, 2024
2 parents bfaf1b4 + e8a1f80 commit 84206fa
Show file tree
Hide file tree
Showing 9 changed files with 4,640 additions and 2,947 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release

on: [push]

jobs:
release:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci') && !contains(github.event.head_commit.message, 'skip release')"
steps:
- uses: actions/checkout@v4

- name: Prepare repository
run: git fetch --unshallow --tags

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc

- name: Install dependencies
uses: bahmutov/npm-install@v1

- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
yarn release
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18
94 changes: 50 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,7 @@
{
"version": "2.0.0",
"name": "@storybook/addon-console",
"author": "Oleg Proskurin (https://github.com/UsulPro)",
"version": "2.0.0",
"description": "Show console output like logs, errors, and warnings in the Storybook",
"dependencies": {
"@storybook/global": "^5.0.0"
},
"scripts": {
"prepare": "package-prepare && yarn build",
"build": "tsc \"src/index.jsx\" --declaration --allowJs --emitDeclarationOnly --outDir dist",
"build:tests": "rm -rdf .jest-dist && babel ./src -d ./.jest-dist -s",
"build:readme.md": "jsdoc2md -t docs/readme.hbs -c docs/jsdoc.config.json src/*.jsx > README.md; echo",
"build:readme": "jsdoc2md -t docs/readme.hbs -c docs/jsdoc.config.json src/*.jsx > README; echo",
"build:docs": "yarn build:readme.md && yarn build:readme",
"deploy:storybook": "storybook-to-ghpages",
"lint": "eslint ./src",
"test": "jest",
"tdd": "jest --watch",
"test:publish": "npm pack",
"dev:docs": "nodemon --config docs/nodemon.json -x 'npm run build:docs'",
"debug": "node --debug-brk --inspect npm test",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"packagePrepare": {
"--copy-files": null
},
"main": "dist/index",
"types": "dist/index.d.ts",
"homepage": "https://github.com/storybooks/storybook-addon-console",
"bugs": {
"url": "https://github.com/storybooks/storybook-addon-console/issues"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/storybooks/storybook-addon-console.git"
},
"storybook": {
"displayName": "Console",
"icon": "https://user-images.githubusercontent.com/263385/101991668-479cc600-3c7c-11eb-9aac-09cd7b5b9f97.png"
},
"keywords": [
"storybook-addons",
"debug",
Expand All @@ -61,6 +22,40 @@
"redirect",
"devtools"
],
"homepage": "https://github.com/storybooks/storybook-addon-console",
"bugs": {
"url": "https://github.com/storybooks/storybook-addon-console/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/storybooks/storybook-addon-console.git"
},
"license": "MIT",
"author": "Oleg Proskurin (https://github.com/UsulPro)",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsup",
"build-storybook": "storybook build",
"build:docs": "yarn build:readme.md && yarn build:readme",
"build:readme": "jsdoc2md -t docs/readme.hbs -c docs/jsdoc.config.json src/*.jsx > README; echo",
"build:readme.md": "jsdoc2md -t docs/readme.hbs -c docs/jsdoc.config.json src/*.jsx > README.md; echo",
"build:tests": "rm -rdf .jest-dist && babel ./src -d ./.jest-dist -s",
"debug": "node --debug-brk --inspect npm test",
"deploy:storybook": "storybook-to-ghpages",
"dev:docs": "nodemon --config docs/nodemon.json -x 'npm run build:docs'",
"lint": "eslint ./src",
"release": "auto shipit",
"prepare": "yarn build",
"storybook": "storybook dev",
"tdd": "jest --watch",
"test": "jest",
"test:publish": "npm pack"
},
"dependencies": {
"@storybook/global": "^5.0.0"
},
"devDependencies": {
"@babel/cli": "^7.21.5",
"@babel/core": "^7.21.8",
Expand All @@ -78,10 +73,10 @@
"@storybook/react-vite": "^7.0.12",
"@storybook/testing-library": "^0.0.14-next.2",
"@storybook/theming": "^7.0.12",
"@usulpro/package-prepare": "^1.1.4",
"babel-eslint": "^10.1.0",
"babel-loader": "^9.1.2",
"enzyme": "^3.3.0",
"auto": "^11.0.4",
"eslint": "^4.3.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-prettier": "^2.3.0",
Expand All @@ -99,15 +94,26 @@
"nodemon": "^1.12.0",
"prettier": "^1.5.3",
"prop-types": "^15.5.10",
"react": "^16.4.0",
"react-dom": "^16.4.0",
"react-test-renderer": "^16.4.0",
"storybook": "^7.0.12",
"tsup": "^8.0.1",
"typescript": "^5.0.3",
"url-loader": "^2.1.0",
"vite": "^4.3.7"
},
"peerDependencies": {
"@storybook/addon-actions": "*"
"@storybook/addon-actions": "*",
"react": "*"
},
"storybook": {
"displayName": "Console",
"icon": "https://user-images.githubusercontent.com/263385/101991668-479cc600-3c7c-11eb-9aac-09cd7b5b9f97.png"
},
"auto": {
"plugins": [
"npm",
"released"
]
}
}
}
10 changes: 5 additions & 5 deletions src/index.jsx → src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ export function setConsoleOptions(optionsOrFn) {
return currentOptions;
}

function handleStoryLogs() {
switch (global.STORYBOOK_ENV) {
function handleStoryLogs(renderer) {
switch (renderer) {
case 'react':
return reactStory;
default:
logger.warn(
`Warning! withConsole doesn't support @storybook/${global.STORYBOOK_ENV}. Use setConsoleOptions instead`
`Warning! withConsole doesn't support @storybook/${renderer}. Use setConsoleOptions instead`
);
return story => story;
}
Expand All @@ -199,7 +199,7 @@ function addConsole(storyFn, context, consoleOptions) {

setScope(options);
const story = storyFn();
const wrapStory = handleStoryLogs();
const wrapStory = handleStoryLogs(context.parameters.renderer);
const wrappedStory = wrapStory(
story,
() => setScope(options),
Expand Down Expand Up @@ -241,7 +241,7 @@ export const Primary: Story = {
// Action Logger Panel:
// withConsole/with Log: ["Data:", 1, 3, 4]
*/
export function withConsole(optionsOrFn) {
export function withConsole(optionsOrFn?: any) {
const newOptions = detectOptions(optionsOrFn);
return storyFn => context => addConsole(storyFn, context, newOptions);
}
26 changes: 0 additions & 26 deletions src/react-decorator.jsx

This file was deleted.

30 changes: 30 additions & 0 deletions src/react-decorator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable import/no-extraneous-dependencies */
import React from 'react';

interface ReactDecoratorProps {
story: React.ReactNode;
onMount: Function;
onUnMount: Function;
}

class ReactDecorator extends React.Component<ReactDecoratorProps> {
constructor(props: ReactDecoratorProps) {
super(props);
this.props.onMount();
}
componentWillUnmount() {
this.props.onUnMount();
}
render() {
return this.props.story;
}
}
export default ReactDecorator;

export function reactStory(
story: ReactDecoratorProps['story'],
onMount: ReactDecoratorProps['onMount'],
onUnMount: ReactDecoratorProps['onUnMount']
) {
return <ReactDecorator story={story} onMount={onMount} onUnMount={onUnMount} />;
}
22 changes: 22 additions & 0 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"compilerOptions": {
"strict": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"declaration": true,
"moduleResolution": "Bundler",
"importHelpers": true,
"target": "ES2022",
"module": "ES2022",
"jsx": "react",
"noImplicitAny": false,
"useDefineForClassFields": false,
"lib": [
"ES2022",
"dom"
]
},
}
13 changes: 13 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable import/no-extraneous-dependencies */
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['./src/index.tsx'],
format: ['cjs', 'esm'],
sourcemap: false,
target: 'chrome100',
clean: true,
// dts: false,
dts: true,
platform: 'neutral',
});
Loading

0 comments on commit 84206fa

Please sign in to comment.