| 1 |
"use strict"; |
| 2 |
|
| 3 |
var tz = require('../moment-timezone-utils').tz, |
| 4 |
groupLeaders = require('./group-leaders.json'); |
| 5 |
|
| 6 |
|
| 7 |
function staleDataWarning() { |
| 8 |
if (moment.suppressDeprecationWarnings === false && |
| 9 |
(typeof console !== 'undefined') && console.warn) { |
| 10 |
console.warn( |
| 11 |
'Deprecation warning: ' + |
| 12 |
'Moment Timezone has been loaded from a file containing data from 2012 to 2022 only. ' + |
| 13 |
'This file is out of date and may be removed in a future release. ' + |
| 14 |
'Dates and times for the current year might be incorrect.' |
| 15 |
); |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
module.exports = function (grunt) { |
| 20 |
grunt.registerMultiTask('build', 'Build minified versions with data included.', function () { |
| 21 |
var dest = 'builds/' + this.target + '.js', |
| 22 |
typesDest = 'builds/' + this.target + '.d.ts', |
| 23 |
data = require('../data/unpacked/latest.json'), |
| 24 |
source = grunt.file.read('moment-timezone.js'), |
| 25 |
typesSrc = grunt.file.read('moment-timezone.d.ts'), |
| 26 |
start = 0, |
| 27 |
end = 9999; |
| 28 |
|
| 29 |
if (this.data && this.data[0]) { |
| 30 |
start = this.data[0]; |
| 31 |
} |
| 32 |
|
| 33 |
if (this.data && this.data[1]) { |
| 34 |
end = this.data[1]; |
| 35 |
} |
| 36 |
|
| 37 |
data = tz.filterLinkPack(data, start, end, groupLeaders); |
| 38 |
data = JSON.stringify(data, null, '\t'); |
| 39 |
data = data.split('\n').join('\n\t'); |
| 40 |
data = 'loadData(' + data + ');\n'; |
| 41 |
|
| 42 |
if (this.data && this.data[2] === 'warn') { |
| 43 |
data += '\n\t' + staleDataWarning.toString().split('\n').join('\n\t') |
| 44 |
+ '\n\tstaleDataWarning();' |
| 45 |
} |
| 46 |
|
| 47 |
source = source.replace('// INJECT DATA', data); |
| 48 |
|
| 49 |
grunt.file.write(dest, source); |
| 50 |
|
| 51 |
typesSrc = typesSrc.replace("'./index'", "'../index'"); |
| 52 |
grunt.file.write(typesDest, typesSrc); |
| 53 |
}); |
| 54 |
}; |