-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgulpfile.js
103 lines (90 loc) · 2.85 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
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
/**
* @file gulpfile
* @author [email protected]
*/
/* eslint-disable fecs-no-require */
const gulp = require('gulp');
const path = require('path');
const { amdWrap } = require('gulp-amd-wrap');
const { resolve } = require('path');
const httpPush = require('gulp-deploy-http-push').httpPush;
const ts = require('gulp-typescript');
const project = ts.createProject('./typescript/tsconfig.amd.json', {
declaration: true
});
const projectEsm = ts.createProject('./typescript/tsconfig.esm5.json', {
declaration: true
});
const projectCjs = ts.createProject('./typescript/tsconfig.cjs.json', {
declaration: true
});
const filter = require('gulp-filter');
gulp.task('build-amd', () => {
const f = filter(['**/*.js'], { restore: true });
const stream = gulp
.src(['src/**/*.ts'], { base: path.resolve('src') })
.pipe(project())
.pipe(f)
.pipe(amdWrap({
baseUrl: path.resolve(__dirname, 'typescript/dist/amd'),
anonymousModule: ['**/*'],
exlude: ['*.ts']
}))
.pipe(gulp.dest('dist/amd'));
f.restore.pipe(gulp.dest('dist/types'));
return stream;
});
gulp.task('build-esm5', () => {
const f = filter(['**/*.js']);
const stream = gulp
.src(['src/**/*.ts'], { base: path.resolve('src') })
.pipe(projectEsm())
.pipe(f)
.pipe(gulp.dest('dist/esm5'));
return stream;
});
gulp.task('build-cjs', () => {
const f = filter(['**/*.js']);
const stream = gulp
.src(['src/**/*.ts'], { base: path.resolve('src') })
.pipe(projectCjs())
.pipe(f)
.pipe(gulp.dest('dist/cjs'));
return stream;
});
gulp.task('build', gulp.series('build-amd', 'build-esm5', 'build-cjs'));
gulp.task('deploy', () => {
const HOST = require('./dev.config.js').receiver;
if (HOST) {
return gulp
.src(
['src/smarty-plugins/*'], { base: resolve(__dirname, 'src/smarty-plugins') }
)
.pipe(httpPush([{
host: HOST,
match: '/**/*.php',
to: '/home/work/search/view-ui/php/phplib/ext/smarty/baiduplugins'
}]));
}
});
gulp.task('deploy:project', () => {
const packages = require('./dev.config.js').packages;
if (packages) {
let out = gulp.src(['dist/**/*']);
packages.forEach(package => {
const path = resolve(package, '@baidu/molecule/dist');
console.log(`=> ${path}`);
out = out.pipe(gulp.dest(path));
});
return out;
}
});
gulp.task('watch', () => {
gulp.watch('./src/**/*.php', gulp.series('deploy'));
if (process.env.NODE_ENV) {
gulp.watch('./src/**/*.ts', gulp.series('build-amd', 'deploy:project'));
} else {
gulp.watch('./src/**/*.ts', gulp.series('build-amd'));
}
});
gulp.task('default', gulp.series('watch'));