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