Update index.js
This commit is contained in:
28
index.js
28
index.js
@@ -111,9 +111,9 @@ async function gitMain() {
|
||||
} else {
|
||||
await git.checkout(GIT_BRANCH)
|
||||
}
|
||||
//console.log(statusResult)
|
||||
const behind = statusResult.behind
|
||||
if (behind > 0 ) {
|
||||
killProcesses()
|
||||
console.log(`${behind} change behind, pulling...`)
|
||||
await git.pull()
|
||||
}
|
||||
@@ -123,20 +123,40 @@ async function gitMain() {
|
||||
}
|
||||
}
|
||||
|
||||
const { execSync, spawn } = require('child_process')
|
||||
const { execSync, spawn, ChildProcess} = require('child_process')
|
||||
/**
|
||||
* @type {Array<ChildProcess>}
|
||||
*/
|
||||
|
||||
const processes = []
|
||||
|
||||
async function ProjectCmd(cmd) {
|
||||
//console.log(`executing "${cmd}"`)
|
||||
const processPromise = new Promise(function(resolve, reject) {
|
||||
const process = spawn(cmd, { stdio: 'inherit', cwd: PROJECT_DIR, shell:true });
|
||||
processes.push(process)
|
||||
|
||||
process.on('close', (code) => {
|
||||
//console.log(`command "${cmd}" exited with code ${code}`);
|
||||
processes.splice(processes.indexOf(process),1)
|
||||
resolve();
|
||||
});
|
||||
})
|
||||
return await processPromise;
|
||||
}
|
||||
|
||||
async function killProcesses() {
|
||||
for (let index = 0; index < processes.length; index++) {
|
||||
const process = processes[index];
|
||||
console.log("killing process",process.pid)
|
||||
await new Promise(function(resolve, reject) {
|
||||
process.on('close', (code) => {
|
||||
console.log(`process exited with code ${code}`);
|
||||
resolve();
|
||||
});
|
||||
process.kill("SIGINT")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function RunProject(commands = ["npm i","npm start"]) {
|
||||
@@ -166,7 +186,11 @@ async function main() {
|
||||
}
|
||||
|
||||
console.log("custom start commands",customCommands)
|
||||
|
||||
if (processes.length == 0) {
|
||||
RunProject(customCommands)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
setInterval(main, 1000 * 60) // 5 minutes
|
||||
Reference in New Issue
Block a user