Debian Codegraph @

tasks/data-download.js

raw symbols SCIP
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-download', '1. Download data from iana.org/time-zones.', function (version) {
8 version = version || 'latest';
9
10 var done = this.async(),
11 fetchCode = grunt.option('fetch-tzcode'),
12 type = fetchCode ? 'code' : 'data',
13 src = (version === 'latest' ?
14 'https://data.iana.org/time-zones/tz' + type + '-latest.tar.gz' :
15 'https://data.iana.org/time-zones/releases/tz' + type + version + '.tar.gz'),
16 curl = path.resolve('temp/curl', version, type + '.tar.gz'),
17 dest = path.resolve('temp/download', version);
18
19 grunt.file.mkdir(path.dirname(curl));
20 grunt.file.mkdir(dest);
21
22 grunt.log.ok('Downloading ' + src);
23
24 execFile('curl', [src, '-o', curl], function (err) {
25 if (err) { throw err; }
26 grunt.log.ok('Downloaded ' + curl + ', extracting . . .');
27 execFile('tar', ['-xzf', curl], { cwd: dest }, function (err) {
28 if (err) { throw err; }
29
30 grunt.log.ok('Extracted ' + dest);
31 done();
32 });
33 });
34 });
35 };