<commit_before>var postcss = require('postcss');

var analyzer = require('./lib/analyzer');
var newParams = require('./lib/params');
var template = require('./lib/template');
var fileWriter = require('./lib/fileWriter');
var markdownParser = require('./lib/markdown');
var syntaxHighlighter = require('./lib/syntaxHighlight');

module.exports = postcss.plugin('postcss-style-guide', function (opts) {
    analyzer.setModules(syntaxHighlighter, markdownParser);
    var func = function (root) {
        if (typeof(opts) === 'object' && !opts.src) {
            opts.src = root.toString();
        }
        var params = newParams(opts);
        var maps = analyzer.analyze(root);
        var promise = syntaxHighlighter.execute({
            src: params.src,
            tmplStyle: params.style,
            stylePath: require.resolve('highlight.js/styles/github.css')
          }).then(function (styles) {
            var html = template.rendering(maps, styles, {
                project: params.project,
                showCode: params.showCode,
                tmpl: params.template
            });
            fileWriter.write(params.dest, html);
          }).then(function () {
            console.log('Successfully created style guide!');
          }).catch(function (err) {
            console.error('generate err:', err);
          });
        return promise;
    };
    return func;
});

<commit_msg>Return root object<commit_after>var postcss = require('postcss');

var analyzer = require('./lib/analyzer');
var newParams = require('./lib/params');
var template = require('./lib/template');
var fileWriter = require('./lib/fileWriter');
var markdownParser = require('./lib/markdown');
var syntaxHighlighter = require('./lib/syntaxHighlight');

module.exports = postcss.plugin('postcss-style-guide', function (opts) {
    analyzer.setModules(syntaxHighlighter, markdownParser);
    var func = function (root) {
        if (typeof(opts) === 'object' && !opts.src) {
            opts.src = root.toString();
        }
        var params = newParams(opts);
        var maps = analyzer.analyze(root);
        var promise = syntaxHighlighter.execute({
            src: params.src,
            tmplStyle: params.style,
            stylePath: require.resolve('highlight.js/styles/github.css')
          }).then(function (styles) {
            var html = template.rendering(maps, styles, {
                project: params.project,
                showCode: params.showCode,
                tmpl: params.template
            });
            fileWriter.write(params.dest, html);
          }).then(function () {
            console.log('Successfully created style guide!');
            return root;
          }).catch(function (err) {
            console.error('generate err:', err);
            return root;
          });
        return promise;
    };
    return func;
});


{'fraction_non_alphanumeric': 0.14201183431952663, 'fraction_numerical': 0.0, 'mean_word_length': 2.314878892733564, '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': '4563253', 'n_tokens_mistral': 777, 'n_tokens_neox': 755, 'n_words': 166}