1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | function _fs() {
|
9 | const data = _interopRequireDefault(require("fs"));
|
10 |
|
11 | _fs = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _path() {
|
19 | const data = _interopRequireDefault(require("path"));
|
20 |
|
21 | _path = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | var _walk = _interopRequireDefault(require("./walk"));
|
29 |
|
30 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | async function copyFiles(srcPath, destPath, options = {}) {
|
43 | return Promise.all((0, _walk.default)(srcPath).map(async absoluteSrcFilePath => {
|
44 | const exclude = options.exclude;
|
45 |
|
46 | if (exclude && exclude.some(p => p.test(absoluteSrcFilePath))) {
|
47 | return;
|
48 | }
|
49 |
|
50 | const relativeFilePath = _path().default.relative(srcPath, absoluteSrcFilePath);
|
51 |
|
52 | await copyFile(absoluteSrcFilePath, _path().default.resolve(destPath, relativeFilePath));
|
53 | }));
|
54 | }
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | function copyFile(srcPath, destPath) {
|
61 | if (_fs().default.lstatSync(srcPath).isDirectory()) {
|
62 | if (!_fs().default.existsSync(destPath)) {
|
63 | _fs().default.mkdirSync(destPath);
|
64 | }
|
65 |
|
66 |
|
67 | return;
|
68 | }
|
69 |
|
70 | return new Promise((resolve, reject) => {
|
71 | copyBinaryFile(srcPath, destPath, err => {
|
72 | if (err) {
|
73 | reject(err);
|
74 | }
|
75 |
|
76 | resolve(destPath);
|
77 | });
|
78 | });
|
79 | }
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | function copyBinaryFile(srcPath, destPath, cb) {
|
86 | let cbCalled = false;
|
87 |
|
88 | const {
|
89 | mode
|
90 | } = _fs().default.statSync(srcPath);
|
91 |
|
92 | const readStream = _fs().default.createReadStream(srcPath);
|
93 |
|
94 | const writeStream = _fs().default.createWriteStream(destPath);
|
95 |
|
96 | readStream.on('error', err => {
|
97 | done(err);
|
98 | });
|
99 | writeStream.on('error', err => {
|
100 | done(err);
|
101 | });
|
102 | readStream.on('close', () => {
|
103 | done();
|
104 |
|
105 | _fs().default.chmodSync(destPath, mode);
|
106 | });
|
107 | readStream.pipe(writeStream);
|
108 |
|
109 | function done(err) {
|
110 | if (!cbCalled) {
|
111 | cb(err);
|
112 | cbCalled = true;
|
113 | }
|
114 | }
|
115 | }
|
116 |
|
117 | var _default = copyFiles;
|
118 | exports.default = _default; |
\ | No newline at end of file |