Skip to content

Add push option to export CLI #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -52,6 +52,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 @@ -64,9 +67,11 @@ 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()

if (this.treemap || this.stats) if (!exporter.pageTree) await exporter.loadRaw()

Expand Down
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
Preview

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