import child_process from 'child_process'
function getNow () {
const d = new Date()
const year = d.getFullYear()
const month = d.getMonth() + 1
const date = d.getDate()
const hour = d.getHours()
const minute = d.getMinutes()
const second = d.getSeconds()
return `${year}/${month}/${date} ${hour}:${minute}:${second}`
}
try {
const [, , commitTitle] = process.argv
const commands = [
'git config user.name',
'git config user.email',
'git add .',
`git commit -m "${commitTitle || 'mac2021 commit: ' + getNow()}"`,
'git pull',
'git push'
]
child_process.execSync(commands.join(' && '), {
stdio: 'inherit'
})
} catch (error) {
console.log('error: ', error)
}
#!/bin/bash
commit_title="$1"
if [ -z "$commit_title" ]; then
commit_title="commit: $(date +'%Y-%m-%d %H:%M:%S')"
fi
commands=(
'git config user.name'
'git config user.email'
'git add .'
"git commit -m \"$commit_title\""
'git pull'
'git push'
)
try() {
local cmd
for cmd in "${commands[@]}"; do
echo "🚀 执行命令: $cmd"
eval "$cmd" || return 1
done
}
if try; then
echo "✅ 所有操作成功完成!"
else
echo "❌ 操作失败(具体错误已在上方输出)" >&2
exit 1
fi