forked from jaysalvat/buzz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gruntfile.js
170 lines (148 loc) · 5.54 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
var semver = require('semver'),
format = require('util').format;
module.exports = function(grunt) {
"use strict";
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner: [
' // ----------------------------------------------------------------------------',
' // <%= pkg.description %>',
' // v<%= pkg.version %> - Built <%= grunt.template.today("yyyy-mm-dd HH:MM") %>',
' // Licensed under the MIT license.',
' // http://buzz.jaysalvat.com/',
' // ----------------------------------------------------------------------------',
' // Copyright (C) 2010-<%= grunt.template.today("yyyy") %> Jay Salvat',
' // http://jaysalvat.com/',
' // ----------------------------------------------------------------------------',
'\n'
].join('\n'),
jshint: {
files: ['gruntfile.js', 'src/**/*.js'],
options: {
jshintrc: '.jshintrc'
}
},
uglify: {
options: {
banner: '<%= banner %>'
},
js: {
options: {
mangle: false,
compress: false,
beautify: true
},
src: 'src/<%= pkg.name %>.js',
dest: 'dist/<%= pkg.name %>.js'
},
jsmin: {
options: {
mangle: true,
compress: true
},
src: 'dist/<%= pkg.name %>.js',
dest: 'dist/<%= pkg.name %>.min.js'
}
},
exec: {
publish: {
cmd: [
'cp -r dist/ tmp/',
'zip -rj tmp/buzz.zip tmp/buzz.js',
'zip -rj tmp/buzz.zip tmp/buzz.min.js',
'git checkout gh-pages',
'rm -rf releases/latest/',
'cp -r tmp/ releases/<%= pkg.version %>/',
'cp -r tmp/ releases/latest/',
'git add -A releases/<%= pkg.version %>',
'git add -A releases/latest',
'git commit -m "Published v<%= pkg.version %>."',
'git push origin gh-pages',
'git checkout -',
'rm -rf tmp/'
].join(' && ')
},
gitFailIfDirty: {
cmd: 'test -z "$(git status --porcelain)"'
},
gitAdd: {
cmd: 'git add .'
},
gitCommit: {
cmd: function(message) {
return format('git commit -m "Build %s"', message);
}
},
gitTag: {
cmd: function(version) {
return format('git tag v%s -am "%s"', version, version);
}
},
gitPush: {
cmd: [
'git push origin master',
'git push origin master --tags'
].join(' && ')
},
npmPublish: {
cmd: 'npm publish'
}
}
});
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.registerTask('default', ['build']);
grunt.registerTask('build', ['jshint', 'uglify', 'metadata']);
grunt.registerTask('publish', ['exec:publish']);
// Audio can't be tested by PhantomJs.
// so just jshint. Better idea?
grunt.registerTask('test', ['jshint']);
grunt.registerTask('release', 'Release lib.', function(version) {
var pkg = grunt.file.readJSON('package.json');
version = semver.inc(pkg.version, version) || version;
if (!semver.valid(version) || semver.lte(version, pkg.version)) {
grunt.fatal('Invalid version.');
}
pkg.version = version;
grunt.config.data.pkg = pkg;
grunt.task.run([
'exec:gitFailIfDirty',
'build',
'metadata:' + version,
'manifests:' + version,
'exec:gitAdd',
'exec:gitCommit:' + version,
'exec:gitTag:' + version,
'exec:gitPush',
'exec:publish',
'exec:npmPublish'
]);
});
grunt.registerTask('manifests', 'Update manifests.', function(version) {
if (!semver.valid(version)) {
grunt.fatal('Invalid version');
}
var pkg = grunt.file.readJSON('package.json'),
bwr = grunt.file.readJSON('bower.json'),
cpt = grunt.file.readJSON('component.json');
pkg.version = version;
bwr.version = version;
cpt.version = version;
grunt.file.write('package.json', JSON.stringify(pkg, null, 2));
grunt.file.write('bower.json', JSON.stringify(bwr, null, 2));
grunt.file.write('component.json', JSON.stringify(cpt, null, 2));
});
grunt.registerTask('metadata', 'Create metadata file.', function(version) {
if (!version) {
version = grunt.file.readJSON('package.json').version;
}
var metadata = {
'date': grunt.template.today("yyyy-mm-dd HH:MM:ss"),
'version': version
}, json = JSON.stringify(metadata, null, 4);
grunt.file.write('dist/metadata.json', json);
grunt.file.write('dist/metadata.js', '__metadata(' + json + ');');
});
};