<commit_before>#! /usr/bin/env babel-node

import {echo, exit} from "shelljs";
import nomnom from "nomnom";
import fs from "fs";
import path from "path";
import {exec} from "child_process";


const transformBasePath = path.join(__dirname, "..", "transforms");
const runFirst = [
    "resolve-relative-imports.js"
];
const runLast = [
    "remove-stilr.js",
    "convert-to-radium.js"
];

const {src, all, single} = nomnom.options({
    src: {
        position: 0,
        help: "Source directory to run the transforms against"
    },
    all: {
        flag: true,
        abbr: "A",
        help: "Run all transforms in transforms folder"
    },
    single: {
        help: "Run single transform",
        abbr: "S"
    }
}).parse();


if (!src) {
    echo("src option is required");
    exit(1);
}

const buildCMD = (filePath, file) => {
    return `jscodeshift -t ${filePath} ${file} --extensions "jsx,js"`;
};

const applyTransform = (transforms) => {
    if (!transforms.length) {
        return;
    }

    const transform = transforms.shift();
    const transformFilePath = path.join(transformBasePath, transform);
    const cmd = buildCMD(transformFilePath, src);

    echo("Applying transform", transform);

    exec(cmd, (err, stout) => {
        echo(stout);
        applyTransform(transforms);
    });
};

if (all) {
    const transforms = fs.readdirSync(transformBasePath)
                        .filter(fileName => fileName.match(".js$"))
                        .filter(filename => runFirst.indexOf(filename) === -1)
                        .filter(filename => runLast.indexOf(filename) === -1);
    const orderedTransforms = [...runFirst, ...transforms, ...runLast];
    applyTransform(orderedTransforms);
}

if (single) {
    const transformFilePath = path.join(transformBasePath, single);
    const cmd = buildCMD(transformFilePath, src);
    exec(cmd, (err, stout) => {
        echo(err);
        echo(stout);
    });
}<commit_msg>Rename files from js to jsx<commit_after>#! /usr/bin/env babel-node

import {echo, exit, find, mv} from "shelljs";
import nomnom from "nomnom";
import fs from "fs";
import path from "path";
import {exec} from "child_process";


const transformBasePath = path.join(__dirname, "..", "transforms");
const runFirst = [
    "resolve-relative-imports.js"
];
const runLast = [
    "remove-stilr.js",
    "convert-to-radium.js"
];

const {src, all, single} = nomnom.options({
    src: {
        position: 0,
        help: "Source directory to run the transforms against"
    },
    all: {
        flag: true,
        abbr: "A",
        help: "Run all transforms in transforms folder"
    },
    single: {
        help: "Run single transform",
        abbr: "S"
    }
}).parse();


if (!src) {
    echo("src option is required");
    exit(1);
}

const buildCMD = (filePath, file) => {
    return `jscodeshift -t ${filePath} ${file} --extensions "jsx,js"`;
};

const renameFiles = (cb) => {
    echo("Renaming files from .jsx to .js");

    find(src)
        .filter(file => {
            return file.match(/\.jsx$/);
        }).map(file => {
            mv(file, file.replace("jsx", "js"));
        });
}

const applyTransform = (transforms) => {
    if (!transforms.length) {
        return;
    }

    const transform = transforms.shift();
    const transformFilePath = path.join(transformBasePath, transform);
    const cmd = buildCMD(transformFilePath, src);

    echo("Applying transform", transform);

    exec(cmd, (err, stout) => {
        echo(stout);
        applyTransform(transforms);
    });
};

if (all) {
    const transforms = fs.readdirSync(transformBasePath)
                        .filter(fileName => fileName.match(".js$"))
                        .filter(filename => runFirst.indexOf(filename) === -1)
                        .filter(filename => runLast.indexOf(filename) === -1);
    const orderedTransforms = [...runFirst, ...transforms, ...runLast];

    renameFiles();
    applyTransform(orderedTransforms);
}

if (single) {
    const transformFilePath = path.join(transformBasePath, single);
    const cmd = buildCMD(transformFilePath, src);
    exec(cmd, (err, stout) => {
        echo(err);
        echo(stout);
    });
}
{'fraction_non_alphanumeric': 0.15529580152671757, 'fraction_numerical': 0.0019083969465648854, 'mean_word_length': 2.602233676975945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '6306420', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1281, 'n_words': 321}