-
Notifications
You must be signed in to change notification settings - Fork 427
/
Gruntfile.js
164 lines (149 loc) · 4.56 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
module.exports = function(grunt) {
var pkg = grunt.file.readJSON('package.json');
var marked = require('marked');
var hl = require('node-syntaxhighlighter');
marked.setOptions({
highlight: function(code, lang) {
var language = hl.getLanguage(lang || 'javascript');
return hl.highlight(code, language);
},
gfm: true
});
// Project configuration.
grunt.initConfig({
pluginName: 'smooth-scroll',
pkg: pkg,
meta: {
banner: '/*!<%= "\\n" %>' +
' * <%= pkg.title %> - 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" %>' +
' * Licensed <%= pkg.license %>' +
'<%= "\\n" %>' + ' */' +
'<%= "\\n\\n" %>'
},
concat: {
all: {
src: ['src/jquery.<%= pluginName %>.js'],
dest: 'jquery.<%= pluginName %>.js'
},
options: {
stripBanners: true,
banner: '<%= meta.banner %>',
process: function(src) {
var umdHead = grunt.file.read('lib/tmpl/umdhead.tpl');
var umdFoot = grunt.file.read('lib/tmpl/umdfoot.tpl');
var ret = src
.replace('(function($) {', umdHead)
.replace('})(jQuery);', umdFoot);
return ret;
}
}
},
uglify: {
all: {
files: {
'jquery.<%= pluginName %>.min.js': ['<%= concat.all.dest %>']
},
options: {
banner: '<%= meta.banner %>'
// preserveComments: /\/\*[\s\S]*/
}
}
},
watch: {
scripts: {
files: '<%= jshint.all %>',
tasks: ['jshint:all']
},
docs: {
files: ['readme.md', 'lib/tmpl/**/*.html'],
tasks: ['docs']
}
},
jshint: {
all: ['Gruntfile.js', 'src/**/*.js'],
options: {
curly: true,
devel: true,
eqeqeq: true,
unused: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true,
globals: {
jQuery: true,
require: false
}
}
},
eslint: {
target: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
fix: true
// configFile: '.eslintrc.js',
}
},
version: {
src: {
src: ['src/jquery.<%= pluginName %>.js']
},
banners: {
pkg: pkg,
src: [
'jquery.<%= pluginName %>.js',
'jquery.<%= pluginName %>.min.js'
],
options: {
prefix: '- v'
}
},
package: {
src: ['package.json']
}
}
});
grunt.registerTask('docs', 'Convert readme.md to html and concat with header and footer for index.html', function() {
var readme = grunt.file.read('readme.md');
var head = grunt.template.process(grunt.file.read('lib/tmpl/header.tpl'));
var foot = grunt.file.read('lib/tmpl/footer.tpl');
var doc = marked(readme);
grunt.file.write('index.html', head + doc + foot);
});
grunt.registerTask('updateBower', 'Update bower.json to match package.json', function() {
var pkg = require('./package.json');
var props = ['name', 'main', 'homepage', 'version', 'repository', 'dependencies', 'keywords', 'license'];
var json = {
description: 'Easy implementation of smooth scrolling for same-page links'
};
props.forEach(function(item) {
if (pkg[item]) {
json[item] = pkg[item];
}
});
json.authors = [pkg.author];
json.moduleType = ['amd', 'node'];
json.ignore = ['demo/', 'lib/', 'src/', 'test/', '**/.*', 'Gruntfile.js', 'package.json'];
grunt.file.write('bower.json', JSON.stringify(json, null, 2));
});
grunt.registerTask('lint', ['eslint']);
grunt.registerTask('build', ['lint', 'concat', 'version', 'updateBower', 'uglify', 'docs']);
grunt.registerTask('default', ['build']);
['patch', 'minor', 'major'].forEach(function(release) {
grunt.registerTask(release, ['lint', 'version:src:' + release, 'concat', 'uglify', 'version:banners:' + release, 'version:package:' + release, 'updateBower']);
});
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-version');
};