1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.isSymbolicLink = void 0;
|
7 | const path_1 = __importDefault(require("path"));
|
8 | const debug_1 = __importDefault(require("../debug"));
|
9 | const file_fs_ref_1 = __importDefault(require("../file-fs-ref"));
|
10 | const fs_extra_1 = require("fs-extra");
|
11 | const S_IFMT = 61440;
|
12 | const S_IFLNK = 40960;
|
13 | function isSymbolicLink(mode) {
|
14 | return (mode & S_IFMT) === S_IFLNK;
|
15 | }
|
16 | exports.isSymbolicLink = isSymbolicLink;
|
17 | async function downloadFile(file, fsPath) {
|
18 | const { mode } = file;
|
19 | if (mode && isSymbolicLink(mode) && file.type === 'FileFsRef') {
|
20 | const [target] = await Promise.all([
|
21 | fs_extra_1.readlink(file.fsPath),
|
22 | fs_extra_1.mkdirp(path_1.default.dirname(fsPath)),
|
23 | ]);
|
24 | await fs_extra_1.symlink(target, fsPath);
|
25 | return file_fs_ref_1.default.fromFsPath({ mode, fsPath });
|
26 | }
|
27 | else {
|
28 | const stream = file.toStream();
|
29 | return file_fs_ref_1.default.fromStream({ mode, stream, fsPath });
|
30 | }
|
31 | }
|
32 | async function removeFile(basePath, fileMatched) {
|
33 | const file = path_1.default.join(basePath, fileMatched);
|
34 | await fs_extra_1.remove(file);
|
35 | }
|
36 | async function download(files, basePath, meta) {
|
37 | const { isDev = false, skipDownload = false, filesChanged = null, filesRemoved = null, } = meta || {};
|
38 | if (isDev || skipDownload) {
|
39 |
|
40 |
|
41 |
|
42 | return files;
|
43 | }
|
44 | debug_1.default('Downloading deployment source files...');
|
45 | const start = Date.now();
|
46 | const files2 = {};
|
47 | const filenames = Object.keys(files);
|
48 | await Promise.all(filenames.map(async (name) => {
|
49 |
|
50 | if (Array.isArray(filesRemoved) && filesRemoved.includes(name)) {
|
51 | await removeFile(basePath, name);
|
52 | return;
|
53 | }
|
54 |
|
55 | if (Array.isArray(filesChanged) && !filesChanged.includes(name)) {
|
56 | return;
|
57 | }
|
58 | const file = files[name];
|
59 | const fsPath = path_1.default.join(basePath, name);
|
60 | files2[name] = await downloadFile(file, fsPath);
|
61 | }));
|
62 | const duration = Date.now() - start;
|
63 | debug_1.default(`Downloaded ${filenames.length} source files: ${duration}ms`);
|
64 | return files2;
|
65 | }
|
66 | exports.default = download;
|