forked from browserless/browserless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.ts
103 lines (83 loc) · 2.54 KB
/
gulpfile.ts
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
101
102
103
import path from 'path';
import { deleteAsync } from 'del';
import gulp from 'gulp';
import nodemon from 'gulp-nodemon';
// @ts-ignore no types :(
import prettier from 'gulp-prettier';
import { default as runExport } from 'gulp-run-command';
import sourcemaps from 'gulp-sourcemaps';
import ts from 'gulp-typescript';
import merge from 'merge2';
import {
generateSelectors,
generateSchemas,
generateOpenAPI,
pullUblockOrigin,
} from './gulp.utils.js';
// @ts-ignore
const run = runExport.default;
const fileInSubDir = (parentDir: string, file: string) => {
const relative = path.relative(parentDir, file);
return relative && !relative.startsWith('..') && !path.isAbsolute(relative);
};
gulp.task('clean', () => deleteAsync(['build', 'static/function/*js*']));
gulp.task('tsc', () => {
const tsProject = ts.createProject('tsconfig.json');
const files = tsProject.src().pipe(tsProject());
return merge([
files.dts.pipe(gulp.dest('build')),
files.js.pipe(sourcemaps.write('.')).pipe(gulp.dest('build')),
]);
});
gulp.task('build:function', run('node esbuild.js'));
gulp.task('build:client', gulp.series(['build:function']));
gulp.task('prettier', () => {
return gulp
.src([
'{src,functions,scripts}/**/*.{js,ts}',
'gulpfile.ts',
'gulp.utils.ts',
])
.pipe(prettier({ logLevel: 'error', write: true }))
.pipe(gulp.dest('./'));
});
gulp.task('lint', run('npx eslint . --ext .ts --fix'));
gulp.task('generate:schemas', generateSchemas);
gulp.task('generate:selectors', generateSelectors);
gulp.task('generate:openapi', generateOpenAPI);
gulp.task(
'install:browsers',
run('npx --yes playwright install chromium firefox webkit'),
);
gulp.task(
'install:cdp-json',
run('node --no-warnings --loader ts-node/esm ./scripts/cdp-json.ts'),
);
gulp.task('install:dev', gulp.series('install:browsers', 'install:cdp-json'));
gulp.task('install:ublock', pullUblockOrigin);
gulp.task('deploy', run('npx ts-node scripts/deploy'));
gulp.task(
'build',
gulp.series(
'clean',
'tsc',
'install:ublock',
'generate:schemas',
'generate:selectors',
'generate:openapi',
),
);
gulp.task('build:dev', gulp.parallel('build', 'build:client'));
gulp.task('serve:dev', (cb) => {
const routesSrc = path.join(process.cwd(), 'src', 'routes');
nodemon({
// nodemon.json gets pulled automatically
done: cb,
tasks: (files) => {
const routesWereModified = files.some((file) =>
fileInSubDir(routesSrc, file),
);
return routesWereModified ? ['generate:schemas'] : [];
},
});
});