This repository has been archived by the owner on Feb 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGruntfile.js
268 lines (248 loc) · 8.81 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*! nQuire-it | GPL | © The Open University (IET).
*/
module.exports = function (grunt) {
'use strict';
var pkg = grunt.file.readJSON('./package.json')
;
grunt.initConfig({
sass: {
options: {
sourceMap: true
},
dist: {
files: {
'static/src/css/nquire-it-bootstrap.css':
'static/sass/nquire-it/nquire-it-bootstrap.scss'
}
}
},
htmlangular: {
options: {
w3cproxy: httpProxy()
},
partials: {
src: [ '<%= js.part %>/layout/**/*.html', '<%= js.part %>/admin/*.html' ],
options: {
customattrs: [ 'siw-user-link', 'translate-comment' ],
customtags: [ 'text-angular', 'translate' ], //'X-ng-form'
relaxerror: [
'A numeric character reference expanded to carriage return.', // Eg. " "
'Attribute “href” without an explicit value seen.', //' The attribute may be dropped by IE7.'
'Element “head” is missing a required instance of child element “title”.',
'Start tag seen without seeing a doctype first.', //' Expected e.g. “<!DOCTYPE html>”.'
'End of file seen without seeing a doctype first.' //' Expected e.g. “<!DOCTYPE html>”.'
]
}
},
index: [ 'static/src/ie8.htm', 'static/src/index.html' ]
},
jshint: {
options: {
bitwise: true,
curly: true,
eqeqeq: true,
futurehostile: true,
laxcomma: true,
undef: true,
//unused: true,
// /~https://github.com/jshint/jshint/blob/master/src/messages.js#L80
'-W018': true, // Ignore confusing use of 'a';
'-W069': true, // Ignore ['a'] is better written in dot notation;
//'-W097': true, // Ignore position of 'use strict';
//'-W100': true, // Ignore this character may get silently deleted by...;
//'-W117': true, // Ignore 'a' is not defined;
//'-W014': true, // Ignore bad line breaking before '+';
globals: {
//_: false,
angular:false, FileReader:false, FormData:false, google:false, grecaptcha:false, MarkerClusterer:false, OverlappingMarkerSpiderfier:true, SigUtils:true,
SiwClone:true, SiwColorGenerator:true, siwCompare:true, SiwFormManager:true, SiwMapIcons:true, SiwMapRenderer:true, SiwSenseItSensorData:true, SiwSenseItTransformations:true
}
},
app: 'static/src/js/app/*.js',
ctrl: 'static/src/js/app/controllers/**/*.js',
directive: 'static/src/js/app/directives/*.js',
filter: 'static/src/js/app/filters/*.js',
serv: 'static/src/js/app/services/*.js',
helper: 'static/src/js/helpers/*.js',
bin: {
files: {
src: [ 'bin/*.js', 'Gruntfile.js' ]
},
options: {
esversion: 6,
node: true //globals: { module:false, require:false, console:false, process:false, __dirname:false }
}
}
},
nggettext_extract: {
pot: {
// Translate strings in Javascript [Bug: #23]
options: {
markerNames: [ '_' ]
},
files: {
'po/template.pot': [
'static/**/*.html', //'static/src/partials/**/*.html',
'static/src/js/app/**/*.js' // Exclude 'js/dist/**' files.
]
}
}
},
nggettext_compile: {
nQuire_it: {
files: {
'static/src/js/app/translations.js': [ 'po/*.po' ]
}
}
},
msgInitMerge: { // requires Grunt ~0.4.5.
nQuire_it: {
src: [ 'po/template.pot' ],
options: {
// I18n / translation - list available languages, except 'en' [Bug: #3]
'locales': [
'el',
'es',
'fr'
],
poFilesPath: 'po/<%= locale %>.po'
}
}
},
/* Javascript page order:
libs, helpers, app.js, config, translations, services, directives, filters, controllers.
*/
nm: 'node_modules',
js: {
part: 'static/src/partials',
out: 'static/src/js/dist',
app: 'static/src/js/app',
lib: 'static/src/js/libs',
srv: 'static/src/js/app/services'
},
uglify: {
app: {
files: {
'<%= js.out %>/app.min.js': [
'<%= js.app %>/app.js', '<%= js.app %>/translations.js' // Not: 'config.js'
],
'<%= js.out %>/controllers.min.js': '<%= js.app %>/controllers/**/**/*.js',
'<%= js.out %>/directives.min.js': '<%= js.app %>/directives/*.js',
'<%= js.out %>/filters.min.js': '<%= js.app %>/filters/*.js',
// Services - order is significant - up to rest OR openid !
'<%= js.out %>/services.min.js': [
'<%= js.srv %>/services-module.js',
'<%= js.srv %>/alert-service.js', // Order: after 'services-module'; before 'rest-service' ?
'<%= js.srv %>/rest-service.js',
'<%= js.srv %>/openid-service.js',
'<%= js.srv %>/vote-service.js',
'<%= js.srv %>/comment-service.js',
'<%= js.srv %>/admin-service.js',
'<%= js.srv %>/modal-service.js',
'<%= js.srv %>/sorted-data-service.js',
'<%= js.srv %>/tracking-service.js',
'<%= js.srv %>/users-service.js',
'<%= js.srv %>/f**-service.js', // 'file-reader', 'filter-tag', 'forum' (3)
'<%= js.srv %>/p**-service.js' // 'project-*', 'page-title' (8)
]
},
options: { mangle: false /* IMPORTANT - 'mangle' must be false for services! */ }
},
helpers: {
files: { '<%= js.out %>/helpers.min.js': 'static/src/js/helpers/*.js' }
},
jquery: {
files: {
'<%= js.out %>/jquery-2.x.min.js': 'node_modules/jquery/dist/jquery.min.js'
},
options: {
banner: "/*!\n 3rd-party library | nQuire-it | <%= grunt.template.today('yyyy-mm-dd HH:MM:ss') %>.\n*/\n"
}
},
libs: { // 3rd party libraries - order is significant - up to 'angular.js'!
files: {
'<%= js.out %>/libs.min.js': [
'node_modules/jquery/dist/jquery.min.js', // v2.2.x;
'<%= nm %>/bootstrap-sass/javascripts/bootstrap.min.js', // v3.3.x;
'<%= nm %>/angular/angular.min.js', // v1.5.x;
'<%= nm %>/angular-gettext/dist/angular-gettext.min.js', // v2.3.x;
'<%= nm %>/textangular/dist/textAngular-*.min.js', // -rangy 1.3.0 + -sanitize;
'<%= nm %>/textangular/dist/textAngular.min.js', // v1.5.x;
'<%= nm %>/angular-ui-router/release/angular-ui-router.min.js', // v0.4.2;
'<%= nm %>/angular-ui-bootstrap/dist/ui-bootstrap-tpls.js', // v2.5.x;
'<%= js.lib %>/markerclusterer.min.js',
'<%= js.lib %>/oms.min.js' // v0.3.3
]
},
options: {
mangle: false, /* Apparently needed - otherwise we get
"Uncaught RangeError: Maximum call stack size exceeded at l (textAngular-rangy.min.js:23)"
(Also: https://docs.angularjs.org/error/$injector/undef?p0=PageTitleService) */
banner: "/*!\n All 3rd-party libraries | nQuire-it | <%= grunt.template.today('yyyy-mm-dd HH:MM:ss') %>.\n*/\n\n"
}
},
options: { // Global uglify options.
banner: "/*!\n nQuire-it | GPL | © The Open University | <%= grunt.template.today('yyyy-mm-dd HH:MM:ss') %>.\n*/\n\n",
compress: true,
mangle: true,
preserveComments: 'some',
sourceMap: true
}
},
watch: {
app: { files: '<%= js.app %>/**/*.js', tasks: 'uglify:app' },
helpers: { files: 'static/src/js/helpers/*.js', tasks: 'uglify:helpers' },
sass: { files: 'static/sass/nquire-it/**/*', tasks: 'sass' }
}
});
grunt.loadNpmTasks('grunt-angular-gettext');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
// Was: grunt.loadNpmTasks('grunt-html-angular-validate');
// Was: grunt.loadNpmTasks('grunt-nice-package');
grunt.loadNpmTasks('grunt-sass');
grunt.registerTask('help', help);
grunt.registerTask('gettext', [
'nggettext_extract', 'nggettext_compile'
]);
grunt.registerTask('test', [
'gettext', /*'htmlangular:index',*/ 'sass', 'jshint', 'uglify', // Was: 'nice-package'
]);
grunt.registerTask('default', [
'sass', 'jshint', 'uglify', /*'nice-package',*/ 'replace:config+html'
]);
grunt.registerTask('git:version.json', 'Output version.JSON containing Git commit & other version info.', function () {
var done = this.async();
require('./bin/git-version.js')(grunt, done);
});
grunt.registerTask(
'replace:config+html',
'Update a "random" parameter for all <script> and CSS includes in "index.html". Plus, add version, add Google Map API key ...',
function () {
require('./bin/replace.js')(grunt);
});
/* ================================== */
function httpProxy() {
var http_proxy = process.env.HTTP_PROXY || false; // Default is false, not null(?)
if (http_proxy) {
http_proxy = http_proxy.replace(/https?:\/\//, '');
http_proxy = 'http://' + http_proxy;
}
grunt.log.debug('HTTP proxy?', http_proxy || '<none>');
return http_proxy;
}
function isTravis() {
return false; //Was: process.env.TRAVIS || false;
}
function help() {
var version = grunt.file.readJSON('./static/src/version.json');
grunt.log.subhead('nQuire-it help\n');
grunt.log.ok(
'Run `grunt --help` to list available tasks.\n' +
'Copyright © 2017 The Open University (IET) <http://iet.open.ac.uk>\n' +
'License: GNU GPL (see LICENSE.txt)\n' +
'Version: ' + version.describe
);
}
};