<commit_before>'use strict';

const async = require('async');
const fs = require('fs-extra');
const path = require('path');
const tarball = require('tarball-extract');

function downloadLexicon(version, dest, cb) {
	const fileName = 'lexicon-ux-' + version + '.tgz';

	const downloadName = path.join(dest, fileName);
	const tarballURL = 'https://registry.npmjs.org/lexicon-ux/-/' + fileName;

	_downloadTarball(tarballURL, downloadName, path.join(dest, 'lexicon', version), function(err, pkg) {
		const lexiconPath = resolveLexiconPath(version, dest);

		_fixLexiconBaseMain(pkg.srcDir);

		const customDir = path.join(lexiconPath, 'custom');

		try {
			fs.copySync(path.join(__dirname, 'lexicon/custom'), customDir, {
				clobber: true
			});
		}
		catch (err) {
		}

		pkg.customDir = customDir;

		cb(err, pkg);
	});
}

exports.downloadLexicon = downloadLexicon;

function downloadSassDependencies(version, dest, cb) {
	async.parallel({
		bourbon: function(cb) {
			_downloadBourbon(dest, cb);
		},
		lexicon: function(cb) {
			downloadLexicon(version, dest, cb);
		}
	}, cb);
}

exports.downloadSassDependencies = downloadSassDependencies;

function resolveLexiconPath(version, dest) {
	return path.join(dest, 'lexicon', version, 'package');
}

exports.resolveLexiconPath = resolveLexiconPath;

function _downloadBourbon(dest, cb) {
	const fileName = 'bourbon-4.2.7.tgz';

	const downloadName = path.join(dest, fileName);
	const tarballURL = 'https://registry.npmjs.org/bourbon/-/' + fileName;

	_downloadTarball(tarballURL, downloadName, path.join(dest, 'bourbon'), cb);
}

function _downloadTarball(url, fileDestination, extractionDestination, cb) {
	const pkgPath = path.join(extractionDestination, 'package');

	try {
		const pkg = require(pkgPath);

		cb(null, pkg);
	}
	catch (err) {
		async.waterfall([
			function(cb) {
				const fileName = path.basename(fileDestination);

				tarball.extractTarball(path.join('./tarballs', fileName), extractionDestination, function(err) {<commit_msg>Find tarball path based on __dirname since relative paths are resolved differently in asar<commit_after>'use strict';

const async = require('async');
const fs = require('fs-extra');
const path = require('path');
const tarball = require('tarball-extract');

function downloadLexicon(version, dest, cb) {
	const fileName = 'lexicon-ux-' + version + '.tgz';

	const downloadName = path.join(dest, fileName);
	const tarballURL = 'https://registry.npmjs.org/lexicon-ux/-/' + fileName;

	_downloadTarball(tarballURL, downloadName, path.join(dest, 'lexicon', version), function(err, pkg) {
		const lexiconPath = resolveLexiconPath(version, dest);

		_fixLexiconBaseMain(pkg.srcDir);

		const customDir = path.join(lexiconPath, 'custom');

		try {
			fs.copySync(path.join(__dirname, 'lexicon/custom'), customDir, {
				clobber: true
			});
		}
		catch (err) {
		}

		pkg.customDir = customDir;

		cb(err, pkg);
	});
}

exports.downloadLexicon = downloadLexicon;

function downloadSassDependencies(version, dest, cb) {
	async.parallel({
		bourbon: function(cb) {
			_downloadBourbon(dest, cb);
		},
		lexicon: function(cb) {
			downloadLexicon(version, dest, cb);
		}
	}, cb);
}

exports.downloadSassDependencies = downloadSassDependencies;

function resolveLexiconPath(version, dest) {
	return path.join(dest, 'lexicon', version, 'package');
}

exports.resolveLexiconPath = resolveLexiconPath;

function _downloadBourbon(dest, cb) {
	const fileName = 'bourbon-4.2.7.tgz';

	const downloadName = path.join(dest, fileName);
	const tarballURL = 'https://registry.npmjs.org/bourbon/-/' + fileName;

	_downloadTarball(tarballURL, downloadName, path.join(dest, 'bourbon'), cb);
}

function _downloadTarball(url, fileDestination, extractionDestination, cb) {
	const pkgPath = path.join(extractionDestination, 'package');

	try {
		const pkg = require(pkgPath);

		cb(null, pkg);
	}
	catch (err) {
		async.waterfall([
			function(cb) {
				const fileName = path.basename(fileDestination);

				tarball.extractTarball(path.join(__dirname, 'tarballs', fileName), extractionDestination, function(err) {
{'fraction_non_alphanumeric': 0.14177277179236042, 'fraction_numerical': 0.0014691478942213516, 'mean_word_length': 5.142857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1495572', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1335, 'n_words': 280}