forked from googleworkspace/apps-script-oauth2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
45 lines (40 loc) · 1.42 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
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}"`);
}
}));
});