<commit_before>'use strict';

var Client = require('poeditor-client');
var Promise = require('bluebird');
var Immutable = require('immutable');
var fs = Promise.promisifyAll(require('fs'));
var path = require('path');
var stringify = require('json-stable-stringify');

exports.clientFactory = function (apiToken) {
	return new Client(apiToken);
};

exports.getProject = function (apiToken, projectName) {
	return Promise.resolve(exports.clientFactory(apiToken).projects.list())
	.then(function (projects) {
		return Immutable.List(projects)
		.find(function (project) {
			return project.name == projectName;
		});
	});
};

exports.getTranslations = function (project) {
	return Promise.resolve(project.languages.list())
	.map(function (language) {
		return Promise.resolve(language.terms.list());
	})
	.then(function (terms) {
		return Immutable.fromJS(terms).flatten(1).toJS();
	});
};

exports.writeTranslations = function (translations, dest) {
	var writes = Immutable.List(translations)
	.groupBy(function (translation) {
		return translation.__languageCode;
	})
	.map(function (translations) {
		return Immutable.List(translations)
		.reduce(function (result, translation) {
			return result.set(translation.term, translation.translation);
		}, Immutable.Map());
	})
	.map(function (translations, languageCode) {
		var file = path.join(dest, languageCode + '.json');
		var data = stringify(translations, {
			space: '\t'
		});
		return fs.writeFileAsync(file, data);
	})
	.toList()
	.toJS();
	return Promise.all(writes);
};<commit_msg>fixed write to return written file names<commit_after>'use strict';

var Client = require('poeditor-client');
var Promise = require('bluebird');
var Immutable = require('immutable');
var fs = Promise.promisifyAll(require('fs'));
var path = require('path');
var stringify = require('json-stable-stringify');

exports.clientFactory = function (apiToken) {
	return new Client(apiToken);
};

exports.getProject = function (apiToken, projectName) {
	return Promise.resolve(exports.clientFactory(apiToken).projects.list())
	.then(function (projects) {
		return Immutable.List(projects)
		.find(function (project) {
			return project.name == projectName;
		});
	});
};

exports.getTranslations = function (project) {
	return Promise.resolve(project.languages.list())
	.map(function (language) {
		return Promise.resolve(language.terms.list());
	})
	.then(function (terms) {
		return Immutable.fromJS(terms).flatten(1).toJS();
	});
};

exports.writeTranslations = function (translations, dest) {
	var writes = Immutable.List(translations)
	.groupBy(function (translation) {
		return translation.__languageCode;
	})
	.map(function (translations) {
		return Immutable.List(translations)
		.reduce(function (result, translation) {
			return result.set(translation.term, translation.translation);
		}, Immutable.Map());
	})
	.map(function (translations, languageCode) {
		var file = path.join(dest, languageCode + '.json');
		var data = stringify(translations, {
			space: '\t'
		});
		return fs.writeFileAsync(file, data)
		.then(function () {
			return file;
		});
	})
	.toList()
	.toJS();
	return Promise.all(writes);
};
{'fraction_non_alphanumeric': 0.15609137055837563, 'fraction_numerical': 0.0006345177664974619, 'mean_word_length': 5.293413173652695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3165239', 'n_tokens_mistral': 1027, 'n_tokens_neox': 980, 'n_words': 201}