This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathGruntfile.js
341 lines (327 loc) · 16.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
var _ = require('lodash');
var sh = require('shelljs');
var path = require('path');
/*global module:false*/
module.exports = function(grunt) {
'use strict';
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
meta: {
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %><%= "\\n" %>' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
'* JBoss, Home of Professional Open Source<%= "\\n" %>' +
'* Copyright <%= pkg.author.name %>, and individual contributors<%= "\\n" %>' +
'*<%= "\\n" %>' +
'* Licensed under the Apache License, Version 2.0 (the "License");<%= "\\n" %>' +
'* you may not use this file except in compliance with the License.<%= "\\n" %>' +
'* You may obtain a copy of the License at<%= "\\n" %>' +
'* <%= pkg.licenses[0].url + "\\n" %>' +
'* Unless required by applicable law or agreed to in writing, software<%= "\\n" %>' +
'* distributed under the License is distributed on an "AS IS" BASIS,<%= "\\n" %>' +
'* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<%= "\\n" %>' +
'* See the License for the specific language governing permissions and<%= "\\n" %>' +
'* limitations under the License.<%= "\\n" %>' +
'*/<%= "\\n" %>'
},
concat: {
options: {
stripBanners: true,
banner: '<%= meta.banner %>'
},
dist: {
src: ['src/aerogear.core.js', 'external/uuid/uuid.js', 'external/crypto/sjcl.js', 'src/data-manager/aerogear.datamanager.js', 'src/data-manager/adapters/base.js', 'src/data-manager/adapters/memory.js', 'src/data-manager/adapters/session-local.js', 'src/data-manager/adapters/indexeddb.js', 'src/data-manager/adapters/websql.js', 'src/notifier/aerogear.notifier.js', 'src/notifier/adapters/base.js', 'src/notifier/adapters/simplePush.js', 'src/notifier/adapters/vertx.js', 'src/notifier/adapters/stompws.js', 'src/notifier/adapters/mqttws.js', 'src/unifiedpush/aerogear.unifiedpush.js', 'src/simplepush/aerogear.simplepush.js', 'src/crypto/aerogear.crypto.js', 'src/diff-sync/aerogear.diff-sync-engine.js', 'src/diff-sync/engine-adapters/diff-match-patch.js', 'src/diff-sync/engine-adapters/json-patch.js', 'src/diff-sync/aerogear.diff-sync-client.js'],
dest: 'dist/<%= pkg.name %>.js'
},
dataManager: {
src: ['src/aerogear.core.js', 'src/data-manager/aerogear.datamanager.js', 'src/data-manager/adapters/base.js', 'src/data-manager/adapters/memory.js', 'src/data-manager/adapters/session-local.js', 'src/data-manager/adapters/indexeddb.js', 'src/data-manager/adapters/websql.js'],
description: 'DataManager full build',
dest: 'dist/<%= pkg.name %>.custom.js'
},
dataManagerIndexedDB: {
src: ['src/aerogear.core.js', 'src/data-manager/aerogear.datamanager.js', 'src/data-manager/adapters/base.js', 'src/data-manager/adapters/memory.js', 'src/data-manager/adapters/indexeddb.js'],
description: 'DataManager IndexedDB adapter build',
dest: 'dist/<%= pkg.name %>.custom.js'
},
dataManagerWebSQL: {
src: ['src/aerogear.core.js', 'src/data-manager/aerogear.datamanager.js', 'src/data-manager/adapters/base.js', 'src/data-manager/adapters/memory.js', 'src/data-manager/adapters/websql.js'],
description: 'DataManager WebSQL adapter build',
dest: 'dist/<%= pkg.name %>.custom.js'
},
dataManagerSessionLocal: {
src: ['src/aerogear.core.js', 'src/data-manager/aerogear.datamanager.js', 'src/data-manager/adapters/base.js', 'src/data-manager/adapters/memory.js', 'src/data-manager/adapters/session-local.js'],
description: 'DataManager SessionLocal adapter build',
dest: 'dist/<%= pkg.name %>.custom.js'
},
dataManagerMemory: {
src: ['src/aerogear.core.js', 'src/data-manager/aerogear.datamanager.js', 'src/data-manager/adapters/base.js', 'src/data-manager/adapters/memory.js'],
description: 'DataManager Memory adapter build',
dest: 'dist/<%= pkg.name %>.custom.js'
},
notifierVertx: {
src: ['src/aerogear.core.js', 'src/notifier/aerogear.notifier.js', 'src/notifier/adapters/base.js', 'src/notifier/adapters/vertx.js'],
description: 'Notifier Vert.x adapter build',
dest: 'dist/<%= pkg.name %>.custom.js'
},
notifierStompWS: {
src: ['src/aerogear.core.js', 'src/notifier/aerogear.notifier.js', 'src/notifier/adapters/base.js', 'src/notifier/adapters/stompws.js'],
description: 'Notifier StompWS adapter build',
dest: 'dist/<%= pkg.name %>.custom.js'
},
notifierMqttWS: {
src: ['src/aerogear.core.js', 'src/notifier/aerogear.notifier.js', 'src/notifier/adapters/base.js', 'src/notifier/adapters/mqttws.js'],
description: 'Notifier MqttWS adapter build',
dest: 'dist/<%= pkg.name %>.custom.js'
},
simplePush: {
src: ['src/aerogear.core.js', 'external/uuid/uuid.js', 'src/notifier/aerogear.notifier.js', 'src/notifier/adapters/simplePush.js', 'src/simplepush/aerogear.simplepush.js'],
description: 'SimplePush Client build',
dest: 'dist/<%= pkg.name %>.custom.js'
},
unifiedPush: {
src: ['src/aerogear.core.js', 'src/unifiedpush/aerogear.unifiedpush.js'],
description: 'UnifiedPush Client build',
dest: 'dist/<%= pkg.name %>.custom.js'
},
push: {
src: ['src/aerogear.core.js', 'external/uuid/uuid.js', 'src/notifier/aerogear.notifier.js', 'src/notifier/adapters/simplePush.js', 'src/simplepush/aerogear.simplepush.js', 'src/unifiedpush/aerogear.unifiedpush.js'],
description: 'Build of both SimplePush and UnifiedPush Clients',
dest: 'dist/<%= pkg.name %>.custom.js'
},
crypto: {
src: ['src/aerogear.core.js', 'external/crypto/sjcl.js', 'src/crypto/aerogear.crypto.js'],
description: 'Crypto build',
dest: 'dist/<%= pkg.name %>.custom.js'
},
diffSync: {
src: ['src/aerogear.core.js', 'src/diff-sync/aerogear.diff-sync-engine.js', 'src/diff-sync/engine-adapters/diff-match-patch.js', 'src/diff-sync/engine-adapters/json-patch.js', 'src/diff-sync/aerogear.diff-sync-client.js'],
description: 'Differential Sync Client and Engine',
dest: 'dist/<%= pkg.name %>.custom.js'
},
diffSyncDiffMatchPatch: {
src: ['src/aerogear.core.js', 'src/diff-sync/aerogear.diff-sync-engine.js', 'src/diff-sync/engine-adapters/diff-match-patch.js', 'src/diff-sync/aerogear.diff-sync-client.js'],
description: 'Differential Sync Client and Engine - Diff Match Patch Only',
dest: 'dist/<%= pkg.name %>.custom.js'
},
diffSyncJsonPatch: {
src: ['src/aerogear.core.js', 'src/diff-sync/aerogear.diff-sync-engine.js', 'src/diff-sync/engine-adapters/json-patch.js', 'src/diff-sync/aerogear.diff-sync-client.js'],
description: 'Differential Sync Client and Engine - JSON Patch Only',
dest: 'dist/<%= pkg.name %>.custom.js'
}
},
qunit: {
dataManager: ['tests/unit/data-manager/**/*.html', 'tests/unit/data-manager-websql/**/*.html'],
notifier: 'tests/unit/notifier/**/*.html',
crypto: 'tests/unit/crypto/**/*.html',
unifiedpush: 'tests/unit/unifiedpush/**/*.html',
simplepush: 'tests/unit/simplepush/**/*.html',
diffSync: 'tests/unit/sync/**/*.html'
},
jshint: {
all: {
src: [ 'Gruntfile.js', 'src/**/*.js' ],
options: {
jshintrc: '.jshintrc'
}
},
tests: {
src: [ 'tests/unit/**/*.js' ],
options: {
jshintrc: 'tests/.jshintrc'
}
}
},
uglify: {
all: {
files: {
'dist/<%= pkg.name %>.min.js': [ 'dist/<%= pkg.name %>.js' ]
},
options: {
preserveComments: 'some',
sourceMap: 'dist/<%= pkg.name %>.js.map',
sourceMappingURL: '<%= pkg.name %>.js.map',
sourceMapPrefix: 1,
beautify: {
ascii_only: true
}
}
},
custom: {
files: {
'dist/<%= pkg.name %>.custom.min.js': [ 'dist/<%= pkg.name %>.custom.js' ]
},
options: {
preserveComments: 'some',
sourceMap: 'dist/<%= pkg.name %>.custom.js.map',
sourceMappingURL: '<%= pkg.name %>.js.map',
sourceMapPrefix: 1,
beautify: {
ascii_only: true
}
}
}
},
watch: {
crypto: {
files: 'src/crypto/**/*.js',
tasks: 'qunit:crypto'
},
dataManager: {
files: 'src/data-manager/**/*.js',
tasks: 'qunit:dataManager'
},
notifier: {
files: 'src/notifier/**/*.js',
tasks: 'qunit:notifier'
},
simplepush: {
files: 'src/simplepush/**/*.js',
tasks: 'qunit:simplepush'
},
unifiedpush: {
files: 'src/unifiedpush/**/*.js',
tasks: 'qunit:unifiedpush'
},
core: {
files: 'src/aerogear.core.js',
tasks: 'qunit'
},
diffSync: {
files: 'src/diff-sync/**/*.js',
tasks: 'qunit:sync'
}
},
ci: {
options: {
force: true
},
vertx: {},
activemq: {},
simplepush: {},
report: {
options: { force: false }
}
}
});
// IIFE wrapper task
grunt.registerTask('iife', function( custom ) {
var fs = require('fs'),
fileName = 'dist/' + grunt.config('pkg').name + (custom ? '.custom' : '') + '.js',
fileText = fs.readFileSync( fileName, 'utf-8' );
fileText = fileText.replace( /\*\//, '*/\n(function( window, undefined ) {\n' );
fs.writeFileSync( fileName, fileText + '})( this );\n', 'utf-8' );
});
// grunt-contrib tasks
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
// Default task
grunt.registerTask('default', ['jshint', 'qunit', 'concat:dist', 'iife', 'uglify:all']);
grunt.registerTask('dev', ['jshint', 'concat:dist', 'iife', 'uglify:all']);
grunt.registerTask('dataManager', ['jshint', 'qunit', 'concat:dataManager', 'iife:custom', 'uglify:custom']);
grunt.registerTask('dataManagerIndexedDB', ['jshint', 'qunit', 'concat:dataManagerIndexedDB', 'iife:custom', 'uglify:custom']);
grunt.registerTask('dataManagerWebSQL', ['jshint', 'qunit', 'concat:dataManagerWebSQL', 'iife:custom', 'uglify:custom']);
grunt.registerTask('dataManagerSessionLocal', ['jshint', 'qunit', 'concat:dataManagerSessionLocal', 'iife:custom', 'uglify:custom']);
grunt.registerTask('dataManagerMemory', ['jshint', 'qunit', 'concat:dataManagerMemory', 'iife:custom', 'uglify:custom']);
grunt.registerTask('notifierVertx', ['jshint', 'qunit', 'concat:notifierVertx', 'uglify:custom']);
grunt.registerTask('notifierStompWS', ['jshint', 'qunit', 'concat:notifierStompWS', 'uglify:custom']);
grunt.registerTask('simplePush', ['concat:simplePush']);
grunt.registerTask('unifiedPush', ['concat:unifiedPush']);
grunt.registerTask('push', ['concat:push']);
grunt.registerTask('crypto', ['concat:crypto']);
grunt.registerTask('diffSync', ['concat:diffSync']);
grunt.registerTask('diffSyncDiffMatchPatch', ['concat:diffSyncDiffMatchPatch']);
grunt.registerTask('diffSyncJsonPatch', ['concat:diffSyncJsonPatch']);
grunt.registerTask('travis', ['jshint', 'qunit', 'concat:dist', 'setupCi', 'ci']);
grunt.registerTask('docs', function() {
sh.exec('jsdoc-aerogear src/ -r -d docs README.md');
});
grunt.registerMultiTask('ci', function () {
var done = this.async();
var options = this.options({
force: !!grunt.option('force')
});
grunt.util.spawn({
grunt: true,
args: ['ci-' + this.target],
opts: {
cwd: './aerogear-js-integration',
stdio: 'inherit'
}
}, function (err, result, code) {
if (err) {
if (options.force) {
grunt.log.ok('Integration tests unstable, continuing...');
} else {
grunt.fail.fatal('Integration tests failed');
}
}
done();
});
});
grunt.registerTask('setupCi', function() {
sh.config.silent = !grunt.option('verbose');
sh.config.fatal = true;
var integrationDir = './aerogear-js-integration/';
if (sh.test( '-d', integrationDir )) {
grunt.log.debug( 'The ./aerogear-js-integration seems to be cloned already, exiting' );
} else {
if (!sh.which( 'git' )) {
grunt.fail.fatal( 'The task "prepareCi" requires "git" to work properly' );
return;
}
grunt.log.ok('Cloning project to ' + integrationDir + '...');
sh.exec( 'git clone https://github.com/aerogear/aerogear-js-integration.git ' + integrationDir );
}
if (!sh.test( '-d', path.resolve( integrationDir, './node_modules' ))) {
if (!sh.which( 'npm' )) {
grunt.fail.fatal('The task "prepareCi" requires "npm" to work properly');
return;
}
grunt.log.ok('Installing dependencies...');
sh.pushd( integrationDir );
sh.exec( 'npm install' );
sh.popd();
}
grunt.log.ok('Copying ./dist/aerogear.js to ' + integrationDir + '...');
sh.cp('-f', './dist/aerogear.js', path.resolve( integrationDir, './aerogear.js' ));
});
// A task to create custom builds of the library based on the 'concat' task
grunt.registerTask('custom', function( opts ) {
var options = opts.split( ',' ),
concatTasks = grunt.config.get( "concat" ),
tasks = [],
src;
if( options.filter( function( item ) { return item === 'help'; } ).length > 0 ) {
grunt.log.writeln( grunt.file.read( 'custom_build_help.txt' ) );
for( var task in concatTasks ) {
if( task !== 'options' && task !== 'dist' ) {
grunt.log.writeln( task + ' - ' + concatTasks[ task ].description );
}
}
return;
}
if( options.length === 1 ) {
grunt.task.run( ['concat:' + options, 'iife:custom', 'uglify:custom'] );
return ;
}
for( var i = 0; i < options.length; i++ ) {
tasks.push( concatTasks[ options[ i ] ].src );
}
src = _.uniq( _.flatten( tasks ) );
grunt.config.set( 'concat', {
options: {
stripBanners: true,
banner: '<%= meta.banner %>'
},
custom: {
src: src,
dest: 'dist/<%= pkg.name %>.custom.js'
}
});
grunt.task.run(['concat:custom', 'iife:custom', 'uglify:custom']);
});
};