-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGruntfile.js
100 lines (82 loc) · 2.58 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
var fs = require('fs');
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-html2js');
grunt.loadNpmTasks('grunt-karma');
// Project configuration.
grunt.util.linefeed = '\n';
grunt.initConfig({
main: 'angularUtils',
modules: [], // to be filled in by build task
pkg: grunt.file.readJSON('package.json'),
dist: 'dist',
filename: 'angular-utils',
meta: {
modules: 'angular.module("angularUtils", [<%= srcModules %>]);',
banner: ['/*',
' * <%= pkg.name %>',
' * <%= pkg.homepage %>',
' * Version: <%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>',
' * License: <%= pkg.license %>',
' */\n'].join('\n')
},
concat: {
dist: {
options: {
banner: '<%= meta.banner %><%= meta.modules %>\n\n',
},
src: [], //src filled in by build task
dest: '<%= dist %>/<%= filename %>.js'
},
},
uglify: {
dist: {
files: {
'<%= dist %>/<%= filename %>.min.js': ['<%= dist %>/<%= filename %>.js']
}
}
},
jshint: {
files: ['Gruntfile.js', 'src/**/*.js'],
options: {
jshintrc: '.jshintrc'
}
},
});
grunt.registerTask('build', 'Create build files', function() {
var _ = grunt.util._;
grunt.file.expand({
filter: 'isDirectory', cwd: '.'
}, 'src/*').forEach(function(dir) {
findModule(dir.split('/')[1]);
});
var modules = grunt.config('modules');
grunt.config('srcModules', _.pluck(modules, 'moduleName'));
var srcFiles = _.pluck(modules, 'srcFiles');
grunt.config('concat.dist.src', grunt.config('concat.dist.src').concat(srcFiles));
grunt.task.run(['concat']);
});
function findModule(name) {
var formattedName = formatName(name);
var module = {
name: formattedName,
moduleName: enquote(grunt.config('main') + '.' + formattedName),
srcFiles: grunt.file.expand('src/' + name + '/*.js'),
};
grunt.config('modules', grunt.config('modules').concat(module));
}
function formatName(name) {
name = name.replace(/-[a-z]/g, function (match) {
return match.charAt(1).toUpperCase() + match.slice(2);
});
return name;
}
function enquote(name) {
return '"' + name + '"';
}
grunt.registerTask('default', ['jshint', 'build']);
};