forked from configit/ngyn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
119 lines (107 loc) · 3.79 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
module.exports = function(grunt) {
'use strict';
var fs = require('fs');
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-contrib-watch' );
grunt.loadNpmTasks( 'grunt-contrib-concat' );
grunt.loadNpmTasks( 'grunt-karma' );
grunt.loadNpmTasks( 'grunt-exec' );
var pkg = grunt.file.readJSON( 'package.json'),
teamcityPropsFile = grunt.option( 'teamcity.properties' ),
teamcityProps = ( teamcityPropsFile && grunt.file.readJSON( teamcityPropsFile ) ) || {},
major = option( 'Major', '0' ),
minor = option( 'Minor', '0' ),
revision = option( 'Revision', '0' ),
semVersionSuffix = option( 'SemVerSuffix', '-beta' ),
isDefaultBranch = option( 'is_default_branch', false ) === 'true',
version = major + '.' + minor + '.' + revision,
semVersion = isDefaultBranch ? version : version + semVersionSuffix;
function option( name, def ) {
return grunt.option( name ) || teamcityProps[ name ] || def;
}
function createConcatOptions( ) {
var options = {
options: {
banner: '/* VERSION: ' + semVersion + ' */\n',
separator: ';'
},
module: {
src: ['src/' + pkg.name + '.js'],
dest: 'dist/' + pkg.name + '.js'
}
};
grunt.file.recurse( 'src',
function( abspath, rootdir, subdir, filename ) {
if ( !subdir ) return;
options[subdir] = {
src: [rootdir + '/' + subdir + '/**/*.js'],
dest: 'dist/' + pkg.name + '-' + subdir + '.js'
};
} );
return options;
}
grunt.initConfig( {
concat: createConcatOptions( ),
jshint: {
files: ['gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
jshintrc: '.jshintrc',
force: true
}
},
watch: {
files: ['<%= jshint.files %>'],
tasks: ['concat', 'jshint', 'karma:background:run']
},
karma: {
options: {
configFile: 'karma.conf.js'
},
background: {
autoWatch: false,
background: true
},
single: {
singleRun: true,
autoWatch: false
},
teamcity: {
singleRun: true,
autoWatch: false,
reporters: 'teamcity,coverage'
}
},
exec: {
nuget: {
cmd: 'build\\nuget.exe pack ngyn.nuspec -outputdirectory packages-build -verbosity detailed -version ' + semVersion
}
}
} );
// development tasks
grunt.registerTask( 'build', [ 'jshint', 'concat' ] );
grunt.registerTask( 'test', [ 'karma:single' ] );
grunt.registerTask( 'default', ['build', 'karma:single'] );
grunt.registerTask( 'packages', 'Create nuget packags', function() {
grunt.file.delete( 'packages-build', { force: true } );
grunt.file.mkdir( 'packages-build' );
grunt.task.run( 'exec:nuget' );
} );
grunt.registerTask('sanitizefoldername', 'Removes the browser specific information from the generated coverage folder name', function() {
fs.readdirSync( 'coverage').forEach( function( dir ) {
fs.renameSync( 'coverage/' + dir, 'coverage/phantom' );
} );
} );
grunt.registerTask('clean', 'Removes the old coverage folder', function() {
var rmdir = require('rimraf');
rmdir.sync('coverage/phantom', function(error){});
} );
// build server tasks
grunt.registerTask( 'patch.karma-teamcity', function() {
// patch to teamcity.reporter
// -- from https://github.com/karma-runner/karma-teamcity-reporter/issues/5
grunt.file.copy( 'patches/karma-teamcity-reporter/index.js',
'node_modules/karma-teamcity-reporter/index.js' );
} );
grunt.registerTask( 'teamcity.commit', ['clean', 'patch.karma-teamcity', 'build', 'karma:teamcity', 'sanitizefoldername'] );
grunt.registerTask( 'teamcity.full', ['patch.karma-teamcity', 'build', 'karma:teamcity', 'packages' ] );
};