<commit_before>var through        = require('through2');
var gutil          = require('gulp-util');
var pathModule     = require('path');
var sass           = require('node-sass');
var less           = require('less');
var fs             = require('fs');
var autoprefixer   = require('autoprefixer');
var postcss        = require('postcss');
var PluginError    = gutil.PluginError;


// Constants
//
const PLUGIN_NAME = 'gulp-angular2-embed-sass';

module.exports = function (options) {

    options = options || {};

    var content;
    var base;
    var matches;
    var styleUrlRegexp = /styleUrls[\'"\s]*:[\s]*\[(.*)\]/;

    const FOUND_SUCCESS = {};
    const FOUND_ERROR   = {};
    const CODE_EXIT     = {};

    var debug = false;
    function log() {
        if (debug) {
            console.log.apply(console, arguments);
        }
    }

    // Calls sass compiler on the file
    //
    function compileSass(sassPaths, cb) {

        if (sassPaths.length > 0) {

            var path = pathModule.join(base, sassPaths.shift());

            sass.render({
              file: path,
              includePaths: options.includePaths || []
            },
            function(err, result) {
                if (err) {
                    cb(FOUND_ERROR, 'Error while compiling sass template "' + path + '". Error from "node-sass" plugin: ' + err);
                }

                if (options.autoprefixer) {
                  // Call autoprefixer on current built css
                  postcss([ autoprefixer(options.autoprefixer) ])
                    .process(result.css)
                    .then(function(prefixedResult) {
                      // escape any backticks that comeup in the compiled css
                      cb(FOUND_SUCCESS, prefixedResult.css.toString().replace(/\\([\s\S])|(`)/g,"\\$1$2"), sassPaths);
                    });
                } else {
                  // escape any backticks that comeup in the compiled css
                  cb(FOUND_SUCCESS, result.css.toString().replace(/\\([\s\S])|(`)/g,"\\$1$2"), sassPaths);
                }
            });
        }
        else {
            cb(CODE_EXIT);
        }
    }

    // Calls sass compiler on the file
    //
    function compileLess(lessPaths, cb) {

        if (lessPaths.length > 0) {

            var path = pathModule.join(base, lessPaths.shift());
            var content = fs.readFileSync(path, 'utf8');

            less.render(
              content,
            
            function(err, result) {
                if (err) {
                    cb(FOUND_ERROR, 'Error while compiling less template "' + path + '". Error from "less" plugin: ' + err);
                }

                if (options.autoprefixer) {
                  // Call autoprefixer on current built css
                  postcss([ autoprefixer(options.autoprefixer) ])
                    .process(result.css)
                    .then(function(prefixedResult) {
                      // escape any backticks that comeup in the compiled css
                      cb(FOUND_SUCCESS, prefixedResult.css.toString().replace(/\\([\s\S])|(`)/g,"\\$1$2"), lessPaths);
                    });
                } else {
                  // escape any backticks that comeup in the compiled css
                  cb(FOUND_SUCCESS, result.css.toString().replace(/\\([\s\S])|(`)/g,"\\$1$2"), lessPaths);
                }
            });
        }
        else {
            cb(CODE_EXIT);
        }
    }

    // Writes the new css strings to the file buffer
    //
    function joinParts(entrances) {

        var parts = [];
        parts.push(Buffer(content.substring(0, matches.index)));
        parts.push(Buffer('styles: [`'));

        for (var i=0; i<entrances.length; i++) {
            parts.push(Buffer(entrances[i].replace(/\n/g, '')));
            if (i < entrances.length - 1) {
                parts.push(Buffer('\', \''));
            }
        }
        parts.push(Buffer('`]'));
        parts.push(Buffer(content.substr(matches.index + matches[0].length)));
        return Buffer.concat(parts);
    }

    function transform(file, enc, cb) {

        var pipe      = this;
        var entrances = [];
        var compilers = {
            sass: compileSass,
            less: compileLess
        }

        // Ignore empty files
        //
        if (file.isNull()) {<commit_msg>Use constistently single quotes instead of backticks. This way won't break if multiple styleUrls were added to the input.<commit_after>var through        = require('through2');
var gutil          = require('gulp-util');
var pathModule     = require('path');
var sass           = require('node-sass');
var less           = require('less');
var fs             = require('fs');
var autoprefixer   = require('autoprefixer');
var postcss        = require('postcss');
var PluginError    = gutil.PluginError;


// Constants
//
const PLUGIN_NAME = 'gulp-angular2-embed-sass';

module.exports = function (options) {

    options = options || {};

    var content;
    var base;
    var matches;
    var styleUrlRegexp = /styleUrls[\'"\s]*:[\s]*\[(.*)\]/;

    const FOUND_SUCCESS = {};
    const FOUND_ERROR   = {};
    const CODE_EXIT     = {};

    var debug = false;
    function log() {
        if (debug) {
            console.log.apply(console, arguments);
        }
    }

    // Calls sass compiler on the file
    //
    function compileSass(sassPaths, cb) {

        if (sassPaths.length > 0) {

            var path = pathModule.join(base, sassPaths.shift());

            sass.render({
              file: path,
              includePaths: options.includePaths || []
            },
            function(err, result) {
                if (err) {
                    cb(FOUND_ERROR, 'Error while compiling sass template "' + path + '". Error from "node-sass" plugin: ' + err);
                }

                if (options.autoprefixer) {
                  // Call autoprefixer on current built css
                  postcss([ autoprefixer(options.autoprefixer) ])
                    .process(result.css)
                    .then(function(prefixedResult) {
                      // escape any backticks that comeup in the compiled css
                      cb(FOUND_SUCCESS, prefixedResult.css.toString().replace(/\\([\s\S])|(`)/g,"\\$1$2"), sassPaths);
                    });
                } else {
                  // escape any backticks that comeup in the compiled css
                  cb(FOUND_SUCCESS, result.css.toString().replace(/\\([\s\S])|(`)/g,"\\$1$2"), sassPaths);
                }
            });
        }
        else {
            cb(CODE_EXIT);
        }
    }

    // Calls sass compiler on the file
    //
    function compileLess(lessPaths, cb) {

        if (lessPaths.length > 0) {

            var path = pathModule.join(base, lessPaths.shift());
            var content = fs.readFileSync(path, 'utf8');

            less.render(
              content,
            
            function(err, result) {
                if (err) {
                    cb(FOUND_ERROR, 'Error while compiling less template "' + path + '". Error from "less" plugin: ' + err);
                }

                if (options.autoprefixer) {
                  // Call autoprefixer on current built css
                  postcss([ autoprefixer(options.autoprefixer) ])
                    .process(result.css)
                    .then(function(prefixedResult) {
                      // escape any backticks that comeup in the compiled css
                      cb(FOUND_SUCCESS, prefixedResult.css.toString().replace(/\\([\s\S])|(`)/g,"\\$1$2"), lessPaths);
                    });
                } else {
                  // escape any backticks that comeup in the compiled css
                  cb(FOUND_SUCCESS, result.css.toString().replace(/\\([\s\S])|(`)/g,"\\$1$2"), lessPaths);
                }
            });
        }
        else {
            cb(CODE_EXIT);
        }
    }

    // Writes the new css strings to the file buffer
    //
    function joinParts(entrances) {

        var parts = [];
        parts.push(Buffer(content.substring(0, matches.index)));
        parts.push(Buffer('styles: [\''));

        for (var i=0; i<entrances.length; i++) {
            parts.push(Buffer(entrances[i].replace(/\n/g, '')));
            if (i < entrances.length - 1) {
                parts.push(Buffer('\', \''));
            }
        }
        parts.push(Buffer('\']'));
        parts.push(Buffer(content.substr(matches.index + matches[0].length)));
        return Buffer.concat(parts);
    }

    function transform(file, enc, cb) {

        var pipe      = this;
        var entrances = [];
        var compilers = {
            sass: compileSass,
            less: compileLess
        }

        // Ignore empty files
        //
        if (file.isNull()) {
{'fraction_non_alphanumeric': 0.13716414540528335, 'fraction_numerical': 0.0038383382253330323, 'mean_word_length': 1.5089209855564996, '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': '1125627', 'n_tokens_mistral': 2560, 'n_tokens_neox': 2471, 'n_words': 548}