Skip to content

Commit

Permalink
refactor: split ui from vite plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjavi committed Aug 11, 2023
1 parent 83f66ea commit 6ae02ef
Show file tree
Hide file tree
Showing 25 changed files with 257 additions and 115 deletions.
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ pnpm install

## Developing

The main `@storylite/storylite` package can be found in `packages/storylite`.
The main packages are `ui` and `vite-plugin`, and can be found in `packages/*`.

You can quickly test and debug your changes in `@storylite/storylite` by running `packages/example`
(it's a playground project with demos in many frameworks to try out storylite):
You can quickly build and preview your changes by running the `dev` command
(it will also start the React example project):

```sh
pnpm dev
Expand Down Expand Up @@ -63,15 +63,15 @@ If possible, your changes should be also documented.

StoryLite uses [changesets](https://github.com/changesets/changesets) to manage the changelog and releases.

If you are changing `@storylite/storylite` you need to
Commit to `main` that comes from a PR, should
[add a changeset](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md)
(or you will be asked to do so in your PR):

```sh
pnpm changeset
```

You will be asked to select the scope (pick `@storylite/storylite`) and version (patch, minor, major).
You will be asked to select the scope and version (patch, minor, major).
Then you should add a summary of the changes in the following format:

- WHAT the change is
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/react/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="/app.tsx"></script>
<script type="module" src="/storylite.tsx"></script>
</body>
</html>
1 change: 1 addition & 0 deletions packages/examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"devDependencies": {
"@storylite/storylite": "workspace:*",
"@storylite/vite-plugin": "workspace:*",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"@vitejs/plugin-react-swc": "^3.3.2",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/examples/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"compilerOptions": {
"jsx": "react-jsx",
"allowSyntheticDefaultImports": true,
"types": ["node", "react", "react-dom", "@storylite/storylite/dist/virtual-modules.d.ts"]
"types": ["node", "react", "react-dom", "@storylite/vite-plugin/dist/virtual-modules.d.ts"]
}
}
2 changes: 1 addition & 1 deletion packages/examples/react/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @see https://vitejs.dev/config
*/

import { storylitePlugin } from '@storylite/storylite/dist/plugins'
import storylitePlugin from '@storylite/vite-plugin'
import react from '@vitejs/plugin-react-swc'
import { defineConfig } from 'vite'

Expand Down
20 changes: 0 additions & 20 deletions packages/storylite/index.html

This file was deleted.

12 changes: 1 addition & 11 deletions packages/storylite/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@storylite/storylite",
"version": "0.2.0",
"description": "A lightweight alternative to StoryBook, built on top of Vite⚡️",
"description": "A lightweight alternative to StoryBook, built on top of Vite⚡️. This package contains the React app.",
"license": "MIT",
"type": "module",
"exports": {
Expand All @@ -10,16 +10,6 @@
"import": "./dist/index.js",
"default": "./dist/index.cjs"
},
"./plugins": {
"types": "./dist/plugins.d.ts",
"import": "./dist/plugins.js",
"default": "./dist/plugins.cjs"
},
"./dist/plugins": {
"types": "./dist/plugins.d.ts",
"import": "./dist/plugins.js",
"default": "./dist/plugins.cjs"
},
"./dist/index.css": "./dist/index.css"
},
"main": "./dist/index.cjs",
Expand Down
4 changes: 0 additions & 4 deletions packages/storylite/src/plugins/index.ts

This file was deleted.

18 changes: 0 additions & 18 deletions packages/storylite/src/plugins/vite-plugin-remove-testid/index.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/storylite/storylite.config-example.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/storylite/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"jsx": "react-jsx",
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
Expand All @@ -15,7 +16,6 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"baseUrl": ".",
"paths": {
"@/": ["./src/"],
Expand Down
8 changes: 1 addition & 7 deletions packages/storylite/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export default defineConfig([
{
entry: {
index: './src/index.ts',
plugins: './src/plugins/index.ts',
},
outDir: './dist',
format: ['esm', 'cjs'],
Expand Down Expand Up @@ -36,11 +35,6 @@ export default defineConfig([
minify: false,
skipNodeModulesBundle: true,
external: ['node_modules'],
onSuccess: [
'sleep 2',
'cp ../../README.md ./README.md',
'cp ../../LICENSE ./LICENSE',
'cp ./src/plugins/vite-plugin-storylite/virtual-modules.d.ts ./dist/virtual-modules.d.ts',
].join(' && '),
onSuccess: ['sleep 2'].join(' && '),
},
])
10 changes: 10 additions & 0 deletions packages/vite-plugin/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/eslintrc.json",
"extends": ["../../.eslintrc.js"],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"react/jsx-key": "warn"
}
}
25 changes: 25 additions & 0 deletions packages/vite-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
vite.config.ts.timestamp-*
46 changes: 46 additions & 0 deletions packages/vite-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# @storylite/vite-plugin

## 0.2.0

### Breaking Changes

- big refactoring to use context instead of virtual modules.
- fixes stories resolution and the issues with the virtual modules being bundled.
- changed: renamed `StoryLiteRouter` -> `StoryLiteApp`
- changed: plugin config now only accepts the `stories` option, which is the relative glob path to the stories.
- changed: `StoryLiteApp` now requires a `stories` prop, which the modules map of the stories, you can load them
dynamically with `import stories from 'virtual:storylite-stories'`
(make sure you import it in the ts config types as `"@storylite/vite-plugin/dist/virtual-modules.d.ts"`)
and Vite with the StoryLite plugin will take care of the rest. Check the react examples for more info.

### Patch Changes

- update react-router-dom to 6.15.0

## 0.1.3

### Patch Changes

- better dependency definitions

## 0.1.2

### Patch Changes

- fix: router has now fully static site support. fix navigation.

## 0.1.1

### Patch Changes

- fix: license

## 0.1.0

### Minor Changes

- 134cf89: refactor: The project is now basically a plugin to integrate with Vite, with a React app.

### Patch Changes

- d4e07ac: initial Vite project setup
21 changes: 21 additions & 0 deletions packages/vite-plugin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Javi Aguilar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
30 changes: 30 additions & 0 deletions packages/vite-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# @storylite/vite-plugin

A Vite plugin to integrate StoryLite with Vite.

## Installation

```bash

npm i -D @storylite/vite-plugin

```

## Usage

```ts
// vite.config.ts

/// <reference types="vite/client" />

import storylite from '@storylite/vite-plugin'
import { defineConfig } from 'vite'

export default defineConfig({
plugins: [
storylite({
stories: 'stories/**/*.stories.tsx', // relative to process.cwd()
}),
],
})
```
38 changes: 38 additions & 0 deletions packages/vite-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@storylite/vite-plugin",
"version": "0.2.0",
"description": "A lightweight alternative to StoryBook, built on top of Vite⚡️",
"license": "MIT",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.cjs"
}
},
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsup",
"dev": "sleep 10 && tsup --watch --clean",
"lint": "eslint --max-warnings=10 .",
"lint-fix": "eslint --fix .",
"prepublishOnly": "pnpm run build",
"publint-check": "pnpm publint",
"type-check": "tsc --noEmit"
},
"dependencies": {
"vite": "^4.4.9"
},
"devDependencies": {
"@r1stack/coding-style": "^0.2.1",
"@types/node": "^20.4.9",
"publint": "^0.2.0",
"tsup": "^7.2.0",
"typescript": "^5.1.6"
}
}
1 change: 1 addition & 0 deletions packages/vite-plugin/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Plugin } from 'vite'

import { StoryLitePluginConfig } from '@/types'
export type StoryLitePluginConfig = {
stories: string
}

const storiesVirtualModuleId = 'virtual:storylite-stories'
const resolvedStoriesVirtualModuleId = '\0virtual:storylite-stories'
Expand Down
4 changes: 4 additions & 0 deletions packages/vite-plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@r1stack/coding-style/tsconfig/base.json",
"include": ["src", "*.ts"]
}
Loading

0 comments on commit 6ae02ef

Please sign in to comment.