Skip to content

Commit 9356d07

Browse files
committed
Added gitCmd init, replaced execSync w/ safer spawnSync, bumped bump.mjs
1 parent 3ddc8db commit 9356d07

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

utils/bump/chatbots.mjs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// NOTE: Pass <--commit-msg|-m> "msg" to commit w/ msg
77
// NOTE: Pass <--no-push|-np> to skip git push
88

9-
import { execSync, spawnSync } from 'child_process'
9+
import { spawnSync } from 'child_process'
1010
import fs from 'fs'
1111
import path from 'path'
1212

@@ -19,15 +19,16 @@ const script = {
1919
cache: args.some(arg => arg.startsWith('--cache')),
2020
commitMsg: (() => {
2121
const idx = args.findIndex(arg => ['--commit-msg', '-m'].includes(arg))
22-
return idx != -1 && args[idx +1] ? args[idx +1].replace(/^"|"$/g, '') : null
22+
return idx != -1 && args[idx+1] ? args[idx+1].replace(/^"|"$/g, '') : null
2323
})(),
2424
noPush: args.some(arg => ['--no-push', '-np'].includes(arg))
2525
},
26-
urls: { bumpmjs: 'https://cdn.jsdelivr.net/gh/adamlui/ai-web-extensions@0f3fc32/utils/bump/lib/bump.min.mjs' }
26+
urls: { bumpmjs: 'https://cdn.jsdelivr.net/gh/adamlui/ai-web-extensions@c664f09/utils/bump/lib/bump.min.mjs' }
2727
}
2828
script.cache.paths.bumpmjs = path.join(process.cwd(), `${script.cache.paths.root}/bump.min.mjs`)
2929
script.cache.paths.chatbots = path.join(process.cwd(), `${script.cache.paths.root}/chatbots.json`)
3030
const { cache: { paths: cachePaths }} = script
31+
const gitCmd = process.platform == 'win32' ? 'git' : '/usr/bin/git' // same as your ext script
3132

3233
// Import bump.mjs
3334
fs.mkdirSync(path.dirname(cachePaths.bumpmjs), { recursive: true })
@@ -59,8 +60,7 @@ if (script.config.cache) {
5960
log.break()
6061
}
6162

62-
let filesUpdatedCnt = 0
63-
const bumpedChatbots = {}
63+
const bumpedChatbots = {} ; let filesUpdatedCnt = 0
6464
for (const chatbotFile of chatbotFiles) {
6565
const chatbotName = path.basename(chatbotFile, '.user.js')
6666
log.working(`\nProcessing ${chatbotName}...\n`)
@@ -86,15 +86,16 @@ if (filesUpdatedCnt == 0) {
8686
if (script.config.commitMsg) {
8787
log.working(`\nCommitting bump${pluralSuffix} to Git...\n`)
8888
try {
89-
execSync('git add ./*.user.js')
90-
initKudoSyncBot()
91-
spawnSync('git', ['commit', '-n', '-m', script.config.commitMsg], { stdio: 'inherit', encoding: 'utf-8' })
89+
spawnSync(gitCmd, ['add', ...Object.keys(bumpedChatbots)], { stdio: 'inherit', encoding: 'utf-8' })
90+
spawnSync(gitCmd, [
91+
'-c', `user.signingkey=${initKudoSyncBot()}`, 'commit', '-n', '-m', script.config.commitMsg
92+
], { stdio: 'inherit', encoding: 'utf-8' })
9293
log.break()
9394
if (!script.config.noPush) {
9495
log.working('\nPulling latest changes from remote to sync local repository...\n')
95-
execSync('git pull')
96+
spawnSync(gitCmd, ['pull', '--rebase'], { stdio: 'inherit', encoding: 'utf-8' })
9697
log.working(`\nPushing bump${pluralSuffix} to Git...\n`)
97-
execSync('git push')
98+
spawnSync(gitCmd, ['push'], { stdio: 'inherit', encoding: 'utf-8' })
9899
}
99100
log.success(`Success! ${filesUpdatedCnt} chatbot${pluralSuffix} updated/committed${
100101
!script.config.noPush ? '/pushed' : ''} to GitHub`)

0 commit comments

Comments
 (0)