const { archiveExtension, archiveKeys } = require('../constants/archive/consts');

/**
 * Class used to construct archive commands.
 */
class Archive {
    /**
     * Construct archive command based on platform.
     * @param {String} src 
     * @param {String} archiveName 
     * @param {String} archiveType zip | targz
     * @returns {String} platform based shell comand.
     */
    static archive(src, archiveName, archiveType = 'zip') {

        const extenstion = archiveExtension[archiveType];
        const platform = process.platform;
        const archiveCmd = archiveKeys[platform][archiveType];

        if (platform === 'win32') {
            return [archiveCmd, `${archiveName}${extenstion}`, src];
        }

        const command = ['COPYFILE_DISABLE=1', archiveCmd]
        const isZip = archiveType === 'zip';
        // archive name.
        command.push(`${archiveName}${extenstion}`);
        // source.
        command.push(src)
        // excluede key.
        command.push(isZip ? '-x' : '');
        // exclude files.
        command.push(isZip ? "*.DS_Store" : ' --exclude=.DS_Store');
        return command;
    }
}

module.exports = Archive;
