1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
11 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
12 | };
|
13 | Object.defineProperty(exports, "__esModule", { value: true });
|
14 | exports.copyFiles = void 0;
|
15 | const path_1 = require("path");
|
16 | const cp_file_1 = __importDefault(require("cp-file"));
|
17 | const fs_1 = require("fs");
|
18 |
|
19 |
|
20 |
|
21 | function copyFiles(sourceBaseDir, destinationBaseDir, files, options) {
|
22 | const overwrite = options ? options.overwrite : false;
|
23 | return files.map((file) => {
|
24 | const absPath = (0, path_1.join)(sourceBaseDir, file);
|
25 | if (!(0, fs_1.existsSync)(absPath)) {
|
26 | throw new Error(`Missing source file "${absPath}"`);
|
27 | }
|
28 | const targetAbsPath = (0, path_1.join)(destinationBaseDir, file);
|
29 | const hasTarget = (0, fs_1.existsSync)(targetAbsPath);
|
30 | if (hasTarget && !overwrite) {
|
31 | return { filePath: file, state: 'skipped' };
|
32 | }
|
33 | cp_file_1.default.sync(absPath, targetAbsPath, { overwrite: true });
|
34 | return { filePath: file, state: 'copied' };
|
35 | });
|
36 | }
|
37 | exports.copyFiles = copyFiles;
|