This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(build): from rollup to vite vitest vitepress
- Loading branch information
0 parents
commit ca0df76
Showing
22 changed files
with
2,853 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"root": true, | ||
"env": { | ||
"browser": true, | ||
"node": true | ||
}, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint"], | ||
"extends": [ | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier" | ||
], | ||
"globals": {}, | ||
// add your custom rules here | ||
"rules": { | ||
"semi": ["error", "never"], | ||
"curly": "off", | ||
"quotes": ["error", "single"], | ||
"comma-dangle": ["error", "always-multiline"], | ||
"no-unused-expressions": "off", | ||
"@typescript-eslint/no-unused-vars": "warn", | ||
"@typescript-eslint/no-unused-expressions": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Build, Lint | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install lint and Build 🔧 | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '16.x' | ||
- run: yarn | ||
- run: yarn lint | ||
- run: yarn build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Docs | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
docs: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install and Build 🔧 | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: '16.x' | ||
- run: yarn | ||
- run: yarn docs:build | ||
|
||
- name: Deploy 🚀 | ||
uses: JamesIves/[email protected] | ||
with: | ||
branch: gh-pages | ||
folder: docs/.vitepress/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Publish Package to npmjs | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Configure Git | ||
run: | | ||
git config user.email "[email protected]" | ||
git config user.name "Seb-L" | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: '16.x' | ||
registry-url: 'https://registry.npmjs.org/' | ||
# Defaults to the user or organization that owns the workflow file | ||
|
||
- id: get-version | ||
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/} | ||
|
||
- name: ⏳ Install dependencies | ||
run: yarn | ||
|
||
- name: 👷 Build lib | ||
run: yarn build | ||
|
||
- name: 📦 Publish | ||
run: yarn publish --new-version ${{ steps.get-version.outputs.VERSION }} | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
coverage |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2019 Eduardo San Martin Morote | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# pinia-plugin-persist | ||
|
||
![Build](https://github.com/Seb-L/pinia-plugin-persist/actions/workflows/build.yml/badge.svg) | ||
![Docs](https://github.com/Seb-L/pinia-plugin-persist/actions/workflows/docs.yml/badge.svg) | ||
|
||
Persist VueJs Pinia state data in sessionStorage or other storages, heavilly influenced by [vuex-persistedstate](https://github.com/robinvdvleuten/vuex-persistedstate). | ||
|
||
Documentation: [HERE](https://seb-l.github.io/pinia-plugin-persist/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { defineConfig } from 'vitepress' | ||
|
||
const META_URL = 'https://seb-l.github.io/pinia-plugin-persist/' | ||
const META_TITLE = 'Pinia Plugin Persist' | ||
const META_DESCRIPTION = 'Persist pinia state data in sessionStorage or other storages.' | ||
|
||
export default defineConfig({ | ||
base: '/pinia-plugin-persist/', | ||
title: META_TITLE, | ||
description: META_DESCRIPTION, | ||
lang: 'en-US', | ||
head: [ | ||
['meta', { property: 'og:type', content: 'website' }], | ||
['meta', { property: 'og:url', content: META_URL }], | ||
['meta', { property: 'og:title', content: META_TITLE }], | ||
['meta', { property: 'og:description', content: META_DESCRIPTION }], | ||
['meta', { property: 'twitter:card', content: 'summary_large_image' }], | ||
['meta', { property: 'twitter:url', content: META_URL }], | ||
['meta', { property: 'twitter:title', content: META_TITLE }], | ||
['meta', { property: 'twitter:description', content: META_DESCRIPTION }], | ||
], | ||
themeConfig: { | ||
nav: [ | ||
{ text: 'Guide', link: '/' }, | ||
{ text: 'Github', link: 'https://github.com/Seb-L/pinia-plugin-persist' }, | ||
], | ||
|
||
sidebar: [ | ||
{ | ||
text: 'Guide', | ||
children: [ | ||
{ | ||
text: 'Install', | ||
link: '/' | ||
}, | ||
{ | ||
text: 'Basic Usage', | ||
link: '/basic-usage' | ||
}, | ||
{ | ||
text: 'Advanced Usage', | ||
children: [ | ||
{ | ||
text: 'Strategies', | ||
link: '/advanced/strategies', | ||
}, | ||
{ | ||
text: 'Custom storage key', | ||
link: '/advanced/custom-key', | ||
}, | ||
{ | ||
text: 'Persist partial state', | ||
link: '/advanced/partial-state', | ||
}, | ||
{ | ||
text: 'Custom Storage', | ||
link: '/advanced/custom-storage', | ||
} | ||
], | ||
}, | ||
] | ||
}, | ||
// { | ||
// text: 'Contribution', | ||
// children: [ | ||
// { | ||
// text: 'Install', | ||
// link: '/contrib/install' | ||
// }, | ||
// { | ||
// text: 'Workflow', | ||
// link: '/contrib/workflow' | ||
// } | ||
// ] | ||
// }, | ||
] | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Custom storage key | ||
|
||
You can set a custom storage key by setting the `key` key in each strategy. | ||
|
||
In this example, the whole state will be stored in the localStorage under the key `user`. | ||
|
||
```typescript | ||
// store/use-user-store.ts | ||
export const useUserStore = defineStore('storeUser', { | ||
state () { | ||
return { | ||
firstName: 'S', | ||
lastName: 'L', | ||
accessToken: 'xxxxxxxxxxxxx', | ||
} | ||
}, | ||
persist: { | ||
enabled: true, | ||
strategies: [ | ||
{ | ||
key: 'user', | ||
storage: localStorage, | ||
}, | ||
], | ||
}, | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Custom storage | ||
|
||
By default the storage is set to sessionStorage, but you can specify the storage you want to use for each strategy by setting the `storage` key. | ||
|
||
You can then use `sessionStorage`, `localStorage` or any custom storage object. | ||
|
||
In this example we create a storage that uses the `js-cookie` npm module to get and set the user's access token into a cookie. | ||
|
||
```typescript | ||
// store/use-user-store.ts | ||
import Cookies from 'js-cookie' | ||
|
||
const cookiesStorage: Storage = { | ||
setItem (key, state) { | ||
return Cookies.set('accessToken', state.accessToken, { expires: 3 }) | ||
}, | ||
getItem (key) { | ||
return JSON.stringify({ | ||
accessToken: Cookies.getJSON('accessToken'), | ||
}) | ||
}, | ||
} | ||
|
||
export const useUserStore = defineStore('storeUser', { | ||
state () { | ||
return { | ||
firstName: 'S', | ||
lastName: 'L', | ||
accessToken: 'xxxxxxxxxxxxx', | ||
} | ||
}, | ||
persist: { | ||
enabled: true, | ||
strategies: [ | ||
{ | ||
storage: cookiesStorage, | ||
paths: ['accessToken'] | ||
}, | ||
], | ||
}, | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Persist partial state | ||
|
||
By default the whole state is persisted, but you can specify the state keys you want ot persist, by setting the `paths` key in each strategy. | ||
|
||
In this example we persist the `firstName` and `lastName` in the sessionStorage, and the `accessToken` in the localStorage. | ||
|
||
```typescript | ||
// store/use-user-store.ts | ||
export const useUserStore = defineStore('storeUser', { | ||
state () { | ||
return { | ||
firstName: 'S', | ||
lastName: 'L', | ||
accessToken: 'xxxxxxxxxxxxx', | ||
} | ||
}, | ||
persist: { | ||
enabled: true, | ||
strategies: [ | ||
{ storage: sessionStorage, paths: ['firstName', 'lastName'] }, | ||
{ storage: localStorage, paths: ['accessToken'] }, | ||
], | ||
}, | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Strategies | ||
|
||
With `pinia-plugin-persist` You can use multiple strategies to persist your store data. | ||
|
||
You can define a strategy list in your store under the `persist` key. | ||
|
||
```typescript | ||
// store/use-user-store.ts | ||
export const useUserStore = defineStore('storeUser', { | ||
state () { | ||
return { | ||
firstName: 'S', | ||
lastName: 'L', | ||
accessToken: 'xxxxxxxxxxxxx', | ||
} | ||
}, | ||
persist: { | ||
enabled: true, | ||
strategies: [], // <- HERE | ||
}, | ||
}) | ||
``` | ||
|
||
Each strategy is an object like so: | ||
|
||
```typescript | ||
interface PersistStrategy { | ||
key?: string; // Storage key | ||
storage?: Storage; // Actual storage (default: sessionStorage) | ||
paths?: string[]; // list ok state keys you want to store in the storage | ||
} | ||
``` |
Oops, something went wrong.