-
Notifications
You must be signed in to change notification settings - Fork 430
/
gulpfile.js
69 lines (61 loc) · 2.22 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
/**
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const concat = require('gulp-concat');
const contains = require('gulp-contains');
const del = require('del');
const eslint = require('gulp-eslint');
const expose = require('gulp-expose');
const gulp = require('gulp');
const rename = require("gulp-rename");
// Regex that looks for a populated client ID in the code. This is used to
// catch cases where the client ID is accidentally committed in a sample.
const CLIENT_ID_REGEX = /CLIENT_ID\s*=\s*'[^.']/;
// String which if it appears in the source code bypasses the client ID check.
// This is to allow samples that use a publicly-available demo client ID to
// not trigger the error.
const CLIENT_ID_BYPASS = '@credentialsOK';
gulp.task('clean', async function() {
return del([
'dist/*'
]);
});
gulp.task('dist', gulp.series('clean', async function(){
return gulp.src('src/*.js')
.pipe(concat('OAuth2.gs'))
.pipe(expose('this', 'OAuth2'))
.pipe(gulp.dest('dist'));
}));
gulp.task('lint', () => {
return gulp.src(['src/*.js', 'samples/*.gs', 'test/**/*.js', '!node_modules/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
.pipe(contains({
search: CLIENT_ID_REGEX,
onFound: (string, file, cb) => {
if (file.contents.toString().includes(CLIENT_ID_BYPASS)) {
return false;
}
return cb(`Client ID found in file: "${file.relative}"`);
}
}));
});
gulp.task('fix', () => {
return gulp.src(['src/*.js', 'samples/*.gs', 'test/**/*.js', '!node_modules/**'])
.pipe(eslint({fix: true}))
.pipe(eslint.format())
.pipe(gulp.dest(file => file.base))
});