"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.packageDirectory = packageDirectory;
const path_1 = require("path");
const tar_fs_1 = __importDefault(require("tar-fs"));
const node_zlib_1 = require("node:zlib");
/**
 * Package a directory into a tarball, base64 encoded
 * @param directory
 */
function packageDirectory(directory, options = { skip_node_modules: false, skip_symlinks: false }) {
    return new Promise((resolve, reject) => {
        // for deployComponent to a remote server, we need to tar the local directory
        const chunks = [];
        // pack the directory
        tar_fs_1.default
            .pack(directory, {
            dereference: !options.skip_symlinks,
            ignore: options.skip_node_modules
                ? (name) => {
                    return name.includes('node_modules') || name.includes((0, path_1.join)('cache', 'webpack'));
                }
                : undefined,
            map: (header) => {
                if (header.type === 'directory') {
                    header.mode = 0o755;
                }
                return header;
            },
        })
            .pipe((0, node_zlib_1.createGzip)())
            .on('data', (chunk) => chunks.push(chunk))
            .on('end', () => {
            resolve(Buffer.concat(chunks));
        })
            .on('error', reject);
    });
}
//# sourceMappingURL=packageComponent.js.map