/
Gruntfile.js
142 lines (121 loc) · 3.03 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
var glob = require('glob'),
path = require('path'),
teamcity = require('release-helpers').teamcity,
release = require('release-helpers').release;
module.exports = function(grunt) {
'use strict';
var isDevelopmentRun = !grunt.option('prod'),
testsReporters = ['coverage'],
coverageReporters = [
{type: 'html', dir:'coverage/'}
],
pkg = grunt.file.readJSON('package.json');
function tcSetBuildVersion() {
teamcity.setBuildVersion();
}
function versionBump() {
var done = this.async(),
type = grunt.option('type');
if (teamcity.isCiRun()) {
type = teamcity.getProperty('release.type');
}
release.versionBump(type, done);
teamcity.setBuildVersion();
}
if (!isDevelopmentRun) {
testsReporters.push('teamcity');
coverageReporters.push({type: 'teamcity'});
} else {
testsReporters.push('dots');
coverageReporters.push({type: 'text'});
}
grunt.initConfig({
pkg: pkg,
phantomFolder: function() {
return path.join(__dirname, glob.sync('coverage/*')[0]);
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
files: ['src/js/**/*.js']
},
clean: {
coverage: ['coverage/'],
docs: ['docs/'],
test: ['test/js/styles/**/*.css']
},
karma: {
options: {
autoWatch: isDevelopmentRun,
singleRun: !isDevelopmentRun
},
unit: {
configFile: 'karma.unit.conf.js',
browsers: ['PhantomJS'],
reporters: testsReporters,
coverageReporter: {
reporters: coverageReporters
}
},
ui: {
configFile: 'karma.ui.conf.js',
browsers: ['Chrome'],
reporters: testsReporters
}
},
jscs: {
options: {
config: '.jscsrc'
},
src: 'src/js/**/*.js'
},
copy: {
coverage:{
files: [
{src: ['**'], cwd: '<%= phantomFolder() %>', expand: true, dest: 'coverage'}
]
}
},
jsdoc: {
docs: {
src: ['src/js/**/*.js'],
dest: 'docs'
}
},
stylus: {
test: {
files: {
'test/js/styles/test.css': ['test/js/styles/test.styl']
}
}
},
connect: {
test: {
options: {
port: 3000,
hostname: '0.0.0.0',
base: '.'
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-jscs');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-contrib-stylus');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.registerTask('version_bump', versionBump);
grunt.registerTask('tc_set_build_version', tcSetBuildVersion);
grunt.registerTask('docs', ['clean:docs', 'jsdoc:docs']);
grunt.registerTask('check_style', ['jscs', 'jshint']);
grunt.registerTask('test_unit', ['clean:coverage', 'karma:unit', 'copy:coverage']);
grunt.registerTask('test_ui', ['clean:test', 'stylus:test', 'connect:test', 'karma:ui']);
grunt.registerTask('test', ['check_style', 'test_unit', 'test_ui']);
grunt.registerTask('build', ['tc_set_build_version']);
grunt.registerTask('default', ['build', 'test']);
grunt.registerTask('release', ['version_bump', 'docs'])
};