flat-cache 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/changelog.md +155 -205
- package/package.json +9 -8
- package/src/cache.js +22 -26
- package/src/del.js +28 -11
- package/src/utils.js +39 -41
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# flat-cache
|
|
2
|
+
|
|
2
3
|
> A stupidly simple key/value storage using files to persist the data
|
|
3
4
|
|
|
4
5
|
[](https://npmjs.org/package/flat-cache)
|
|
@@ -15,19 +16,19 @@ npm i --save flat-cache
|
|
|
15
16
|
## Usage
|
|
16
17
|
|
|
17
18
|
```js
|
|
18
|
-
|
|
19
|
+
const flatCache = require('flat-cache');
|
|
19
20
|
// loads the cache, if one does not exists for the given
|
|
20
21
|
// Id a new one will be prepared to be created
|
|
21
|
-
|
|
22
|
+
const cache = flatCache.load('cacheId');
|
|
22
23
|
|
|
23
24
|
// sets a key on the cache
|
|
24
25
|
cache.setKey('key', { foo: 'var' });
|
|
25
26
|
|
|
26
27
|
// get a key from the cache
|
|
27
|
-
cache.getKey('key') // { foo: 'var' }
|
|
28
|
+
cache.getKey('key'); // { foo: 'var' }
|
|
28
29
|
|
|
29
30
|
// fetch the entire persisted object
|
|
30
|
-
cache.all() // { 'key': { foo: 'var' } }
|
|
31
|
+
cache.all(); // { 'key': { foo: 'var' } }
|
|
31
32
|
|
|
32
33
|
// remove a key
|
|
33
34
|
cache.removeKey('key'); // removes a key from the cache
|
|
@@ -38,11 +39,11 @@ cache.save(); // very important, if you don't save no changes will be persisted.
|
|
|
38
39
|
|
|
39
40
|
// loads the cache from a given directory, if one does
|
|
40
41
|
// not exists for the given Id a new one will be prepared to be created
|
|
41
|
-
|
|
42
|
+
const cache = flatCache.load('cacheId', path.resolve('./path/to/folder'));
|
|
42
43
|
|
|
43
44
|
// The following methods are useful to clear the cache
|
|
44
45
|
// delete a given cache
|
|
45
|
-
flatCache.clearCacheById('cacheId') // removes the cacheId document if one exists.
|
|
46
|
+
flatCache.clearCacheById('cacheId'); // removes the cacheId document if one exists.
|
|
46
47
|
|
|
47
48
|
// delete all cache
|
|
48
49
|
flatCache.clearAll(); // remove the cache directory
|
|
@@ -56,6 +57,7 @@ To make that possible we need to store the `fileSize` and `modificationTime` of
|
|
|
56
57
|
storage was needed and Bam! this module was born.
|
|
57
58
|
|
|
58
59
|
## Important notes
|
|
60
|
+
|
|
59
61
|
- If no directory is especified when the `load` method is called, a folder named `.cache` will be created
|
|
60
62
|
inside the module directory when `cache.save` is called. If you're committing your `node_modules` to any vcs, you
|
|
61
63
|
might want to ignore the default `.cache` folder, or specify a custom directory.
|
package/changelog.md
CHANGED
|
@@ -1,328 +1,278 @@
|
|
|
1
|
-
|
|
2
1
|
# flat-cache - Changelog
|
|
2
|
+
|
|
3
3
|
## v3.0.4
|
|
4
|
+
|
|
4
5
|
- **Refactoring**
|
|
5
|
-
- add files by name to the list of exported files - [89a2698](
|
|
6
|
+
- add files by name to the list of exported files - [89a2698](https://github.com/royriojas/flat-cache/commit/89a2698), [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 02:35:39
|
|
6
7
|
|
|
7
|
-
|
|
8
8
|
## v3.0.3
|
|
9
|
+
|
|
9
10
|
- **Bug Fixes**
|
|
10
|
-
- Fix wrong eslint command - [f268e42](
|
|
11
|
+
- Fix wrong eslint command - [f268e42](https://github.com/royriojas/flat-cache/commit/f268e42), [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 02:15:04
|
|
11
12
|
|
|
12
|
-
|
|
13
13
|
## v3.0.2
|
|
14
|
-
- **Refactoring**
|
|
15
|
-
- Update the files paths - [6983a80]( https://github.com/royriojas/flat-cache/commit/6983a80 ), [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 01:58:39
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
- Move code to src/ - [18ed6e8]( https://github.com/royriojas/flat-cache/commit/18ed6e8 ), [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 01:57:17
|
|
15
|
+
- **Refactoring**
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
-
|
|
17
|
+
- Update the files paths - [6983a80](https://github.com/royriojas/flat-cache/commit/6983a80), [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 01:58:39
|
|
18
|
+
- Move code to src/ - [18ed6e8](https://github.com/royriojas/flat-cache/commit/18ed6e8), [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 01:57:17
|
|
19
|
+
- Change eslint-cache location - [beed74c](https://github.com/royriojas/flat-cache/commit/beed74c), [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 01:48:32
|
|
22
20
|
|
|
23
|
-
|
|
24
21
|
## v3.0.1
|
|
22
|
+
|
|
25
23
|
- **Refactoring**
|
|
26
|
-
- Remove unused deps - [8c6d9dc](
|
|
24
|
+
- Remove unused deps - [8c6d9dc](https://github.com/royriojas/flat-cache/commit/8c6d9dc), [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 01:43:29
|
|
27
25
|
|
|
28
|
-
|
|
29
26
|
## v3.0.0
|
|
30
|
-
- **Refactoring**
|
|
31
|
-
- Fix engines - [52b824c]( https://github.com/royriojas/flat-cache/commit/52b824c ), [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 01:01:52
|
|
32
27
|
|
|
33
|
-
|
|
28
|
+
- **Refactoring**
|
|
29
|
+
- Fix engines - [52b824c](https://github.com/royriojas/flat-cache/commit/52b824c), [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 01:01:52
|
|
34
30
|
- **Other changes**
|
|
35
|
-
- Replace write with combination of mkdir and writeFile ([#49](https://github.com/royriojas/flat-cache/issues/49)) - [ef48276]( https://github.com/royriojas/flat-cache/commit/ef48276 ), [Bogdan Chadkin](https://github.com/Bogdan Chadkin), 08/11/2020 00:17:15
|
|
36
31
|
|
|
37
|
-
|
|
38
|
-
get rid from mkdirp package and easily rewrite "write" package usage
|
|
39
|
-
with two function calls.
|
|
40
|
-
|
|
41
|
-
https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback
|
|
42
|
-
- Added a testcase for clearAll ([#48](https://github.com/royriojas/flat-cache/issues/48)) - [45b51ca]( https://github.com/royriojas/flat-cache/commit/45b51ca ), [Aaron Chen](https://github.com/Aaron Chen), 21/05/2020 08:40:03
|
|
32
|
+
- Replace write with combination of mkdir and writeFile ([#49](https://github.com/royriojas/flat-cache/issues/49)) - [ef48276](https://github.com/royriojas/flat-cache/commit/ef48276), [Bogdan Chadkin](https://github.com/Bogdan Chadkin), 08/11/2020 00:17:15
|
|
43
33
|
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
Node v10 introduced a great "recursive" option for mkdir which allows to
|
|
35
|
+
get rid from mkdirp package and easily rewrite "write" package usage
|
|
36
|
+
with two function calls.
|
|
46
37
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
- Update README.md - [29fe40b]( https://github.com/royriojas/flat-cache/commit/29fe40b ), [Roy Riojas](https://github.com/Roy Riojas), 10/04/2020 20:08:05
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
- reduce vulnerability to 1 - [e9db1b2]( https://github.com/royriojas/flat-cache/commit/e9db1b2 ), [yumetodo](https://github.com/yumetodo), 30/03/2020 11:10:43
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
- reduce vulnerabilities dependencies to 8 - [b58d196]( https://github.com/royriojas/flat-cache/commit/b58d196 ), [yumetodo](https://github.com/yumetodo), 30/03/2020 10:54:56
|
|
38
|
+
https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback
|
|
56
39
|
|
|
57
|
-
|
|
58
|
-
-
|
|
40
|
+
- Added a testcase for clearAll ([#48](https://github.com/royriojas/flat-cache/issues/48)) - [45b51ca](https://github.com/royriojas/flat-cache/commit/45b51ca), [Aaron Chen](https://github.com/Aaron Chen), 21/05/2020 08:40:03
|
|
41
|
+
- requet node>=10 - [a5c482c](https://github.com/royriojas/flat-cache/commit/a5c482c), [yumetodo](https://github.com/yumetodo), 10/04/2020 23:14:53
|
|
59
42
|
|
|
60
|
-
|
|
61
|
-
- update proxyquire - [c2f048d]( https://github.com/royriojas/flat-cache/commit/c2f048d ), [yumetodo](https://github.com/yumetodo), 30/03/2020 10:16:16
|
|
43
|
+
thanks @SuperITMan
|
|
62
44
|
|
|
63
|
-
|
|
64
|
-
-
|
|
45
|
+
- Update README.md - [29fe40b](https://github.com/royriojas/flat-cache/commit/29fe40b), [Roy Riojas](https://github.com/Roy Riojas), 10/04/2020 20:08:05
|
|
46
|
+
- reduce vulnerability to 1 - [e9db1b2](https://github.com/royriojas/flat-cache/commit/e9db1b2), [yumetodo](https://github.com/yumetodo), 30/03/2020 11:10:43
|
|
47
|
+
- reduce vulnerabilities dependencies to 8 - [b58d196](https://github.com/royriojas/flat-cache/commit/b58d196), [yumetodo](https://github.com/yumetodo), 30/03/2020 10:54:56
|
|
48
|
+
- use prettier instead of esbeautifier - [03b1db7](https://github.com/royriojas/flat-cache/commit/03b1db7), [yumetodo](https://github.com/yumetodo), 30/03/2020 10:27:14
|
|
49
|
+
- update proxyquire - [c2f048d](https://github.com/royriojas/flat-cache/commit/c2f048d), [yumetodo](https://github.com/yumetodo), 30/03/2020 10:16:16
|
|
50
|
+
- update flatted and mocha - [a0e56da](https://github.com/royriojas/flat-cache/commit/a0e56da), [yumetodo](https://github.com/yumetodo), 30/03/2020 09:46:45
|
|
65
51
|
|
|
66
52
|
mocha > mkdirp is updated
|
|
67
53
|
istanble >>> optimist > minimist is not updated
|
|
68
|
-
|
|
69
|
-
- drop support node.js < 10 in develop - [beba691](
|
|
54
|
+
|
|
55
|
+
- drop support node.js < 10 in develop - [beba691](https://github.com/royriojas/flat-cache/commit/beba691), [yumetodo](https://github.com/yumetodo), 18/03/2020 01:31:09
|
|
70
56
|
|
|
71
57
|
see mkdirp
|
|
72
|
-
|
|
73
|
-
- npm aufit fix(still remains) - [ce166cb](
|
|
58
|
+
|
|
59
|
+
- npm aufit fix(still remains) - [ce166cb](https://github.com/royriojas/flat-cache/commit/ce166cb), [yumetodo](https://github.com/yumetodo), 18/03/2020 01:18:08
|
|
74
60
|
|
|
75
61
|
37 vulnerabilities required manual review and could not be updated
|
|
76
|
-
|
|
77
|
-
- updtate sinon - [9f2d1b6]( https://github.com/royriojas/flat-cache/commit/9f2d1b6 ), [yumetodo](https://github.com/yumetodo), 18/03/2020 01:17:51
|
|
78
62
|
|
|
79
|
-
|
|
80
|
-
- apply eslint-plugin-mocha - [07343b5](
|
|
63
|
+
- updtate sinon - [9f2d1b6](https://github.com/royriojas/flat-cache/commit/9f2d1b6), [yumetodo](https://github.com/yumetodo), 18/03/2020 01:17:51
|
|
64
|
+
- apply eslint-plugin-mocha - [07343b5](https://github.com/royriojas/flat-cache/commit/07343b5), [yumetodo](https://github.com/yumetodo), 13/03/2020 22:17:21
|
|
65
|
+
- Less strint version check ([#44](https://github.com/royriojas/flat-cache/issues/44)) - [92aca1c](https://github.com/royriojas/flat-cache/commit/92aca1c), [Wojciech Maj](https://github.com/Wojciech Maj), 13/11/2019 16:18:25
|
|
81
66
|
|
|
82
|
-
|
|
83
|
-
|
|
67
|
+
- Use ^ version matching for production dependencies
|
|
68
|
+
- Run npm audit fix
|
|
84
69
|
|
|
85
|
-
* Use ^ version matching for production dependencies
|
|
86
|
-
|
|
87
|
-
* Run npm audit fix
|
|
88
|
-
|
|
89
70
|
- **Bug Fixes**
|
|
90
|
-
- update dependencies and use eslint directly - [73fbed2](
|
|
71
|
+
- update dependencies and use eslint directly - [73fbed2](https://github.com/royriojas/flat-cache/commit/73fbed2), [yumetodo](https://github.com/yumetodo), 18/03/2020 01:17:27
|
|
91
72
|
|
|
92
|
-
|
|
93
73
|
## v2.0.1
|
|
74
|
+
|
|
94
75
|
- **Refactoring**
|
|
95
|
-
- upgrade node modules to latest versions - [6402ed3](
|
|
76
|
+
- upgrade node modules to latest versions - [6402ed3](https://github.com/royriojas/flat-cache/commit/6402ed3), [Roy Riojas](https://github.com/Roy Riojas), 08/01/2019 18:47:05
|
|
96
77
|
|
|
97
|
-
|
|
98
78
|
## v2.0.0
|
|
79
|
+
|
|
99
80
|
- **Bug Fixes**
|
|
100
|
-
- upgrade package.json lock file - [8d21c7b]( https://github.com/royriojas/flat-cache/commit/8d21c7b ), [Roy Riojas](https://github.com/Roy Riojas), 08/01/2019 17:03:13
|
|
101
81
|
|
|
102
|
-
|
|
103
|
-
- Use the same versions of node_js that eslint use - [8d23379](
|
|
82
|
+
- upgrade package.json lock file - [8d21c7b](https://github.com/royriojas/flat-cache/commit/8d21c7b), [Roy Riojas](https://github.com/Roy Riojas), 08/01/2019 17:03:13
|
|
83
|
+
- Use the same versions of node_js that eslint use - [8d23379](https://github.com/royriojas/flat-cache/commit/8d23379), [Roy Riojas](https://github.com/Roy Riojas), 08/01/2019 16:25:11
|
|
104
84
|
|
|
105
|
-
|
|
106
85
|
- **Other changes**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
* There's a bunch of dependencies in this pkg requires node >=4, so I changed it to 4
|
|
122
|
-
|
|
123
|
-
* Remove and add node versions
|
|
124
|
-
|
|
125
|
-
* I have seen this pkg is not available with node 0.12 so I removed it
|
|
126
|
-
* I have added a popular used LTS version of node - 10
|
|
127
|
-
|
|
86
|
+
|
|
87
|
+
- Replace circular-json with flatted ([#36](https://github.com/royriojas/flat-cache/issues/36)) - [b93aced](https://github.com/royriojas/flat-cache/commit/b93aced), [C. K. Tang](https://github.com/C. K. Tang), 08/01/2019 17:03:01
|
|
88
|
+
- Change JSON parser from circular-json to flatted & 1 more changes ([#37](https://github.com/royriojas/flat-cache/issues/37)) - [745e65a](https://github.com/royriojas/flat-cache/commit/745e65a), [Andy Chen](https://github.com/Andy Chen), 08/01/2019 16:17:20
|
|
89
|
+
|
|
90
|
+
- Change JSON parser from circular-json to flatted & 1 more changes
|
|
91
|
+
- Change JSON parser from circular-json
|
|
92
|
+
- Audited 2 vulnerabilities
|
|
93
|
+
- Update package.json
|
|
94
|
+
- Update Engine require
|
|
95
|
+
- There's a bunch of dependencies in this pkg requires node >=4, so I changed it to 4
|
|
96
|
+
- Remove and add node versions
|
|
97
|
+
- I have seen this pkg is not available with node 0.12 so I removed it
|
|
98
|
+
- I have added a popular used LTS version of node - 10
|
|
99
|
+
|
|
128
100
|
## v1.3.4
|
|
101
|
+
|
|
129
102
|
- **Refactoring**
|
|
130
|
-
- Add del.js and utils.js to the list of files to be beautified - [9d0ca9b](
|
|
103
|
+
- Add del.js and utils.js to the list of files to be beautified - [9d0ca9b](https://github.com/royriojas/flat-cache/commit/9d0ca9b), [Roy Riojas](https://github.com/Roy Riojas), 14/11/2018 12:19:02
|
|
131
104
|
|
|
132
|
-
|
|
133
105
|
## v1.3.3
|
|
134
|
-
- **Refactoring**
|
|
135
|
-
- Make sure package-lock.json is up to date - [a7d2598]( https://github.com/royriojas/flat-cache/commit/a7d2598 ), [Roy Riojas](https://github.com/Roy Riojas), 14/11/2018 11:36:08
|
|
136
106
|
|
|
137
|
-
|
|
107
|
+
- **Refactoring**
|
|
108
|
+
- Make sure package-lock.json is up to date - [a7d2598](https://github.com/royriojas/flat-cache/commit/a7d2598), [Roy Riojas](https://github.com/Roy Riojas), 14/11/2018 11:36:08
|
|
138
109
|
- **Other changes**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
110
|
+
|
|
111
|
+
- Removed the need for del ([#33](https://github.com/royriojas/flat-cache/issues/33)) - [c429012](https://github.com/royriojas/flat-cache/commit/c429012), [S. Gilroy](https://github.com/S. Gilroy), 13/11/2018 13:56:37
|
|
112
|
+
|
|
113
|
+
- Removed the need for del
|
|
114
|
+
|
|
115
|
+
Removed the need for del as newer versions have broken backwards
|
|
116
|
+
compatibility. del mainly uses rimraf for deleting folders
|
|
117
|
+
and files, replaceing it with rimraf only is a minimal change.
|
|
118
|
+
|
|
119
|
+
- Disable glob on rimraf calls
|
|
120
|
+
- Added glob disable to wrong call
|
|
121
|
+
- Wrapped rimraf to simplify solution
|
|
122
|
+
|
|
153
123
|
## v1.3.2
|
|
154
|
-
- **Refactoring**
|
|
155
|
-
- remove yarn.lock file - [704c6c4]( https://github.com/royriojas/flat-cache/commit/704c6c4 ), [Roy Riojas](https://github.com/Roy Riojas), 07/11/2018 15:41:08
|
|
156
124
|
|
|
157
|
-
|
|
125
|
+
- **Refactoring**
|
|
126
|
+
- remove yarn.lock file - [704c6c4](https://github.com/royriojas/flat-cache/commit/704c6c4), [Roy Riojas](https://github.com/Roy Riojas), 07/11/2018 15:41:08
|
|
158
127
|
- **Other changes**
|
|
159
|
-
|
|
128
|
+
|
|
129
|
+
- replace circular-json with flatted ([#23](https://github.com/royriojas/flat-cache/issues/23))" - [db12d74](https://github.com/royriojas/flat-cache/commit/db12d74), [Roy Riojas](https://github.com/Roy Riojas), 07/11/2018 15:40:39
|
|
160
130
|
|
|
161
131
|
This reverts commit 00f689277a75e85fef28e6a048fad227afc525e6.
|
|
162
|
-
|
|
132
|
+
|
|
163
133
|
## v1.3.1
|
|
164
|
-
- **Refactoring**
|
|
165
|
-
- upgrade deps to remove some security warnings - [f405719]( https://github.com/royriojas/flat-cache/commit/f405719 ), [Roy Riojas](https://github.com/Roy Riojas), 06/11/2018 12:07:31
|
|
166
134
|
|
|
167
|
-
|
|
135
|
+
- **Refactoring**
|
|
136
|
+
- upgrade deps to remove some security warnings - [f405719](https://github.com/royriojas/flat-cache/commit/f405719), [Roy Riojas](https://github.com/Roy Riojas), 06/11/2018 12:07:31
|
|
168
137
|
- **Bug Fixes**
|
|
169
|
-
- replace circular-json with flatted ([#23](https://github.com/royriojas/flat-cache/issues/23)) - [00f6892](
|
|
170
|
-
|
|
171
|
-
|
|
138
|
+
- replace circular-json with flatted ([#23](https://github.com/royriojas/flat-cache/issues/23)) - [00f6892](https://github.com/royriojas/flat-cache/commit/00f6892), [Terry](https://github.com/Terry), 05/11/2018 18:44:16
|
|
172
139
|
- **Other changes**
|
|
173
|
-
|
|
140
|
+
|
|
141
|
+
- update del to v3.0.0 ([#26](https://github.com/royriojas/flat-cache/issues/26)) - [d42883f](https://github.com/royriojas/flat-cache/commit/d42883f), [Patrick Silva](https://github.com/Patrick Silva), 03/11/2018 01:00:44
|
|
174
142
|
|
|
175
143
|
Closes <a target="_blank" class="info-link" href="https://github.com/royriojas/flat-cache/issues/25"><span>#25</span></a>
|
|
144
|
+
|
|
176
145
|
## v1.3.0
|
|
146
|
+
|
|
177
147
|
- **Other changes**
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
* Beautified file
|
|
191
|
-
|
|
192
|
-
- fix changelog title style ([#14](https://github.com/royriojas/flat-cache/issues/14)) - [af8338a]( https://github.com/royriojas/flat-cache/commit/af8338a ), [前端小武](https://github.com/前端小武), 19/12/2016 20:34:48
|
|
193
|
-
|
|
194
|
-
|
|
148
|
+
|
|
149
|
+
- Added #all method ([#16](https://github.com/royriojas/flat-cache/issues/16)) - [12293be](https://github.com/royriojas/flat-cache/commit/12293be), [Ozair Patel](https://github.com/Ozair Patel), 25/09/2017 14:46:38
|
|
150
|
+
|
|
151
|
+
- Added #all method
|
|
152
|
+
- Added #all method test
|
|
153
|
+
- Updated readme
|
|
154
|
+
- Added yarn.lock
|
|
155
|
+
- Added more keys for #all test
|
|
156
|
+
- Beautified file
|
|
157
|
+
|
|
158
|
+
- fix changelog title style ([#14](https://github.com/royriojas/flat-cache/issues/14)) - [af8338a](https://github.com/royriojas/flat-cache/commit/af8338a), [前端小武](https://github.com/前端小武), 19/12/2016 20:34:48
|
|
159
|
+
|
|
195
160
|
## v1.2.2
|
|
161
|
+
|
|
196
162
|
- **Bug Fixes**
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
163
|
+
|
|
164
|
+
- Do not crash if cache file is invalid JSON. ([#13](https://github.com/royriojas/flat-cache/issues/13)) - [87beaa6](https://github.com/royriojas/flat-cache/commit/87beaa6), [Roy Riojas](https://github.com/Roy Riojas), 19/12/2016 18:03:35
|
|
165
|
+
|
|
166
|
+
Fixes <a target="_blank" class="info-link" href="https://github.com/royriojas/flat-cache/issues/12"><span>#12</span></a>
|
|
167
|
+
|
|
168
|
+
Not sure under which situations a cache file might exist that does
|
|
169
|
+
not contain a valid JSON structure, but just in case to cover
|
|
170
|
+
the possibility of this happening a try catch block has been added
|
|
171
|
+
|
|
172
|
+
If the cache is somehow not valid the cache will be discarded an a
|
|
206
173
|
a new cache will be stored instead
|
|
174
|
+
|
|
207
175
|
- **Other changes**
|
|
208
|
-
- Added travis ci support for modern node versions ([#11](https://github.com/royriojas/flat-cache/issues/11)) - [1c2b1f7]( https://github.com/royriojas/flat-cache/commit/1c2b1f7 ), [Amila Welihinda](https://github.com/Amila Welihinda), 10/11/2016 23:47:52
|
|
209
176
|
|
|
210
|
-
|
|
211
|
-
- Bumping `circular-son` version ([#10](https://github.com/royriojas/flat-cache/issues/10)) - [4d5e861](
|
|
177
|
+
- Added travis ci support for modern node versions ([#11](https://github.com/royriojas/flat-cache/issues/11)) - [1c2b1f7](https://github.com/royriojas/flat-cache/commit/1c2b1f7), [Amila Welihinda](https://github.com/Amila Welihinda), 10/11/2016 23:47:52
|
|
178
|
+
- Bumping `circular-son` version ([#10](https://github.com/royriojas/flat-cache/issues/10)) - [4d5e861](https://github.com/royriojas/flat-cache/commit/4d5e861), [Andrea Giammarchi](https://github.com/Andrea Giammarchi), 02/08/2016 07:13:52
|
|
179
|
+
|
|
180
|
+
As mentioned in https://github.com/WebReflection/circular-json/issues/25 `circular-json` wan't rightly implementing the license field.
|
|
212
181
|
|
|
213
|
-
As mentioned in https://github.com/WebReflection/circular-json/issues/25 `circular-json` wan't rightly implementing the license field.
|
|
214
|
-
|
|
215
182
|
Latest version bump changed only that bit so that ESLint should now be happy.
|
|
183
|
+
|
|
216
184
|
## v1.2.1
|
|
185
|
+
|
|
217
186
|
- **Bug Fixes**
|
|
218
|
-
- Add missing utils.js file to the package. closes [#8](https://github.com/royriojas/flat-cache/issues/8) - [ec10cf2](
|
|
187
|
+
- Add missing utils.js file to the package. closes [#8](https://github.com/royriojas/flat-cache/issues/8) - [ec10cf2](https://github.com/royriojas/flat-cache/commit/ec10cf2), [Roy Riojas](https://github.com/Roy Riojas), 01/08/2016 02:18:57
|
|
219
188
|
|
|
220
|
-
|
|
221
189
|
## v1.2.0
|
|
190
|
+
|
|
222
191
|
- **Documentation**
|
|
223
|
-
- Add documentation about noPrune option - [23e11f9](
|
|
192
|
+
- Add documentation about noPrune option - [23e11f9](https://github.com/royriojas/flat-cache/commit/23e11f9), [Roy Riojas](https://github.com/Roy Riojas), 01/08/2016 02:06:49
|
|
224
193
|
|
|
225
|
-
|
|
226
194
|
## v1.0.11
|
|
195
|
+
|
|
227
196
|
- **Features**
|
|
228
|
-
- Add noPrune option to cache.save() method. closes [#7](https://github.com/royriojas/flat-cache/issues/7) - [2c8016a]( https://github.com/royriojas/flat-cache/commit/2c8016a ), [Roy Riojas](https://github.com/Roy Riojas), 01/08/2016 02:00:29
|
|
229
197
|
|
|
230
|
-
|
|
231
|
-
- Add json read and write utility based on circular-json - [c31081e](
|
|
198
|
+
- Add noPrune option to cache.save() method. closes [#7](https://github.com/royriojas/flat-cache/issues/7) - [2c8016a](https://github.com/royriojas/flat-cache/commit/2c8016a), [Roy Riojas](https://github.com/Roy Riojas), 01/08/2016 02:00:29
|
|
199
|
+
- Add json read and write utility based on circular-json - [c31081e](https://github.com/royriojas/flat-cache/commit/c31081e), [Jean Ponchon](https://github.com/Jean Ponchon), 28/07/2016 08:58:17
|
|
232
200
|
|
|
233
|
-
|
|
234
201
|
- **Bug Fixes**
|
|
235
|
-
- Remove UTF16 BOM stripping - [4a41e22]( https://github.com/royriojas/flat-cache/commit/4a41e22 ), [Jean Ponchon](https://github.com/Jean Ponchon), 29/07/2016 02:18:06
|
|
236
202
|
|
|
237
|
-
|
|
203
|
+
- Remove UTF16 BOM stripping - [4a41e22](https://github.com/royriojas/flat-cache/commit/4a41e22), [Jean Ponchon](https://github.com/Jean Ponchon), 29/07/2016 02:18:06
|
|
204
|
+
|
|
205
|
+
Since we control both writing and reading of JSON stream, there no needs
|
|
238
206
|
to handle unicode BOM.
|
|
239
|
-
- Use circular-json to handle circular references (fix [#5](https://github.com/royriojas/flat-cache/issues/5)) - [cd7aeed]( https://github.com/royriojas/flat-cache/commit/cd7aeed ), [Jean Ponchon](https://github.com/Jean Ponchon), 25/07/2016 11:11:59
|
|
240
207
|
|
|
241
|
-
|
|
208
|
+
- Use circular-json to handle circular references (fix [#5](https://github.com/royriojas/flat-cache/issues/5)) - [cd7aeed](https://github.com/royriojas/flat-cache/commit/cd7aeed), [Jean Ponchon](https://github.com/Jean Ponchon), 25/07/2016 11:11:59
|
|
209
|
+
|
|
242
210
|
- **Tests Related fixes**
|
|
243
|
-
- Add missing file from eslint test - [d6fa3c3]( https://github.com/royriojas/flat-cache/commit/d6fa3c3 ), [Jean Ponchon](https://github.com/Jean Ponchon), 29/07/2016 02:15:51
|
|
244
211
|
|
|
245
|
-
|
|
246
|
-
- Add test for circular json serialization / deserialization - [07d2ddd](
|
|
212
|
+
- Add missing file from eslint test - [d6fa3c3](https://github.com/royriojas/flat-cache/commit/d6fa3c3), [Jean Ponchon](https://github.com/Jean Ponchon), 29/07/2016 02:15:51
|
|
213
|
+
- Add test for circular json serialization / deserialization - [07d2ddd](https://github.com/royriojas/flat-cache/commit/07d2ddd), [Jean Ponchon](https://github.com/Jean Ponchon), 28/07/2016 08:59:36
|
|
247
214
|
|
|
248
|
-
|
|
249
215
|
- **Refactoring**
|
|
250
|
-
- Remove unused read-json-sync - [2be1c24](
|
|
251
|
-
|
|
252
|
-
|
|
216
|
+
- Remove unused read-json-sync - [2be1c24](https://github.com/royriojas/flat-cache/commit/2be1c24), [Jean Ponchon](https://github.com/Jean Ponchon), 28/07/2016 08:59:18
|
|
253
217
|
- **Build Scripts Changes**
|
|
254
|
-
- travis tests on 0.12 and 4x - [3a613fd](
|
|
218
|
+
- travis tests on 0.12 and 4x - [3a613fd](https://github.com/royriojas/flat-cache/commit/3a613fd), [royriojas](https://github.com/royriojas), 15/11/2015 14:34:40
|
|
255
219
|
|
|
256
|
-
|
|
257
220
|
## v1.0.10
|
|
221
|
+
|
|
258
222
|
- **Build Scripts Changes**
|
|
259
|
-
- add eslint-fix task - [fd29e52]( https://github.com/royriojas/flat-cache/commit/fd29e52 ), [royriojas](https://github.com/royriojas), 01/11/2015 15:04:08
|
|
260
223
|
|
|
261
|
-
|
|
262
|
-
- make sure the test script also verify beautification and linting of files before running tests - [e94e176](
|
|
224
|
+
- add eslint-fix task - [fd29e52](https://github.com/royriojas/flat-cache/commit/fd29e52), [royriojas](https://github.com/royriojas), 01/11/2015 15:04:08
|
|
225
|
+
- make sure the test script also verify beautification and linting of files before running tests - [e94e176](https://github.com/royriojas/flat-cache/commit/e94e176), [royriojas](https://github.com/royriojas), 01/11/2015 11:54:48
|
|
263
226
|
|
|
264
|
-
|
|
265
227
|
- **Other changes**
|
|
266
|
-
- add clearAll for cacheDir - [97383d9](
|
|
228
|
+
- add clearAll for cacheDir - [97383d9](https://github.com/royriojas/flat-cache/commit/97383d9), [xieyaowu](https://github.com/xieyaowu), 31/10/2015 21:02:18
|
|
267
229
|
|
|
268
|
-
|
|
269
230
|
## v1.0.9
|
|
231
|
+
|
|
270
232
|
- **Bug Fixes**
|
|
271
|
-
- wrong default values for changelogx user repo name - [7bb52d1](
|
|
233
|
+
- wrong default values for changelogx user repo name - [7bb52d1](https://github.com/royriojas/flat-cache/commit/7bb52d1), [royriojas](https://github.com/royriojas), 11/09/2015 15:59:30
|
|
272
234
|
|
|
273
|
-
|
|
274
235
|
## v1.0.8
|
|
236
|
+
|
|
275
237
|
- **Build Scripts Changes**
|
|
276
|
-
- test against node 4 - [c395b66](
|
|
238
|
+
- test against node 4 - [c395b66](https://github.com/royriojas/flat-cache/commit/c395b66), [royriojas](https://github.com/royriojas), 11/09/2015 15:51:39
|
|
277
239
|
|
|
278
|
-
|
|
279
240
|
## v1.0.7
|
|
280
|
-
- **Other changes**
|
|
281
|
-
- Move dependencies into devDep - [7e47099]( https://github.com/royriojas/flat-cache/commit/7e47099 ), [Bogdan Chadkin](https://github.com/Bogdan Chadkin), 11/09/2015 15:10:57
|
|
282
241
|
|
|
283
|
-
|
|
242
|
+
- **Other changes**
|
|
243
|
+
- Move dependencies into devDep - [7e47099](https://github.com/royriojas/flat-cache/commit/7e47099), [Bogdan Chadkin](https://github.com/Bogdan Chadkin), 11/09/2015 15:10:57
|
|
284
244
|
- **Documentation**
|
|
285
|
-
- Add missing changelog link - [f51197a](
|
|
245
|
+
- Add missing changelog link - [f51197a](https://github.com/royriojas/flat-cache/commit/f51197a), [royriojas](https://github.com/royriojas), 11/09/2015 14:48:05
|
|
286
246
|
|
|
287
|
-
|
|
288
247
|
## v1.0.6
|
|
248
|
+
|
|
289
249
|
- **Build Scripts Changes**
|
|
290
|
-
- Add helpers/code check scripts - [bdb82f3](
|
|
250
|
+
- Add helpers/code check scripts - [bdb82f3](https://github.com/royriojas/flat-cache/commit/bdb82f3), [royriojas](https://github.com/royriojas), 11/09/2015 14:44:31
|
|
291
251
|
|
|
292
|
-
|
|
293
252
|
## v1.0.5
|
|
294
|
-
- **Documentation**
|
|
295
|
-
- better description for the module - [436817f]( https://github.com/royriojas/flat-cache/commit/436817f ), [royriojas](https://github.com/royriojas), 11/09/2015 14:35:33
|
|
296
253
|
|
|
297
|
-
|
|
254
|
+
- **Documentation**
|
|
255
|
+
- better description for the module - [436817f](https://github.com/royriojas/flat-cache/commit/436817f), [royriojas](https://github.com/royriojas), 11/09/2015 14:35:33
|
|
298
256
|
- **Other changes**
|
|
299
|
-
- Update dependencies - [be88aa3](
|
|
257
|
+
- Update dependencies - [be88aa3](https://github.com/royriojas/flat-cache/commit/be88aa3), [Bogdan Chadkin](https://github.com/Bogdan Chadkin), 11/09/2015 13:47:41
|
|
300
258
|
|
|
301
|
-
|
|
302
259
|
## v1.0.4
|
|
303
|
-
- **Refactoring**
|
|
304
|
-
- load a cache file using the full filepath - [b8f68c2]( https://github.com/royriojas/flat-cache/commit/b8f68c2 ), [Roy Riojas](https://github.com/Roy Riojas), 30/08/2015 04:19:14
|
|
305
260
|
|
|
306
|
-
|
|
261
|
+
- **Refactoring**
|
|
262
|
+
- load a cache file using the full filepath - [b8f68c2](https://github.com/royriojas/flat-cache/commit/b8f68c2), [Roy Riojas](https://github.com/Roy Riojas), 30/08/2015 04:19:14
|
|
307
263
|
- **Documentation**
|
|
308
|
-
- Add documentation about `clearAll` and `clearCacheById` - [13947c1](
|
|
309
|
-
|
|
310
|
-
|
|
264
|
+
- Add documentation about `clearAll` and `clearCacheById` - [13947c1](https://github.com/royriojas/flat-cache/commit/13947c1), [Roy Riojas](https://github.com/Roy Riojas), 01/03/2015 23:44:05
|
|
311
265
|
- **Features**
|
|
312
|
-
- Add methods to remove the cache documents created - [af40443](
|
|
266
|
+
- Add methods to remove the cache documents created - [af40443](https://github.com/royriojas/flat-cache/commit/af40443), [Roy Riojas](https://github.com/Roy Riojas), 01/03/2015 23:39:27
|
|
313
267
|
|
|
314
|
-
|
|
315
268
|
## v1.0.1
|
|
269
|
+
|
|
316
270
|
- **Other changes**
|
|
317
|
-
- Update README.md - [c2b6805](
|
|
271
|
+
- Update README.md - [c2b6805](https://github.com/royriojas/flat-cache/commit/c2b6805), [Roy Riojas](https://github.com/Roy Riojas), 26/02/2015 04:28:07
|
|
318
272
|
|
|
319
|
-
|
|
320
273
|
## v1.0.0
|
|
321
|
-
- **Refactoring**
|
|
322
|
-
- flat-cache v.1.0.0 - [c984274]( https://github.com/royriojas/flat-cache/commit/c984274 ), [Roy Riojas](https://github.com/Roy Riojas), 26/02/2015 04:11:50
|
|
323
274
|
|
|
324
|
-
|
|
275
|
+
- **Refactoring**
|
|
276
|
+
- flat-cache v.1.0.0 - [c984274](https://github.com/royriojas/flat-cache/commit/c984274), [Roy Riojas](https://github.com/Roy Riojas), 26/02/2015 04:11:50
|
|
325
277
|
- **Other changes**
|
|
326
|
-
- Initial commit - [d43cccf](
|
|
327
|
-
|
|
328
|
-
|
|
278
|
+
- Initial commit - [d43cccf](https://github.com/royriojas/flat-cache/commit/d43cccf), [Roy Riojas](https://github.com/Roy Riojas), 26/02/2015 01:12:16
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flat-cache",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "A stupidly simple key/value storage using files to persist some data",
|
|
5
5
|
"repository": "jaredwray/flat-cache",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"verify": "npm run eslint && npm run test:cache",
|
|
33
33
|
"test:cache": "c8 mocha -R spec test/specs",
|
|
34
34
|
"test:ci:cache": "c8 --reporter=lcov mocha -R spec test/specs",
|
|
35
|
-
"test": "npm run verify --silent"
|
|
35
|
+
"test": "npm run verify --silent",
|
|
36
|
+
"format": "prettier --write ."
|
|
36
37
|
},
|
|
37
38
|
"keywords": [
|
|
38
39
|
"json cache",
|
|
@@ -43,20 +44,20 @@
|
|
|
43
44
|
"cache"
|
|
44
45
|
],
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"c8": "^
|
|
47
|
+
"c8": "^9.1.0",
|
|
47
48
|
"chai": "^4.3.10",
|
|
48
49
|
"eslint": "^8.56.0",
|
|
49
50
|
"eslint-config-prettier": "^9.1.0",
|
|
50
51
|
"eslint-plugin-mocha": "^10.2.0",
|
|
51
|
-
"eslint-plugin-prettier": "^5.0.1",
|
|
52
52
|
"glob-expand": "^0.2.1",
|
|
53
|
-
"mocha": "^10.
|
|
54
|
-
"prettier": "^3.
|
|
53
|
+
"mocha": "^10.3.0",
|
|
54
|
+
"prettier": "^3.2.4",
|
|
55
|
+
"rimraf": "^5.0.5",
|
|
56
|
+
"sinon": "^17.0.1",
|
|
55
57
|
"write": "^2.0.0"
|
|
56
58
|
},
|
|
57
59
|
"dependencies": {
|
|
58
60
|
"flatted": "^3.2.9",
|
|
59
|
-
"keyv": "^4.5.4"
|
|
60
|
-
"rimraf": "^5.0.5"
|
|
61
|
+
"keyv": "^4.5.4"
|
|
61
62
|
}
|
|
62
63
|
}
|
package/src/cache.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var cache = {
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const Keyv = require('keyv');
|
|
4
|
+
const { writeJSON, tryParse } = require('./utils');
|
|
5
|
+
const { del } = require('./del');
|
|
6
|
+
|
|
7
|
+
const cache = {
|
|
9
8
|
/**
|
|
10
9
|
* Load a cache identified by the given Id. If the element does not exists, then initialize an empty
|
|
11
10
|
* cache storage. If specified `cacheDir` will be used as the directory to persist the data to. If omitted
|
|
@@ -16,16 +15,16 @@ var cache = {
|
|
|
16
15
|
* @param [cacheDir] {String} directory for the cache entry
|
|
17
16
|
*/
|
|
18
17
|
load: function (docId, cacheDir) {
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const me = this;
|
|
21
19
|
me.keyv = new Keyv();
|
|
22
20
|
|
|
23
21
|
me.__visited = {};
|
|
24
22
|
me.__persisted = {};
|
|
23
|
+
|
|
25
24
|
me._pathToFile = cacheDir ? path.resolve(cacheDir, docId) : path.resolve(__dirname, '../.cache/', docId);
|
|
26
25
|
|
|
27
26
|
if (fs.existsSync(me._pathToFile)) {
|
|
28
|
-
me._persisted =
|
|
27
|
+
me._persisted = tryParse(me._pathToFile, {});
|
|
29
28
|
}
|
|
30
29
|
},
|
|
31
30
|
|
|
@@ -35,7 +34,6 @@ var cache = {
|
|
|
35
34
|
|
|
36
35
|
set _persisted(value) {
|
|
37
36
|
this.__persisted = value;
|
|
38
|
-
this.keyv.set('persisted', value);
|
|
39
37
|
},
|
|
40
38
|
|
|
41
39
|
get _visited() {
|
|
@@ -44,7 +42,6 @@ var cache = {
|
|
|
44
42
|
|
|
45
43
|
set _visited(value) {
|
|
46
44
|
this.__visited = value;
|
|
47
|
-
this.keyv.set('visited', value);
|
|
48
45
|
},
|
|
49
46
|
|
|
50
47
|
/**
|
|
@@ -53,9 +50,9 @@ var cache = {
|
|
|
53
50
|
* @param {String} pathToFile the path to the file containing the info for the cache
|
|
54
51
|
*/
|
|
55
52
|
loadFile: function (pathToFile) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
const me = this;
|
|
54
|
+
const dir = path.dirname(pathToFile);
|
|
55
|
+
const fName = path.basename(pathToFile);
|
|
59
56
|
|
|
60
57
|
me.load(fName, dir);
|
|
61
58
|
},
|
|
@@ -109,10 +106,10 @@ var cache = {
|
|
|
109
106
|
* @private
|
|
110
107
|
*/
|
|
111
108
|
_prune: function () {
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
const me = this;
|
|
110
|
+
const obj = {};
|
|
114
111
|
|
|
115
|
-
|
|
112
|
+
const keys = Object.keys(me._visited);
|
|
116
113
|
|
|
117
114
|
// no keys visited for either get or set value
|
|
118
115
|
if (keys.length === 0) {
|
|
@@ -134,8 +131,7 @@ var cache = {
|
|
|
134
131
|
* @method save
|
|
135
132
|
*/
|
|
136
133
|
save: function (noPrune) {
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
const me = this;
|
|
139
135
|
!noPrune && me._prune();
|
|
140
136
|
writeJSON(me._pathToFile, me._persisted);
|
|
141
137
|
},
|
|
@@ -153,7 +149,7 @@ var cache = {
|
|
|
153
149
|
* @method destroy
|
|
154
150
|
*/
|
|
155
151
|
destroy: function () {
|
|
156
|
-
|
|
152
|
+
const me = this;
|
|
157
153
|
me._visited = {};
|
|
158
154
|
me._persisted = {};
|
|
159
155
|
|
|
@@ -184,13 +180,13 @@ module.exports = {
|
|
|
184
180
|
* @returns {cache} cache instance
|
|
185
181
|
*/
|
|
186
182
|
create: function (docId, cacheDir) {
|
|
187
|
-
|
|
183
|
+
const obj = Object.create(cache);
|
|
188
184
|
obj.load(docId, cacheDir);
|
|
189
185
|
return obj;
|
|
190
186
|
},
|
|
191
187
|
|
|
192
188
|
createFromFile: function (filePath) {
|
|
193
|
-
|
|
189
|
+
const obj = Object.create(cache);
|
|
194
190
|
obj.loadFile(filePath);
|
|
195
191
|
return obj;
|
|
196
192
|
},
|
|
@@ -203,7 +199,7 @@ module.exports = {
|
|
|
203
199
|
* @returns {Boolean} true if the cache folder was deleted. False otherwise
|
|
204
200
|
*/
|
|
205
201
|
clearCacheById: function (docId, cacheDir) {
|
|
206
|
-
|
|
202
|
+
const filePath = cacheDir ? path.resolve(cacheDir, docId) : path.resolve(__dirname, '../.cache/', docId);
|
|
207
203
|
return del(filePath);
|
|
208
204
|
},
|
|
209
205
|
/**
|
|
@@ -212,7 +208,7 @@ module.exports = {
|
|
|
212
208
|
* @returns {Boolean} true if the cache folder was deleted. False otherwise
|
|
213
209
|
*/
|
|
214
210
|
clearAll: function (cacheDir) {
|
|
215
|
-
|
|
211
|
+
const filePath = cacheDir ? path.resolve(cacheDir) : path.resolve(__dirname, '../.cache/');
|
|
216
212
|
return del(filePath);
|
|
217
213
|
},
|
|
218
214
|
};
|
package/src/del.js
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (fs.existsSync(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
function del(targetPath) {
|
|
5
|
+
if (!fs.existsSync(targetPath)) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
if (fs.statSync(targetPath).isDirectory()) {
|
|
11
|
+
// If it's a directory, delete its contents first
|
|
12
|
+
fs.readdirSync(targetPath).forEach(file => {
|
|
13
|
+
const curPath = path.join(targetPath, file);
|
|
14
|
+
|
|
15
|
+
if (fs.statSync(curPath).isFile()) {
|
|
16
|
+
fs.unlinkSync(curPath); // Delete file
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
fs.rmdirSync(targetPath); // Delete the now-empty directory
|
|
20
|
+
} else {
|
|
21
|
+
fs.unlinkSync(targetPath); // If it's a file, delete it directly
|
|
22
|
+
}
|
|
23
|
+
|
|
10
24
|
return true;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(`Error while deleting ${targetPath}: ${error.message}`);
|
|
11
27
|
}
|
|
12
|
-
|
|
13
|
-
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = { del };
|
package/src/utils.js
CHANGED
|
@@ -1,44 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const flatted = require('flatted');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
5
|
+
function tryParse(filePath, defaultValue) {
|
|
6
|
+
let result;
|
|
7
|
+
try {
|
|
8
|
+
result = readJSON(filePath);
|
|
9
|
+
} catch (ex) {
|
|
10
|
+
result = defaultValue;
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
15
|
+
/**
|
|
16
|
+
* Read json file synchronously using flatted
|
|
17
|
+
*
|
|
18
|
+
* @param {String} filePath Json filepath
|
|
19
|
+
* @returns {*} parse result
|
|
20
|
+
*/
|
|
21
|
+
function readJSON(filePath) {
|
|
22
|
+
return flatted.parse(
|
|
23
|
+
fs.readFileSync(filePath, {
|
|
24
|
+
encoding: 'utf8',
|
|
25
|
+
})
|
|
26
|
+
);
|
|
27
|
+
}
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
29
|
+
/**
|
|
30
|
+
* Write json file synchronously using circular-json
|
|
31
|
+
*
|
|
32
|
+
* @param {String} filePath Json filepath
|
|
33
|
+
* @param {*} data Object to serialize
|
|
34
|
+
*/
|
|
35
|
+
function writeJSON(filePath, data) {
|
|
36
|
+
fs.mkdirSync(path.dirname(filePath), {
|
|
37
|
+
recursive: true,
|
|
38
|
+
});
|
|
39
|
+
fs.writeFileSync(filePath, flatted.stringify(data));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = { tryParse, readJSON, writeJSON };
|