-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
155 lines (151 loc) · 5.76 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
/*
* Copyright (c) 2012-2015 S-Core Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
// for jshint check based on .jshintrc
// package.json doesn't have jshint-stylish and grunt-contrib-jshint plugins.
// Therefore, users of jshint must install these plugins by using npm install ...
jshint : {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
files: {
expand: true,
cwd: './',
src: ['src/**/*.js',
'common/**/*.js', // common
'!**/lib/**', '!**/custom-lib/**', '!**/Gruntfile.js', // ignore lib and Gruntfile
'!**/*.min.js', '!**/*.back.js' // ignore min/back.js files
]
}
},
bower: {
install: {
// just run grunt bower install
},
options: {
copy: false
}
},
copy: {
all: {
files: [
{
expand: true,
cwd: './',
src: ['**'],
dest: 'deploy/'
}
]
},
uncompressed: {
files: [
{
expand: true,
cwd: './',
src: ['**/*.js', '**/lib/**', '!node_modules/**', '!deploy/**', '!bower_components/**'],
dest: 'deploy/',
rename: function (dest, src) {
return dest + src.substring(0, src.lastIndexOf('.js')) + '.uncompressed.js';
}
}
]
}
},
uglify: {
debug: {
options: {
mangle: true,
compress: true,
preserveComments: false,
sourceMap: function(path) {
return path + '.map';
},
sourceMappingURL: function(path) {
return path.substring(path.lastIndexOf('/') + 1) + '.map';
}
},
files: [
{
expand: true,
cwd: 'deploy/',
src: ['**/*.js', '!node_modules/*.js', '!node_modules/**/*.js', '!**/lib/**/*.js', '!&&/lib/*.js', '!*.uncompressed.js', '!**/*.uncompressed.js', '!bower_components/**/*.js'],
dest: 'deploy/'
}
]
},
release: {
options: {
mangle: true,
compress: true,
preserveCommnets: false
},
files: [
{
expand: true,
cwd: 'deploy/',
src: ['**/*.js', '!node_modules/**/*.js', '!node_modules/*.js', '!**/lib/**/*.js', '!**/lib/*.js', '!bower_components/**/*.js'],
dest: 'deploy/'
}
]
}
},
clean: {
all: ['deploy'],
unnecessary: ['deploy/Gruntfile.js', 'deploy/node_modules']
},
fix_source_maps: {
files: {
expand: true,
cwd: 'deploy/',
src: ['*.map', '**/*.map'],
dest: 'deploy'
}
}
});
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-bower-task');
grunt.registerMultiTask('fix_source_maps', 'Fixes uglified source maps', function() {
this.files.forEach(function(f) {
var json, src;
src = f.src.filter(function(filepath) {
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
});
json = grunt.file.readJSON(src);
var length = json.sources.length;
for(var i = 0; i < length; i++) {
json.sources[i] = json.sources[i].substring(json.sources[i].lastIndexOf('/') + 1);
json.sources[i] = json.sources[i].substring(0, json.sources[i].lastIndexOf('.js')) + '.uncompressed.js';
}
json.file= json.file.substring(json.file.lastIndexOf('/') + 1);
grunt.file.write(f.dest, JSON.stringify(json));
grunt.log.writeln('Source map in ' + src + ' fixed');
});
});
grunt.registerTask('default', ['clean:all', 'bower', 'copy:all'/*, 'copy:uncompressed', 'clean:unnecessary', 'uglify:debug', 'fix_source_maps'*/]);
grunt.registerTask('release', ['clean:all', 'bower', 'copy:all', 'clean:unnecessary', 'uglify:release']);
grunt.registerTask('convention', ['jshint']);
};