File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,14 @@ export class Database extends Hookable {
4545 }
4646 }
4747
48+ async toJSON ( ) {
49+ const omit = ( key , val ) => this . omitKeys . includes ( key ) ? undefined : val
50+ const sort = ( a , b ) => a . path . localeCompare ( b . path )
51+ const data = ( await this . db . find ( { } ) . toArray ( ) ) . sort ( sort )
52+
53+ return JSON . stringify ( data , omit )
54+ }
55+
4856 async init ( ) {
4957 const startTime = process . hrtime ( )
5058
@@ -71,9 +79,7 @@ export class Database extends Hookable {
7179 filename = filename || this . name
7280
7381 const path = join ( dir , filename )
74- const data = await this . db . find ( { } ) . toArray ( )
75- const omit = ( key , val ) => this . omitKeys . includes ( key ) ? undefined : val
76- const json = JSON . stringify ( data , omit )
82+ const json = await this . toJSON ( )
7783
7884 await fs . mkdir ( dir , { recursive : true } )
7985 await fs . writeFile ( path , json , 'utf-8' )
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ export default defineNuxtModule({
5656
5757 await database . init ( )
5858
59- const dbHash = hash ( database . db )
59+ const dbHash = hash ( await database . toJSON ( ) )
6060 const dbName = `db-${ dbHash } .json`
6161 const dbUrl = joinURL ( baseURL , dbFolder , dbName )
6262 const dbPath = resolve ( pubDir , dbName )
You can’t perform that action at this time.
0 commit comments