-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Gruntfile.coffee
123 lines (105 loc) · 3.63 KB
/
Gruntfile.coffee
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
module.exports = (grunt) ->
pkgFile = 'sieve.jquery.json'
pkg = grunt.file.readJSON pkgFile
# Project configuration.
grunt.initConfig
# Metadata.
pkg: pkg
basename: 'jquery.<%= pkg.name %>'
headline: '<%= pkg.title || pkg.name %> v<%= pkg.version %>'
copyright: '<%= grunt.template.today("yyyy") %> <%= pkg.author.name %>'
licenses: '<%= _.pluck(pkg.licenses, "type").join(", ") %>'
banner: '''
/*!
* <%= headline %> (<%= grunt.template.today("yyyy-mm-dd") %>)
* <%= pkg.homepage %>
* Copyright (c) <%= copyright %>; Licensed <%= licenses %>
*/
'''
# Task configuration.
clean:
files: ['dist', 'test/compiled']
coffee:
compile:
src: 'src/**/*.coffee'
dest: 'dist/<%= basename %>.js'
test:
src: 'test/*.coffee'
dest: 'test/compiled/test.js'
uglify:
dist:
src: '<%= coffee.compile.dest %>'
dest: 'dist/<%= basename %>.min.js'
concat:
options:
banner: '<%= banner %>'
stripBanners: true
dist:
files:
'<%= coffee.compile.dest %>': ['<%= coffee.compile.dest %>']
'<%= uglify.dist.dest %>': ['<%= uglify.dist.dest %>']
qunit:
files: ['test/**/*.html']
watch:
src:
files: '<%= coffee.compile.src %>'
tasks: ['compile', 'qunit']
test:
files: '<%= coffee.test.src %>'
tasks: ['coffee:test', 'qunit']
replace:
site:
src: ['index.html']
overwrite: true
replacements: [
{ from: /v[0-9]+\.[0-9]+\.[0-9]+(-\w+)?/g, to: 'v<%= pkg.version %>' }
]
# These plugins provide necessary tasks.
grunt.loadNpmTasks 'grunt-contrib-clean'
grunt.loadNpmTasks 'grunt-contrib-concat'
grunt.loadNpmTasks 'grunt-contrib-uglify'
grunt.loadNpmTasks 'grunt-contrib-qunit'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-text-replace'
grunt.registerTask 'compile', ['coffee', 'uglify', 'concat']
grunt.registerTask 'build', ['compile', 'replace']
grunt.registerTask 'test', ['qunit']
grunt.registerTask 'default', ['clean', 'build', 'test']
grunt.registerTask 'bump', 'Bump, build, and commit the next version.', (type) ->
oldVersion = pkg.version
pkg.version = versionBump(oldVersion, type)
grunt.log.write('Bumping version to ' + pkg.version);
grunt.file.write(pkgFile, JSON.stringify(pkg, null, ' ') + '\n')
grunt.log.ok()
grunt.task.run('default', 'commitBump');
grunt.registerTask "commitBump", 'Add and commit all bumped version changes.', ->
run "git add ."
run "git commit -m 'Bumped version to v#{pkg.version}'"
grunt.log.subhead("DON'T FORGET TO `grunt release`")
grunt.registerTask 'release', ['tag', 'push', 'publish']
grunt.registerTask 'tag', "Tag a new release", ->
version = grunt.config("pkg.version")
run "git checkout master"
run "git tag v#{version}"
grunt.registerTask 'push', "Push tags", ->
run "git push origin master:master"
run "git push --tags"
shell = require 'shelljs'
run = (command) ->
grunt.log.write "Running `#{command}`..."
p = shell.exec(command, silent: true)
if p.code == 0
grunt.log.ok()
else
grunt.log.error()
grunt.log.error(p.output)
grunt.warn "Non-zero exit code for `#{command}`."
versionBump = (version, versionType) ->
type = major: 0, minor: 1, patch: 2
parts = version.split('.')
idx = type[versionType || 'patch']
parts[idx] = parseInt(parts[idx], 10) + 1
while ++idx < parts.length
parts[idx] = 0
return parts.join('.')