forked from nodester/nodester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync_githook.js
executable file
·42 lines (39 loc) · 1.12 KB
/
sync_githook.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
#!/usr/bin/env node
require('colors');
var path = require('path');
var fs = require('fs');
var config = require('../config').opt;
var hosted = path.join(config.home_dir, config.hosted_apps_subdir);
var exists = path.existsSync;
var util = require('util');
process.chdir(hosted);
util.print('Reading git repos:'.magenta);
var src = path.join(config.app_dir, 'scripts', 'gitrepoclone.sh');
var copy = function () {
if (repos.length) {
var dest = repos.pop();
var is = fs.createReadStream(src);
var os = fs.createWriteStream(dest);
util.pump(is, os, copy);
} else {
util.print(' [done]\n'.white);
}
};
var repos = [];
var dirs = fs.readdirSync('.');
dirs.forEach(function (v) {
if (exists(v)) {
var stat = fs.statSync(v);
if (stat.isDirectory()) {
var dirs = fs.readdirSync(v);
dirs.forEach(function (i) {
if (path.extname(i) === '.git') {
repos.push(path.join(hosted, v, i, 'hooks', 'post-receive'));
}
});
}
}
});
util.print((' (' + repos.length + ')').yellow + ' [done]\n'.white);
util.print('Processing git commit hooks'.magenta);
copy();