import { copy, remove } from 'fs-extra';
import getCachedItemPath from './getCachedItemPath.js';
import getEmulsifyConfig from '../project/getEmulsifyConfig.js';
export default async function copyFileFromCache(bucket, itemPath, destination, force = false) {
    const emulsifyConfig = await getEmulsifyConfig();
    let checkout = '';
    if (emulsifyConfig != undefined &&
        emulsifyConfig.system &&
        emulsifyConfig.system.checkout) {
        checkout = emulsifyConfig.system.checkout;
    }
    const source = getCachedItemPath(bucket, itemPath, checkout);
    if (force) {
        await remove(destination);
    }
    return copy(source, destination);
}
