-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync-git.js
31 lines (27 loc) · 1.13 KB
/
sync-git.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import shell from "shelljs";
var time = new Date();
var strTime = `${(String(time.getDate()).length == 1)? `0${String(time.getDate())}`: String(time.getDate())}/${(String(time.getMonth()+1).length == 1)? `0${String(time.getMonth()+1)}`: String(time.getMonth()+1)}/${time.getFullYear()} ${(String(time.getHours()).length == 1)? `0${String(time.getHours())}`: String(time.getHours())}:${(String(time.getMinutes()).length == 1)? `0${String(time.getMinutes())}`: String(time.getMinutes())}hs`;
function execute(command) {
return new Promise((resolve, reject)=>{
var request = shell.exec(command);
if (request.code !== 0) {
console.error(request.stderr);
shell.exit(1);
reject();
} else {
console.log(request.stderr);
resolve();
}
});
}
async function init() {
try {
await execute('git add .');
await execute(`git commit -m "${strTime}"`);
await execute('git push -u origin main');
console.log('Sincronizacion finalizada');
} catch {
console.error('Oparacion detenida: Ocurrio un error.');
}
}
init();