forked from metafizzy/isotope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
87 lines (74 loc) · 2.17 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
/*jshint node: true, strict: false */
// -------------------------- grunt -------------------------- //
module.exports = function( grunt ) {
var banner = ( function() {
var src = grunt.file.read('js/isotope.js');
var re = new RegExp('^\\s*(?:\\/\\*[\\s\\S]*?\\*\\/)\\s*');
var matches = src.match( re );
var banner = matches[0].replace( 'Isotope', 'Isotope PACKAGED' );
return banner;
})();
grunt.initConfig({
// ----- global settings ----- //
namespace: 'isotope',
dataDir: 'tasks/data',
// ----- tasks settings ----- //
jshint: {
docs: [ 'js/**/*.js' ],
options: grunt.file.readJSON('.jshintrc')
},
requirejs: {
pkgd: {
options: {
baseUrl: 'bower_components',
include: [
'jquery-bridget/jquery.bridget',
'isotope/js/isotope'
],
out: 'dist/isotope.pkgd.js',
optimize: 'none',
paths: {
isotope: '../',
jquery: 'empty:'
},
wrap: {
start: banner
}
}
}
},
uglify: {
pkgd: {
files: {
'dist/isotope.pkgd.min.js': [ 'dist/isotope.pkgd.js' ]
},
options: {
banner: banner
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-requirejs');
grunt.registerTask( 'pkgd-edit', function() {
var outFile = grunt.config.get('requirejs.pkgd.options.out');
var contents = grunt.file.read( outFile );
// get requireJS definition code
var definitionRE = /define\(\s*'isotope\/js\/isotope'(.|\n)+isotopeDefinition\s*\)/;
var definition = contents.match( definitionRE )[0];
// remove name module
var fixDefinition = definition.replace( "'isotope/js/isotope',", '' )
// ./item -> isotope/js/item
.replace( /'.\//g, "'isotope/js/" );
contents = contents.replace( definition, fixDefinition );
grunt.file.write( outFile, contents );
grunt.log.writeln( 'Edited ' + outFile );
});
grunt.registerTask( 'default', [
'jshint',
'requirejs',
'pkgd-edit',
'uglify'
]);
};