Skip to content

Commit

Permalink
feat: add publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Jan 30, 2024
1 parent 8778f9d commit 92b2550
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 36 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/release-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Publish Package

permissions:
id-token: write
contents: write

on:
push:
branches: [perf/code]

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@v2

- name: Use Node.js v18
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: https://registry.npmjs.org/
cache: pnpm

- run: pnpm install

- name: Publish
if: success()
uses: author/action-publish@stable
with:
# Optionally specify the directories to scan
# for modules. If this is not specified, the
# root directory is scanned.
scan: './packages'
# Optionally force publishing as a public
# module. We don't recommend setting this,
# unless you have a very specific use case.
force: true
env:
REGISTRY_TOKEN: '${{ secrets.NPM_TOKEN }}'
76 changes: 41 additions & 35 deletions packages/vite-plugin-msw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@ npm install --save-dev @admin-pkg/vite-plugin-msw

https://mswjs.io/docs/getting-started/mocks

### Add to Vite config

```ts
// Import plugin
import msw from '@admin-pkg/vite-plugin-msw';

// Import msw handlers
import { handlers } from '../mocks/handlers';

// Pass them to plugin
export default defineConfig({
plugins: [msw({ handlers })],
});
```

---

## Config
Expand Down Expand Up @@ -58,36 +43,57 @@ MSW handlers. More information on how to define these: https://mswjs.io/docs/get

To start MSW in the client, please follow the [Configure worker step](https://mswjs.io/docs/getting-started/integrate/browser#configure-worker) and [Start worker step](https://mswjs.io/docs/getting-started/integrate/browser#start-worker) in the MSW docs. The `mockServiceWorker.js` file will be provided by the Vite Dev Server.

#### Node
##### Example vite application

This will handle the mocked service worker handlers via a Vite Dev Server plugin.
```ts
import { enableMocking } from '@admin-pkg/vite-plugin-msw';
import { HttpHandler } from 'msw';

### Build
const modules = import.meta.glob<any>('./**/*.ts', {
eager: true,
});

- Optional
- Default: `false`
export const setupMock = async () => {
const handlers = Object.values(modules).reduce<HttpHandler[]>((prev, curr) => {
const arr = curr?.default;
if (Array.isArray(arr)) {
arr.forEach((item) => {
if (item instanceof HttpHandler) {
prev.push(item);
}
});
}
return prev;
}, []);
// console.log('handlers', handlers);
await enableMocking(handlers);
};
```

A true value will output MSW's `mockServiceWorker.js` file to the Vite build directory, in case if MSW is needed in production.
#### Node

---
This will handle the mocked service worker handlers via a Vite Dev Server plugin.

## Development
##### Add to Vite config

```
npm run dev
```
```ts
// Import plugin
import msw from '@admin-pkg/vite-plugin-msw';

### Example vite application with plugin
// Import msw handlers
import { handlers } from '../mocks/handlers';

```
npm run build
cd examples/with-vite
npm run dev
curl http://localhost:3000/api/health
// Pass them to plugin
export default defineConfig({
plugins: [msw({ handlers })],
});
```

### Build

```
npm run build
```
- Optional
- Default: `false`

A true value will output MSW's `mockServiceWorker.js` file to the Vite build directory, in case if MSW is needed in production.

---
5 changes: 4 additions & 1 deletion packages/vite-plugin-msw/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"name": "@admin-pkg/vite-plugin-msw",
"version": "0.0.1",
"version": "0.0.2",
"description": "",
"module": "./dist/browser/index.mjs",
"main": "./dist/browser/index.mjs",
"files": [
"dist"
],
"exports": {
".": {
"import": "./dist/browser/index.mjs",
Expand Down

0 comments on commit 92b2550

Please sign in to comment.