-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
64 lines (52 loc) · 1.66 KB
/
gulpfile.js
File metadata and controls
64 lines (52 loc) · 1.66 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
56
57
58
59
60
61
62
63
64
const gulp = require('gulp');
const path = require('path');
const flatten = require('gulp-flatten');
const jeditor = require('gulp-json-editor');
gulp.task('default', ['packages']);
gulp.task(
'definitions',
copyTask({
source: path.resolve('./src/definitions'),
destination: path.resolve('./lib/definitions'),
pattern: '**/*.d.ts',
transform: flatten()
})
);
gulp.task(
'packages',
copyTask({
source: path.resolve('./src'),
destination: path.resolve('./lib'),
pattern: '**/package.json',
transform: jeditor((json) => {
if (json.main !== undefined) {
json.main = json.main.replace(/\.ts$/, '.js');
}
if (json.typings) {
json.typings = json.typings.replace(/\.ts$/, '.d.ts');
}
if (json.types) {
json.types = json.types.replace(/\.ts$/, '.d.ts');
}
return json;
})
})
);
function copyTask(opts) {
const {source, destination, destinations = [destination], pattern = '**/*', excludePattern, transform} = opts;
return function () {
let stream;
if (excludePattern !== undefined) {
stream = gulp.src([path.join(source, pattern), `!${path.join(source, excludePattern)}`], {base: source});
} else {
stream = gulp.src(path.join(source, pattern), {base: source});
}
if (transform !== undefined) {
stream = stream.pipe(transform);
}
destinations.forEach((destination) => {
stream = stream.pipe(gulp.dest(destination));
});
return stream;
};
}