-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathGruntfile.js
173 lines (154 loc) · 3.75 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
/**
* Created by Tivie on 12-11-2014.
*/
module.exports = function (grunt) {
'use strict';
//load Package configuration
var pkg = grunt.file.readJSON('package.json'),
// load pkg hst
hst = grunt.file.readJSON('.hst.json'),
// Project configuration.
config = {
pkg: pkg,
// File concatenation
concat: {
options: {
sourceMap: true,
banner: ';/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n(function(){\n',
footer: '}).call(this);'
},
dist: {
src: [
'src/**/*.js'
],
dest: 'dist/<%= pkg.name %>.js'
}
},
// File minification
uglify: {
options: {
sourceMap: true,
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
},
dist: {
files: {
'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
}
}
},
// Enforce lint
jshint: {
files: [
'Gruntfile.js',
'src/**/*.js',
'test/**/*.js'
]
},
// Enforce codestyle
jscs: {
options: {
config: '.jscs.json'
},
files: {
src: [
'src/**/*.js',
'test/**/*.js'
]
}
},
// Create changelog based on git commits
changelog: {
options: {
repository: pkg.repository,
dest: 'CHANGELOG.md'
}
},
//Run tests
simplemocha: {
node: {
src: 'test/node/**/*.js',
options: {
globals: ['should'],
timeout: 3000,
ignoreLeaks: false,
reporter: 'spec'
}
}
},
/**
* EXTRA
*
* The following tasks are used to prepare and configure the boilerplate with your values automatically
* You can remove them safely if you don't need them anymore
*/
// This task ensures data in bower.json and component.json is always in sync with package.json
update_json: {
options: {
src: 'package.json',
indent: ' '
},
bower: {
dest: 'bower.json',
fields: [
'name',
'version',
'description',
'author',
'keywords',
'license',
'repository',
'main',
'dependencies'
]
},
component: {
dest: 'component.json',
fields: [
'name',
{
repository: function(src) {
return src.repository.url.match(/([^\/]+\/[^\/]+).git/)[1];
}
},
'description',
'version',
'keywords',
{
scripts: function(src) {
return [src.main];
}
},
'license'
]
}
},
// This task renames the main library file in src directory matches the one you supplied in package.json
rename: {
mainFile: {
src: 'src/' + hst.src + '.js',
dest: 'src/' + pkg.name + '.js'
},
testFile: {
src: 'test/' + hst.src + '.js',
dest: 'src/' + pkg.name + '.js'
}
}
};
// Load config
grunt.initConfig(config);
// load all grunt tasks
require('load-grunt-tasks')(grunt);
// Alias tasks
grunt.registerTask('lint', ['jshint', 'jscs']);
grunt.registerTask('test', ['lint', 'simplemocha']);
grunt.registerTask('build', ['test', 'concat', 'uglify']);
grunt.registerTask('prep-release', ['build', 'changelog']);
// Default task(s).
grunt.registerTask('default', ['test']);
// Extra tasks (can be deleted)
grunt.registerTask('saveHst', function (arg1, arg2) {
hst.src = pkg.name;
grunt.file.write('.hst.json', JSON.stringify(hst));
});
grunt.registerTask('prepare', ['update_json', 'rename', 'saveHst']);
};