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 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')
39 LOCALE = 'extension/locale'
41 read = (filepath) -> fs.readFileSync(filepath).toString()
42 template = (data) -> mustache(data, {extension: ''})
44 gulp.task('default', ['push'])
46 gulp.task('clean', (callback) ->
47 rimraf(DEST, callback)
51 gulp.src(['extension/**/!(*.coffee|*.tmpl)', 'COPYING'])
52 .pipe(gulp.dest(DEST))
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"))
63 gulp.task('coffee', ->
64 gulp.src('extension/**/*.coffee')
65 .pipe(coffee({bare: true}).on('error', util.log))
66 .pipe(gulp.dest(DEST))
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))
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}))
80 getDescription = (locale) -> read(join(LOCALE, locale, 'description')).trim()
82 descriptions = fs.readdirSync(LOCALE)
85 description: getDescription(locale)
88 gulp.src('extension/install.rdf.tmpl')
91 minVersion: pkg.firefoxVersions.min
92 maxVersion: pkg.firefoxVersions.max
93 creator, developers, contributors, translators
94 defaultDescription: getDescription('en-US')
97 .pipe(gulp.dest(DEST))
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))
107 gulp.task('templates', [
113 gulp.task('build', (callback) ->
116 ['copy', 'node_modules', 'coffee', 'templates'],
121 gulp.task('xpi', ['build'], ->
122 gulp.src("#{ DEST }/**/*")
123 .pipe(zip(XPI, {compress: false}))
124 .pipe(gulp.dest(DEST))
127 gulp.task('push', ['xpi'], ->
128 body = fs.readFileSync(join(DEST, XPI))
129 request.post({url: 'http://localhost:8888', body })
133 gulp.src(['extension/**/*.coffee', 'gulpfile.coffee'])
135 .pipe(coffeelint.reporter())
138 gulp.task('release', ->
140 message = "VimFx v#{ version }"
141 today = new Date().toISOString()[...10]
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)