-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathGruntfile.js
184 lines (162 loc) · 4.9 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
/* global module:false*/
module.exports = function(grunt) {
var _ = grunt.util._;
var m = require('marked');
var marked = m.marked;
// var hl = require('highlight').Highlight;
var hl = require('node-syntaxhighlighter');
marked.setOptions({
highlight: function(code, lang) {
lang = hl.getLanguage(lang);
return hl.highlight(code, lang);
},
gfm: true
});
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('jcarousellite.jquery.json'),
bowerjson: './bower.json',
meta: {
banner: '/*!<%= "\\n" %>' +
' * <%= 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" %>' +
' * based on the original by Ganeshji Marwaha (gmarwaha.com)' +
'<%= "\\n" %>' +
' * Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>' +
' (<%= _.pluck(pkg.licenses, "url").join(", ") %>)' +
'<%= "\\n" %>' + ' */' +
'<%= "\\n\\n" %>'
},
concat: {
all: {
src: ['src/jquery.<%= pkg.name %>.js'],
dest: '<%= pkg.name %>.js'
},
options: {
stripBanners: true,
banner: '<%= meta.banner %>'
}
},
uglify: {
all: {
files: {
'<%= pkg.name %>.min.js': ['<%= concat.all.dest %>']
},
options: {
preserveComments: false,
banner: '<%= meta.banner %>'
}
}
},
watch: {
scripts: {
files: '<%= jshint.all %>',
tasks: ['jshint']
},
docs: {
files: ['readme.md', 'lib/tpl/**/*.tpl', 'Gruntfile.js'],
tasks: ['docs']
}
},
eslint: {
all: ['Gruntfile.js', 'src/**/*.js'],
options: {
configFile: '.eslintrc.js'
}
},
jshint: {
all: ['Gruntfile.js', 'src/**/*.js'],
options: {
curly: true,
// eqeqeq: true,
// immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true,
globals: {
jQuery: true,
require: false
}
}
},
version: {
all: {
src: ['src/*.js', '*.json']
},
banner: {
src: ['<%= pkg.name %>.js'],
options: {
prefix: 'Lite - v'
}
}
}
});
grunt.registerMultiTask('setshell', 'Set grunt shell commands', function() {
var settings, cmd;
var tgt = this.target;
var cmdLabel = 'shell.' + tgt + '.command';
var file = this.data.file;
var append = this.data.cmdAppend || '';
if (!grunt.file.exists(file)) {
grunt.warn('File does not exist: ' + file);
}
settings = grunt.file.readJSON(file);
if (!settings[tgt]) {
grunt.warn('No ' + tgt + ' property found in ' + file);
}
cmd = settings[tgt] + append;
grunt.config(cmdLabel, cmd);
grunt.log.writeln(('Setting ' + cmdLabel + ' to:').cyan);
grunt.log.writeln(cmd);
});
grunt.registerTask('bower', 'update bower.json', function() {
var comp = grunt.config('bowerjson');
var pkg = grunt.file.readJSON('jcarousellite.jquery.json');
var json = {};
['name', 'version', 'title', 'description', 'author', 'licenses', 'dependencies'].forEach(function(el) {
json[el] = pkg[el];
});
_.extend(json, {
main: grunt.config('concat.all.dest'),
ignore: [
'demo/',
'lib/',
'test/',
'src/',
'Gruntfile.js',
'package.json',
'jcarousellite.jquery.json'
]
});
json.name = 'jquery.' + json.name;
grunt.file.write(comp, JSON.stringify(json, null, 2));
grunt.log.writeln('File "' + comp + ' updated."');
});
grunt.registerTask('docs', function() {
var doc;
var readme = grunt.file.read('readme.md');
var head = grunt.template.process(grunt.file.read('lib/tpl/header.tpl'));
var foot = grunt.file.read('lib/tpl/footer.tpl');
// Convert to markdown (with the highlight.js processing in setOptions.highlight)
doc = marked(readme);
// Remove function foo() {} after processing
// doc = doc.replace(/<span class="keyword">function<\/span> foo\(\) \{\}(\n)?/g, '');
grunt.file.write('index.html', head + doc + foot);
});
grunt.registerTask('build', ['eslint', 'version', 'concat', 'bower', 'uglify', 'docs']);
grunt.registerTask('patch', ['eslint', 'version::patch', 'concat', 'bower', 'uglify']);
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-version');
};