|
1 | 1 | const gulp = require('gulp') |
2 | 2 | const path = require('path') |
3 | 3 | const fs = require('fs') |
| 4 | +const es = require('event-stream') |
| 5 | +const tsfmt = require('typescript-formatter') |
| 6 | +const tslint = require('tslint') |
| 7 | +const gTslint = require('gulp-tslint') |
4 | 8 | const clean = require('gulp-clean') |
5 | 9 | const webpack = require('webpack') |
6 | 10 | const crx = require('gulp-crx-pack') |
7 | 11 | const zip = require('gulp-zip') |
8 | 12 |
|
9 | | -gulp.task('clean', () => { |
10 | | - gulp.src(['pack/js/', 'dist']).pipe(clean()) |
| 13 | +gulp.task('clean', () => gulp.src(['pack/js/', 'dist']).pipe(clean())) |
| 14 | + |
| 15 | +gulp.task('lint', () => gulp.src(['src/**/*.ts'], { base: '.' }) |
| 16 | + .pipe(gTslint({ |
| 17 | + tslint: tslint, |
| 18 | + program: tslint.Linter.createProgram(path.resolve('tsconfig.json')), |
| 19 | + configuration: path.resolve('tslint.json') |
| 20 | + })) |
| 21 | + .pipe(gTslint.report({ |
| 22 | + summarizeFailureOutput: true, |
| 23 | + allowWarnings: false, |
| 24 | + reportLimit: 5 |
| 25 | + })) |
| 26 | +) |
| 27 | + |
| 28 | +gulp.task('fmt', () => { |
| 29 | + const formatting = es.map((file, cb) => { |
| 30 | + tsfmt.processString(file.path, file.contents.toString('utf8'), { |
| 31 | + replace: true, |
| 32 | + // verbose: true, |
| 33 | + tsfmt: true, |
| 34 | + tsfmtFile: path.resolve('tsfmt.json') |
| 35 | + }).then(result => { |
| 36 | + if (result.error) console.error(result.message) |
| 37 | + cb(null, file) |
| 38 | + }, err => cb(err)) |
| 39 | + }) |
| 40 | + gulp.src(['src/**/*.ts'], { base: '.' }).pipe(formatting) |
11 | 41 | }) |
12 | 42 |
|
13 | | -gulp.task('build', ['clean'], done => { |
| 43 | +gulp.task('build', ['clean', 'fmt', 'lint'], done => |
14 | 44 | webpack(require(path.resolve('webpack.config.js'))).run((err, stats) => { |
15 | 45 | if (err) console.error(err) |
16 | 46 | if (done) done() |
17 | 47 | }) |
18 | | -}) |
| 48 | +) |
19 | 49 |
|
20 | | -gulp.task('crx', ['build'], () => { |
21 | | - gulp.src(path.resolve('pack')) |
22 | | - .pipe(crx({ |
23 | | - privateKey: fs.readFileSync(path.resolve('key.pem'), 'utf8'), |
24 | | - filename: 'bcy-helper.crx' |
25 | | - })) |
26 | | - .pipe(gulp.dest('./dist')) |
27 | | -}) |
| 50 | +gulp.task('crx', ['build'], () => gulp.src(path.resolve('pack')) |
| 51 | + .pipe(crx({ |
| 52 | + privateKey: fs.readFileSync(path.resolve('key.pem'), 'utf8'), |
| 53 | + filename: 'bcy-helper.crx' |
| 54 | + })) |
| 55 | + .pipe(gulp.dest('./dist')) |
| 56 | +) |
28 | 57 |
|
29 | | -gulp.task('zip', ['build'], () => { |
30 | | - gulp.src(path.resolve('pack/**')) |
31 | | - .pipe(zip('bcy-helper.zip')) |
32 | | - .pipe(gulp.dest('./dist')) |
33 | | -}) |
| 58 | +gulp.task('zip', ['build'], () => gulp.src(path.resolve('pack/**')) |
| 59 | + .pipe(zip('bcy-helper.zip')) |
| 60 | + .pipe(gulp.dest('./dist')) |
| 61 | +) |
34 | 62 |
|
35 | 63 | gulp.task('default', ['build']) |
0 commit comments