-
Notifications
You must be signed in to change notification settings - Fork 0
/
maintainerizer.js
82 lines (75 loc) · 2.91 KB
/
maintainerizer.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const path = require('path');
const fs = require('fs');
const { promisify } = require('util');
const exec = promisify(require('child_process').exec)
async function TurnOnGitMaintenance(path) {
let configOutput;
try{
configOutput = await exec('git maintenance start', {
cwd: path,
shell: isWin ? 'C:\\Program Files\\Git\\bin\\bash.exe' : 'bash',
windowsHide: true,
});
} catch (e) {
console.error(e);
}
return configOutput?.stdout?.trim();
};
async function ListGitMaintenanceRepos(path) {
let result;
try{
result = await exec('git config --global --get-all maintenance.repo', {
cwd: path,
shell: isWin ? 'C:\\Program Files\\Git\\bin\\bash.exe' : 'bash',
windowsHide: true,
});
} catch (e) {
console.error(e);
}
return result?.stdout?.trim();
};
var args = process.argv.slice(2);
var directoryPath = args[0] || __dirname;
var isWin = process.platform === "win32";
fs.readdir(directoryPath, {withFileTypes: true}, async (err, entries) => {
tape();
if (err) {
return console.log('Sorry, friend. Unable to scan directory: ' + err);
}
const directories = entries
.filter(dirent => dirent.isDirectory())
.filter(d => d.name.indexOf('$RECYCLE') === -1)
.filter(d => d.name.indexOf('.nuget') === -1)
.filter(d => d.name.indexOf('System Volume Information') === -1);
directories.forEach(async dirent => {
const _path = path.join(directoryPath, dirent.name);
console.log(`[Turning on maintenance for]: ${dirent.name}; ${_path}`);
try{
await TurnOnGitMaintenance(_path);
} catch (e) {
console.error(e);
}
});
console.log('Repos under maintenance: ');
const result = await ListGitMaintenanceRepos(path.join(directoryPath));
console.log(result);
});
const tape = () => {
console.log(' __________________________________________ ');
console.log('| _______________________________________ |');
console.log('| / .-----------------------------------. \ |');
console.log('| | | /\\ : 90 min| | |');
console.log('| | |/--\\:...................... NR [ ]| | |');
console.log('| | `-----------------------------------\'| |');
console.log('| | //-\\\\ | | //-\\\\ | |');
console.log('| | ||( )|| |_________| ||( )|| | |');
console.log('| | \\\\-// :....:....: \\\\-// | |');
console.log('| | _ _ ._ _ _ .__|_ _.._ _ | |');
console.log('| | (_(_)| |(_(/_| |_(_||_)(/_ | |');
console.log('| | low noise | | |');
console.log('| `______ ____________________ ____ _____\' |');
console.log('| / [] [] \\ |');
console.log('| / () () \\ |');
console.log('!______/____________________________\\______!');
console.log(' ');
};