Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/cli/src/notion/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export class NotionExportCommand extends Command {
wait = Option.Counter('-w,--wait', {
description: 'Wait couter for missed collection view'
})
push = Option.Boolean('--push', {
description: 'Push exported data to remote repositories'
})

async execute() {
const exporter = new NotionExporter({
Expand All @@ -56,8 +59,10 @@ export class NotionExportCommand extends Command {
load: this.load,
raw: this.raw,
dataset: this.dataset,
token: this.token
token: this.token,
push: this.push
})
await exporter.execute()
if (this.push) await exporter.pushRepos()
}
}
29 changes: 29 additions & 0 deletions packages/cli/src/notion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { mkdir, readFile } from 'fs/promises'
import JSONStream from 'JSONStream'
import fs from 'graceful-fs'
import { promisify } from 'util'
import { execSync } from 'child_process'
import stream from 'stream'
import { format } from 'prettier'
import { isCollection, isSpace } from '@texonom/ntypes'
Expand Down Expand Up @@ -51,6 +52,7 @@ export class NotionExporter {
load: boolean = false
raw: boolean = false
dataset: boolean = false
push: boolean = false
debug: boolean = false
wait: number = 5
token: string | undefined
Expand All @@ -68,6 +70,7 @@ export class NotionExporter {
raw?: boolean
dataset?: boolean
token?: string
push?: boolean
}) {
this.page = parsePageId(options.page)
this.folder = options.folder ?? this.folder
Expand All @@ -81,6 +84,7 @@ export class NotionExporter {
this.raw = options.raw ?? this.raw
this.dataset = options.dataset ?? this.dataset
this.token = options.token
this.push = options.push ?? this.push

this.notion = new NotionAPI({ authToken: this.token })
if (this.validation) writeFile = async () => {}
Expand Down Expand Up @@ -713,6 +717,31 @@ export class NotionExporter {
}
return space
}

pushRepos() {
const run = (cmd: string, cwd: string) => {
try {
execSync(cmd, { cwd, stdio: 'ignore' })
} catch {}
Copy link

Copilot AI Jun 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silently swallowing errors makes debugging push failures difficult; consider logging caught exceptions or at least printing a warning.

Suggested change
} catch {}
} catch (error) {
console.error(`Failed to execute command "${cmd}" in directory "${cwd}":`, error.message);
}

Copilot uses AI. Check for mistakes.
}
const message = new Date().toString()

// push raw
run('git init', this.folder)
run('git add .', this.folder)
run(`git commit -m "${message}"`, this.folder)
run('git branch -M main', this.folder)
run('git remote add origin https://github.com/texonom/texonom-raw.git', this.folder)
run('git push -u origin main --force', this.folder)

// push md
run('git init', this.md)
run('git add .', this.md)
run(`git commit -m "${message}"`, this.md)
run('git branch -M main', this.md)
run('git remote add origin https://github.com/texonom/texonom-md.git', this.md)
run('git push -u origin main --force', this.md)
}
}

export async function loadRaw(
Expand Down
Loading