<commit_before>"use strict";

import * as fs from "fs";
import * as handlebars from "handlebars";
import * as _ from "lodash";
import * as mkdirp from "mkdirp";
import * as path from "path";

import * as constants from "./constants";
import { getTemplateManifestAtTemplateDirectory } from "./getTemplateManifest";

export interface IFileCreatorInputData {
    templateFolderPath: string;
    pathToCreateAt: string;
    inputName: string;
    templateName: string;
}

interface ITemplateContext {
    name: string;
}

handlebars.registerHelper({
    camelCase: (input) => {
        return _.camelCase(input);
    },
    kebabCase: (input) => {
        return _.kebabCase(input);
    },
    pascalCase: (input) => {
        return _.chain(input).camelCase().upperFirst().value();
    },
    snakeCase: (input) => {
        return _.snakeCase(input);
    },
    snakeDotCase: (input) => {
        return _.snakeCase(input).replace(/_/g, ".");
    },
});

function escapeRegExp(str): string {
    return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}

function replaceAll(str, find, replace): string {
  return str.replace(new RegExp(escapeRegExp(find), "g"), replace);
}

function replaceName(stringToReplace: string, name: string): string {
    let result = replaceAll(stringToReplace, "__kebabCase_name__", _.kebabCase(name));
    result = replaceAll(result, "__pascalCase_name__", _.chain(name).camelCase().upperFirst().value());
    result = replaceAll(result, "__snakeCase_name__", _.snakeCase(name));
    result = replaceAll(result, "__snakeDotCase_name__", _.snakeCase(name).replace(/_/g, "."));
    result = replaceAll(result, "__camelCase_name__", _.camelCase(name));
    return result;
}

function getTemplateFileNamesAtTemplateDirectory(templateFolderPath: string): string[] {
    const files = fs
        .readdirSync(templateFolderPath)
        .filter((f) => {
            const folderPath = path.join(templateFolderPath, f);
            return !fs.statSync(folderPath).isDirectory();
        })
        .filter((f) => f !== constants.MANIFEST_FILE_NAME)
        .filter((f) => !f.startsWith("."));
    return files;
}

function getFolderNamesAtDirectory(directoryPath: string): string[] {
    const folderNames = fs
        .readdirSync(directoryPath)
        .filter((f) => {
            const folderPath = path.join(directoryPath, f);
            return fs.statSync(folderPath).isDirectory();
        })
        .filter((f) => f !== constants.MANIFEST_FILE_NAME)<commit_msg>Renamed to lowerDotCase per Reese's recommendation.<commit_after>"use strict";

import * as fs from "fs";
import * as handlebars from "handlebars";
import * as _ from "lodash";
import * as mkdirp from "mkdirp";
import * as path from "path";

import * as constants from "./constants";
import { getTemplateManifestAtTemplateDirectory } from "./getTemplateManifest";

export interface IFileCreatorInputData {
    templateFolderPath: string;
    pathToCreateAt: string;
    inputName: string;
    templateName: string;
}

interface ITemplateContext {
    name: string;
}

handlebars.registerHelper({
    camelCase: (input) => {
        return _.camelCase(input);
    },
    kebabCase: (input) => {
        return _.kebabCase(input);
    },
    pascalCase: (input) => {
        return _.chain(input).camelCase().upperFirst().value();
    },
    snakeCase: (input) => {
        return _.snakeCase(input);
    },
    lowerDotCase: (input) => {
        return _.snakeCase(input).replace(/_/g, ".");
    },
});

function escapeRegExp(str): string {
    return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}

function replaceAll(str, find, replace): string {
  return str.replace(new RegExp(escapeRegExp(find), "g"), replace);
}

function replaceName(stringToReplace: string, name: string): string {
    let result = replaceAll(stringToReplace, "__kebabCase_name__", _.kebabCase(name));
    result = replaceAll(result, "__pascalCase_name__", _.chain(name).camelCase().upperFirst().value());
    result = replaceAll(result, "__snakeCase_name__", _.snakeCase(name));
    result = replaceAll(result, "__lowerDotCase_name__", _.snakeCase(name).replace(/_/g, "."));
    result = replaceAll(result, "__camelCase_name__", _.camelCase(name));
    return result;
}

function getTemplateFileNamesAtTemplateDirectory(templateFolderPath: string): string[] {
    const files = fs
        .readdirSync(templateFolderPath)
        .filter((f) => {
            const folderPath = path.join(templateFolderPath, f);
            return !fs.statSync(folderPath).isDirectory();
        })
        .filter((f) => f !== constants.MANIFEST_FILE_NAME)
        .filter((f) => !f.startsWith("."));
    return files;
}

function getFolderNamesAtDirectory(directoryPath: string): string[] {
    const folderNames = fs
        .readdirSync(directoryPath)
        .filter((f) => {
            const folderPath = path.join(directoryPath, f);
            return fs.statSync(folderPath).isDirectory();
        })
        .filter((f) => f !== constants.MANIFEST_FILE_NAME)
{'fraction_non_alphanumeric': 0.15427435387673957, 'fraction_numerical': 0.00039761431411530816, 'mean_word_length': 3.5777979981801638, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '722725', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1545, 'n_words': 316}