File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 11import { join , extname } from 'pathe'
2+ import { hash } from 'ohash'
23import { promises as fs } from 'fs'
34
45import fsDriver from 'unstorage/drivers/fs'
@@ -52,6 +53,16 @@ export class Database extends Hookable {
5253 return JSON . stringify ( data , omit )
5354 }
5455
56+ async toHash ( ) {
57+ const keys = [ 'createdAt' , 'updatedAt' , ...this . omitKeys ]
58+ const omit = ( key , val ) => keys . includes ( key ) ? undefined : val
59+
60+ const sort = ( a , b ) => a . path . localeCompare ( b . path )
61+ const data = ( await this . db . find ( { } ) . toArray ( ) ) . sort ( sort )
62+
63+ return hash ( JSON . stringify ( data , omit ) )
64+ }
65+
5566 async init ( ) {
5667 const startTime = process . hrtime ( )
5768
Original file line number Diff line number Diff line change 11import { fileURLToPath } from 'url'
22import { resolve , join } from 'pathe'
33import { joinURL } from 'ufo'
4- import { hash } from 'ohash'
54import { defineNuxtModule , extendViteConfig , updateTemplates } from '@nuxt/kit'
65import { addPlugin , addImports , addComponent , addTemplate } from '@nuxt/kit'
76import { Database } from './builder'
@@ -56,7 +55,7 @@ export default defineNuxtModule({
5655
5756 await database . init ( )
5857
59- const dbHash = hash ( await database . toJSON ( ) )
58+ const dbHash = await database . toHash ( )
6059 const dbName = `db-${ dbHash } .json`
6160 const dbUrl = joinURL ( baseURL , dbFolder , dbName )
6261 const dbPath = resolve ( pubDir , dbName )
You can’t perform that action at this time.
0 commit comments