| 1 |
"use strict"; |
| 2 |
|
| 3 |
var path = require('path'), |
| 4 |
execFile = require('child_process').execFile; |
| 5 |
|
| 6 |
module.exports = function (grunt) { |
| 7 |
grunt.registerTask('data-zic', '3. Compile data sources with zic(8).', function (version) { |
| 8 |
version = version || 'latest'; |
| 9 |
|
| 10 |
var done = this.async(), |
| 11 |
dest = path.resolve('temp/zic', version), |
| 12 |
files = 'africa antarctica asia australasia etcetera europe northamerica southamerica backward'.split(' '); |
| 13 |
|
| 14 |
grunt.file.mkdir(dest); |
| 15 |
|
| 16 |
|
| 17 |
var zicBinary = 'zic', |
| 18 |
zicPathOption = grunt.option('zic-path'); |
| 19 |
if (zicPathOption && grunt.file.exists(zicPathOption)) { |
| 20 |
zicBinary = zicPathOption; |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
execFile(zicBinary, ['--help'], function (err, stdout) { |
| 27 |
if (!stdout.includes('[ -b ')) { |
| 28 |
grunt.log.warn('WARNING: The version of `zic` on this machine is old and might produce incorrect values'); |
| 29 |
} |
| 30 |
|
| 31 |
next(); |
| 32 |
}); |
| 33 |
|
| 34 |
function next () { |
| 35 |
if (!files.length) { |
| 36 |
grunt.log.ok('Compiled zic for ' + version); |
| 37 |
return done(); |
| 38 |
} |
| 39 |
|
| 40 |
var file = files.shift(), |
| 41 |
src = path.resolve('temp/download', version, file); |
| 42 |
|
| 43 |
if (!grunt.file.exists(src)) { |
| 44 |
throw new Error("Can't process " + src + " with zic. File doesn't exist"); |
| 45 |
} |
| 46 |
execFile(zicBinary, ['-d', dest, src], function (err) { |
| 47 |
if (err) { throw err; } |
| 48 |
|
| 49 |
grunt.verbose.ok('Compiled zic ' + version + ':' + file); |
| 50 |
|
| 51 |
next(); |
| 52 |
}); |
| 53 |
} |
| 54 |
}); |
| 55 |
}; |