-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.js
52 lines (44 loc) · 1.11 KB
/
index.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
import path from 'node:path';
import archiver from 'archiver';
import Vinyl from 'vinyl';
import {gulpPlugin} from 'gulp-plugin-extras';
export default function gulpTar(filename, options) {
if (!filename) {
throw new Error('gulp-tar: `filename` required');
}
let firstFile;
const archive = archiver('tar', options);
return gulpPlugin('gulp-tar', async file => {
if (file.relative === '') {
return;
}
if (firstFile === undefined) {
firstFile = file;
}
const nameNormalized = file.relative.replaceAll('\\', '/');
if (file.isSymbolic()) {
archive.symlink(nameNormalized, file.symlink);
} else {
archive.append(file.contents, {
name: nameNormalized + (file.isNull() ? '/' : ''),
mode: file.stat && file.stat.mode,
date: file.stat && file.stat.mtime ? file.stat.mtime : null,
...options,
});
}
}, {
supportsAnyType: true,
async * onFinish() {
if (firstFile === undefined) {
return;
}
archive.finalize();
yield new Vinyl({
cwd: firstFile.cwd,
base: firstFile.base,
path: path.join(firstFile.base, filename),
contents: archive,
});
},
});
}