-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGruntfile.js
68 lines (56 loc) · 2.29 KB
/
Gruntfile.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
var libphonenumberConvert = require("libphonenumber-convert"),
fs = require("fs");
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
download: {
"libphonenumber-xml": "http://libphonenumber.googlecode.com/svn/trunk/resources/PhoneNumberMetadata.xml",
"output-js": "PhoneNumberMetadata.js"
}
});
grunt.registerTask('dryrun', 'Downloads libphonenumber XML and generates JS file', function() {
grunt.config.requires('download.libphonenumber-xml');
var done = this.async();
libphonenumberConvert(grunt.config('download.libphonenumber-xml'), function(err, data){
if(err){
grunt.log.writeln(err.message);
return done(false);
}
grunt.log.writeln(data);
done();
});
});
grunt.registerTask('clean', 'Downloads libphonenumber XML and generates JS file', function() {
grunt.config.requires('download.output-js');
var done = this.async();
fs.unlink(grunt.config('download.output-js'), function(err){
if(err && err.code != "ENOENT"){
grunt.log.writeln(err.message);
return done(false);
}
grunt.log.writeln(grunt.config('download.output-js') + " removed successfully");
done();
})
});
grunt.registerTask('download', 'Downloads libphonenumber XML and generates JS file', function() {
grunt.config.requires('download.libphonenumber-xml');
grunt.config.requires('download.output-js');
var done = this.async();
libphonenumberConvert(grunt.config('download.libphonenumber-xml'), function(err, data){
if(err){
grunt.log.writeln(err.message);
return done(false);
}
fs.writeFile(grunt.config('download.output-js'), data, function(err){
if(err){
grunt.log.writeln(err.message);
done(false);
}
grunt.log.writeln(grunt.config('download.output-js') + " generated successfully");
done();
});
});
});
grunt.registerTask('default', ['download']);
};