node.js 定時執行git pull


node.js 定時執行git pull
有時候需要定時執行git pull 的操作
效果圖:

示例代碼:

let fs = require('fs');
let child_process = require('child_process');
let sd = require('silly-datetime');

const argv = process.argv

if (argv.length <= 2) {
    console.log("請指定目標地址!--->例如:node gitpull.js 'D:\\xxx\\xxxx' ")
    return
}
const githref = argv[2]

if (argv.length <= 3) {
  console.log("請指定腳本執行間隔時間!--->例如:60s 則輸入:node gitpull.js 'D:\\xxx\\xxxx'  60")
  return
}
const looptime = argv[3]

const timeout = setInterval(() => {
  let time=sd.format(new Date(), 'YYYY-MM-DD HH:mm:ss');
  child_process.exec('git pull', {cwd:githref}, function (error, stdout, stderr) {
    if (error !== null) {
      console.log('exec error: ' + error);
    }else{
      console.log(time+' '+ stdout)
      // console.log(stdout)
    }
});
}, looptime * 1000)

運行時候只需要 執行 node 文件名稱.js '路徑' 時間(時間以s為單位)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM