Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit ca0df76

Browse files
committed
chore(build): from rollup to vite vitest vitepress
0 parents  commit ca0df76

22 files changed

+2853
-0
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

.eslintrc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"root": true,
3+
"env": {
4+
"browser": true,
5+
"node": true
6+
},
7+
"parser": "@typescript-eslint/parser",
8+
"plugins": ["@typescript-eslint"],
9+
"extends": [
10+
"plugin:@typescript-eslint/recommended",
11+
"prettier"
12+
],
13+
"globals": {},
14+
// add your custom rules here
15+
"rules": {
16+
"semi": ["error", "never"],
17+
"curly": "off",
18+
"quotes": ["error", "single"],
19+
"comma-dangle": ["error", "always-multiline"],
20+
"no-unused-expressions": "off",
21+
"@typescript-eslint/no-unused-vars": "warn",
22+
"@typescript-eslint/no-unused-expressions": "error"
23+
}
24+
}

.github/workflows/build.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Build, Lint
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout 🛎️
15+
uses: actions/checkout@v2
16+
17+
- name: Install lint and Build 🔧
18+
uses: actions/setup-node@v2
19+
with:
20+
node-version: '16.x'
21+
- run: yarn
22+
- run: yarn lint
23+
- run: yarn build
24+

.github/workflows/docs.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
docs:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout 🛎️
14+
uses: actions/checkout@v2
15+
16+
- name: Install and Build 🔧
17+
uses: actions/setup-node@v1
18+
with:
19+
node-version: '16.x'
20+
- run: yarn
21+
- run: yarn docs:build
22+
23+
- name: Deploy 🚀
24+
uses: JamesIves/github-pages-deploy-action@4.1.3
25+
with:
26+
branch: gh-pages
27+
folder: docs/.vitepress/dist

.github/workflows/publish.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Publish Package to npmjs
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Configure Git
14+
run: |
15+
git config user.email "sebastien.lombard75@gmail.com"
16+
git config user.name "Seb-L"
17+
18+
- uses: actions/setup-node@v2
19+
with:
20+
node-version: '16.x'
21+
registry-url: 'https://registry.npmjs.org/'
22+
# Defaults to the user or organization that owns the workflow file
23+
24+
- id: get-version
25+
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}
26+
27+
- name: ⏳ Install dependencies
28+
run: yarn
29+
30+
- name: 👷 Build lib
31+
run: yarn build
32+
33+
- name: 📦 Publish
34+
run: yarn publish --new-version ${{ steps.get-version.outputs.VERSION }}
35+
env:
36+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
37+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
25+
coverage

.prettierrc

