forked from kimmobrunfeldt/progressbar.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
125 lines (114 loc) · 3.19 KB
/
Gruntfile.js
File metadata and controls
125 lines (114 loc) · 3.19 KB
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
var fs = require('fs');
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['progressbar.js', 'test/**/*.js'],
options: {
globals: {
jQuery: true,
module: true
}
}
},
replace: {
bundleShifty: {
src: ['progressbar.js'],
dest: 'dist/progressbar.js',
replacements: [{
from: '// #include shifty',
to: grunt.file.read('shifty.min.js')
}]
}
},
uglify: {
progressbar: {
options: {
sourceMap: true
},
files: {
'dist/progressbar.min.js': ['dist/progressbar.js']
}
}
},
shell: {
mocha: {
options: {
stdout: true
},
command: 'mocha'
},
updateDevVersion: {
options: {
stdout: true
},
command: 'git add bower.json; git commit -m "Update to dev version"'
},
commitMinified: {
options: {
stdout: true,
// If minified files do not change on release,
// git command fails
failOnError: false
},
command: 'git add dist/progressbar.js dist/progressbar.min.js dist/progressbar.min.js.map; git commit -m "Add built scripts"'
}
},
// https://github.com/geddski/grunt-release/issues/84
release: {
options: {
npm: false,
npmtag: false,
commitMessage: 'Release <%= version %>',
file: 'bower.json'
}
},
extRelease: {
options: {
npm: false,
npmtag: false,
commitMessage: 'Release <%= version %>',
file: 'bower.json'
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-release');
// To be able to register custom release task, rename plugin's task
grunt.task.renameTask('release', 'extRelease');
// Updates version to development version. There should be only one
// commit in history where bower.json contains the actual released version.
// Other commits contain -dev suffix.
grunt.registerTask('updateDevVersion', function() {
var bowerJson = grunt.file.readJSON('bower.json');
if (endsWith(bowerJson.version, '-dev')) {
return;
}
bowerJson.version += '-dev';
var prettyJson = JSON.stringify(bowerJson, null, 2);
grunt.file.write('bower.json', prettyJson);
grunt.task.run(['shell:updateDevVersion']);
});
grunt.registerTask('commitMinified', function() {
grunt.task.run(['shell:commitMinified']);
});
// Build distributables to dist folder
grunt.registerTask('build', ['replace:bundleShifty', 'uglify:progressbar'])
// Test, build, and release library to public
grunt.registerTask('release', function(arg) {
arg = arg || 'patch';
grunt.task.run([
'jshint',
'build',
'commitMinified',
'extRelease:' + arg,
'updateDevVersion'
]);
});
};