-
Notifications
You must be signed in to change notification settings - Fork 2
/
sync.js
28 lines (24 loc) · 1.04 KB
/
sync.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* Sync the changes from the main Slidev repository to this repo
* https://stackoverflow.com/a/63745988
*
* Use `bun sync.js` to run this script
*/
/* eslint-disable no-console */
import process from 'node:process'
import { $ } from 'bun'
await $`git remote rm slidev`
await $`git remote add slidev https://github.com/slidevjs/slidev`
await $`git fetch slidev main`
console.log('\nTimestamp of last commit:')
const { stdout: timestamp } = await $`git log -1 --format="%at" main`
console.log('\nCommits since last time:')
const { stdout: hashes } = await $`git log --since="${+(timestamp.toString()) + 1}" slidev/main --format="%H"`
const firstHash = hashes.toString().trim().split('\n').at(-1)
if (!firstHash) {
console.log('No changes to sync')
process.exit(0)
}
const command = `git format-patch -k --stdout ${firstHash}...slidev/main --remove-empty -- docs | git am -3 -k --empty=drop`
console.log('\nRunning command:', command)
await $`git format-patch -k --stdout ${firstHash}...slidev/main --remove-empty -- docs | git am -3 -k --empty=drop`