forked from floccusaddon/floccus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
151 lines (125 loc) · 3.44 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
var gulp = require('gulp')
var fs = require('fs')
var webpack = require('webpack')
var config = require('./webpack.prod')
var devConfig = require('./webpack.dev')
var gulpZip = require('gulp-zip')
var crx3 = require('crx3')
var webstoreClient = require('chrome-webstore-upload')
const VERSION = require('./package.json').version
const paths = {
zip: [
'./**',
//'!dist/js/test.js', // only for releases
'!builds/**',
'!src/**',
'!node_modules/**',
'!img/**',
'!ISSUE_TEMPLATE.md',
'!gulpfile.js',
'!key.pem'
],
views: './views/*.html',
entries: 'src/entries/*.js',
js: 'src/**',
builds: './builds/'
}
const WEBSTORE_ID = 'fnaicdffflnofjppbagibeoednhnbjhg'
let WEBSTORE_CREDENTIALS
let webstore
try {
WEBSTORE_CREDENTIALS = require('./builds/google-api.json')
webstore = webstoreClient(
Object.assign({}, WEBSTORE_CREDENTIALS, {
extensionId: WEBSTORE_ID
})
)
} catch (e) {}
const js = function() {
return new Promise(resolve => webpack(config, (err, stats) => {
if (err) console.log('Webpack', err)
console.log(stats.toString({ /* stats options */ }))
resolve()
}))
}
const devjs = function() {
return new Promise(resolve => webpack(devConfig, (err, stats) => {
if (err) console.log('Webpack', err)
console.log(stats.toString({ /* stats options */ }))
resolve()
}))
}
const html = function() {
return gulp.src(paths.views).pipe(gulp.dest('./dist/html/'))
}
const polyfill = function() {
return gulp
.src('./node_modules/babel-polyfill/dist/polyfill.js')
.pipe(gulp.dest('./dist/js/'))
}
const mochajs = function() {
return gulp.src('./node_modules/mocha/mocha.js').pipe(gulp.dest('./dist/js/'))
}
const mochacss = function() {
return gulp
.src('./node_modules/mocha/mocha.css')
.pipe(gulp.dest('./dist/css/'))
}
const mocha = gulp.parallel(mochajs, mochacss)
const thirdparty = gulp.parallel(polyfill, mocha)
const main = gulp.series(html, js, thirdparty)
const dev = gulp.series(html, devjs, thirdparty)
const zip = function() {
return gulp
.src(paths.zip, { buffer: false })
.pipe(gulpZip(`floccus-build-v${VERSION}.zip`))
.pipe(gulp.dest(paths.builds))
}
const xpi = function() {
return gulp
.src(paths.zip, { buffer: false })
.pipe(gulpZip(`floccus-build-v${VERSION}.xpi`))
.pipe(gulp.dest(paths.builds))
}
const crx = function() {
return crx3(
fs.createReadStream(`${paths.builds}/floccus-build-v${VERSION}.zip`),
{
keyPath: 'key.pem',
crxPath: `${paths.builds}/floccus-build-v${VERSION}.crx`
}
)
}
const release = gulp.series(main, zip, xpi, crx)
const publish = gulp.series(main, zip, function() {
return webstore
.uploadExisting(
fs.createReadStream(`${paths.builds}floccus-build-v${VERSION}.zip`)
)
.then(function() {
return webstore.publish('default')
})
})
const watch = function() {
let jsWatcher = gulp.watch(paths.js, dev)
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...'
)
}
exports.html = html
exports.js = js
exports.mocha = mocha
exports.watch = watch
exports.release = release
exports.watch = gulp.series(dev, watch)
exports.publish = publish
exports.dev = dev
/*
* Define default task that can be called by just running `gulp` from cli
*/
exports.default = main