<commit_before>"use strict";

const fs = require('fs');
const fsx = require('../helpers/fs-additions');
const path = require('path');
const Promise = require('bluebird');
const _ = require('lodash');

/**
 *  Helper function for populating the context with API spec path and
 *  whether API should be skipped or not
 */
function populateAPIContext(context) {
    return new Promise(function(resolve) {
        process.stdout.write('\tChecking if API spec is present');

        // Make sure the API spec exists
        const appendedContext = {
            api: {

            }
        };

        const apiPath = path.join(context.directories.cwd, 'api.json');
        if (!fsx.fileExists(apiPath)) {
            console.log(' ✖'.red);
            appendedContext.api.configuration = undefined;
            appendedContext.api.skip = true;
        } else {
            console.log(' ✔'.green);

            // Write the API to the staging directory
            const deploymentAPIPath = path.join(context.directories.staging, 'deployment.api.json');
            fs.writeFileSync(deploymentAPIPath, fs.readFileSync(apiPath, 'utf8'));

            appendedContext.api.configuration = deploymentAPIPath;
            appendedContext.api.skip = false;
        }

        resolve(_.assign({}, context, appendedContext));
    });
}

//
// Step that preps the API spec/context for deployment in the next step
//
module.exports = populateAPIContext;
<commit_msg>Improve deployment log output<commit_after>"use strict";

const fs = require('fs');
const fsx = require('../helpers/fs-additions');
const path = require('path');
const Promise = require('bluebird');
const _ = require('lodash');

/**
 *  Helper function for populating the context with API spec path and
 *  whether API should be skipped or not
 */
function populateAPIContext(context) {
    return new Promise(function(resolve) {
        console.log('');

        // Make sure the API spec exists
        const appendedContext = {
            api: {

            }
        };

        process.stdout.write('Checking if API spec is present');
        const apiPath = path.join(context.directories.cwd, 'api.json');
        if (!fsx.fileExists(apiPath)) {
            console.log(' ✖'.red);
            appendedContext.api.configuration = undefined;
            appendedContext.api.skip = true;
        } else {
            console.log(' ✔'.green);

            // Write the API to the staging directory
            const deploymentAPIPath = path.join(context.directories.staging, 'deployment.api.json');
            fs.writeFileSync(deploymentAPIPath, fs.readFileSync(apiPath, 'utf8'));

            appendedContext.api.configuration = deploymentAPIPath;
            appendedContext.api.skip = false;
        }

        resolve(_.assign({}, context, appendedContext));
    });
}

//
// Step that preps the API spec/context for deployment in the next step
//
module.exports = populateAPIContext;

{'fraction_non_alphanumeric': 0.11970159376059682, 'fraction_numerical': 0.0006781959986436081, 'mean_word_length': 2.5244922341696534, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1980246', 'n_tokens_mistral': 814, 'n_tokens_neox': 793, 'n_words': 212}