Skip to content

Commit 0d75d07

Browse files
committed
chore: init
0 parents  commit 0d75d07

14 files changed

+4243
-0
lines changed

.eslintrc.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@antfu/eslint-config-ts"
3+
}

.gitignore

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port
105+
test/temp

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Anthony Fu
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

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<p align='center'>
2+
<img src='https://github.com/vue-reactivity/art/blob/master/svg/package-fs.svg?raw=true' height='250'>
3+
</p>
4+
5+
<p align='center'>
6+
Reactive file system for <a href="https://github.com/vuejs/vue-next/tree/master/packages/reactivity"><code>@vue/reactivity</code></a>
7+
</p>
8+
9+
<p align='center'>
10+
<a href="https://www.npmjs.com/package/@vue-reactivity/fs"><img src="https://img.shields.io/npm/v/@vue-reactivity/fs?color=43b883&label=" alt="npm"></a>
11+
<a href="https://bundlephobia.com/result?p=@vue-reactivity/fs"><img src="https://img.shields.io/bundlephobia/minzip/@vue-reactivity/fs?color=364a5e&label=" alt="npm bundle size"></a>
12+
</p>
13+
14+
## Install
15+
16+
<pre>
17+
npm i @vue-reactivity/<b>fs</b>
18+
</pre>
19+
20+
### Usage
21+
22+
> Work only in Node.js
23+
24+
```ts
25+
import { useFile } from '@vue-reactivity/fs'
26+
27+
const fileRef = useFile('messages.txt')
28+
29+
await fileRef.waitForReady()
30+
31+
console.log(fileRef.value) // output file content
32+
33+
fileRef.value += 'Hello World' // append to file
34+
35+
fileRef.value = 'Good Morning' // write to file
36+
```
37+
38+
Watch for file changes (via [`chokidar`](https://github.com/paulmillr/chokidar))
39+
40+
```ts
41+
const fileRef = useFile('messages.txt', { watchFileChanges: true })
42+
```
43+
44+
`useJson`
45+
46+
```ts
47+
import { useJSON } from '@vue-reactivity/fs'
48+
49+
const data = useJSON('data.json', { initialValue: { foo: 'bar' }})
50+
51+
console.log(data.value) // { foo: 'bar' }
52+
53+
data.value = { bar: 'foo' } // write to json file
54+
```
55+
56+
Custom serializer
57+
58+
```ts
59+
import YAML from 'js-yaml'
60+
import { useFileWithSerializer } from '@vue-reactivity/fs'
61+
62+
export function useYAML<T>(path: string, options: JSONSerializerOptions<T> = {}) {
63+
return useFileWithSerializer<T>(
64+
path,
65+
{
66+
...options,
67+
serialize: v => YAML.safeDump(v)
68+
deserialize: v => YAML.safeLoad(v),
69+
},
70+
)
71+
}
72+
```
73+
74+
## License
75+
76+
MIT

package.json

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "@vue-reactivity/fs",
3+
"version": "0.0.1",
4+
"main": "dist/index.js",
5+
"module": "dist/index.mjs",
6+
"types": "dist/index.d.ts",
7+
"repository": "https://github.com/vue-reactivity/fs.git",
8+
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
9+
"license": "MIT",
10+
"files": [
11+
"dist",
12+
"src"
13+
],
14+
"sideEffects": false,
15+
"scripts": {
16+
"prepare": "npm run build",
17+
"build": "tsup src/index.ts --format cjs,esm --dts",
18+
"dev": "npm run build -- --watch",
19+
"test": "c8 ava",
20+
"release": "npx bumpp --tag --commit --push && pnpm publish --access public"
21+
},
22+
"dependencies": {
23+
"@vue-reactivity/watch": "^0.1.4",
24+
"@vue/reactivity": ">=3.0.0",
25+
"@vue/shared": ">=3.0.0",
26+
"chokidar": "^3.4.2"
27+
},
28+
"devDependencies": {
29+
"@antfu/eslint-config-ts": "^0.3.3",
30+
"@types/fs-extra": "^9.0.2",
31+
"@types/node": "^14.11.8",
32+
"@vue-reactivity/when": "^0.1.4",
33+
"ava": "^3.13.0",
34+
"c8": "^7.3.3",
35+
"esbuild-register": "^1.0.2",
36+
"eslint": "^7.11.0",
37+
"esm": "^3.2.25",
38+
"fs-extra": "^9.0.1",
39+
"tsup": "^3.7.0",
40+
"typescript": "^4.0.3"
41+
},
42+
"ava": {
43+
"extensions": [
44+
"ts"
45+
],
46+
"ignoredByWatcher": [
47+
"**/temp/**"
48+
],
49+
"require": [
50+
"esm",
51+
"esbuild-register"
52+
]
53+
}
54+
}

0 commit comments

Comments
 (0)