]> git.gir.st - VimFx.git/blob - gulpfile.coffee
Exclude test scripts from node_modules
[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('|') })/\
63 {LICENSE,{,**/!(test)/}*.js}")
64 .pipe(gulp.dest("#{ DEST }/node_modules"))
65 )
66
67 gulp.task('coffee', ->
68 gulp.src([
69 'extension/bootstrap.coffee'
70 'extension/lib/**/*.coffee'
71 ifTest('extension/test/**/*.coffee')...
72 ], {base: 'extension'})
73 .pipe(coffee({bare: true}))
74 .pipe(gulp.dest(DEST))
75 )
76
77 gulp.task('chrome.manifest', ->
78 gulp.src('extension/chrome.manifest.tmpl')
79 .pipe(template({locales: fs.readdirSync(LOCALE).map((locale) -> {locale})}))
80 .pipe(gulp.dest(DEST))
81 )
82
83 gulp.task('install.rdf', ->
84 [ [ { name: creator } ], developers, contributors, translators ] =
85 read('PEOPLE.md').trim().replace(/^#.+\n|^\s*-\s*/mg, '').split('\n\n')
86 .map((block) -> block.split('\n').map((name) -> {name}))
87
88 getDescription = (locale) -> read(join(LOCALE, locale, 'description')).trim()
89
90 descriptions = fs.readdirSync(LOCALE)
91 .map((locale) -> {
92 locale: locale
93 description: getDescription(locale)
94 })
95
96 gulp.src('extension/install.rdf.tmpl')
97 .pipe(template({
98 version: pkg.version
99 minVersion: pkg.firefoxVersions.min
100 maxVersion: pkg.firefoxVersions.max
101 creator, developers, contributors, translators
102 defaultDescription: getDescription('en-US')
103 descriptions
104 }))
105 .pipe(gulp.dest(DEST))
106 )
107
108 gulp.task('require-data', ['node_modules'], ->
109 data = JSON.stringify(precompute('.'), null, 2)
110 gulp.src('extension/require-data.js.tmpl')
111 .pipe(template({data}))
112 .pipe(gulp.dest(DEST))
113 )
114
115 gulp.task('tests-list', ->
116 list = JSON.stringify(fs.readdirSync(TEST)
117 .map((name) -> name.match(/^(test-.+)\.coffee$/)?[1])
118 .filter(Boolean)
119 )
120 gulp.src("#{ TEST }/tests-list.js.tmpl", {base: 'extension'})
121 .pipe(template({list}))
122 .pipe(gulp.dest(DEST))
123 )
124
125 gulp.task('templates', [
126 'chrome.manifest'
127 'install.rdf'
128 'require-data'
129 ifTest('tests-list')...
130 ])
131
132 gulp.task('build', (callback) ->
133 runSequence(
134 'clean',
135 ['copy', 'node_modules', 'coffee', 'templates'],
136 callback
137 )
138 )
139
140 gulp.task('xpi', ['build'], ->
141 gulp.src("#{ DEST }/**/*")
142 .pipe(zip(XPI, {compress: false}))
143 .pipe(gulp.dest(DEST))
144 )
145
146 gulp.task('push', ['xpi'], ->
147 body = fs.readFileSync(join(DEST, XPI))
148 request.post({url: 'http://localhost:8888', body })
149 )
150
151 gulp.task('lint', ->
152 gulp.src(['extension/**/*.coffee', 'gulpfile.coffee'])
153 .pipe(coffeelint())
154 .pipe(coffeelint.reporter())
155 )
156
157 gulp.task('release', ->
158 { version } = pkg
159 message = "VimFx v#{ version }"
160 today = new Date().toISOString()[...10]
161 merge(
162 gulp.src('package.json'),
163 gulp.src('CHANGELOG.md')
164 .pipe(header("### #{ version } (#{ today })\n\n"))
165 .pipe(gulp.dest('.'))
166 ).pipe(git.commit(message))
167 git.tag("v#{ version }", message, (error) -> throw error if error)
168 )
Imprint / Impressum