Whitespace-only changes.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Eduardo San Martin Morote
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# pinia-plugin-persist
2+
3+
![Build](https://github.com/Seb-L/pinia-plugin-persist/actions/workflows/build.yml/badge.svg)
4+
![Docs](https://github.com/Seb-L/pinia-plugin-persist/actions/workflows/docs.yml/badge.svg)
5+
6+
Persist VueJs Pinia state data in sessionStorage or other storages, heavilly influenced by [vuex-persistedstate](https://github.com/robinvdvleuten/vuex-persistedstate).
7+
8+
Documentation: [HERE](https://seb-l.github.io/pinia-plugin-persist/)

docs/.vitepress/config.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { defineConfig } from 'vitepress'
2+
3+
const META_URL = 'https://seb-l.github.io/pinia-plugin-persist/'
4+
const META_TITLE = 'Pinia Plugin Persist'
5+
const META_DESCRIPTION = 'Persist pinia state data in sessionStorage or other storages.'
6+
7+
export default defineConfig({
8+
base: '/pinia-plugin-persist/',
9+
title: META_TITLE,
10+
description: META_DESCRIPTION,
11+
lang: 'en-US',
12+
head: [
13+
['meta', { property: 'og:type', content: 'website' }],
14+
['meta', { property: 'og:url', content: META_URL }],
15+
['meta', { property: 'og:title', content: META_TITLE }],
16+
['meta', { property: 'og:description', content: META_DESCRIPTION }],
17+
['meta', { property: 'twitter:card', content: 'summary_large_image' }],
18+
['meta', { property: 'twitter:url', content: META_URL }],
19+
['meta', { property: 'twitter:title', content: META_TITLE }],
20+
['meta', { property: 'twitter:description', content: META_DESCRIPTION }],
21+
],
22+
themeConfig: {
23+
nav: [
24+
{ text: 'Guide', link: '/' },
25+
{ text: 'Github', link: 'https://github.com/Seb-L/pinia-plugin-persist' },
26+
],
27+
28+
sidebar: [
29+
{
30+
text: 'Guide',
31+
children: [
32+
{
33+
text: 'Install',
34+
link: '/'
35+
},
36+
{
37+
text: 'Basic Usage',
38+
link: '/basic-usage'
39+
},
40+
{
41+
text: 'Advanced Usage',
42+
children: [
43+
{
44+
text: 'Strategies',
45+
link: '/advanced/strategies',
46+
},
47+
{
48+
text: 'Custom storage key',
49+
link: '/advanced/custom-key',
50+
},
51+
{
52+
text: 'Persist partial state',
53+
link: '/advanced/partial-state',
54+
},
55+
{
56+
text: 'Custom Storage',
57+
link: '/advanced/custom-storage',
58+
}
59+
],
60+
},
61+
]
62+
},
63+
// {
64+
// text: 'Contribution',
65+
// children: [
66+
// {
67+
// text: 'Install',
68+
// link: '/contrib/install'
69+
// },
70+
// {
71+
// text: 'Workflow',
72+
// link: '/contrib/workflow'
73+
// }
74+
// ]
75+
// },
76+
]
77+
},
78+
})

docs/advanced/custom-key.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Custom storage key
2+
3+
You can set a custom storage key by setting the `key` key in each strategy.
4+
5+
In this example, the whole state will be stored in the localStorage under the key `user`.
6+
7+
```typescript
8+
// store/use-user-store.ts
9+
export const useUserStore = defineStore('storeUser', {
10+
state () {
11+
return {
12+
firstName: 'S',
13+
lastName: 'L',
14+
accessToken: 'xxxxxxxxxxxxx',
15+
}
16+
},
17+
persist: {
18+
enabled: true,
19+
strategies: [
20+
{
21+
key: 'user',
22+
storage: localStorage,
23+
},
24+
],
25+
},
26+
})
27+
```

docs/advanced/custom-storage.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Custom storage
2+
3+
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.
4+
5+
You can then use `sessionStorage`, `localStorage` or any custom storage object.
6+
7+
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.
8+
9+
```typescript
10+
// store/use-user-store.ts
11+
import Cookies from 'js-cookie'
12+
13+
const cookiesStorage: Storage = {
14+
setItem (key, state) {
15+
return Cookies.set('accessToken', state.accessToken, { expires: 3 })
16+
},
17+
getItem (key) {
18+
return JSON.stringify({
19+
accessToken: Cookies.getJSON('accessToken'),
20+
})
21+
},
22+
}
23+
24+
export const useUserStore = defineStore('storeUser', {
25+
state () {
26+
return {
27+
firstName: 'S',
28+
lastName: 'L',
29+
accessToken: 'xxxxxxxxxxxxx',
30+
}
31+
},
32+
persist: {
33+
enabled: true,
34+
strategies: [
35+
{
36+
storage: cookiesStorage,
37+
paths: ['accessToken']
38+
},
39+
],
40+
},
41+
})
42+
```

docs/advanced/partial-state.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Persist partial state
2+
3+
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.
4+
5+
In this example we persist the `firstName` and `lastName` in the sessionStorage, and the `accessToken` in the localStorage.
6+
7+
```typescript
8+
// store/use-user-store.ts
9+
export const useUserStore = defineStore('storeUser', {
10+
state () {
11+
return {
12+
firstName: 'S',
13+
lastName: 'L',
14+
accessToken: 'xxxxxxxxxxxxx',
15+
}
16+
},
17+
persist: {
18+
enabled: true,
19+
strategies: [
20+
{ storage: sessionStorage, paths: ['firstName', 'lastName'] },
21+
{ storage: localStorage, paths: ['accessToken'] },
22+
],
23+
},
24+
})
25+
```

docs/advanced/strategies.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Strategies
2+
3+
With `pinia-plugin-persist` You can use multiple strategies to persist your store data.
4+
5+
You can define a strategy list in your store under the `persist` key.
6+
7+
```typescript
8+
// store/use-user-store.ts
9+
export const useUserStore = defineStore('storeUser', {
10+
state () {
11+
return {
12+
firstName: 'S',
13+
lastName: 'L',
14+
accessToken: 'xxxxxxxxxxxxx',
15+
}
16+
},
17+
persist: {
18+
enabled: true,
19+
strategies: [], // <- HERE
20+
},
21+
})
22+
```
23+
24+
Each strategy is an object like so:
25+
26+
```typescript
27+
interface PersistStrategy {
28+
key?: string; // Storage key
29+
storage?: Storage; // Actual storage (default: sessionStorage)
30+
paths?: string[]; // list ok state keys you want to store in the storage
31+
}
32+
```

0 commit comments

Comments
 (0)