<commit_before>import {DocumentReadDatastore} from '../../datastore/document-read-datastore';
import {getExportDocuments} from './get-export-documents';
import {Settings} from '../../settings/settings';
import {ResourceId} from '../../constants';
import {RelationsManager} from '../../model/relations-manager';
import {ImageRelationsManager} from '../../model/image-relations-manager';

const fs = typeof window !== 'undefined' ? window.require('fs') : require('fs');


export module CatalogExporter {

    export async function performExport(datastore: DocumentReadDatastore,
                                        relationsManager: RelationsManager,
                                        imageRelationsManager: ImageRelationsManager,
                                        outputFilePath: string,
                                        catalogId: string,
                                        settings: Settings): Promise<void> {

        const [exportDocuments, imageResourceIds] =
            await getExportDocuments(datastore, relationsManager, imageRelationsManager, catalogId, settings.selectedProject);

        copyImageFiles(outputFilePath, imageResourceIds, settings);

        fs.writeFileSync(
            outputFilePath,
            exportDocuments
                .map(stringify)
                .join('\n') // TODO different operating systems?
        );
    }


    function copyImageFiles(outputFilePath: string,
                            imageResourceIds: Array<ResourceId>,
                            settings: Settings) {

        const basePath = outputFilePath
            .slice(0, outputFilePath.lastIndexOf('.')) + '/'; // TODO operating systems
        if (!fs.existsSync(basePath)) fs.mkdirSync(basePath);

        for (let image of imageResourceIds) {
            const source = settings.imagestorePath
                + settings.selectedProject + '/' + image;
            const target = basePath + image;
            fs.copyFileSync(source, target);
        }
    }
}<commit_msg>Remove todo<commit_after>import {DocumentReadDatastore} from '../../datastore/document-read-datastore';
import {getExportDocuments} from './get-export-documents';
import {Settings} from '../../settings/settings';
import {ResourceId} from '../../constants';
import {RelationsManager} from '../../model/relations-manager';
import {ImageRelationsManager} from '../../model/image-relations-manager';

const fs = typeof window !== 'undefined' ? window.require('fs') : require('fs');


export module CatalogExporter {

    export async function performExport(datastore: DocumentReadDatastore,
                                        relationsManager: RelationsManager,
                                        imageRelationsManager: ImageRelationsManager,
                                        outputFilePath: string,
                                        catalogId: string,
                                        settings: Settings): Promise<void> {

        const [exportDocuments, imageResourceIds] =
            await getExportDocuments(datastore, relationsManager, imageRelationsManager, catalogId, settings.selectedProject);

        copyImageFiles(outputFilePath, imageResourceIds, settings);

        fs.writeFileSync(
            outputFilePath,
            exportDocuments
                .map(stringify)
                .join('\n')
        );
    }


    function copyImageFiles(outputFilePath: string,
                            imageResourceIds: Array<ResourceId>,
                            settings: Settings) {

        const basePath = outputFilePath
            .slice(0, outputFilePath.lastIndexOf('.')) + '/'; // TODO operating systems
        if (!fs.existsSync(basePath)) fs.mkdirSync(basePath);

        for (let image of imageResourceIds) {
            const source = settings.imagestorePath
                + settings.selectedProject + '/' + image;
            const target = basePath + image;
            fs.copyFileSync(source, target);
        }
    }
}
{'fraction_non_alphanumeric': 0.10372406898275431, 'fraction_numerical': 0.0004998750312421895, 'mean_word_length': 1.9887976101568334, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '127017', 'n_tokens_mistral': 908, 'n_tokens_neox': 868, 'n_words': 207}