forked from manuelbieh/geolib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
189 lines (173 loc) · 4.22 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*global module:false*/
module.exports = function(grunt) {
require('time-grunt')(grunt);
require('load-grunt-tasks')(grunt);
grunt.registerTask('version', function(target, op) {
var fs = require('fs');
var data = JSON.parse(fs.readFileSync('package.json', {encoding: 'utf-8'}));
var version = data.version.split('.');
var major = parseInt(version[0], 10);
var minor = parseInt(version[1], 10);
var patch = parseInt(version[2].split('+')[0], 10);
var info = version[2].split('+')[1];
var log = '';
if(typeof op == 'undefined' || op === '+') {
op = '+';
log += 'Incrementing ';
} else if(op === '-') {
op = op;
log += 'Decrementing ';
} else if(!isNaN(parseInt(op, 10))) {
op = parseInt(op, 10);
log += 'Using ' + op + ' as new ';
} else {
grunt.log.fail('Illegal operation.');
return false;
}
if(['major', 'minor', 'patch'].indexOf(target) > -1) {
log += target + ' version. ';
}
switch(target) {
case 'major':
major = op == '-' ? major-1 : (op == '+' ? major+1 : op);
if(major < 0) major = 0;
break;
case 'minor':
minor = op == '-' ? minor-1 : (op == '+' ? minor+1 : op);
if(minor < 0) minor = 0;
break;
case 'patch':
patch = op == '-' ? patch-1 : (op == '+' ? patch+1 : op);
if(patch < 0) patch = 0;
break;
}
data.version = [major, minor, patch].join('.') + (info ? '+' + info : '');
grunt.log.writeln(log + 'New version is ' + data.version);
fs.writeFileSync('package.json', JSON.stringify(data, null, 2), {encoding: 'utf-8'})
grunt.config.data.pkg.version = data.version;
grunt.task.run('default');
});
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner: '/*! <%= pkg.name %> <%= pkg.version %> by <%= pkg.author.name %>\n'+
'* Library to provide geo functions like distance calculation,\n' +
'* conversion of decimal coordinates to sexagesimal and vice versa, etc.\n' +
'* WGS 84 (World Geodetic System 1984)\n' +
'* \n' +
'* @author <%= pkg.author.name %>\n' +
'* @url <%= pkg.author.url %>\n' +
'* @version <%= pkg.version %>\n' +
'* @license <%= _.pluck(pkg.licenses, "type").join(", ") %> \n**/',
lint: {
files: ['src/geolib.js']
},
qunit: {
files: ['tests/*.html']
},
concat: {
main: {
options: {
banner: '<%= banner %>',
report: false
},
src: ['src/geolib.js'],
dest: 'dist/geolib.js'
}
},
copy: {
component: {
files: [{
src: "package.json",
dest: "component.json"
}]
},
elev: {
files: [{
src: ['src/geolib.elevation.js'],
dest: 'dist/geolib.elevation.js'
}]
},
pointInside: {
files: [{
src: ['src/geolib.isPointInsideRobust.js'],
dest: 'dist/geolib.isPointInsideRobust.js'
}]
},
},
replace: {
version: {
src: ['dist/*.js', 'bower.json', 'README.md'],
overwrite: true,
replacements: [
{
from: '$version$',
to: '<%= pkg.version %>'
}, {
from: /"version": "([0-9a-zA-Z\-\.\+]*)",/,
to: '"version": "<%= pkg.version %>",'
}, {
from: /v[0-9]+\.[0-9]{1,2}\.[0-9]{1,}/,
to: 'v<%= pkg.version %>'
}
]
}
},
uglify: {
options: {
preserveComments: 'some'
},
main: {
files: {
'dist/geolib.min.js': ['dist/geolib.js']
}
},
elev: {
files: {
'dist/geolib.elevation.min.js': ['dist/geolib.elevation.js']
}
},
pointInside: {
files: {
'dist/geolib.isPointInsideRobust.min.js': ['dist/geolib.isPointInsideRobust.js']
}
},
},
watch: {
all: {
files: '<%= jshint.all %>',
tasks: ['default']
}
},
jshint: {
all: [
'src/geolib.js',
'src/geolib.elevation.js',
'src/geolib.isPointInsideRobust.js',
],
options: {
curly: true,
eqeqeq: false,
immed: true,
latedef: true,
newcap: false,
noarg: true,
sub: true,
undef: true,
evil: true,
boss: true,
eqnull: true,
globals: {
module: true,
define: true,
require: true,
elevationResult: true
}
}
}
});
// Default task.
grunt.registerTask('default', ['concat:main', 'copy', 'replace', 'uglify']);
grunt.registerTask('travis', ['jshint','qunit']);
grunt.registerTask('test', ['qunit']);
};