-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathGruntfile.js
247 lines (232 loc) · 7.4 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
module.exports = function(grunt) {
// load all tasks from package.json
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
var time = (new Date()).getTime();
// config
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// CSS compilation
sass: {
main: {
options: {
style: "compact"
},
files: {
'build/css/intlTelInput.css': 'src/css/intlTelInput.scss'
}
},
demo: {
files: {
'build/css/demo.css': 'src/css/demo.scss'
}
}
},
// JS Code Lint
jshint: {
all: "src/js/**/*.js",
options: {
// this is for data.js which sometimes has commas on the following line
laxcomma: true
}
},
// JS compilation
uglify: {
options: {
banner: '/*\n'+
'<%= pkg.name %> \n'+
'version: <%= pkg.version %>\n'+
'description: <%= pkg.description %>\n'+
'repository: <%= pkg.repository.url %>\n'+
'license: <%= pkg.license %>\n'+
'author: <%= pkg.author %>\n'+
'*/\n'+
// wrap in UMD - see https://github.com/umdjs/umd/blob/master/jqueryPlugin.js
'(function (factory) {\n'+
' if (typeof define === "function" && define.amd) {\n'+
' // AMD. Register as an anonymous module.\n'+
' define(["jquery"], function($){factory($, window, document);});\n'+
' } else {\n'+
' // Browser globals\n'+
' factory(jQuery, window, document);\n'+
' }\n'+
'}(function ($, window, document, undefined) {\n'+
'"use strict";\n\n',
footer: '\n\n}));\n'
},
dev: {
options: {
beautify: true,
compress: false,
mangle: false,
preserveComments: true
},
files: {
'build/js/intlTelInput.js': ['src/js/intlTelInput.js', 'src/js/data.js']
}
},
prod: {
files: {
'build/js/intlTelInput.min.js': ['src/js/intlTelInput.js', 'src/js/data.js']
}
}
},
// Auto-compilation of assets
watch: {
js: {
files: "src/js/**/*.js",
tasks: ["jshint", "uglify:dev"]
},
pluginCss: {
files: ["src/css/flags.scss", "src/css/intlTelInput.scss"],
tasks: "sass:main"
},
demoCss: {
files: "src/css/demo.scss",
tasks: "sass:demo"
}
},
// This is needed for travis task
bower: {
install: {
// defaults are fine
}
},
// Testing
jasmine: {
src: [
'src/js/data.js',
'src/js/intlTelInput.js'
],
options: {
vendor: [
'lib/jquery/dist/jquery.js',
'lib/jasmine-jquery/lib/jasmine-jquery.js'
],
helpers: [
'src/spec/helpers/**/*.js'
],
specs: [
'src/spec/tests/**/*.js'
],
outfile: 'spec.html',
keepRunner: true
}
},
template: {
defaultCountryIp: {
src: 'examples/template.html.ejs',
dest: 'examples/gen/default-country-ip.html',
variables: function () {
return {
time: time,
title: "Lookup user's country",
desc: "Use IP address lookup to set the defaultCountry option to the user's country.",
stylesheet: "",
markup: grunt.file.read('examples/partials/simpleInput.html'),
code: grunt.file.read('examples/js/defaultCountryIp.js'),
script: "defaultCountryIp.js"
}
}
},
modifyCountryData: {
src: 'examples/template.html.ejs',
dest: 'examples/gen/modify-country-data.html',
variables: function () {
return {
time: time,
title: "Modify country data",
desc: "Use static getCountryData method to update the data to only show localised country names.",
stylesheet: "",
markup: grunt.file.read('examples/partials/simpleInput.html'),
code: grunt.file.read('examples/js/modifyCountryData.js'),
script: "modifyCountryData.js"
}
}
},
onlyCountries: {
src: 'examples/template.html.ejs',
dest: 'examples/gen/only-countries-europe.html',
variables: function () {
return {
time: time,
title: "European countries",
desc: "Set onlyCountries option to just European country codes.",
stylesheet: "",
markup: grunt.file.read('examples/partials/simpleInput.html'),
code: grunt.file.read('examples/js/onlyCountriesEurope.js'),
script: "onlyCountriesEurope.js"
}
}
},
defaultStyling: {
src: 'examples/template.html.ejs',
dest: 'examples/gen/default-styling.html',
variables: function () {
return {
time: time,
title: "Styling",
desc: "The 3 different settings for the defaultStyling option: 'inside' (default), 'outside' and 'none'.",
stylesheet: 'defaultStyling.css',
markup: grunt.file.read('examples/partials/defaultStyling.html'),
code: grunt.file.read('examples/js/defaultStyling.js'),
script: "defaultStyling.js"
}
}
},
countrySync: {
src: 'examples/template.html.ejs',
dest: 'examples/gen/country-sync.html',
variables: function () {
return {
time: time,
title: "Country sync",
desc: "Use static getCountryData method to create a separate country dropdown for an address form, and then listen for change events to keep the two dropdowns in sync.",
stylesheet: 'countrySync.css',
markup: grunt.file.read('examples/partials/countrySync.html'),
code: grunt.file.read('examples/js/countrySync.js'),
script: "countrySync.js"
}
}
},
validation: {
src: 'examples/template.html.ejs',
dest: 'examples/gen/validation.html',
variables: function () {
return {
time: time,
title: "Validation",
desc: "Use public isValidNumber method (utilising Google's libphonenumber) to validate the telephone number on the change event.",
stylesheet: 'validation.css',
markup: grunt.file.read('examples/partials/validation.html'),
code: grunt.file.read('examples/js/validation.js'),
script: "validation.js"
}
}
}
},
bump: {
options: {
files: ['package.json', 'bower.json', 'intl-tel-input.jquery.json'],
updateConfigs: ['pkg'],
commitFiles: ['-a'],
pushTo: 'origin'
}
}
});
/**
* TASKS
*/
// build everything ready for a commit
grunt.registerTask('build', ['jshint', 'sass', 'uglify']);
// just javascript
grunt.registerTask('js', ['jshint', 'uglify']);
// build examples
grunt.registerTask('examples', ['template']);
// Travis CI
grunt.registerTask('travis', ['bower', 'jasmine']);
// prepare everything for the demo.html
grunt.registerTask('demo', ['jshint', 'sass', 'uglify:dev']);
// bump version number in 3 files, build to update js headers, then commit, tag and push
grunt.registerTask('version', ['bump-only', 'uglify', 'bump-commit']);
};