File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /* eslint-disable no-console */
2+ const { PrismaClient } = require ( "@prisma/client" ) ;
3+ const fs = require ( "fs" ) ;
4+ const path = require ( "path" ) ;
5+
6+ const prisma = new PrismaClient ( ) ;
7+
8+ async function main ( ) {
9+ const pages = await prisma . page . findMany ( {
10+ include : {
11+ finalDraft : true ,
12+ } ,
13+ } ) ;
14+
15+ const output = { } ;
16+
17+ for ( const page of pages ) {
18+ if ( ! page . finalDraft ) {
19+ console . warn ( `Skipping "${ page . name } " (${ page . path } ) — no published draft.` ) ;
20+ continue ;
21+ }
22+
23+ output [ page . path ] = page . finalDraft . content ;
24+ }
25+
26+ const count = Object . keys ( output ) . length ;
27+
28+ if ( count === 0 ) {
29+ console . warn ( "No published pages found." ) ;
30+ return ;
31+ }
32+
33+ const json = JSON . stringify ( output , null , 4 ) + "\n" ;
34+ const outputPath = process . argv [ 2 ] ;
35+
36+ if ( outputPath ) {
37+ fs . writeFileSync ( path . resolve ( outputPath ) , json , "utf-8" ) ;
38+ console . info ( `Dumped ${ count } page(s) to ${ outputPath } ` ) ;
39+ } else {
40+ process . stdout . write ( json ) ;
41+ }
42+ }
43+
44+ main ( )
45+ . catch ( ( error ) => {
46+ console . error ( "Failed to dump database" , error ) ;
47+ process . exit ( 1 ) ;
48+ } )
49+ . finally ( async ( ) => {
50+ await prisma . $disconnect ( ) ;
51+ } ) ;
You can’t perform that action at this time.
0 commit comments