Skip to content

Commit

Permalink
chore(build): from rollup to vite vitest vitepress
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb-L committed Mar 10, 2022
0 parents commit ca0df76
Show file tree
Hide file tree
Showing 22 changed files with 2,853 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
24 changes: 24 additions & 0 deletions .eslintrc
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"
}
}
24 changes: 24 additions & 0 deletions .github/workflows/build.yml
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

27 changes: 27 additions & 0 deletions .github/workflows/docs.yml
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/github-pages-deploy-action@4.1.3
with:
branch: gh-pages
folder: docs/.vitepress/dist
37 changes: 37 additions & 0 deletions .github/workflows/publish.yml
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 "sebastien.lombard75@gmail.com"
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 }}
25 changes: 25 additions & 0 deletions .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?
coverage
Empty file added .prettierrc
Empty file.
21 changes: 21 additions & 0 deletions LICENSE
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.
8 changes: 8 additions & 0 deletions README.md
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/)
78 changes: 78 additions & 0 deletions docs/.vitepress/config.ts
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'
// }
// ]
// },
]
},
})
27 changes: 27 additions & 0 deletions docs/advanced/custom-key.md
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,
},
],
},
})
```
42 changes: 42 additions & 0 deletions docs/advanced/custom-storage.md
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']
},
],
},
})
```
25 changes: 25 additions & 0 deletions docs/advanced/partial-state.md
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'] },
],
},
})
```
32 changes: 32 additions & 0 deletions docs/advanced/strategies.md
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
}
```

0 comments on commit ca0df76

Please sign in to comment.