machinepack
Advanced tools
Comparing version 2.0.8 to 2.0.9
@@ -9,3 +9,2 @@ #!/usr/bin/env node | ||
var chalk = require('chalk'); | ||
var Machinepacks = require('machinepack-machines'); | ||
var Machine = require('machine'); | ||
@@ -25,6 +24,6 @@ var _ = require('lodash'); | ||
if (!program.args[0]) { | ||
console.error('`identity` required'); | ||
process.exit(1); | ||
} | ||
// if (!program.args[0]) { | ||
// console.error('`identity` required'); | ||
// process.exit(1); | ||
// } | ||
@@ -41,3 +40,3 @@ | ||
(Machine.build({ | ||
Machine.build({ | ||
inputs: { | ||
@@ -71,5 +70,6 @@ identity: { | ||
error: {}, | ||
noMachines: {}, | ||
invalidMachine: {} | ||
}, | ||
fn: function (inputs, exits, env){ | ||
fn: function (inputs, exits){ | ||
@@ -79,2 +79,3 @@ // Dependencies | ||
var _ = require('lodash'); | ||
var inquirer = require('inquirer'); | ||
var Filesystem = require('machinepack-fs'); | ||
@@ -85,89 +86,86 @@ var Machinepacks = require('machinepack-machines'); | ||
console.log('\n'+chalk.gray(' Running machine...')); | ||
console.log(); | ||
Machinepacks.readPackageJson({dir: inputs.dir}).exec({ | ||
error: exits, | ||
success: function (machinepack){ | ||
Filesystem.readJson({ | ||
source: Path.resolve(process.cwd(), 'package.json') | ||
}).exec({ | ||
error: function (err){ | ||
return exits.error(err); | ||
}, | ||
success: function (jsonData){ | ||
try { | ||
if (!_.contains(jsonData.machinepack.machines, inputs.identity)) { | ||
return exits.notFound(); | ||
// If no identity was provided, choose the machine to run from a list, interactively. | ||
(function (next){ | ||
if (identity) { | ||
return next(null, identity); | ||
} | ||
jsonData.machinepack.machines = _.difference(jsonData.machinepack.machines, [inputs.identity]); | ||
} | ||
catch (e) { | ||
return exits.error(e); | ||
} | ||
// Calculate appropriate variable name for machinepack | ||
machinepackVarName = (function (moduleName){ | ||
var varname = moduleName.replace(/^machinepack-/,''); | ||
varname = varname.replace(/-[a-z]/ig,function (match){ | ||
return match.slice(1).toUpperCase(); | ||
}); | ||
varname = varname[0].toUpperCase() + varname.slice(1); | ||
return varname; | ||
})(jsonData.name); | ||
if (machinepack.machines.length < 1) { | ||
return next((function (){ | ||
var err = new Error('There are no machines in this machinepack.'); | ||
err.exit = err.code = 'noMachines'; | ||
return err; | ||
})()); | ||
} | ||
// Calculate appropriate machine method name | ||
// TODO: use machinepack-javascript to do this | ||
machineMethodName = (function(identity){ | ||
return identity.replace(/-[a-z]/ig, function (match) { | ||
return match.slice(1).toUpperCase(); | ||
inquirer.prompt([{ | ||
name: 'machine', | ||
message: 'Please choose a machine to run.', | ||
type: 'list', | ||
// when: function (){ | ||
// return !machine; | ||
// }, | ||
choices: _.reduce(machinepack.machines, function (memo, machine){ | ||
memo.push({ | ||
name: machine, | ||
value: machine | ||
}); | ||
return memo; | ||
}, []) | ||
}], function (answers){ | ||
next(null, answers.machine); | ||
}); | ||
})(identity); | ||
})(function (err, _identity){ | ||
if (err) return exits(err); | ||
Machinepacks.getMachinesDir({ | ||
dir: Path.resolve(process.cwd(), inputs.dir) | ||
}).exec({ | ||
error: function (err){ | ||
return exits.error(err); | ||
}, | ||
success: function (pathToMachines){ | ||
// Expose _identity on closure scope for convenience. (this is a hack) | ||
identity = _identity; | ||
var pathToMachine = Path.resolve(pathToMachines, inputs.identity+'.js'); | ||
Machinepacks.runMachineInteractive({ | ||
machinepackPath: machinepackPath, | ||
identity: inputs.identity, | ||
inputValues: (function (){ | ||
return _.reduce(cliOpts, function (memo, inputValue, inputName){ | ||
memo.push({ | ||
name: inputName, | ||
value: inputValue, | ||
protect: false | ||
}); | ||
return memo; | ||
}, []); | ||
})() | ||
}).exec({ | ||
error: function (err){ | ||
return exits.error(err); | ||
}, | ||
invalidMachine: function (err){ | ||
return exits.invalidMachine(err); | ||
}, | ||
success: function (result){ | ||
return exits.success(result); | ||
} | ||
// Calculate appropriate variable name for machinepack and expose in closure scope (quick hack) | ||
machinepackVarName = machinepack.variableName; | ||
// Calculate appropriate machine method name and expose in closure scope (quick hack) | ||
// TODO: use machinepack-javascript to do this | ||
machineMethodName = (function(identity){ | ||
return identity.replace(/-[a-z]/ig, function (match) { | ||
return match.slice(1).toUpperCase(); | ||
}); | ||
})(identity); | ||
}, | ||
console.log('\n'+chalk.gray(' Running machine...')); | ||
console.log(); | ||
Machinepacks.runMachineInteractive({ | ||
machinepackPath: machinepackPath, | ||
identity: identity, | ||
inputValues: (function (){ | ||
return _.reduce(cliOpts, function (memo, inputValue, inputName){ | ||
memo.push({ | ||
name: inputName, | ||
value: inputValue, | ||
protect: false | ||
}); | ||
return memo; | ||
}, []); | ||
})() | ||
}).exec({ | ||
error: exits.error, | ||
invalidMachine: exits.invalidMachine, | ||
success: function (result){ | ||
return exits.success(result); | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
} | ||
}))({ | ||
}).configure({ | ||
identity: identity, | ||
dir: process.cwd() | ||
}) | ||
.setEnvironment({ | ||
log: console.log | ||
}) | ||
.exec({ | ||
}).exec({ | ||
error: function (err){ | ||
@@ -182,2 +180,5 @@ console.error('Unexpected error occurred:\n',typeof err === 'object' && err instanceof Error ? err.stack : err); | ||
}, | ||
noMachines: function (err){ | ||
console.error(chalk.gray('There are no machines in this machinepack...\n(you should make some!)')); | ||
}, | ||
success: function (result){ | ||
@@ -265,1 +266,4 @@ | ||
} | ||
{ | ||
"name": "machinepack", | ||
"version": "2.0.8", | ||
"version": "2.0.9", | ||
"description": "CLI tool for working with machinepacks and their machines.", | ||
@@ -48,4 +48,5 @@ "bin": { | ||
"yargs": "^1.3.3", | ||
"machinepack-javascript": "^0.2.1" | ||
"machinepack-javascript": "^0.2.1", | ||
"inquirer": "^0.8.0" | ||
} | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
21743
0
9
+ Addedinquirer@^0.8.0