2 # Copyright Simon Lydell 2014.
4 # This file is part of VimFx.
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.
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.
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/>.
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')
38 LOCALE = 'extension/locale'
39 TEST = 'extension/test'
41 test = '--test' in process.argv or '-t' in process.argv
42 ifTest = (value) -> if test then [value] else []
44 read = (filepath) -> fs.readFileSync(filepath).toString()
45 template = (data) -> mustache(data, {extension: ''})
47 gulp.task('default', ['push'])
49 gulp.task('clean', (callback) ->
50 rimraf(DEST, callback)
54 gulp.src(['extension/**/!(*.coffee|*.tmpl)', 'COPYING'])
55 .pipe(gulp.dest(DEST))
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"))
66 gulp.task('coffee', ->
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))
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))
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}))
87 getDescription = (locale) -> read(join(LOCALE, locale, 'description')).trim()
89 descriptions = fs.readdirSync(LOCALE)
92 description: getDescription(locale)
95 gulp.src('extension/install.rdf.tmpl')
98 minVersion: pkg.firefoxVersions.min
99 maxVersion: pkg.firefoxVersions.max
100 creator, developers, contributors, translators
101 defaultDescription: getDescription('en-US')
104 .pipe(gulp.dest(DEST))
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))
114 gulp.task('tests-list', ->
115 list = JSON.stringify(fs.readdirSync(TEST)
116 .map((name) -> name.match(/^(test-.+)\.coffee$/)?[1])
119 gulp.src("#{ TEST }/tests-list.js.tmpl", {base: 'extension'})
120 .pipe(template({list}))
121 .pipe(gulp.dest(DEST))
124 gulp.task('templates', [
128 ifTest('tests-list')...
131 gulp.task('build', (callback) ->
134 ['copy', 'node_modules', 'coffee', 'templates'],
139 gulp.task('xpi', ['build'], ->
140 gulp.src("#{ DEST }/**/*")
141 .pipe(zip(XPI, {compress: false}))
142 .pipe(gulp.dest(DEST))
145 gulp.task('push', ['xpi'], ->
146 body = fs.readFileSync(join(DEST, XPI))
147 request.post({url: 'http://localhost:8888', body })
151 gulp.src(['extension/**/*.coffee', 'gulpfile.coffee'])
153 .pipe(coffeelint.reporter())
156 gulp.task('release', ->
158 message = "VimFx v#{ version }"
159 today = new Date().toISOString()[...10]
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)