-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.ts
81 lines (74 loc) · 2.05 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
import del from 'del';
import * as esbuild from 'esbuild';
import Mocha from 'mocha';
import { ESLint } from 'eslint';
import gulp, { TaskFunctionCallback } from 'gulp';
import gulp_typescript from 'gulp-typescript';
/**
* Cleans the build directories
*/
export function clean(): Promise<string[]> {
return del([
'./dist',
'./dist-test'
])
}
clean.description = 'Cleans the build directories';
/**
* Bundles the plugin.
*/
export async function bundle(): Promise<void> {
await esbuild.build({
entryPoints: ['./src/index.ts'],
bundle: true,
minify: true,
outfile: './dist/index.js',
format: 'cjs',
platform: 'node',
target: 'node12'
});
}
clean.description = 'Bundles the plugin';
/**
* Generates type definitions for the plugin.
*/
export function types(): NodeJS.ReadWriteStream {
const project = gulp_typescript.createProject('tsconfig.json');
return project.src()
.pipe(project())
.pipe(gulp.dest('dist'));
}
clean.description = 'Generates type definitions for the plugin';
/**
* Runs tests
*/
export function test(done: TaskFunctionCallback): void {
const mocha = new Mocha();
mocha.addFile('./test/test.ts');
mocha.run((failCount) => {
if (failCount) {
done(new Error(`${failCount} tests failed.`));
}
else {
done();
}
})
}
test.description = 'Runs tests';
/**
* Runs lint
*/
export async function lint(): Promise<void> {
const eslint = new ESLint();
const results = await eslint.lintFiles('.');
const formatter = await eslint.loadFormatter('stylish');
const resultText = formatter.format(results);
console.log(resultText);
const errorCount = results.reduce((pv, result) => pv + result.errorCount, 0);
if (errorCount > 0) process.exitCode = 1;
}
test.description = 'Runs lint';
export const build = gulp.series(clean, gulp.parallel(bundle, types));
export const prepare = gulp.series(build);
export const prepublishOnly = gulp.series(lint, test);
export default build;