-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrunt.js
More file actions
53 lines (47 loc) · 1.39 KB
/
grunt.js
File metadata and controls
53 lines (47 loc) · 1.39 KB
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
/*
* Grunt Task File
* ---------------
*
* Task: logless
* Description: Parses JavaScript files and removes logging statements
*
* Usage:
*
* logless: {
* task: {
* src: ["file1.js", "file2.js", "other/stuff/*.js"],
* dest: "path/to/destination",
* names: ["console", "alert"],
* strip: "path/to/remove",
* options: {beautify: true}
* }
* }
*
*/
var path = require('path');
var logless = require('logless');
var stripRegex = /[\-\[\]{}()*+?.,\\\^$|#\s]/g;
module.exports = function(grunt) {
grunt.registerMultiTask('logless',
'Parses JavaScript files and removes logging statements', function() {
var data = this.data;
var files = grunt.file.expandFiles( data.src );
var strip = this.data.strip;
if ( typeof strip === "string" ) {
strip = new RegExp('^' + grunt.template.process(strip, grunt.config()).replace(stripRegex, '\\$&'));
}
files.forEach(function(src) {
try {
var parsed = logless.parse(grunt.file.read(src), data.names, data.options);
var target = path.join(data.dest, strip ? src.replace(strip, '') : src);
grunt.file.write(target, parsed);
grunt.log.writeln('File "' + src + '" parsed -> "' + target + '"');
} catch (err) {
grunt.log.error(src + '\n' + err.stack);
}
});
grunt.log.writeln('Processed ' + files.length + ' files.');
if (this.errorCount) {return false;}
}
);
};