-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
3aa9b19
4c84671
da5a807
d2505be
6f52c6a
b60b1c5
6319e1f
b3abde1
22b5247
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,33 @@ export class NotionExporter { | |
| } | ||
| return space | ||
| } | ||
|
|
||
| pushRepos() { | ||
| const run = (cmd: string, cwd: string) => { | ||
| try { | ||
| execSync(cmd, { cwd, stdio: 'ignore' }) | ||
| } catch { | ||
| // Ignore errors - some commands may fail (e.g., remote already exists) | ||
| } | ||
| } | ||
| 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) | ||
seonglae marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+721
to
+745
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Check if the file exists
fd "index.ts" packages/cli/src/notion/
# Get line count to verify the file size
wc -l packages/cli/src/notion/index.tsRepository: texonom/notion-node Length of output: 132 🏁 Script executed: # Read the specific lines mentioned in the review (721-745)
sed -n '721,745p' packages/cli/src/notion/index.tsRepository: texonom/notion-node Length of output: 958 🏁 Script executed: # Get broader context around the pushRepos function
sed -n '710,760p' packages/cli/src/notion/index.tsRepository: texonom/notion-node Length of output: 2190 🏁 Script executed: # Search for where pushRepos is called
rg "pushRepos" packages/cli/src/notion/index.tsRepository: texonom/notion-node Length of output: 78 🏁 Script executed: # Get more context - find the class definition
sed -n '650,730p' packages/cli/src/notion/index.ts | head -100Repository: texonom/notion-node Length of output: 3421 🏁 Script executed: # Check imports at the top of the file
head -50 packages/cli/src/notion/index.tsRepository: texonom/notion-node Length of output: 1455 🏁 Script executed: # Search for pushRepos usage in the entire codebase
rg "pushRepos" --type tsRepository: texonom/notion-node Length of output: 191 Avoid silent failures and hard force-pushes in Swallowing all exec errors makes failed pushes look successful, and 🔧 Safer push flow- const run = (cmd: string, cwd: string) => {
+ const run = (cmd: string, cwd: string, allowFailure = false) => {
try {
- execSync(cmd, { cwd, stdio: 'ignore' })
- } catch {
- // Ignore errors - some commands may fail (e.g., remote already exists)
+ execSync(cmd, { cwd, stdio: 'inherit' })
+ } catch (err) {
+ if (allowFailure) {
+ console.warn(`[push] ${cmd} failed in ${cwd}`, err)
+ return
+ }
+ throw err
}
}
@@
- run('git remote add origin https://github.com/texonom/texonom-raw.git', this.folder)
- run('git push -u origin main --force', this.folder)
+ run('git remote add origin https://github.com/texonom/texonom-raw.git', this.folder, true)
+ run('git push -u origin main --force-with-lease', this.folder)
@@
- run('git remote add origin https://github.com/texonom/texonom-md.git', this.md)
- run('git push -u origin main --force', this.md)
+ run('git remote add origin https://github.com/texonom/texonom-md.git', this.md, true)
+ run('git push -u origin main --force-with-lease', this.md)🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
|
|
||
| export async function loadRaw( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.