<commit_before>'use strict'

const fs = require('fs');
const glob = require('glob');
const postcss = require('postcss');

 /**
  * Simple function to translate given css to less. Only supports
  * transformations that are required for tachyons.
  */
function toLess(css) {
    var root = postcss.parse(css);
    var variables = '';

    // Handle global variables.
    root.walk(node => {
        if (node.selector == ':root') {
            node.walkDecls(decl => {
                variables += [
                decl.prop.replace('--', '@'), ': ', decl.value, ';\n'
                ].join('');
            });
            node.remove();
        }
    });

    // Replace css3 variables with less variables.
    root.replaceValues(/var\(--(.*)\)/, {fast: 'var'}, (_, p1) => {
        return '@' + p1;
    });

    // Convert @custom-media into variables.
    root.walkAtRules(atRule => {
        if (atRule.name == 'custom-media') {
            var line = atRule.params;
            var idx = line.indexOf(' ');
            var variableName = line.slice(0, idx);
            var value = line.slice(idx + 1);
            variables += [
                variableName.replace('--', '@'), ': ', '~"', value, '";\n'
            ].join('');
            atRule.remove();
        } else if (atRule.name == 'media') {
            atRule.params = atRule.params.replace(/\(--(.*)\)/, (_, p1) => {
                return '@' + p1;
            });
        }
    });

    return root.toString() + variables;
}

glob('./node_modules/tachyons/src/**/*.css', function(err, files) {
    if (err) {
        throw err;
    }
    var baseFile = '';

    if (!fs.existsSync('less')){
        fs.mkdirSync('less');
    }

    files.forEach(function(file) {
        var css = fs.readFileSync(file, 'utf8');
        var fileName = file.replace(/(\.\/node_modules\/tachyons\/src\/|\.css)/g, '');
        if (fileName == 'tachyons') {
            return;
        }

        fs.writeFileSync('less/' + fileName + '.less', toLess(css));
        baseFile += '@import "less/' + fileName + '";';
        baseFile += '\n';
    });

    fs.writeFileSync('tachyons.less', baseFile);
 });
<commit_msg>Use tachyons.css to build main file.<commit_after>'use strict'

const fs = require('fs');
const glob = require('glob');
const postcss = require('postcss');

 /**
  * Simple function to translate given css to less. Only supports
  * transformations that are required for tachyons.
  */
function toLess(css) {
    var root = postcss.parse(css);
    var variables = '';

    // Handle global variables.
    root.walk(node => {
        if (node.selector == ':root') {
            node.walkDecls(decl => {
                variables += [
                decl.prop.replace('--', '@'), ': ', decl.value, ';\n'
                ].join('');
            });
            node.remove();
        }
    });

    // Replace css3 variables with less variables.
    root.replaceValues(/var\(--(.*)\)/, {fast: 'var'}, (_, p1) => {
        return '@' + p1;
    });

    root.walkAtRules(atRule => {
        // Convert @custom-media into variables.
        if (atRule.name == 'custom-media') {
            var line = atRule.params;
            var idx = line.indexOf(' ');
            var variableName = line.slice(0, idx);
            var value = line.slice(idx + 1);
            variables += [
                variableName.replace('--', '@'), ': ', '~"', value, '";\n'
            ].join('');
            atRule.remove();
        }
        // Handle @media variables
        if (atRule.name == 'media') {
            atRule.params = atRule.params.replace(/\(--(.*)\)/, (_, p1) => {
                return '@' + p1;
            });
        }

        // Handle @imports
        if (atRule.name == 'import') {
            atRule.params = atRule.params.replace('./', 'less/');
        }
    });

    return root.toString() + variables;
}

glob('./node_modules/tachyons/src/**/*.css', function(err, files) {
    if (err) {
        throw err;
    }
    if (!fs.existsSync('less')){
        fs.mkdirSync('less');
    }

    files.forEach(function(file) {
        var css = fs.readFileSync(file, 'utf8');
        var fileName = file.replace(/(\.\/node_modules\/tachyons\/src\/|\.css)/g, '');
        if (fileName == 'tachyons') {
            return;
        }
        fs.writeFileSync('less/' + fileName + '.less', toLess(css));
    });

    // Handle tachyons.css
    var main = fs.readFileSync('./node_modules/tachyons/src/tachyons.css', 'utf8');
    fs.writeFileSync('tachyons.less', toLess(main));
 });
{'fraction_non_alphanumeric': 0.19128329297820823, 'fraction_numerical': 0.0037420206911732336, 'mean_word_length': 1.811881188118812, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1927632', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1374, 'n_words': 285}