Fork of Chiri for Astro for my blog
1#!/usr/bin/env tsx
2
3/**
4 * Update theme from upstream repository
5 * Usage: pnpm update-theme
6 */
7
8import { execSync } from 'node:child_process'
9import fs from 'node:fs'
10import path from 'node:path'
11import process from 'node:process'
12
13// Check and set up the upstream remote repository
14try {
15 execSync('git remote get-url upstream', { stdio: 'ignore' })
16} catch {
17 execSync('git remote add upstream https://github.com/the3ash/astro-chiri.git', {
18 stdio: 'inherit'
19 })
20}
21
22// Update theme from upstream repository
23try {
24 execSync('git fetch upstream', { stdio: 'inherit' })
25
26 const currentCommit = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim()
27 execSync('git merge upstream/main --allow-unrelated-histories', { stdio: 'inherit' })
28 const newCommit = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim()
29
30 if (currentCommit === newCommit) {
31 console.log('🤗 No updates available, already up to date')
32 } else {
33 console.log('✅ Theme updated')
34 }
35} catch (error) {
36 // Check if there's a merge conflict
37 const gitDirectory = execSync('git rev-parse --git-dir', { encoding: 'utf8' }).trim()
38 const mergeHeadFile = path.join(gitDirectory, 'MERGE_HEAD')
39
40 if (fs.existsSync(mergeHeadFile)) {
41 console.log('⚠️ Update fetched with merge conflicts. Please resolve manually')
42 } else {
43 console.error('❌ Update failed:', error)
44 process.exit(1)
45 }
46}