-
Notifications
You must be signed in to change notification settings - Fork 6
/
Gruntfile.js
148 lines (139 loc) · 5.33 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
'use strict';
module.exports = function (grunt) {
var stripBanner = function (src, options) {
if (!options) { options = {}; }
var m = [];
if (options.line) {
// Strip // ... leading banners.
m.push('(/{2,}[\\s\\S].*)');
}
if (options.block) {
// Strips all /* ... */ block comment banners.
m.push('(\/+\\*+[\\s\\S]*?\\*\\/+)');
} else {
// Strips only /* ... */ block comment banners, excluding /*! ... */.
m.push('(\/+\\*+[^!][\\s\\S]*?\\*\\/+)');
}
var re = new RegExp('\\s*(' + m.join('|') + ')\\s*', 'g');
src = src.replace(re, '');
src = src.replace(/\s{2,}(\r|\n|\s){2,}$/gm, '');
return src;
};
grunt.registerMultiTask('concat', 'Concatenate files.', function () {
// Merge task-specific and/or target-specific options with these defaults.
var options = this.options({
separator: grunt.util.linefeed,
banner: '',
footer: '',
stripBanners: false,
process: false
});
// Normalize boolean options that accept options objects.
if (typeof options.stripBanners === 'boolean' && options.stripBanners === true) { options.stripBanners = {}; }
if (typeof options.process === 'boolean' && options.process === true) { options.process = {}; }
// Process banner and footer.
var banner = grunt.template.process(options.banner);
var footer = grunt.template.process(options.footer);
// Iterate over all src-dest file pairs.
this.files.forEach(function (f) {
// Concat banner + specified files + footer.
var src = banner + f.src.filter(function (filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
}).map(function (filepath) {
// Read file source.
var src = grunt.file.read(filepath);
// Process files as templates if requested.
if (options.process) {
src = grunt.template.process(src, options.process);
}
// Strip banners if requested.
if (options.stripBanners) {
src = stripBanner(src, options.stripBanners);
}
return src;
}).join(grunt.util.normalizelf(options.separator)) + footer;
// Write the destination file.
grunt.file.write(f.dest, src);
// Print a success message.
grunt.log.writeln('File "' + f.dest + '" created.');
});
});
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
srcFiles: [
'src/namespace.js',
'src/services/*.js',
'src/httpInterceptor.js',
],
karma: {
unit: {
options: {
configFile: 'test/karma.conf.js'
}
}
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'<%= srcFiles %>'
]
},
concat: {
options: {
banner: '/***********************************************\n' +
'* secure-ng-resource JavaScript Library\n' +
'* https://github.com/AmericanCouncils/secure-ng-resource/ \n' +
'* License: MIT (http://www.opensource.org/licenses/mit-license.php)\n' +
'* Compiled At: <%= grunt.template.today("mm/dd/yyyy HH:MM") %>\n' +
'***********************************************/\n' +
'(function(window) {\n' +
'\'use strict\';\n',
footer: '\n}(window));'
},
prod: {
options: {
stripBanners: {
block: true,
line: true
}
},
src: ['<%= srcFiles %>'],
dest: 'build/<%= pkg.name %>.js'
},
debug: {
src: ['<%= srcFiles %>'],
dest: 'build/<%= pkg.name %>.debug.js'
}
},
uglify: {
build: {
src: 'build/<%= pkg.name %>.js',
dest: 'build/<%= pkg.name %>.min.js'
}
}
});
// Load grunt-karma task plugin
grunt.loadNpmTasks('grunt-karma');
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
//grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
// Default task(s).
grunt.registerTask('test', ['jshint', 'concat:debug', 'karma']);
grunt.registerTask('default', ['test', 'prod']);
//grunt.registerTask('test', ['karma']);
grunt.registerTask('debug', ['concat:debug']);
grunt.registerTask('prod', ['concat:prod', 'uglify']);
};