<commit_before>/*jshint node:true*/
'use strict';
var Q = require('q'),
	async = require('async'),
	fetchDropletCmd = require('./fetch-droplet');

/**
 *
 * @param {Speedboat} speedboat
 * @returns {Function}
 */
module.exports = function (speedboat, _fetchDropletCmd_) {
	var DEFAULT_DIR = '/opt/app';

	fetchDropletCmd = _fetchDropletCmd_ || fetchDropletCmd;

	return function runNpmCommand (options, cwd) {
		var fetchDroplet = fetchDropletCmd(speedboat),
			deferred = Q.defer(),
			promise = deferred.promise,
			dropletName = options.subdomain + '.' + options.configObject.hostname,
			cmdOptions = [];

		cwd = cwd || DEFAULT_DIR;

		if (options.command === 'install') {
			cmdOptions.push('--unsafe-perm');
		}

		fetchDroplet(dropletName)
			.then(function (droplet) {
				if (!droplet) {
					throw new Error('Unable to retrieve droplet by name: ' + dropletName);
				}
				
				async.series([
					
					// Make the cwd directory if it doesn't exist (prevents errors)
					// then change into it and run custom command
					speedboat.plot(droplet.id, [
						'mkdir ' + cwd + ';',
						'cd ' + cwd + ';',
						'[ -f "package.json" ] && npm run-script ' + options.command + ' ' + cmdOptions.join(' ')
					].join(' '))<commit_msg>Added check for missing package.json file<commit_after>/*jshint node:true*/
'use strict';
var Q = require('q'),
	async = require('async'),
	fetchDropletCmd = require('./fetch-droplet');

/**
 *
 * @param {Speedboat} speedboat
 * @returns {Function}
 */
module.exports = function (speedboat, _fetchDropletCmd_) {
	var DEFAULT_DIR = '/opt/app';

	fetchDropletCmd = _fetchDropletCmd_ || fetchDropletCmd;

	return function runNpmCommand (options, cwd) {
		var fetchDroplet = fetchDropletCmd(speedboat),
			deferred = Q.defer(),
			promise = deferred.promise,
			dropletName = options.subdomain + '.' + options.configObject.hostname,
			cmdOptions = [];

		cwd = cwd || DEFAULT_DIR;

		if (options.command === 'install') {
			cmdOptions.push('--unsafe-perm');
		}

		fetchDroplet(dropletName)
			.then(function (droplet) {
				if (!droplet) {
					throw new Error('Unable to retrieve droplet by name: ' + dropletName);
				}
				
				async.series([
					
					// Make the cwd directory if it doesn't exist (prevents errors)
					// then change into it and run custom command
					speedboat.plot(droplet.id, [
						'mkdir ' + cwd + ';',
						'cd ' + cwd + ';',
						[
							'[ -f "package.json" ] && npm run-script',
							options.command,
							cmdOptions.join(' '),
							'|| echo "No package.json file found"'
						].join(' ');
					].join(' '))
{'fraction_non_alphanumeric': 0.1550925925925926, 'fraction_numerical': 0.0, 'mean_word_length': 3.115873015873016, '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': '2982014', 'n_tokens_mistral': 1044, 'n_tokens_neox': 853, 'n_words': 199}