forked from qTip2/qTip2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grunt.js
206 lines (189 loc) · 6.14 KB
/
grunt.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
/*global module:false*/
module.exports = function(grunt) {
// Load grunt helpers
grunt.loadNpmTasks('grunt-contrib');
grunt.loadNpmTasks('grunt-text-replace');
// Project configuration.
grunt.initConfig({
// Meta properties
pkg: '<json:package.json>',
meta: {
banners: {
full: '/*! <%= 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 %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */',
min:'/*! <%= pkg.name %> v<%= pkg.version %> | <%= pkg.homepage %> | '+
'Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
}
},
// Directories
dirs: { src: 'src', dist: 'dist' },
// Styles and plugins map
styles: {
basic: '<%=dirs.src%>/basic.css',
css3: '<%=dirs.src%>/css3.css'
},
plugins: {
svg: { js: '<%=dirs.src%>/svg/svg.js' },
ajax: { js: '<%=dirs.src%>/ajax/ajax.js' },
tips: { js: '<%=dirs.src%>/tips/tips.js', css: '<%=dirs.src%>/tips/tips.css' },
modal: { js: '<%=dirs.src%>/modal/modal.js', css: '<%=dirs.src%>/modal/modal.css' },
viewport: { js: '<%=dirs.src%>/viewport/viewport.js' },
imagemap: { js: '<%=dirs.src%>/imagemap/imagemap.js' },
ie6: { js: '<%=dirs.src%>/ie6/ie6.js', css: '<%=dirs.src%>/ie6/ie6.css' }
},
// Actual tasks
clean: {
dist: 'dist/**/*' // Changed by the 'dist' command-line option (see "init" task)
},
concat: {
basic: {
src: [
'<banner:meta.banners.full>', '<%=dirs.src%>/intro.js',
'<%=dirs.src%>/core.js', '<%=dirs.src%>/outro.js'
],
dest: '<%=dirs.dist%>/basic/jquery.qtip.js'
},
basic_css: {
src: [ '<banner:meta.banners.full>', '<%=dirs.src%>/core.css', '<%=styles.basic%>' ],
dest: '<%=dirs.dist%>/basic/jquery.qtip.css'
},
dist: {
// See "init" task for src
dest: '<%=dirs.dist%>/jquery.qtip.js'
},
dist_css: {
// See "init" task for src
dest: '<%=dirs.dist%>/jquery.qtip.css'
}
},
min: {
basic: {
src: ['<banner:meta.banners.min>', '<file_strip_banner:<%=dirs.dist%>/basic/jquery.qtip.js:block>'],
dest: '<%=dirs.dist%>/basic/jquery.qtip.min.js'
},
dist: {
src: ['<banner:meta.banners.min>', '<file_strip_banner:<%=dirs.dist%>/jquery.qtip.js:block>'],
dest: '<%=dirs.dist%>/jquery.qtip.min.js'
}
},
mincss: {
basic: {
files: {
'<%=dirs.dist%>/basic/jquery.qtip.min.css': [
'<banner:meta.banners.min>', '<file_strip_banner:<%=dirs.dist%>/basic/jquery.qtip.css:block>'
]
}
},
dist: {
files: {
'<%=dirs.dist%>/jquery.qtip.min.css': [
'<banner:meta.banners.min>', '<file_strip_banner:<%=dirs.dist%>/jquery.qtip.css:block>'
]
}
}
},
replace: {
dist: {
src: '<%=dirs.dist%>/**/*.js',
overwrite: true
}
},
lint: {
beforeconcat: ['grunt.js', '<%=dirs.src%>/core.js', '<%=dirs.src%>/*/*.js']
},
watch: {
files: '<config:lint.beforeconcat.files>',
tasks: 'lint'
},
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
boss: true,
eqnull: true,
browser: true,
undef: false
},
globals: {
jQuery: true,
'$': true
}
},
uglify: {}
});
// Parse command line options
grunt.registerTask('init', 'Default build', function() {
if(grunt.config('concat.dist.src')) { return; } // Only do it once
// Grab command-line options, using valid defaults if not given
var plugins = (grunt.option('plugins') || Object.keys( grunt.config('plugins')).join(' ')).replace(/ /g, ' ').split(' '),
styles = (grunt.option('styles') || Object.keys( grunt.config('styles')).join(' ')).replace(/ /g, ' ').split(' '),
valid;
// Setup JS/CSS arrays
var js = ['<banner:meta.banners.full>', '<%=dirs.src%>/intro.js', '<%=dirs.src%>/core.js'],
css = ['<banner:meta.banners.full>', '<%=dirs.src%>/core.css'],
dist = grunt.option('dist');
// Parse 'styles' option (decides which stylesheets are included)
if(grunt.option('styles') !== 0) {
styles.forEach(function(style, i) {
if( (valid = grunt.config('styles.'+style)) ) {
css.push(valid);
}
else { styles[i] = style+('*'.red); }
});
}
else { styles = ['None']; }
// Parse 'plugins' option (decides which plugins are included)
if(grunt.option('plugins') !== 0) {
plugins.forEach(function(plugin, i) {
if( (valid = grunt.config('plugins.'+plugin)) ) {
if(valid.js) { js.push(valid.js); }
if(valid.css) { css.push(valid.css); }
}
else { plugins[i] = plugin+('*'.red); }
});
}
else { plugins = ['None']; }
// Update config
grunt.config('concat.dist.src', js.concat(['<%=dirs.src%>/outro.js']));
grunt.config('concat.dist_css.src', css);
// Parse 'dist' option (decides which directory to build into)
if(dist) {
grunt.config('dirs.dist', dist);
grunt.config('clean.dist', dist + '/**/*');
}
// Output current build properties
grunt.log.write("\nBuilding " + "qTip2".green + " with " +
"plugins " + plugins.join(' ').green + " and " +
"styles " +styles.join(' ').green + "\n"
);
});
// Called post-commit
grunt.registerTask('version', 'Replace versioning/date holders in files', function(nightly) {
var done = this.async();
// Get the current commit
grunt.utils.spawn({ cmd: 'git', args: ['hash-object', 'dist/jquery.qtip.js' ] }, function(err, sha1) {
var version = grunt.config('pkg.version') + (nightly !== false ? '-nightly-'+sha1.substr(0,10) : '');
grunt.config('replace.dist.replacements', [{
from: '@VERSION',
to: version
}, {
from: '@DATE',
to: grunt.template.today("dd-mm-yyyy")
}]);
done();
});
});
// Setup all other tasks
grunt.registerTask('css', 'init clean concat:dist_css mincss:dist');
grunt.registerTask('basic', 'init clean lint concat:basic concat:basic_css min:basic mincss:basic version replace');
grunt.registerTask('default', 'init clean lint concat:dist concat:dist_css min:dist mincss:dist version replace');
grunt.registerTask('dev', 'init clean lint concat min mincss version replace');
};