File tree 1 file changed +14
-10
lines changed 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -156,23 +156,27 @@ module.exports = function (argv) {
156
156
if ( is . URL ( source ) ) throw new Error ( 'Can\'t watch URL' )
157
157
158
158
// Watch .js or .json file
159
+ // Since lowdb uses atomic writing, directory is watched instead of file
159
160
chokidar
160
- . watch ( source )
161
+ . watch ( path . dirname ( source ) )
161
162
. on ( 'change' , function ( file ) {
162
- if ( is . JSON ( file ) ) {
163
- var obj = JSON . parse ( fs . readFileSync ( file ) )
164
- // Compare .json file content with in memory database
165
- var isDatabaseDifferent = ! _ . eq ( obj , app . db . getState ( ) )
166
- if ( isDatabaseDifferent ) {
163
+ if ( file === source ) {
164
+ if ( is . JSON ( file ) ) {
165
+ console . log ( file , fs . readFileSync ( file ) )
166
+ var obj = JSON . parse ( fs . readFileSync ( file ) )
167
+ // Compare .json file content with in memory database
168
+ var isDatabaseDifferent = ! _ . eq ( obj , app . db . getState ( ) )
169
+ if ( isDatabaseDifferent ) {
170
+ console . log ( chalk . gray ( ' ' + file + ' has changed, reloading...' ) )
171
+ server && server . destroy ( )
172
+ start ( )
173
+ }
174
+ } else {
167
175
console . log ( chalk . gray ( ' ' + file + ' has changed, reloading...' ) )
168
176
server && server . destroy ( )
169
177
start ( )
170
178
}
171
- return
172
179
}
173
-
174
- server && server . destroy ( )
175
- start ( )
176
180
} )
177
181
178
182
// Watch routes
You can’t perform that action at this time.
0 commit comments