-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathgulpfile.js
More file actions
55 lines (47 loc) · 1.38 KB
/
gulpfile.js
File metadata and controls
55 lines (47 loc) · 1.38 KB
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
const gulp = require('gulp');
const babel = require('gulp-babel');
const ts = require('gulp-typescript');
const del = require('del');
gulp.task('clean', async () => {
await del('lib/**');
await del('es/**');
await del('dist/**');
});
gulp.task('cjs', () =>
gulp
.src(['./es/**/*.js'])
.pipe(
babel({
configFile: '../../.babelrc',
}),
)
.pipe(gulp.dest('lib/')),
);
gulp.task('es', async () => {
const { execSync } = require('node:child_process');
// 使用 tsc 直接编译
console.log('Running TypeScript compilation...');
execSync('npx tsc --project tsconfig.pro.json --outDir es --module esnext', { stdio: 'inherit' });
console.log('TypeScript compilation completed');
// 然后运行 babel 转换
console.log('Running Babel transformation...');
return gulp
.src(['es/**/*.js'])
.pipe(
babel({
configFile: './.babelrc',
}),
)
.pipe(gulp.dest('es/'));
});
gulp.task('declaration', () => {
const tsProject = ts.createProject('tsconfig.pro.json', {
declaration: true,
emitDeclarationOnly: true,
});
return tsProject.src().pipe(tsProject()).pipe(gulp.dest('es/')).pipe(gulp.dest('lib/'));
});
gulp.task('copyReadme', async () => {
await gulp.src('../../README.md').pipe(gulp.dest('../../packages/hooks'));
});
exports.default = gulp.series('clean', 'es', 'cjs', 'declaration', 'copyReadme');