<commit_before>const Generator = require('yeoman-generator');
// To log a coloured message with Yeoman
const chalk = require('chalk');
// Tell Yeoman what to say in the console
const yosay = require('yosay');
// Random cool words
const { random } = require('superb');
// To create folder
const mkdirp = require('mkdirp');
// To handle WP
const WP = require('wp-cli');
// Allows us to execute shell commands
const { exec } = require('child_process');

const destPath = 'dest';

/**
 * Execute simple shell command (async wrapper).
 * @param {String} cmd
 * @return {Object} { stdout: String, stderr: String }
 */
const sh = async cmd =>
    new Promise(function(resolve, reject) {
        exec(cmd, (err, stdout, stderr) => {
            if (err) {
                reject(err);
            } else {
                console.log(`✅ ${cmd}`);

                resolve({ stdout, stderr });
            }
        });
    });

module.exports = class extends Generator {
    _script() {
        if (this.superConfig.wordpress) {
            this.folder.src = 'wp-content/themes/' + this.superConfig.name + '/src';
        }

        this.fs.copyTpl(this.templatePath('js/**'), this.destinationPath(this.folder.src + '/js'), {
            gsap: this.superConfig.gsap,
            customEase: this.superConfig.customEase
        });

        // If GSAP's CustomEase plugin used along with GSAP
        if (this.superConfig.gsap && this.superConfig.customEase) {
            this.fs.copyTpl(
                this.templatePath('plugins/CustomEase.js'),
                this.destinationPath(`${this.folder.src}/js/plugins/CustomEase.js`)
            );
        }
    }

    _fonts() {
        if (this.superConfig.wordpress) {
            this.folder.src = 'wp-content/themes/' + this.superConfig.name;
        }

        mkdirp.sync(this.destinationPath(this.folder.src + '/fonts'));
    }

    _img() {
        if (this.superConfig.wordpress) {
            this.folder.src = 'wp-content/themes/' + this.superConfig.name;
        }

        mkdirp.sync(this.destinationPath(this.folder.src + '/img'));
    }

    _scss() {
        if (this.superConfig.wordpress) {
            this.folder.src = 'wp-content/themes/' + this.superConfig.name + '/src';
        }

        this.fs.copyTpl(this.templatePath('scss/**/*'), this.destinationPath(this.folder.src + '/scss'));
    }

    _webpack() {
        if (this.superConfig.wordpress) {
            this.fs.copyTpl(
                this.templatePath('webpack/webpack-wordpress.config.js'),
                this.destinationPath('webpack.config.js'),
                { name: this.superConfig.name }
            );
        } else {
            this.fs.copyTpl(
                this.templatePath('webpack/webpack-static.config.js'),
                this.destinationPath('webpack.config.js')
            );
        }
    }

    _npm() {
        this.fs.copyTpl(this.templatePath('_package.json'), this.destinationPath('package.json'), {
            config: this.superConfig
        });
    }

    _template() {
        if (!this.superConfig.wordpress) {
            this.fs.copyTpl(
                this.templatePath('html/index.html'),
                this.destinationPath(this.folder.src + '/index.html')
            );
        }
    }

    _miscellaneous() {
        if (this.superConfig.wordpress) {
            this.fs.copyTpl(this.templatePath('.htaccess-wp'), this.destinationPath('.htaccess'));
            this.fs.copyTpl(this.templatePath('robots-wp.txt'), this.destinationPath('robots.txt'));
            this.fs.copyTpl(this.templatePath('.gitignore-wp'), this.destinationPath('.gitignore'));
            this.fs.copyTpl(this.templatePath('robots-preprod.txt'), this.destinationPath('robots-preprod.txt'));
            mkdirp.sync(this.destinationPath('wp-content/themes/' + this.superConfig.name + '/acf-json'));
        } else {
            this.fs.copyTpl(this.templatePath('.htaccess'), this.destinationPath(this.folder.src + '/.htaccess'));
            this.fs.copyTpl(this.templatePath('robots.txt'), this.destinationPath(this.folder.src + '/robots.txt'));<commit_msg>✨ add package.json name validation<commit_after>const Generator = require('yeoman-generator');
// To log a coloured message with Yeoman
const chalk = require('chalk');
// Tell Yeoman what to say in the console
const yosay = require('yosay');
// Random cool words
const { random } = require('superb');
// To create folder
const mkdirp = require('mkdirp');
// To handle WP
const WP = require('wp-cli');
// Allows us to execute shell commands
const { exec } = require('child_process');
const validate = require('validate-npm-package-name');

const destPath = 'dest';

/**
 * Execute simple shell command (async wrapper).
 * @param {String} cmd
 * @return {Object} { stdout: String, stderr: String }
 */
const sh = async cmd =>
    new Promise(function(resolve, reject) {
        exec(cmd, (err, stdout, stderr) => {
            if (err) {
                reject(err);
            } else {
                console.log(`✅ ${cmd}`);

                resolve({ stdout, stderr });
            }
        });
    });

module.exports = class extends Generator {
    _script() {
        if (this.superConfig.wordpress) {
            this.folder.src = 'wp-content/themes/' + this.superConfig.name + '/src';
        }

        this.fs.copyTpl(this.templatePath('js/**'), this.destinationPath(this.folder.src + '/js'), {
            gsap: this.superConfig.gsap,
            customEase: this.superConfig.customEase
        });

        // If GSAP's CustomEase plugin used along with GSAP
        if (this.superConfig.gsap && this.superConfig.customEase) {
            this.fs.copyTpl(
                this.templatePath('plugins/CustomEase.js'),
                this.destinationPath(`${this.folder.src}/js/plugins/CustomEase.js`)
            );
        }
    }

    _fonts() {
        if (this.superConfig.wordpress) {
            this.folder.src = 'wp-content/themes/' + this.superConfig.name;
        }

        mkdirp.sync(this.destinationPath(this.folder.src + '/fonts'));
    }

    _img() {
        if (this.superConfig.wordpress) {
            this.folder.src = 'wp-content/themes/' + this.superConfig.name;
        }

        mkdirp.sync(this.destinationPath(this.folder.src + '/img'));
    }

    _scss() {
        if (this.superConfig.wordpress) {
            this.folder.src = 'wp-content/themes/' + this.superConfig.name + '/src';
        }

        this.fs.copyTpl(this.templatePath('scss/**/*'), this.destinationPath(this.folder.src + '/scss'));
    }

    _webpack() {
        if (this.superConfig.wordpress) {
            this.fs.copyTpl(
                this.templatePath('webpack/webpack-wordpress.config.js'),
                this.destinationPath('webpack.config.js'),
                { name: this.superConfig.name }
            );
        } else {
            this.fs.copyTpl(
                this.templatePath('webpack/webpack-static.config.js'),
                this.destinationPath('webpack.config.js')
            );
        }
    }

    _npm() {
        const validation = validate(this.superConfig.name);
        validation.warnings &&
            validation.warnings.forEach(warn => {
                console.warn('Warning:', warn);
            });
        validation.errors &&
            validation.errors.forEach(err => {
                console.error('Error:', err);
            });
        validation.errors && validation.errors.length && process.exit(1);

        this.fs.copyTpl(this.templatePath('_package.json'), this.destinationPath('package.json'), {
            config: this.superConfig
        });
    }

    _template() {
        if (!this.superConfig.wordpress) {
            this.fs.copyTpl(
                this.templatePath('html/index.html'),
                this.destinationPath(this.folder.src + '/index.html')
            );
        }
    }

    _miscellaneous() {
        if (this.superConfig.wordpress) {
            this.fs.copyTpl(this.templatePath('.htaccess-wp'), this.destinationPath('.htaccess'));
            this.fs.copyTpl(this.templatePath('robots-wp.txt'), this.destinationPath('robots.txt'));
            this.fs.copyTpl(this.templatePath('.gitignore-wp'), this.destinationPath('.gitignore'));
            this.fs.copyTpl(this.templatePath('robots-preprod.txt'), this.destinationPath('robots-preprod.txt'));
            mkdirp.sync(this.destinationPath('wp-content/themes/' + this.superConfig.name + '/acf-json'));
        } else {
            this.fs.copyTpl(this.templatePath('.htaccess'), this.destinationPath(this.folder.src + '/.htaccess'));
            this.fs.copyTpl(this.templatePath('robots.txt'), this.destinationPath(this.folder.src + '/robots.txt'));
{'fraction_non_alphanumeric': 0.15314076111875286, 'fraction_numerical': 0.00011462631820265933, 'mean_word_length': 2.160086925027164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '7355563', 'n_tokens_mistral': 2623, 'n_tokens_neox': 2522, 'n_words': 404}