-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
173 lines (158 loc) · 4.6 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
'use strict';
var fs = require('fs');
var gulp = require('gulp');
var rename = require('gulp-rename');
var less = require('gulp-less');
var jade = require('gulp-jade');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var jshint = require('gulp-jshint');
var zip = require('gulp-zip');
var paths = {
js: {
all: ['gulpfile.js', 'assets/js/**/*.js', 'test/**/*.js'],
entryPoints: [
'assets/js/background.js',
'assets/js/popover.js',
'assets/js/first-run.js',
'assets/js/advanced-settings.js',
'assets/js/settings.js',
'assets/js/content-script/content-script.js',
'assets/js/mixpanel.js',
],
target: 'extension/js'
},
libs: [
{
files: ['bower_components/anyfetch-assets/dist/index-moment.min.js'],
target: 'extension/js'
},
{
files: ['./images/**/*'],
target: 'extension/images'
},
{
files: ['bower_components/anyfetch-assets/images/document-types/**/*'],
target: 'extension/images/document-types/'
},
{
files: ['bower_components/anyfetch-assets/images/providers/**/*'],
target: 'extension/images/providers/'
}
],
less: {
all: 'assets/less/**/*.less',
entryPoints: [
'assets/less/style.less',
'assets/less/popover.less',
'assets/less/settings.less',
'assets/less/injection/*.less',
],
target: 'extension/css'
},
jade: {
all: 'assets/jade/**/*.jade',
entryPoints: [
'assets/jade/popover.jade',
'assets/jade/background.jade',
'assets/jade/settings.jade',
'assets/jade/advanced-settings.jade',
'assets/jade/first-run.jade',
'assets/jade/how-to-use.jade',
'assets/jade/oauth-callback.jade',
'assets/jade/injection/*.jade',
],
target: 'extension/'
},
templates: {
all: 'assets/templates/**/*'
},
target: 'extension/',
package: 'extension/**/*'
};
var swallowError = function swallowError(error) {
// If you want details of the error in the console
console.log(error.toString());
this.emit('end');
};
// LESS compiling
gulp.task('less', function() {
return gulp.src(paths.less.entryPoints)
.pipe(less())
.on('error', swallowError)
.pipe(gulp.dest(paths.less.target));
});
// Libs (copy)
gulp.task('libs', function() {
paths.libs.forEach(function(path) {
var p = gulp.src(path.files);
return p.pipe(gulp.dest(path.target));
});
});
// JS compiling
// gulp-browserify seems to be a deprecated plugin. http://goo.gl/bz8n4L
gulp.task('browserify', function() {
paths.js.entryPoints.forEach(function(file) {
var bundler = browserify({
entries: './' + file
});
bundler.transform('brfs');
return bundler
.bundle()
.on('error', swallowError)
.pipe(source(file))
.pipe(buffer())
.pipe(rename(function(path) {
path.dirname = '';
}))
.pipe(gulp.dest(paths.js.target));
});
});
// JS linting
gulp.task('lint', function() {
return gulp.src(paths.js.all)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
// Jade view compiling
gulp.task('jade', function() {
var locals = {};
gulp.src(paths.jade.entryPoints)
.pipe(jade({
locals: locals
}))
.on('error', swallowError)
.pipe(gulp.dest(paths.jade.target));
});
// Manifest generation
gulp.task('manifest', function() {
var manifestFilename = './assets/manifest.json';
// We are not using require because it is caching the file
var manifestFile = JSON.parse(fs.readFileSync(manifestFilename, 'utf8'));
// Read version number from `package.json`
var packageFile = require('./package.json');
// Update manifest version
manifestFile.version = packageFile.version;
// Write it back to the file
fs.writeFileSync(manifestFilename, JSON.stringify(manifestFile, null, 2) + '\n');
gulp.src(manifestFilename).pipe(gulp.dest(paths.target));
});
// Packaging the app as a zip for publishing
gulp.task('package', ['lint', 'less', 'browserify', 'libs', 'jade', 'manifest'], function() {
return gulp.src(paths.package)
.pipe(zip('anyfetch-chrome.zip'))
.pipe(gulp.dest('./'));
});
// Auto-run tasks on file changes
gulp.task('watch', function() {
gulp.watch(paths.js.all, ['lint', 'browserify']);
gulp.watch(paths.templates.all, ['browserify']);
gulp.watch(paths.less.all, ['less']);
gulp.watch(paths.jade.all, ['jade']);
gulp.watch('assets/manifest.json', ['manifest']);
});
// Run main tasks on launch
gulp.task('default', ['lint', 'less', 'browserify', 'libs', 'jade', 'manifest', 'watch'], function() {
});