<commit_before>const fs = require('fs-extra');
const AdmZip = require('adm-zip');

const prettify = (json) => JSON.stringify(json, null, 2);

const zipProject = ({gdslProject, gdslInstances}) => {
  const dir = 'export';
  if (!fs.exists(dir)) {
    fs.mkdirpSync(dir);
  }
  const zip = new AdmZip();
  zip.addFile('gdslProject.json', new Buffer(prettify(gdslProject)));
  gdslInstances.forEach((gdslInstance, index) => {
    zip.addFile(`gdslInstance${index}.json`, new Buffer(prettify(gdslInstance)));
  });
  zip.writeZip(`${dir}/${gdslProject.name}.zip`);
};

const getProjectDocuments = async (db, projectName) => {
  const gdslProject = await db.collection('GdslProject').findOne({name: projectName});
  if (gdslProject === null) {
    throw `no project named '${projectName}' found ...`;
  }
  const projectId = gdslProject._id;
  const gdslInstances = await db.collection('GraphicalDslInstance').find({graphicalDslId: projectId}).toArray();
  return {gdslProject, gdslInstances};
};

const exportProject = async (db, projectName) => {<commit_msg>create export directory if it does not exist<commit_after>const fs = require('fs-extra');
const AdmZip = require('adm-zip');

const prettify = (json) => JSON.stringify(json, null, 2);

const zipProject = ({gdslProject, gdslInstances}) => {
  const dir = './export';
  if (!fs.exists(dir)) {
    fs.mkdirpSync(dir);
  }
  const zip = new AdmZip();
  zip.addFile('gdslProject.json', new Buffer(prettify(gdslProject)));
  gdslInstances.forEach((gdslInstance, index) => {
    zip.addFile(`gdslInstance${index}.json`, new Buffer(prettify(gdslInstance)));
  });
  zip.writeZip(`${dir}/${gdslProject.name}.zip`);
};

const getProjectDocuments = async (db, projectName) => {
  const gdslProject = await db.collection('GdslProject').findOne({name: projectName});
  if (gdslProject === null) {
    throw `no project named '${projectName}' found ...`;
  }
  const projectId = gdslProject._id;
  const gdslInstances = await db.collection('GraphicalDslInstance').find({graphicalDslId: projectId}).toArray();
  return {gdslProject, gdslInstances};
};

const exportProject = async (db, projectName) => {
{'fraction_non_alphanumeric': 0.17078861409239385, 'fraction_numerical': 0.0009332711152589828, 'mean_word_length': 5.305882352941176, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3851038', 'n_tokens_mistral': 724, 'n_tokens_neox': 729, 'n_words': 147}