]> git.gir.st - VimFx.git/blob - gulpfile.coffee
Add gulp release task
[VimFx.git] / gulpfile.coffee
1 ###
2 # Copyright Simon Lydell 2014.
3 #
4 # This file is part of VimFx.
5 #
6 # VimFx is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # VimFx is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with VimFx. If not, see <http://www.gnu.org/licenses/>.
18 ###
19
20 fs = require('fs')
21 { join } = require('path')
22 request = require('request')
23 gulp = require('gulp')
24 changed = require('gulp-changed')
25 coffee = require('gulp-coffee')
26 coffeelint = require('gulp-coffeelint')
27 git = require('gulp-git')
28 header = require('gulp-header')
29 merge = require('gulp-merge')
30 mustache = require('gulp-mustache')
31 util = require('gulp-util')
32 zip = require('gulp-zip')
33 rimraf = require('rimraf')
34
35 DEST = 'build'
36 XPI = 'VimFx.xpi'
37 LOCALE = 'extension/locale'
38
39 read = (filepath) -> fs.readFileSync(filepath).toString()
40 template = (data) -> mustache(data, {extension: ''})
41
42 gulp.task('default', ['push'])
43
44 gulp.task('clean', (callback) ->
45 rimraf(DEST, callback)
46 )
47
48 gulp.task('copy', ->
49 gulp.src(['extension/**/!(*.coffee|*.tmpl)', 'COPYING'])
50 .pipe(changed(DEST))
51 .pipe(gulp.dest(DEST))
52 )
53
54 gulp.task('coffee', ->
55 gulp.src('extension/**/*.coffee')
56 .pipe(changed(DEST, {extension: '.coffee'}))
57 .pipe(coffee({bare: true}).on('error', util.log))
58 .pipe(gulp.dest(DEST))
59 )
60
61 gulp.task('chrome.manifest', ->
62 gulp.src('extension/chrome.manifest.tmpl')
63 .pipe(template({locales: fs.readdirSync(LOCALE).map((locale) -> {locale})}))
64 .pipe(gulp.dest(DEST))
65 )
66
67 gulp.task('install.rdf', ->
68 pkg = require('./package.json')
69
70 [ [ { name: creator } ], developers, contributors, translators ] =
71 read('PEOPLE.md').trim().replace(/^#.+\n|^\s*-\s*/mg, '').split('\n\n')
72 .map((block) -> block.split('\n').map((name) -> {name}))
73
74 getDescription = (locale) -> read(join(LOCALE, locale, 'description')).trim()
75
76 descriptions = fs.readdirSync(LOCALE)
77 .map((locale) -> {
78 locale: locale
79 description: getDescription(locale)
80 })
81
82 gulp.src('extension/install.rdf.tmpl')
83 .pipe(template({
84 version: pkg.version
85 minVersion: pkg.firefoxVersions.min
86 maxVersion: pkg.firefoxVersions.max
87 creator, developers, contributors, translators
88 defaultDescription: getDescription('en-US')
89 descriptions
90 }))
91 .pipe(gulp.dest(DEST))
92 )
93
94 gulp.task('build', ['copy', 'coffee', 'chrome.manifest', 'install.rdf'])
95
96 gulp.task('xpi', ['build'], ->
97 gulp.src("#{ DEST }/**/!(#{ XPI })")
98 .pipe(zip(XPI, {compress: false}))
99 .pipe(gulp.dest(DEST))
100 )
101
102 gulp.task('push', ['xpi'], ->
103 body = fs.readFileSync(join(DEST, XPI))
104 request.post({url: 'http://localhost:8888', body })
105 )
106
107 gulp.task('lint', ->
108 gulp.src(['extension/**/*.coffee', 'gulpfile.coffee'])
109 .pipe(coffeelint())
110 .pipe(coffeelint.reporter())
111 )
112
113 gulp.task('release', ->
114 { version } = require('./package.json')
115 message = "VimFx v#{ version }"
116 today = new Date().toISOString()[...10]
117 merge(
118 gulp.src('package.json'),
119 gulp.src('CHANGELOG.md')
120 .pipe(header("### #{ version } (#{ today })\n\n"))
121 .pipe(gulp.dest('.'))
122 ).pipe(git.commit(message))
123 git.tag("v#{ version }", message, (error) -> throw error if error)
124 )
Imprint / Impressum