<commit_before>/*
 * Inspired by the Denali-CLI command class
 * https://github.com/denali-js/denali-cli/blob/master/lib/command.ts
 */
'use strict';

const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
const each = require('lodash/each');
const createDebug = require('debug');
const kebabCase = require('lodash/kebabCase');

const UI = require('./ui');
const System = require('./system');

const debug = createDebug('ghost-cli:command');

/**
 * Checks if the cwd is a valid ghost installation. Also checks if the current
 * directory contains a development install of ghost (e.g. a git clone), and outputs
 * a helpful error message if so.
 *
 * @param {string} name Name of command, will be output if there's an error
 */
function checkValidInstall(name) {
    /*
     * CASE: a `config.js` file exists, which means this is a LTS installation
     * which we don't support in the CLI
     */
    if (fs.existsSync(path.join(process.cwd(), 'config.js'))) {
        console.error(
            chalk.yellow('Ghost-CLI only works with Ghost versions >= 1.0.0.'),
            '\nIf you are trying to upgrade Ghost LTS to 1.0.0 ' +
            `please see ${chalk.blue.underline('https://docs.ghost.org/v1/docs/migrating-to-1-0-0')}.`,
            `\nOtherwise, please run \`ghost ${name}\` again within a valid Ghost installation.`
        );
        process.exit(1);
    }

    /*
     * We assume it's a Ghost development install if 3 things are true:
     * 1) package.json exists
     * 2) package.json "name" field is "ghost"
     * 3) Gruntfile.js exists
     */
    if (fs.existsSync(path.join(process.cwd(), 'package.json')) &&
        fs.readJsonSync(path.join(process.cwd(), 'package.json')).name === 'ghost' &&
        fs.existsSync(path.join(process.cwd(), 'Gruntfile.js'))) {
        console.error(
            chalk.yellow('Ghost-CLI commands do not work inside of a git clone, zip download or with Ghost <1.0.0.'),
            `\nPerhaps you meant \`grunt ${name}\`?`,
            `\nOtherwise, please run \`ghost ${name}\` again within a valid Ghost installation.`
        );
        process.exit(1);
    }

    /*
     * Assume it's not a valid CLI install if the `.ghost-cli` file doesn't exist
     */
    if (!fs.existsSync(path.join(process.cwd(), '.ghost-cli'))) {
        console.error(<commit_msg>chore(docs): update migration docs URL (#465)<commit_after>/*
 * Inspired by the Denali-CLI command class
 * https://github.com/denali-js/denali-cli/blob/master/lib/command.ts
 */
'use strict';

const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
const each = require('lodash/each');
const createDebug = require('debug');
const kebabCase = require('lodash/kebabCase');

const UI = require('./ui');
const System = require('./system');

const debug = createDebug('ghost-cli:command');

/**
 * Checks if the cwd is a valid ghost installation. Also checks if the current
 * directory contains a development install of ghost (e.g. a git clone), and outputs
 * a helpful error message if so.
 *
 * @param {string} name Name of command, will be output if there's an error
 */
function checkValidInstall(name) {
    /*
     * CASE: a `config.js` file exists, which means this is a LTS installation
     * which we don't support in the CLI
     */
    if (fs.existsSync(path.join(process.cwd(), 'config.js'))) {
        console.error(
            chalk.yellow('Ghost-CLI only works with Ghost versions >= 1.0.0.'),
            '\nIf you are trying to upgrade Ghost LTS to 1.0.0 ' +
            `please see ${chalk.blue.underline('https://docs.ghost.org/v1/docs/migrating-to-ghost-1-0-0')}.`,
            `\nOtherwise, please run \`ghost ${name}\` again within a valid Ghost installation.`
        );
        process.exit(1);
    }

    /*
     * We assume it's a Ghost development install if 3 things are true:
     * 1) package.json exists
     * 2) package.json "name" field is "ghost"
     * 3) Gruntfile.js exists
     */
    if (fs.existsSync(path.join(process.cwd(), 'package.json')) &&
        fs.readJsonSync(path.join(process.cwd(), 'package.json')).name === 'ghost' &&
        fs.existsSync(path.join(process.cwd(), 'Gruntfile.js'))) {
        console.error(
            chalk.yellow('Ghost-CLI commands do not work inside of a git clone, zip download or with Ghost <1.0.0.'),
            `\nPerhaps you meant \`grunt ${name}\`?`,
            `\nOtherwise, please run \`ghost ${name}\` again within a valid Ghost installation.`
        );
        process.exit(1);
    }

    /*
     * Assume it's not a valid CLI install if the `.ghost-cli` file doesn't exist
     */
    if (!fs.existsSync(path.join(process.cwd(), '.ghost-cli'))) {
        console.error(
{'fraction_non_alphanumeric': 0.15021008403361344, 'fraction_numerical': 0.008613445378151261, 'mean_word_length': 2.775574940523394, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '176481', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1474, 'n_words': 450}