From 3aa9b19b841e08dd46761bbfada82cc6672600b7 Mon Sep 17 00:00:00 2001 From: Seonglae Cho <sungle3737@gmail.com> Date: Fri, 6 Jun 2025 15:50:28 +0100 Subject: [PATCH 1/2] feat(cli): add push option for export --- packages/cli/src/notion/export.ts | 7 ++++++- packages/cli/src/notion/index.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/notion/export.ts b/packages/cli/src/notion/export.ts index bd2c68fc..09604f05 100644 --- a/packages/cli/src/notion/export.ts +++ b/packages/cli/src/notion/export.ts @@ -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({ @@ -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.push() } } diff --git a/packages/cli/src/notion/index.ts b/packages/cli/src/notion/index.ts index 7f88efbe..47313557 100644 --- a/packages/cli/src/notion/index.ts +++ b/packages/cli/src/notion/index.ts @@ -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' @@ -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 @@ -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 @@ -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 () => {} @@ -713,6 +717,31 @@ export class NotionExporter { } return space } + + push() { + const run = (cmd: string, cwd: string) => { + try { + execSync(cmd, { cwd, stdio: 'ignore' }) + } catch {} + } + 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( From 4c846718f76d692610f33cec14e5cd449fc255cc Mon Sep 17 00:00:00 2001 From: Seonglae Cho <sungle3737@gmail.com> Date: Sat, 7 Jun 2025 18:24:42 +0100 Subject: [PATCH 2/2] Fix push option naming --- packages/cli/src/notion/export.ts | 2 +- packages/cli/src/notion/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/notion/export.ts b/packages/cli/src/notion/export.ts index 09604f05..23bd77f6 100644 --- a/packages/cli/src/notion/export.ts +++ b/packages/cli/src/notion/export.ts @@ -63,6 +63,6 @@ export class NotionExportCommand extends Command { push: this.push }) await exporter.execute() - if (this.push) await exporter.push() + if (this.push) await exporter.pushRepos() } } diff --git a/packages/cli/src/notion/index.ts b/packages/cli/src/notion/index.ts index 47313557..26fb19c0 100644 --- a/packages/cli/src/notion/index.ts +++ b/packages/cli/src/notion/index.ts @@ -718,7 +718,7 @@ export class NotionExporter { return space } - push() { + pushRepos() { const run = (cmd: string, cwd: string) => { try { execSync(cmd, { cwd, stdio: 'ignore' })