@@ -29,11 +29,11 @@ const getPages = (target) => {
2929 const settings = JSON . parse ( readFileSync ( settingsPath ) ) ;
3030 const targetSlugs = settings . slugs . join ( ',' ) ;
3131
32- console . log ( `Fetching data from ${ normalizedTarget } ...\n` ) ;
32+ console . log ( `Fetching data from ${ normalizedTarget } ...\n\n ` ) ;
3333
3434 return new Promise ( ( resolve , reject ) => {
3535 client . pages
36- . browse ( { filter : `slug:[${ targetSlugs } ]` } )
36+ . browse ( { filter : `slug:[${ targetSlugs } ]` , limit : 1000 } )
3737 . then ( ( pages ) => {
3838 const jsonString = `{ "pages": ${ JSON . stringify ( pages ) } }` ;
3939 writeFileSync ( dataPath , jsonString , { flag : 'a' } ) ;
@@ -46,16 +46,31 @@ const getPages = (target) => {
4646const cleanTmpFile = ( target ) => {
4747 const relativePath = `tmp/${ target . toLowerCase ( ) } .json` ;
4848
49- console . log ( `Removing "${ relativePath } "...\n` ) ;
49+ console . log ( `Removing "${ relativePath } "...\n\n ` ) ;
5050 rmSync ( join ( process . cwd ( ) , relativePath ) ) ;
5151} ;
5252
53- getPages ( STAGING ) . then ( ( ) => {
54- getPages ( PRODUCTION )
55- . then ( ( ) => {
56- cleanTmpFile ( STAGING ) ;
57- } )
58- . then ( ( ) => {
59- cleanTmpFile ( PRODUCTION ) ;
53+ const moveToProduction = ( ) => {
54+ const stagingDataPath = join ( process . cwd ( ) , 'tmp/staging.json' ) ;
55+ const stagingData = JSON . parse ( readFileSync ( stagingDataPath ) ) . pages ;
56+
57+ console . log ( `Adding page copies from ${ STAGING } to ${ PRODUCTION } ...\n\n` ) ;
58+
59+ return new Promise ( ( resolve ) => {
60+ stagingData . forEach ( ( stagingPage ) => {
61+ clientProduction . pages . add ( {
62+ lexical : stagingPage . lexical ,
63+ status : 'published' ,
64+ title : stagingPage . title ,
65+ published_at : stagingPage . published_at ,
66+ } ) ;
67+ resolve ( ) ;
6068 } ) ;
69+ } ) ;
70+ } ;
71+
72+ getPages ( STAGING ) . then ( ( ) => {
73+ moveToProduction ( ) . then ( ( ) => {
74+ cleanTmpFile ( STAGING ) ;
75+ } ) ;
6176} ) ;
0 commit comments