forked from floccusaddon/floccus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
126 lines (110 loc) · 2.96 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
var gulp = require('gulp')
var fs = require('fs')
var browserify = require('browserify')
var babelify = require('babelify')
var tap = require('gulp-tap')
var zip = require('gulp-zip')
var crx = require('./lib/gulp-crx')
var run = require('gulp-run-command').default
const VERSION = require('./package.json').version
const paths = {
zip: [
'**',
'!builds/**',
'!src/**',
'!node_modules/**',
'!img/**',
'!ISSUE_TEMPLATE.md',
'!gulpfile.js',
'!key.pem'
],
views: './views/*.html',
entries: 'src/entries/*.js',
js: 'src/**',
builds: './builds/'
}
gulp.task('default', ['html', 'js', '3rd-party'])
gulp.task('js', function() {
return (
gulp
.src(paths.entries, { read: false }) // no need of reading file because browserify does.
// transform file objects using gulp-tap plugin
.pipe(
tap(function(file) {
// replace file contents with browserify's bundle stream
file.contents = browserify(file.path, {
debug: true
})
.transform(babelify, {
global: true,
presets: [
'@babel/preset-env',
['@babel/preset-react', { pragma: 'h' }]
]
})
.bundle()
})
)
.pipe(gulp.dest('./dist/js/'))
)
})
gulp.task('html', function() {
return gulp.src(paths.views).pipe(gulp.dest('./dist/html/'))
})
gulp.task('3rd-party', ['polyfill', 'mocha'])
gulp.task('polyfill', function() {
return gulp
.src('./node_modules/babel-polyfill/dist/polyfill.js')
.pipe(gulp.dest('./dist/js/'))
})
gulp.task('mocha', ['mochajs', 'mochacss'])
gulp.task('mochajs', function() {
return gulp.src('./node_modules/mocha/mocha.js').pipe(gulp.dest('./dist/js/'))
})
gulp.task('mochacss', function() {
return gulp
.src('./node_modules/mocha/mocha.css')
.pipe(gulp.dest('./dist/css/'))
})
gulp.task('release', ['zip', 'xpi', 'crx'])
gulp.task('zip', ['default'], function() {
return gulp
.src(paths.zip)
.pipe(zip(`floccus-build-v${VERSION}.zip`))
.pipe(gulp.dest(paths.builds))
})
gulp.task('xpi', ['default'], function() {
return gulp
.src(paths.zip)
.pipe(zip(`floccus-build-v${VERSION}.xpi`))
.pipe(gulp.dest(paths.builds))
})
gulp.task(
'keygen',
run(
'openssl genpkey' +
' -algorithm RSA -out ./key.pem -pkeyopt rsa_keygen_bits:2048'
)
)
gulp.task('crx', ['default'], function() {
return gulp
.src(paths.zip)
.pipe(
crx({
privateKey: fs.readFileSync('./key.pem', 'utf8'),
filename: `floccus-build-v${VERSION}.crx`
})
)
.pipe(gulp.dest(paths.builds))
})
gulp.task('watch', function() {
let jsWatcher = gulp.watch(paths.js, ['js'])
let viewsWatcher = gulp.watch(paths.views, ['html'])
jsWatcher.on('change', onWatchEvent)
viewsWatcher.on('change', onWatchEvent)
})
function onWatchEvent(event) {
console.log(
'File ' + event.path + ' was ' + event.type + ', running tasks...'
)
}