]> git.gir.st - VimFx.git/blob - gulpfile.coffee
Always remove build/ and build from scratch
[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 gulp = require('gulp')
23 coffee = require('gulp-coffee')
24 coffeelint = require('gulp-coffeelint')
25 git = require('gulp-git')
26 header = require('gulp-header')
27 merge = require('gulp-merge')
28 mustache = require('gulp-mustache')
29 util = require('gulp-util')
30 zip = require('gulp-zip')
31 precompute = require('require-precompute')
32 request = require('request')
33 rimraf = require('rimraf')
34 runSequence = require('run-sequence')
35 pkg = require('./package.json')
36
37 DEST = 'build'
38 XPI = 'VimFx.xpi'
39 LOCALE = 'extension/locale'
40
41 read = (filepath) -> fs.readFileSync(filepath).toString()
42 template = (data) -> mustache(data, {extension: ''})
43
44 gulp.task('default', ['push'])
45
46 gulp.task('clean', (callback) ->
47 rimraf(DEST, callback)
48 )
49
50 gulp.task('copy', ->
51 gulp.src(['extension/**/!(*.coffee|*.tmpl)', 'COPYING'])
52 .pipe(gulp.dest(DEST))
53 )
54
55 gulp.task('node_modules', ->
56 dependencies = (name for name of pkg.dependencies)
57 # Note! When installing or updating node modules, make sure that the following
58 # glob does not include too much or too little!
59 gulp.src("node_modules/+(#{ dependencies.join('|') })/**/{*.js,LICENSE}")
60 .pipe(gulp.dest("#{ DEST }/node_modules"))
61 )
62
63 gulp.task('coffee', ->
64 gulp.src('extension/**/*.coffee')
65 .pipe(coffee({bare: true}).on('error', util.log))
66 .pipe(gulp.dest(DEST))
67 )
68
69 gulp.task('chrome.manifest', ->
70 gulp.src('extension/chrome.manifest.tmpl')
71 .pipe(template({locales: fs.readdirSync(LOCALE).map((locale) -> {locale})}))
72 .pipe(gulp.dest(DEST))
73 )
74
75 gulp.task('install.rdf', ->
76 [ [ { name: creator } ], developers, contributors, translators ] =
77 read('PEOPLE.md').trim().replace(/^#.+\n|^\s*-\s*/mg, '').split('\n\n')
78 .map((block) -> block.split('\n').map((name) -> {name}))
79
80 getDescription = (locale) -> read(join(LOCALE, locale, 'description')).trim()
81
82 descriptions = fs.readdirSync(LOCALE)
83 .map((locale) -> {
84 locale: locale
85 description: getDescription(locale)
86 })
87
88 gulp.src('extension/install.rdf.tmpl')
89 .pipe(template({
90 version: pkg.version
91 minVersion: pkg.firefoxVersions.min
92 maxVersion: pkg.firefoxVersions.max
93 creator, developers, contributors, translators
94 defaultDescription: getDescription('en-US')
95 descriptions
96 }))
97 .pipe(gulp.dest(DEST))
98 )
99
100 gulp.task('require-data', ['node_modules'], ->
101 data = JSON.stringify(precompute('.'), null, 2)
102 gulp.src('extension/require-data.js.tmpl')
103 .pipe(template({data}))
104 .pipe(gulp.dest(DEST))
105 )
106
107 gulp.task('templates', [
108 'chrome.manifest'
109 'install.rdf'
110 'require-data'
111 ])
112
113 gulp.task('build', (callback) ->
114 runSequence(
115 'clean',
116 ['copy', 'node_modules', 'coffee', 'templates'],
117 callback
118 )
119 )
120
121 gulp.task('xpi', ['build'], ->
122 gulp.src("#{ DEST }/**/*")
123 .pipe(zip(XPI, {compress: false}))
124 .pipe(gulp.dest(DEST))
125 )
126
127 gulp.task('push', ['xpi'], ->
128 body = fs.readFileSync(join(DEST, XPI))
129 request.post({url: 'http://localhost:8888', body })
130 )
131
132 gulp.task('lint', ->
133 gulp.src(['extension/**/*.coffee', 'gulpfile.coffee'])
134 .pipe(coffeelint())
135 .pipe(coffeelint.reporter())
136 )
137
138 gulp.task('release', ->
139 { version } = pkg
140 message = "VimFx v#{ version }"
141 today = new Date().toISOString()[...10]
142 merge(
143 gulp.src('package.json'),
144 gulp.src('CHANGELOG.md')
145 .pipe(header("### #{ version } (#{ today })\n\n"))
146 .pipe(gulp.dest('.'))
147 ).pipe(git.commit(message))
148 git.tag("v#{ version }", message, (error) -> throw error if error)
149 )
Imprint / Impressum