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