-
Notifications
You must be signed in to change notification settings - Fork 12
/
Gruntfile.js
171 lines (149 loc) · 4.07 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
module.exports = function (grunt) {
'use strict'
// Force use of Unix newlines
grunt.util.linefeed = '\n'
RegExp.quote = function (string) {
return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&')
}
// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON('package.json'),
banner: '/*!\n' +
' * trackswitchjs v<%= pkg.version %> (<%= pkg.homepage %>)\n' +
' * Copyright <%= grunt.template.today("yyyy") %> International Audio Laboratories Erlangen\n' +
' * Licensed under MIT (https://github.com/audiolabs/trackswitchjs/blob/master/LICENSE)\n' +
' */\n',
jqueryCheck: 'if (typeof jQuery === \'undefined\') {\n' +
' throw new Error(\'trackswitchjs\\\'s JavaScript requires jQuery. jQuery must be included before trackswitchjs\\\'s JavaScript.\')\n' +
'}\n',
jqueryVersionCheck: '+function ($) {\n' +
' var version = $.fn.jquery.split(\' \')[0].split(\'.\')\n' +
' if ((version[0] < 2 && version[1] < 9) || (version[0] == 1 && version[1] == 9 && version[2] < 1) || (version[0] >= 4)) {\n' +
' throw new Error(\'trackswitchjs\\\'s JavaScript requires at least jQuery v1.9.1 but less than v4.0.0\')\n' +
' }\n' +
'}(jQuery);\n\n',
// Task configuration.
clean: {
dist: 'dist',
},
stamp: {
options: {
banner: '<%= banner %>\n<%= jqueryCheck %>\n<%= jqueryVersionCheck %>\n+function () {\n',
footer: '\n}();'
},
js: {
files: {
src: '<%= concat.js.dest %>'
}
}
},
concat: {
options: {
// Custom function to remove all export and import statements
process: function (src) {
return src.replace(/^(export|import).*/gm, '')
}
},
js: {
src: [
'js/trackswitch.js'
],
dest: 'dist/js/<%= pkg.name %>.js'
},
css: {
src: [
'dist/tmp/reset.css',
'css/trackswitch.css'
],
dest: 'dist/tmp/concat.css'
}
},
connect: {
server: {
options: {
livereload: true,
base: './',
port: 8000,
open: 'http://localhost:8000/examples/'
}
}
},
watch: {
scripts: {
files: 'js/*.*',
tasks: ['dist-js'],
options: {
interrupt: true,
}
},
css: {
files: 'css/*.*',
tasks: ['dist-css'],
options: {
interrupt: true,
}
}
},
cssmin: {
options: {
mergeIntoShorthands: false,
roundingPrecision: -1
},
target: {
files: {
'dist/css/trackswitch.min.css': ['dist/tmp/concat.css']
}
}
},
uglify: {
main: {
files: {
'dist/js/trackswitch.min.js': ['dist/js/trackswitch.js']
}
}
},
compress: {
main: {
options: {
archive: 'trackswitchjs-<%= pkg.version %>-dist.zip',
mode: 'zip',
level: 9,
pretty: true
},
files: [
{
expand: true,
cwd: 'dist/',
src: ['css/*', 'js/*'],
dest: 'trackswitchjs-<%= pkg.version %>-dist'
}
]
}
},
exec: {
sass: {
command: 'npm run sass'
}
},
'gh-pages': {
options: {
base: 'dist',
add: true
},
src: [
'css/*',
'js/*',
]
}
})
// These plugins provide necessary tasks.
require('load-grunt-tasks')(grunt)
require('time-grunt')(grunt)
grunt.loadNpmTasks('grunt-gh-pages');
grunt.registerTask('dist-js', ['concat:js', 'stamp', 'uglify'])
grunt.registerTask('dist-css', ['exec:sass', 'concat:css', 'cssmin'])
grunt.registerTask('dist', ['clean:dist', 'dist-css', 'dist-js'])
grunt.registerTask('serve', ['dist', 'connect:server', 'watch']);
grunt.registerTask('default', ['dist'])
}