-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
100 lines (90 loc) · 2.56 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
'use strict'
const gulp = require('gulp')
const path = require('path')
const fs = require('fs')
const es = require('event-stream')
const tsfmt = require('typescript-formatter')
const tslint = require('tslint')
const gTslint = require('gulp-tslint')
const clean = require('gulp-clean')
const webpack = require('webpack')
const webpackMerge = require('webpack-merge')
const crx = require('gulp-crx-pack')
const zip = require('gulp-zip')
let webpackConfig = require(path.resolve('webpack.config'))
gulp.task('clean', () => gulp.src(['pack/js/', 'dist']).pipe(clean()))
gulp.task('lint', () => gulp.src(['src/**/*.ts'])
.pipe(gTslint({
fix: true,
tslint,
formatter: 'verbose',
program: tslint.Linter.createProgram(path.resolve('tsconfig.json')),
configuration: path.resolve('tslint.json')
}))
.pipe(gTslint.report({
summarizeFailureOutput: true,
allowWarnings: false,
reportLimit: 5
}))
)
gulp.task('fmt', () => {
const formatting = es.map((file, cb) => {
tsfmt.processString(file.path, file.contents.toString('utf8'), {
replace: true,
// verbose: true,
tsfmt: true,
tsfmtFile: path.resolve('tsfmt.json')
}).then((result) => {
if (result.error) console.error(result.message)
cb(null, file)
}, cb)
})
gulp.src(['src/**/*.ts'], { base: '.' }).pipe(formatting)
})
gulp.task('build:dev', ['clean', 'fmt', 'lint'], done => {
webpackConfig = webpackMerge(webpackConfig, {
devtool: 'source-map',
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
sourceMap: true,
minChunks: Infinity
})
]
})
webpack(webpackConfig).run((err, stats) => {
if (err) console.error(err)
if (done) done()
})
})
gulp.task('build', ['clean', 'fmt', 'lint'], done => {
webpackConfig = webpackMerge(webpackConfig, {
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: false,
comments: false
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
sourceMap: false,
minChunks: Infinity
})
]
})
webpack(webpackConfig).run((err, stats) => {
if (err) console.error(err)
if (done) done()
})
})
gulp.task('crx', ['build'], () => gulp.src(path.resolve('pack'))
.pipe(crx({
privateKey: fs.readFileSync(path.resolve('key.pem'), 'utf8'),
filename: 'image-helper.crx'
}))
.pipe(gulp.dest('./dist'))
)
gulp.task('zip', ['build'], () => gulp.src(path.resolve('pack/**'))
.pipe(zip('image-helper.zip'))
.pipe(gulp.dest('./dist'))
)
gulp.task('default', ['build'])