-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathbeautify.js
62 lines (54 loc) · 1.79 KB
/
beautify.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
/*
* grunt-beautify.git
* https://github.com/pix/grunt-beautify
*
* Copyright (c) 2012 Camille Moncelier
* Licensed under the MIT license.
*/
var beautifier = require('js-beautify');
module.exports = function (grunt) {
// Please see the grunt documentation for more information regarding task and
// helper creation: https://github.com/cowboy/grunt/blob/master/docs/toc.md
// ==========================================================================
// TASKS
// ==========================================================================a
var default_options = {
indentSize : 2
};
grunt.registerMultiTask('beautify', 'Javascript beautifier', function () {
var options = null;
var tmp = grunt.config(['beautifier', this.target, 'options']);
if (typeof tmp === 'object') {
grunt.verbose.writeln('Using "' + this.target + '" beautifier options.');
options = tmp;
} else {
tmp = grunt.config('beautifier.options');
if (typeof tmp === 'object') {
grunt.verbose.writeln('Using master beautifier options.');
options = tmp;
} else {
grunt.verbose.writeln('Using beautifier default options.');
options = default_options;
}
}
// Beautify specified files.
var excludes = grunt.config(['beautifier', this.target, 'exclude']);
grunt.file.expand(this.filesSrc).filter(function (file) {
if(/\.min\./.test(file)) {
grunt.log.writeln('Not beautifying ' + file);
return false;
}
for (var i = 0; i < excludes.length; i++) {
if (excludes[i].test(file)) {
grunt.log.writeln('Not beautifying ' + file);
return false;
}
}
return true;
}).forEach(function (filepath) {
grunt.log.writeln('Beautifying ' + filepath);
var result = beautifier(grunt.file.read(filepath), options);
grunt.file.write(filepath, result);
});
});
};