-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
101 lines (90 loc) · 3.45 KB
/
main.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/** jshint node:true */
var path = require('path'),
fs = require('fs'),
mkdirp = require('mkdirp'),
async = require('async'),
exec = require('child_process').exec,
cpus = require('os').cpus().length;
var versions = require('./versions');
var gaiaLocales = require('./gaia-locales.json');
var geckoLocales = getGeckoLocales('./gecko-locales.list');
function getGeckoLocales(filename) {
console.log('getGeckoLocales()');
var filepath = path.resolve(__dirname, filename);
var contents = fs.readFileSync(filepath, { encoding: 'utf8'});
return contents.split(' ');
}
function expandPathsWithRepos(callback) {
console.log('expandPathsWithRepos()');
var rv = {};
var mainVersions = Object.keys(versions);
mainVersions.forEach(function(version) {
if (versions[version].gecko) {
geckoLocales.forEach(function(lang) {
//console.log('detecting', version, 'gecko', lang);
var localPath, repository;
localPath = path.join(__dirname, version, 'gecko', lang);
repository = versions[version].gecko.replace('$lang', lang);
rv[localPath] = repository;
});
}
if (versions[version].gaia) {
var gaiaLocalesKeys = Object.keys(gaiaLocales);
gaiaLocalesKeys.forEach(function(lang) {
//console.log('detecting', version, 'gaia', lang);
var localPath, repository;
localPath = path.join(__dirname, version, 'gaia', lang);
repository = versions[version].gaia.replace('$lang', lang);
rv[localPath] = repository;
});
}
});
callback(null, rv);
}
// On versions we have a object of what directories must exist for
// this to work. So let's create them in case they are not present
// mkdirp handle if there are a directory or need to create it
function checkOrCreateSkeleton(repoObject, callback) {
console.log('checkOrCreateSkeleton()');
var paths = Object.keys(repoObject);
for (var i = paths.length - 1; i >= 0; i--) {
//console.log('Making ' + paths[i]);
mkdirp.sync(paths[i]);
}
return callback(null, repoObject);
}
function cloneOrUpdatePaths(repoObject, callback) {
console.log('cloneOrUpdatePaths()');
console.log(repoObject);
var keys = Object.keys(repoObject);
var tasks = {};
for (var i = keys.length - 1; i >= 0; i--) {
//console.log('checking' + keys[i]);
var hgHiddenPath = path.join(keys[i], '.hg');
if (fs.existsSync(hgHiddenPath) && fs.statSync(hgHiddenPath).isDirectory) {
//console.log('to update ' + keys[i]);
tasks[keys[i]] = updateClone.bind(null, keys[i]);
} else {
//console.log('to CLONE ' + keys[i]);
tasks[keys[i]] = initialClone.bind(null, repoObject[keys[i]], keys[i]);
}
}
// Let's launch number of cpus tasks for mercurial.
async.parallelLimit(tasks, cpus, callback);
}
function initialClone(repository, path, callback) {
console.log('initialClone', repository, path);
exec('hg clone --insecure ' + repository + ' ' + path, callback);
}
function updateClone(path, callback) {
console.log('updateClone', path);
exec('hg pull --insecure -u', { cwd: path }, callback);
}
async.waterfall([
//getGeckoLocales,
expandPathsWithRepos,
checkOrCreateSkeleton,
cloneOrUpdatePaths
], function(err, results) {
console.log(results);
});