3 var gulp
= require('gulp');
4 var argv
= require('yargs').argv
;
5 var gutil
= require('gulp-util');
6 var eslint
= require('gulp-eslint');
7 var jsonlint
= require('gulp-jsonlint');
8 var gulpIf
= require('gulp-if');
9 var fs
= require('fs-extra');
10 var mkdirp
= require('mkdirp');
11 var github
= require('gulp-github');
12 var eslintFilter
= require('./eslint-filter');
13 var del
= require('del');
19 '!node_modules_linux/**',
23 function guessBaseBranch() {
24 var branch
= process
.env
.CI_COMMIT_REF_NAME
|| process
.env
.GIT_BRANCH
;
25 if (!branch
) return 'develop';
27 if (branch
.match(/\bfeature\//)) return 'origin/develop';
29 return 'origin/master';
32 gulp
.task('linter:validate:config', function() {
34 .src(['config/*.json'])
36 .pipe(jsonlint
.reporter())
37 .pipe(jsonlint
.failOnError());
41 gulp
.task('linter:validate:eslint', function() {
42 mkdirp
.sync('output/eslint/');
49 extensions
: ['.js', '.vue']
52 .pipe(eslint
.format('unix'))
54 eslint
.format('checkstyle', function(checkstyleData
) {
55 fs
.writeFileSync('output/eslint/checkstyle.xml', checkstyleData
);
58 .pipe(gulpIf(file
=> file
.eslint
!= null && file
.eslint
.fixed
, gulp
.dest('./')))
59 .pipe(eslint
.failAfterError());
63 gulp
.task('linter:validate:eslint-diff', function() {
64 var baseBranch
= process
.env
.BASE_BRANCH
|| guessBaseBranch();
65 gutil
.log('Performing eslint comparison to', baseBranch
);
68 .src(JS_GLOBS
, { read
: false })
69 .pipe(eslintFilter
.filterFiles(baseBranch
))
75 .pipe(eslintFilter
.filterMessages())
76 .pipe(eslint
.format('unix'));
79 process
.env
.SONARQUBE_GITHUB_ACCESS_TOKEN
&&
80 process
.env
.ghprbPullId
&&
81 process
.env
.GIT_COMMIT
83 eslintPipe
= eslintPipe
.pipe(
85 git_token
: process
.env
.SONARQUBE_GITHUB_ACCESS_TOKEN
,
86 git_repo
: 'troupe/gitter-webapp',
87 git_prid
: process
.env
.ghprbPullId
,
88 git_sha
: process
.env
.GIT_COMMIT
97 * Hook into the validate phase
99 gulp
.task('linter:validate', [
100 'linter:validate:config',
101 'linter:validate:eslint'
102 // 'linter:validate:eslint-diff',
105 gulp
.task('linter:clean', function(cb
) {
106 del(['output/'], cb
);