This repository has been archived by the owner on Jan 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
/
gulpfile.js
173 lines (155 loc) · 4.72 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
var browserify = require('browserify');
var watchify = require('watchify');
var gulp = require('gulp');
var gutil = require('gulp-util');
var source = require('vinyl-source-stream');
var crx = require('gulp-crx');
var manifest = require('./extension/manifest.json');
var fs = require('fs');
var pathmodify = require('pathmodify');
var path = require('path');
var assign = require('lodash.assign');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var minifyCss = require('gulp-cssnano');
var zip = require('gulp-zip');
var scripts = [
'stackoverflow',
'background',
'buttons',
'options',
'github',
'npmjs',
'popup'
];
var vendorsContentScript = [
'inherit',
'sprintf-js',
'lazyloadjs',
'lodash/debounce',
'to-array'
];
var vendors = [
'angular'
];
var options = {
mods: [
pathmodify.mod.dir('common', path.join(__dirname, './src/js/common')),
pathmodify.mod.dir('background', path.join(__dirname, './src/js/background')),
pathmodify.mod.dir('buttons', path.join(__dirname, './src/js/buttons')),
pathmodify.mod.dir('popup', path.join(__dirname, './src/js/popup')),
pathmodify.mod.dir('options', path.join(__dirname, './src/js/options'))
]
};
scripts.forEach(function(script) {
gulp.task('browserify:' + script, function() {
var browserifyBuilder = browserify('./src/js/' + script + '/init.js');
vendors.concat(vendorsContentScript).forEach(function(lib) {
browserifyBuilder.exclude(lib);
});
return browserifyBuilder
.plugin(pathmodify, options)
.bundle()
.pipe(source(script + '.js'))
.pipe(gulp.dest('./extension/compile/js/'));
});
});
gulp.task('browserify:vendors', function() {
var b = browserify();
vendors.forEach(function(lib) {
b.require(lib);
});
return b
.bundle()
.pipe(source('vendors.js'))
.pipe(gulp.dest('./extension/compile/js/'));
});
gulp.task('browserify:vendors-content-script', function() {
var b = browserify();
vendorsContentScript.forEach(function(lib) {
b.require(lib);
});
return b
.bundle()
.pipe(source('vendors_content_script.js'))
.pipe(gulp.dest('./extension/compile/js/'));
});
gulp.task('browserify', function() {
scripts.forEach(function(script) {
gulp.start('browserify:' + script);
});
gulp.start('browserify:vendors');
gulp.start('browserify:vendors-content-script');
});
gulp.task('concat:css', function() {
return gulp.src(['./src/css/fonts.css', './src/css/bootstrap.css'])
.pipe(concat('vendors.css'))
.pipe(gulp.dest('./extension/compile/css/'));
});
gulp.task('concat:css-highlight', function() {
return gulp.src(['./node_modules/highlight.js/styles/default.css'])
.pipe(concat('highlight.css'))
.pipe(gulp.dest('./extension/compile/css/'));
});
gulp.task('watch', function() {
scripts.forEach(function(script) {
var customOpts = {
entries: ['./src/js/' + script + '/init.js'],
debug: false
};
var opts = assign({}, watchify.args, customOpts),
browserifyBuilder = browserify(opts);
vendors.concat(vendorsContentScript).forEach(function(lib) {
browserifyBuilder.exclude(lib);
});
var watch = watchify(browserifyBuilder)
.plugin(pathmodify, options);
var bundle = function() {
watch
.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source(script + '.js'))
.pipe(gulp.dest('./extension/compile/js/'));
};
watch.on('update', bundle); // on any dep update, runs the bundler
watch.on('log', gutil.log); // output build logs to terminal
bundle();
});
gulp.start('browserify:vendors');
gulp.start('browserify:vendors-content-script');
gulp.start('concat:css');
gulp.start('concat:css-highlight');
gulp.watch('src/scss/**/*.scss', ['scss']);
});
gulp.task('scss', function () {
gulp.src('src/scss/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('extension/compile/css'));
});
gulp.task('uglify-js', function() {
return gulp.src('extension/compile/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('extension/compile/js/'));
});
gulp.task('minify-css', function() {
return gulp.src('extension/**/*.css')
.pipe(minifyCss())
.pipe(gulp.dest('extension'));
});
gulp.task('compress', function () {
return gulp.src('extension/**/*')
.pipe(zip(manifest.name + '-v' + manifest.version + '.zip'))
.pipe(gulp.dest('dist'));
});
gulp.task('crx', function() {
return gulp.src('extension/**/*')
.pipe(crx({
privateKey: fs.readFileSync('certificates/extension.pem', 'utf8'),
filename: manifest.name + '-v' + manifest.version + '.crx'
}))
.pipe(gulp.dest('dist'));
});
gulp.task('default', function() {
gulp.start('scss', 'watch');
});