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

const cp = require("child_process");
const inquirer = require("inquirer");

function runCommand(command) {
	cp.exec(command, (error, stdout, stderr) => {
		if(!error) {
			console.log("webpack-cli installed successfully");
			return true;
		}
		console.log("failed to install webpack-cli");
		console.error(stderr);
		return false;
	});
}

let webpackCliInstalled = false;
try {
	require.resolve("webpack-cli");
	webpackCliInstalled = true;
} catch(err) {
	webpackCliInstalled = false;
}

if(!webpackCliInstalled) {
	const path = require("path");
	const fs = require("fs");
	const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock"));

	const question = {
		type: "confirm",
		name: "shouldInstall",
		message: "Would you like to install webpack-cli?",
		default: true
	};

	console.error("The CLI moved into a separate package: webpack-cli");
	inquirer.prompt(question).then((answer) => {
		if(answer) {
			console.error("Installing webpack-cli");

			let command;
			if(isYarn) {
				command = "yarn add -D webpack-cli";
			} else {
				command = "npm install --save-dev webpack-cli";
			}

			if(runCommand(command)) {
				require("webpack-cli"); // eslint-disable-line node/no-missing-require, node/no-extraneous-require, node/no-unpublished-require
			}
		}
	});
} else {
	require("webpack-cli"); // eslint-disable-line node/no-missing-require, node/no-extraneous-require, node/no-unpublished-require
}<commit_msg>* Pipe stdout and stderr from child_process to main process * code refactoring and using promises<commit_after>#!/usr/bin/env node

const cp = require("child_process");
const inquirer = require("inquirer");

function runCommand(command, options) {
	return new Promise((resolve, reject) => {
		const executedCommand = cp.spawn(command, options, {
			stdio: "inherit"
		});

		executedCommand.on("error", error => {
			reject(error);
		});

		executedCommand.on("exit", code => {
			if (code === 0) {
				resolve(true);
			} else {
				reject();
			}
		});
	});
}

let webpackCliInstalled = false;
try {
	require.resolve("webpack-cli");
	webpackCliInstalled = true;
} catch (err) {
	webpackCliInstalled = false;
}

if (!webpackCliInstalled) {
	const path = require("path");
	const fs = require("fs");
	const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock"));

	let packageManager;
	let options = [];
	if (isYarn) {
		packageManager = "yarn";
		options = ["add", "-D", "webpack-cli"];
	} else {
		packageManager = "npm";
		options = ["install", "--save-dev", "webpack-cli"];
	}

	const commandToBeRun = `${packageManager} ${options.join(" ")}`;

	const question = {
		type: "confirm",
		name: "shouldInstall",
		message: `Would you like to install webpack-cli? (That will run ${commandToBeRun})`,
		default: true
	};

	console.error("The CLI moved into a separate package: webpack-cli");
	inquirer.prompt(question).then(answer => {
		if (answer) {
			console.error("Installing webpack-cli");
			runCommand(packageManager, options)
				.then(result => require("webpack-cli")) // eslint-disable-line
				.catch(error => console.error(error));
		} else {
			process.exitCode(1);
		}
	});
} else {
	require("webpack-cli"); // eslint-disable-line
}
{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.0006207324643078833, 'mean_word_length': 4.181672025723473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2170212', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1067, 'n_words': 237}