forked from dimsemenov/Magnific-Popup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
199 lines (166 loc) · 5.09 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
/**
*
* Run 'grunt' to generate JS and CSS in folder 'dist' and site in folder '_site'
* *
* Run 'grunt watch' to automatically regenerate '_site' when you change files in 'src' or in 'website'
*
*/
module.exports = function(grunt) {
'use strict';
var jekyllConfig = "isLocal : false \r\n"+
"permalink: /:title/ \r\n"+
"exclude: ['.json', '.rvmrc', '.rbenv-version', 'README.md', 'Rakefile', 'changelog.md', 'compiler.jar', 'private', 'magnific-popup.sublime-project', 'magnific-popup.sublime-workspace', '.htaccess'] \r\n"+
"auto: true \r\n"+
"mfpversion: <%= pkg.version %> \r\n"+
"pygments: true \r\n";
// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON('magnific-popup.jquery.json'),
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>; */\n',
// Task configuration.
clean: {
files: ['dist']
},
sass: {
dist: {
files: {
'dist/magnific-popup.css': 'src/css/main.scss'
}
}
},
jshint: {
all: [
'Gruntfile.js',
'src/js/*.js'
],
options: {
jshintrc: '.jshintrc'
}
},
mfpbuild: {
all: {
src: [
'inline',
'ajax',
'image',
'zoom',
'iframe',
'gallery',
'retina',
'fastclick'
],
basePath: 'src/js/',
dest: 'dist/jquery.magnific-popup.js',
banner: '<%= banner %>'
}
},
jekyll: {
dev: {
src: 'website',
dest: '_site',
url: 'local',
raw: jekyllConfig + "url: local"
},
production: {
src: 'website',
dest: '_production',
url: 'production',
raw: jekyllConfig + "url: production"
}
},
copy: {
main: {
files: [
{src: ['dist/**'], dest: 'website/'}
]
},
dev: {
files: [
{src: ['dist/**'], dest: '_site/'}
]
}
},
uglify: {
my_target: {
files: {
'dist/jquery.magnific-popup.min.js': ['dist/jquery.magnific-popup.js']
},
preserveComments: 'some'
},
options: {
preserveComments: 'some'
}
},
watch: { // for development run 'grunt watch'
jekyll: {
files: ['website/**'],
tasks: ['jekyll:dev', 'copy:dev']
},
files: ['src/**'],
tasks: [ 'sass', 'mfpbuild', 'copy:dev', 'uglify']
},
cssmin: {
compress: {
files: {
"website/site-assets/all.min.css": ["website/site-assets/site.css", "website/dist/magnific-popup.css"]
}
}
}
});
// Makes Magnific Popup JS file.
// grunt mfpbuild --mfp-exclude=ajax,image
grunt.task.registerMultiTask('mfpbuild', 'Makes Magnific Popup JS file.', function() {
var files = this.data.src,
includes = grunt.option('mfp-exclude'),
basePath = this.data.basePath,
newContents = this.data.banner + ";(function($) {\n";
if(includes) {
includes = includes.split(/[\s,]+/); // 'a,b,c' => ['a','b','c']
var removeA = function (arr) {
var what, a = arguments, L = a.length, ax;
while (L > 1 && arr.length) {
what = a[--L];
while ((ax= arr.indexOf(what)) !== -1) {
arr.splice(ax, 1);
}
}
return arr;
};
includes.forEach(function( name ) {
if(name) {
grunt.log.writeln( 'removed "'+name +'"' );
files = removeA(files, name);
}
});
}
files.unshift('core');
grunt.log.writeln( 'Your build is made of:'+files );
files.forEach(function( name ) {
// Wrap each module with a pience of code to be able to exlude it, stolen for modernizr.com
newContents += "\n/*>>"+name+"*/\n";
newContents += grunt.file.read( basePath + name + '.js' ) + '\n';
newContents += "\n/*>>"+name+"*/\n";
});
newContents+= " _checkInstance(); })(window.jQuery || window.Zepto);";
grunt.file.write( this.data.dest, newContents );
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-jekyll');
grunt.loadNpmTasks('grunt-contrib-cssmin');
// Default task.
grunt.registerTask('default', ['sass', 'mfpbuild', 'uglify', 'copy', 'jekyll:dev']);
grunt.registerTask('production', ['sass', 'mfpbuild', 'uglify', 'copy', 'cssmin', 'jekyll:production']);
grunt.registerTask('nosite', ['sass', 'mfpbuild', 'uglify']);
grunt.registerTask('hint', ['jshint']);
};