UNPKG

1.36 kBJavaScriptView Raw
1"use strict";
2/*
3 * @adonisjs/sink
4 *
5 * (c) Harminder Virk <virk@adonisjs.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10var __importDefault = (this && this.__importDefault) || function (mod) {
11 return (mod && mod.__esModule) ? mod : { "default": mod };
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14exports.copyFiles = void 0;
15const path_1 = require("path");
16const cp_file_1 = __importDefault(require("cp-file"));
17const fs_1 = require("fs");
18/**
19 * Utility method to copy files
20 */
21function 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}
37exports.copyFiles = copyFiles;