@@ -16,6 +16,7 @@ import { mkdir, readFile } from 'fs/promises'
1616import JSONStream from 'JSONStream'
1717import fs from 'graceful-fs'
1818import { promisify } from 'util'
19+ import { execSync } from 'child_process'
1920import stream from 'stream'
2021import { format } from 'prettier'
2122import { isCollection , isSpace } from '@texonom/ntypes'
@@ -51,6 +52,7 @@ export class NotionExporter {
5152 load : boolean = false
5253 raw : boolean = false
5354 dataset : boolean = false
55+ push : boolean = false
5456 debug : boolean = false
5557 wait : number = 5
5658 token : string | undefined
@@ -68,6 +70,7 @@ export class NotionExporter {
6870 raw ?: boolean
6971 dataset ?: boolean
7072 token ?: string
73+ push ?: boolean
7174 } ) {
7275 this . page = parsePageId ( options . page )
7376 this . folder = options . folder ?? this . folder
@@ -81,6 +84,7 @@ export class NotionExporter {
8184 this . raw = options . raw ?? this . raw
8285 this . dataset = options . dataset ?? this . dataset
8386 this . token = options . token
87+ this . push = options . push ?? this . push
8488
8589 this . notion = new NotionAPI ( { authToken : this . token } )
8690 if ( this . validation ) writeFile = async ( ) => { }
@@ -713,6 +717,31 @@ export class NotionExporter {
713717 }
714718 return space
715719 }
720+
721+ push ( ) {
722+ const run = ( cmd : string , cwd : string ) => {
723+ try {
724+ execSync ( cmd , { cwd, stdio : 'ignore' } )
725+ } catch { }
726+ }
727+ const message = new Date ( ) . toString ( )
728+
729+ // push raw
730+ run ( 'git init' , this . folder )
731+ run ( 'git add .' , this . folder )
732+ run ( `git commit -m "${ message } "` , this . folder )
733+ run ( 'git branch -M main' , this . folder )
734+ run ( 'git remote add origin https://github.com/texonom/texonom-raw.git' , this . folder )
735+ run ( 'git push -u origin main --force' , this . folder )
736+
737+ // push md
738+ run ( 'git init' , this . md )
739+ run ( 'git add .' , this . md )
740+ run ( `git commit -m "${ message } "` , this . md )
741+ run ( 'git branch -M main' , this . md )
742+ run ( 'git remote add origin https://github.com/texonom/texonom-md.git' , this . md )
743+ run ( 'git push -u origin main --force' , this . md )
744+ }
716745}
717746
718747export async function loadRaw (
0 commit comments