@@ -13,11 +13,14 @@ module.exports = function (grunt) {
13
13
grunt . initConfig ( {
14
14
builddir : 'build' ,
15
15
pkg : grunt . file . readJSON ( 'package.json' ) ,
16
+ buildtag : '-dev-' + grunt . template . today ( 'yyyy-mm-dd' ) ,
16
17
meta : {
17
- banner : '/**\n' + ' * <%= pkg.description %>\n' +
18
- ' * @version v<%= pkg.version %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
18
+ banner : '/**\n' +
19
+ ' * <%= pkg.description %>\n' +
20
+ ' * @version v<%= pkg.version %><%= buildtag %>\n' +
19
21
' * @link <%= pkg.homepage %>\n' +
20
- ' * @license MIT License, http://www.opensource.org/licenses/MIT\n' + ' */'
22
+ ' * @license MIT License, http://www.opensource.org/licenses/MIT\n' +
23
+ ' */'
21
24
} ,
22
25
clean : [ '<%= builddir %>' ] ,
23
26
concat : {
@@ -48,6 +51,11 @@ module.exports = function (grunt) {
48
51
}
49
52
}
50
53
} ,
54
+ release : {
55
+ files : [ '<%= pkg.name %>.js' , '<%= pkg.name %>.min.js' ] ,
56
+ src : '<%= builddir %>' ,
57
+ dest : 'release'
58
+ } ,
51
59
jshint : {
52
60
all : [ 'Gruntfile.js' , 'src/*.js' , '<%= builddir %>/<%= pkg.name %>.js' ] ,
53
61
options : {
@@ -79,11 +87,62 @@ module.exports = function (grunt) {
79
87
} ) ;
80
88
81
89
grunt . registerTask ( 'default' , [ 'build' , 'jshint' , 'karma:unit' ] ) ;
82
-
83
90
grunt . registerTask ( 'build' , 'Perform a normal build' , [ 'concat' , 'uglify' ] ) ;
84
91
grunt . registerTask ( 'dist' , 'Perform a clean build and generate documentation' , [ 'clean' , 'build' , 'jsdoc' ] ) ;
92
+ grunt . registerTask ( 'release' , 'Tag and perform a release' , [ 'prepare-release' , 'dist' , 'perform-release' ] ) ;
85
93
grunt . registerTask ( 'dev' , 'Run dev server and watch for changes' , [ 'build' , 'connect' , 'karma:debug' , 'watch' ] ) ;
86
94
95
+ grunt . registerTask ( 'jsdoc' , 'Generate documentation' , function ( ) {
96
+ promising ( this ,
97
+ system ( 'node_modules/jsdoc/jsdoc -c jsdoc-conf.json -d \'' + grunt . config ( 'builddir' ) + '\'/doc src' )
98
+ ) ;
99
+ } ) ;
100
+
101
+ grunt . registerTask ( 'publish-pages' , 'Publish a clean build, docs, and sample to github.io' , function ( ) {
102
+ promising ( this ,
103
+ ensureCleanMaster ( ) . then ( function ( ) {
104
+ shjs . rm ( '-rf' , 'build' ) ;
105
+ return system ( 'git checkout gh-pages' ) ;
106
+ } ) . then ( function ( ) {
107
+ return system ( 'grunt dist' ) ;
108
+ } ) . then ( function ( ) {
109
+ return system ( 'git commit -a -m \'Automatic gh-pages build\'' ) ;
110
+ } ) . then ( function ( ) {
111
+ return system ( 'git checkout master' ) ;
112
+ } )
113
+ ) ;
114
+ } ) ;
115
+
116
+ grunt . registerTask ( 'prepare-release' , function ( ) {
117
+ var bower = grunt . file . readJSON ( 'bower.json' ) ,
118
+ version = bower . version ;
119
+ if ( version != grunt . config ( 'pkg.version' ) ) throw 'Version mismatch in bower.json' ;
120
+
121
+ promising ( this ,
122
+ ensureCleanMaster ( ) . then ( function ( ) {
123
+ return exec ( 'git tag -l \'' + version + '\'' ) ;
124
+ } ) . then ( function ( result ) {
125
+ if ( result . stdout . trim ( ) !== '' ) throw 'Tag \'' + version + '\' already exists' ;
126
+ grunt . config ( 'buildtag' , '' ) ;
127
+ grunt . config ( 'builddir' , 'release' ) ;
128
+ } )
129
+ ) ;
130
+ } ) ;
131
+
132
+ grunt . registerTask ( 'perform-release' , function ( ) {
133
+ grunt . task . requires ( [ 'prepare-release' , 'dist' ] ) ;
134
+
135
+ var version = grunt . config ( 'pkg.version' ) , releasedir = grunt . config ( 'builddir' ) ;
136
+ promising ( this ,
137
+ system ( 'git add \'' + releasedir + '\'' ) . then ( function ( ) {
138
+ return system ( 'git commit -m \'release ' + version + '\'' ) ;
139
+ } ) . then ( function ( ) {
140
+ return system ( 'git tag \'' + version + '\'' ) ;
141
+ } )
142
+ ) ;
143
+ } ) ;
144
+
145
+
87
146
// Helpers for custom tasks, mainly around promises / exec
88
147
var exec = require ( 'faithful-exec' ) , shjs = require ( 'shelljs' ) ;
89
148
@@ -107,30 +166,12 @@ module.exports = function (grunt) {
107
166
} ) ;
108
167
}
109
168
110
- grunt . registerTask ( 'jsdoc' , 'Generate documentation' , function ( ) {
111
- promising ( this ,
112
- system ( "node_modules/jsdoc/jsdoc -c jsdoc-conf.json -d '" + grunt . config ( 'builddir' ) + "'/doc src" )
113
- ) ;
114
- } ) ;
115
-
116
- grunt . registerTask ( 'publish-pages' , 'Publish a clean build, docs, and sample to github.io' , function ( ) {
117
- promising ( this ,
118
- exec ( 'git symbolic-ref HEAD' ) . then ( function ( result ) {
119
- if ( result . stdout . trim ( ) !== 'refs/heads/master' ) throw 'Not on master branch, aborting' ;
120
- } ) . then ( function ( ) {
121
- return exec ( 'git status --porcelain' ) ;
122
- } ) . then ( function ( result ) {
123
- if ( result . stdout . trim ( ) !== '' ) throw 'Working copy is dirty, aborting' ;
124
- } ) . then ( function ( ) {
125
- shjs . rm ( '-rf' , 'build' ) ;
126
- return system ( 'git checkout gh-pages' ) ;
127
- } ) . then ( function ( ) {
128
- return system ( 'grunt dist' ) ;
129
- } ) . then ( function ( ) {
130
- return system ( 'git commit -a -m "Automatic gh-pages build"' ) ;
131
- } ) . then ( function ( ) {
132
- return system ( 'git checkout master' ) ;
133
- } )
134
- ) ;
135
- } ) ;
169
+ function ensureCleanMaster ( ) {
170
+ return exec ( 'git symbolic-ref HEAD' ) . then ( function ( result ) {
171
+ if ( result . stdout . trim ( ) !== 'refs/heads/master' ) throw 'Not on master branch, aborting' ;
172
+ return exec ( 'git status --porcelain' ) ;
173
+ } ) . then ( function ( result ) {
174
+ if ( result . stdout . trim ( ) !== '' ) throw 'Working copy is dirty, aborting' ;
175
+ } ) ;
176
+ }
136
177
} ;
0 commit comments