<commit_before>/// <reference path="../typings/tsd.d.ts"/>

var _ = require('lodash'),
    chalk = require('chalk'),
    log = require('./../helpers/log'),
    path = require('path'),
    sass = require('node-sass');

function Sass ( config ) {
    // Helpers
    function parseFileName ( filePath ) {
        var file = path.basename(filePath);
        return file.replace(/.s[ca]ss$/, '.css');
    }

    // Conform metalsmith API
    return function ( files, metalsmith, done ) {
        var fileName;

        // Normalize settings
        config.file = metalsmith.path(config.file);
        config.outputDir = config.outDir || './' ;
        config.outFile = path.join(
            config.outputDir,
            parseFileName(config.file)
        );
        fileName = config.outFile; // node-sass messes with the config >.<

        sass.render( config, function ( err, result ) {
            if ( err ) {
                log(
                    chalk.red('ERROR: Sass could not be compiled!\n\n') +
                    chalk.red(err)
                );

                // Use previous sass build if possible.
                if( metalsmith._metadata['sass_backup'] ) {
                    log(chalk.white('Using last sass build.'))
                    result = metalsmith._metadata['sass_backup'];
                }
            }

            files[fileName] = {
                contents: result.css
            };

            if( result.map ) {
                files[fileName + '.map'] = {
                    contents: result.map
                };
            }

            // Write a backup fale in case next time rendering fails.<commit_msg>Better log messages.<commit_after>/// <reference path="../typings/tsd.d.ts"/>

var _ = require('lodash'),
    chalk = require('chalk'),
    log = require('./../helpers/log'),
    path = require('path'),
    sass = require('node-sass');

function Sass ( config ) {
    // Helpers
    function parseFileName ( filePath ) {
        var file = path.basename(filePath);
        return file.replace(/.s[ca]ss$/, '.css');
    }

    // Conform metalsmith API
    return function ( files, metalsmith, done ) {
        var fileName;

        // Normalize settings
        config.file = metalsmith.path(config.file);
        config.outputDir = config.outDir || './' ;
        config.outFile = path.join(
            config.outputDir,
            parseFileName(config.file)
        );
        fileName = config.outFile; // node-sass messes with the config >.<

        sass.render( config, function ( err, result ) {
            if ( err ) {
                log(
                    chalk.red('ERROR: Sass could not be compiled!\n\n') +
                    chalk.red(err)
                );

                // Use previous sass build if possible.
                if( metalsmith._metadata['sass_backup'] ) {
                    log(chalk.white('Previous Sass build restored.'))
                    result = metalsmith._metadata['sass_backup'];
                }
            }

            files[fileName] = {
                contents: result.css
            };

            if( result.map ) {
                files[fileName + '.map'] = {
                    contents: result.map
                };
            }

            // Write a backup fale in case next time rendering fails.
{'fraction_non_alphanumeric': 0.12770432692307693, 'fraction_numerical': 0.0, 'mean_word_length': 1.4406158357771262, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3549172', 'n_tokens_mistral': 933, 'n_tokens_neox': 877, 'n_words': 203}