Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

machinepack-machines

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

machinepack-machines - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

36

machines/prompt-for-input-vals.js

@@ -10,5 +10,7 @@ module.exports = {

description: 'An array of prompt objects this machine will use to properly prompt for and validate user-defined values for runtime inputs.',
extendedDescription: '`expectType` may be "string" or "password". If it is "password", the relevant prompt will not display typed characters.',
example: [{
name: 'foobar',
example: 'here is what a foobar should look like',
description: 'The foobar that will be used to foo the bar (i.e. input description)',
expectType: 'string'

@@ -54,15 +56,35 @@ }]

name: promptDef.name,
message: util.format('Please enter a value for "%s"', promptDef.name),
message: (
( promptDef.description ? chalk.reset('Please enter '+promptDef.description[0].toLowerCase()+promptDef.description.slice(1))
: chalk.reset('Please enter a value for ')+chalk.bold(promptDef.name)
) +'\n'+
chalk.bold(promptDef.name)+': '
),
// chalk.reset(chalk.gray(promptDef.description?' '+(promptDef.description[0].toLowerCase()+promptDef.description.slice(1))+'':''))+'\n'+chalk.bold(promptDef.name)+': ',
// message: util.format(chalk.reset('Please enter a value for ')+'%s', chalk.bold(promptDef.name) + chalk.reset(chalk.gray(promptDef.description?' '+(promptDef.description[0].toLowerCase()+promptDef.description.slice(1))+'':''))+'\n'+chalk.bold(promptDef.name)+': '),
// message: util.format('%s', promptDef.name, chalk.reset(chalk.gray(promptDef.description?', '+(promptDef.description[0].toLowerCase()+promptDef.description.slice(1))+'':'')), (promptDef.example?('\n(e.g. '+promptDef.example+')'):''),'\n?'),
// message: util.format('Please enter a value for "%s"', promptDef.name, chalk.reset(chalk.gray(promptDef.description?', '+(promptDef.description[0].toLowerCase()+promptDef.description.slice(1))+'':'')), '\n?'),
type: (function (){
// Always string for now:
// Always "string" or "password" for now:
if (promptDef.expectType === 'string') {
return 'input';
}
throw new Error('Unexpected `expectType`');
if (promptDef.expectType === 'password') {
return 'password';
}
throw new Error('Unexpected `expectType` for prompt: '+promptDef.expectType);
})(),
validate: function _isTruthy(value){ return !!value; }
validate: function _isTruthy(value){
if (value) {
return true;
}
if (_.isUndefined(promptDef.example)) {
return false;
}
return 'e.g. '+promptDef.example;
}
};
if (promptDef.example){
inquirerPromptDef.default = promptDef.example;
}
// if (promptDef.example){
// inquirerPromptDef.default = promptDef.example;
// }
memo.push(inquirerPromptDef);

@@ -69,0 +91,0 @@ return memo;

63

machines/run-machine-interactive.js

@@ -15,2 +15,10 @@ module.exports = {

required: true
},
inputValues: {
description: 'A set of input values (interactive prompt will be skipped for required inputs provided this way)',
example: [{
name: 'someInput',
value: 'some configured string value for the input',
protect: false
}]
}

@@ -35,2 +43,3 @@ },

name: 'foobar',
protect: false,
value: 'fiddle diddle'

@@ -58,2 +67,5 @@ // ^^^^^ this is ok because it's always a string entered on the CLI interactive prompt

// `inputValues` defaults to an empty array
inputs.inputValues = inputs.inputValues||[];
// Require the machinepack

@@ -89,4 +101,6 @@ var mp;

name: inputName,
description: inputDef.description||'',
example: inputDef.example||'',
expectType: 'string' // Always expect strings for now
// Always expect "string" or "password" for now
expectType: !!inputDef.protect?'password':'string'
});

@@ -96,18 +110,6 @@ }

// Quick hack to parse CLI opts and use them as inputs if applicable
// (TODO: this should be refactored eventually so that pre-existing
// input values can be passed into the machine itself)
// var cliOpts = _.reduce(process.argv.slice(3), function (memo, argstr){
// var optionName = argstr.replace(/^--/, '').replace(/[=].*$/, '');
// var optionValue = argstr.replace(/^--[^=]+[=]/, '');
// memo.push({
// name: optionName,
// value: optionValue
// });
// return memo;
// }, []);
// // Remove required inputs that are defined in cliOpts
// _.remove(requiredInputPrompts, function (requirement) {
// return !!_.find(cliOpts, {name: requirement.name});
// });
// Remove required inputs that are defined in inputValues
_.remove(requiredInputPrompts, function (requirement) {
return !!_.find(inputs.inputValues, {name: requirement.name});
});

@@ -123,10 +125,8 @@ // Prompt for required inputs

// // Completes quick hack using CLI args from above ^^
// // (plug in cliopts into inputValues)
// _.each(cliOpts, function (cliOpt){
// promptAnswers.unshift({name: cliOpt.name, value: cliOpt.value});
// });
// Add back in the explicitly declared `inputValues` from above,
// now that prompting is done
_.each(inputs.inputValues, function (inputValue){
promptAnswers.unshift({name: inputValue.name, value: inputValue.value});
});
console.log('\n',chalk.gray('Running machine...'));
Machine.build(require('./run-machine'))({

@@ -141,2 +141,17 @@ machinepackPath: inputs.machinepackPath,

success: function (result){
// Now loop through `promptAnswers` one more time and strip out sensitive
// input data that was flagged with `expectType: "password"` in the original
// `requiredInputPrompts`.
_.each(promptAnswers, function (answer){
var isProtected = !!_.find(requiredInputPrompts, {
name: answer.name,
expectType: 'password'
});
if (isProtected) {
answer.value = '[**protected**]';
answer.protect = true;
}
});
return exits.success({

@@ -143,0 +158,0 @@ withInputs: promptAnswers,

@@ -147,3 +147,11 @@ module.exports = {

jsonValue: jsonValue,
inspectedValue: util.inspect(exitsTraversed[0].returnValue, false, null),
inspectedValue: (function (){
var rawReturnValue = exitsTraversed[0].returnValue;
// Send back the `stack` property if this is an error instance
// (don't worry about util.inspecting it)
if (typeof rawReturnValue === 'object' && rawReturnValue instanceof Error) {
return rawReturnValue.stack;
}
return util.inspect(rawReturnValue, false, null);
})(),
void: isVoid

@@ -150,0 +158,0 @@ });

{
"name": "machinepack-machines",
"version": "1.0.0",
"version": "1.0.1",
"description": "Work with machines and machinepacks.",

@@ -5,0 +5,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc