]> git.gir.st - VimFx.git/blob - gulpfile.coffee
Generate install.rdf and chrome.manifest
[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 mustache = require('gulp-mustache')
28 util = require('gulp-util')
29 zip = require('gulp-zip')
30 rimraf = require('rimraf')
31
32 DEST = 'build'
33 XPI = 'VimFx.xpi'
34 LOCALE = 'extension/locale'
35
36 read = (filepath) -> fs.readFileSync(filepath).toString()
37 template = (data) -> mustache(data, {extension: ''})
38
39 gulp.task('default', ['push'])
40
41 gulp.task('clean', (callback) ->
42 rimraf(DEST, callback)
43 )
44
45 gulp.task('copy', ->
46 gulp.src(['extension/**/!(*.coffee|*.tmpl)', 'COPYING'])
47 .pipe(changed(DEST))
48 .pipe(gulp.dest(DEST))
49 )
50
51 gulp.task('coffee', ->
52 gulp.src('extension/**/*.coffee')
53 .pipe(changed(DEST, {extension: '.coffee'}))
54 .pipe(coffee({bare: true}).on('error', util.log))
55 .pipe(gulp.dest(DEST))
56 )
57
58 gulp.task('chrome.manifest', ->
59 gulp.src('extension/chrome.manifest.tmpl')
60 .pipe(template({locales: fs.readdirSync(LOCALE).map((locale) -> {locale})}))
61 .pipe(gulp.dest(DEST))
62 )
63
64 gulp.task('install.rdf', ->
65 pkg = require('./package.json')
66
67 [ [ { name: creator } ], developers, contributors, translators ] =
68 read('PEOPLE.md').trim().replace(/^#.+\n|^\s*-\s*/mg, '').split('\n\n')
69 .map((block) -> block.split('\n').map((name) -> {name}))
70
71 getDescription = (locale) -> read(join(LOCALE, locale, 'description')).trim()
72
73 descriptions = fs.readdirSync(LOCALE)
74 .map((locale) -> {
75 locale: locale
76 description: getDescription(locale)
77 })
78
79 gulp.src('extension/install.rdf.tmpl')
80 .pipe(template({
81 version: pkg.version
82 minVersion: pkg.firefoxVersions.min
83 maxVersion: pkg.firefoxVersions.max
84 creator, developers, contributors, translators
85 defaultDescription: getDescription('en-US')
86 descriptions
87 }))
88 .pipe(gulp.dest(DEST))
89 )
90
91 gulp.task('build', ['copy', 'coffee', 'chrome.manifest', 'install.rdf'])
92
93 gulp.task('xpi', ['build'], ->
94 gulp.src("#{ DEST }/**/!(#{ XPI })")
95 .pipe(zip(XPI, {compress: false}))
96 .pipe(gulp.dest(DEST))
97 )
98
99 gulp.task('push', ['xpi'], ->
100 body = fs.readFileSync(join(DEST, XPI))
101 request.post({url: 'http://localhost:8888', body })
102 )
103
104 gulp.task('lint', ->
105 gulp.src(['extension/**/*.coffee', 'gulpfile.coffee'])
106 .pipe(coffeelint())
107 .pipe(coffeelint.reporter())
108 )
Imprint / Impressum