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