forked from frapontillo/angular-gage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
179 lines (157 loc) · 4.43 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
172
173
174
175
176
177
178
179
/*jshint unused:false */
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// configurable paths
var yeomanConfig = {
src: 'src',
dist: 'dist',
test: 'test',
temp: '.temp'
};
var bower = grunt.file.readJSON('bower.json');
try {
yeomanConfig.src = bower.appPath || yeomanConfig.src;
} catch (e) {}
grunt.initConfig({
yeoman: yeomanConfig,
bower: bower,
util: {
getAuthors: function(authors) {
var authorsString = '';
for (var a in authors) {
if (authors[a].name) {
authorsString += authors[a].name;
}
if (authors[a].email) {
authorsString += ' (' + authors[a].email + '), ';
}
}
authorsString = authorsString.substring(0, authorsString.length - 2);
return authorsString;
}
},
meta: {
banner:
'/**\n' +
' * <%= bower.name %>\n' +
' * @version v<%= bower.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' +
' * @author <%= util.getAuthors(bower.authors) %>\n' +
' * @link <%= bower.homepage %>\n' +
' * @license <%= bower.license.join(", ") %>\n' +
'**/\n\n'
},
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: [
'Gruntfile.js',
'<%= yeoman.src %>/**/*.js'
],
test: {
src: ['<%= yeoman.test %>/spec/**/*.js'],
options: {
jshintrc: '<%= yeoman.test %>/.jshintrc'
}
}
},
// Empties folders to start fresh
clean: {
dist: {
files: [{
dot: true,
src: [
'<%= yeoman.dist %>/*',
'!<%= yeoman.dist %>/.git*'
]
}]
},
temp: {
src: ['<%= yeoman.dist %>/<%= yeoman.temp %>']
}
},
// Automatically inject Bower components into the app
bowerInstall: {
app: {
src: ['<%= yeoman.app %>/index.html'],
ignorePath: '<%= yeoman.app %>/'
}
},
// ngmin tries to make the code safe for minification automatically by
// using the Angular long form for dependency injection. It doesn't work on
// things like resolve or inject so those have to be done manually.
ngmin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.src %>',
src: ['**/*.js'],
dest: '<%= yeoman.dist %>/<%= yeoman.temp %>'
}]
}
},
// Test settings
karma: {
options: {
configFile: 'karma.conf.js'
},
debug: {
options: {
singleRun: false
}
},
unit: {
browsers: ['PhantomJS'],
options: {
singleRun: true
}
}
},
concat: {
options: {
banner: '<%= meta.banner %>\'use strict\';\n',
process: function(src, filepath) {
return '// Source: ' + filepath + '\n' +
src.replace(/(^|\n)[ \t]*('use strict'|"use strict");?\s*/g, '$1');
}
},
dist: {
src: ['common/*.js', '<%= yeoman.dist %>/<%= yeoman.temp %>/**/*.js'],
dest: '<%= yeoman.dist %>/<%= bower.name %>.js'
}
},
uglify: {
options: {
banner: '<%= meta.banner %>'
},
min: {
files: {
'<%= yeoman.dist %>/<%= bower.name %>.min.js': '<%= concat.dist.dest %>'
}
}
}
});
// Test the directive
grunt.registerTask('debug', ['newer:jshint', 'karma:debug']);
grunt.registerTask('test', ['newer:jshint', 'karma:unit']);
// Build the directive
// - clean, cleans the output directory
// - ngmin, prepares the angular files
// - concat, concatenates and adds a banner to the debug file
// - uglify, minifies and adds a banner to the minified file
// - clean:temp, cleans the ngmin-ified directory
grunt.registerTask('build', ['clean', 'ngmin', 'concat', 'uglify', 'clean:temp']);
// Default task, do everything
grunt.registerTask('default', ['test', 'build']);
};