New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

machinepack

Package Overview
Dependencies
Maintainers
5
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

machinepack - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

182

bin/machinepack-exec.js

@@ -7,11 +7,8 @@ #!/usr/bin/env node

var Path = require('path');
var _ = require('lodash');
var program = require('commander');
var chalk = require('chalk');
var Filesystem = require('machinepack-fs');
var Machinepacks = require('machinepack-machinepacks');
var Machine = require('machine');
var _ = require('lodash');
program

@@ -27,12 +24,46 @@ .usage('[options] <identity>')

var identity = program.args[0];
Machinepacks.getMachinesDir({
dir: Path.resolve(process.cwd())
}).exec({
error: function (err){
console.error('Unexpected error occurred:\n',err);
(Machine.build({
inputs: {
identity: {
example: 'do-stuff'
},
dir: {
example: '/Users/mikermcneil/machinepack-foo/'
}
},
success: function (pathToMachines){
defaultExit: 'success',
exits: {
success: {
example: {
withInputs: [
{
name: 'foobar',
value: 'fiddle diddle'
// ^^^^^ this is ok because it's always a string entered on the CLI interactive prompt
}
],
exited: {
exit: 'success',
jsonValue: '{"stuff": "things"}',
inspectedValue: '{stuff: "things"}',
void: false
}
}
},
error: {},
invalidMachine: {}
},
fn: function (inputs, exits, env){
// Dependencies
var Path = require('path');
var _ = require('lodash');
var Filesystem = require('machinepack-fs');
var Machinepacks = require('machinepack-machinepacks');
var machinepackPath = Path.resolve(process.cwd(), inputs.dir);
Filesystem.readJson({

@@ -42,27 +73,134 @@ source: Path.resolve(process.cwd(), 'package.json')

error: function (err){
console.error('Unexpected error occurred:\n',err);
return exits.error(err);
},
success: function (jsonData){
try {
if (!_.contains(jsonData.machinepack.machines, identity)) {
console.error('Cannot run machine `'+chalk.red(identity)+'`. No machine with that identity exists in this machinepack.');
return;
if (!_.contains(jsonData.machinepack.machines, inputs.identity)) {
return exits.notFound();
}
jsonData.machinepack.machines = _.difference(jsonData.machinepack.machines, [identity]);
jsonData.machinepack.machines = _.difference(jsonData.machinepack.machines, [inputs.identity]);
}
catch (e) {
console.error('Unexpected error occurred:\n',err);
return;
return exits.error(e);
}
// Calculate appropriate variable name for machinepack
var 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);
// Calculate appropriate machine method name
// TODO: use machinepack-javascript to do this
var machineMethodName = (function(identity){
return identity.replace(/-[a-z]/ig, function (match) {
return match.slice(1).toUpperCase();
});
})(identity);
console.log();
console.log(chalk.red('TODO: .exec() implementation is not finished yet!'));
console.log(chalk.gray('(i.e. interactive prompt that asks for input values...'));
console.log(chalk.gray(' then a log explaining which exit was traversed and the return value, if relevant)'));
console.log(chalk.gray('%s.%s()'), chalk.bold(chalk.white(machinepackVarName)), chalk.bold(chalk.yellow(machineMethodName)));
Machinepacks.getMachinesDir({
dir: Path.resolve(process.cwd(), inputs.dir)
}).exec({
error: function (err){
return exits.error(err);
},
success: function (pathToMachines){
},
var pathToMachine = Path.resolve(pathToMachines, inputs.identity+'.js');
env.log();
Machinepacks.runMachine({
// path: pathToMachine
machinepackPath: machinepackPath,
identity: inputs.identity
}).exec({
error: function (err){
return exits.error(err);
},
invalidMachine: function (err){
return exits.invalidMachine(err);
},
success: function (result){
// env.log(chalk.gray(' then a log explaining which exit was traversed and the return value, if relevant)'));
return exits.success(result);
}
});
},
});
}
});
}
}))({
identity: identity,
dir: process.cwd()
})
.setEnvironment({
log: console.log
})
.exec({
error: function (err){
console.error('Unexpected error occurred:\n',err);
},
notFound: function (){
console.error('Cannot run machine `'+chalk.red(identity)+'`. No machine with that identity exists in this machinepack.');
},
invalidMachine: function (err){
console.error('Cannot run machine `'+chalk.red(identity)+'`. Machine is invalid. Error details:\n',err);
},
success: function (result){
// console.log('');
// console.log(chalk.white(' * * * * * * * * * * * * * * * * * * * * * * * * '));
// console.log(chalk.white(' * OUTCOME * '));
// console.log(chalk.white(' * * * * * * * * * * * * * * * * * * * * * * * * '));
console.log('');
// console.log(' using input values:\n', chalk.bold(chalk.yellow(identity)), _.reduce(result.withInputs, function(memo, configuredInput) {
// console.log(' Used input values:\n', _.reduce(result.withInputs, function(memo, configuredInput) {
// memo += '\n • ' + configuredInput.name + ' : ' + chalk.gray(JSON.stringify(configuredInput.value));
// return memo;
// }, ''));
// console.log('');
// console.log(' Triggered '+chalk.blue(result.exited.exit)+' callback'+(function (){
// if (!result.exited.void) {
// return ', returning:\n ' + chalk.gray(result.exited.jsonValue);
// }
// return '.';
// })());
console.log(' The machine triggered its '+chalk.bold((function (){
if (result.exited.exit === 'error') {
return chalk.red(result.exited.exit);
}
return chalk.blue(result.exited.exit);
})())+' exit'+(function (){
if (!result.exited.void) {
return ' and returned a value:\n '+chalk.gray(result.exited.inspectedValue);
}
return '.';
})());
console.log();
console.log();
console.log(chalk.white(' To run again:'));
console.log(chalk.white((function (){
var cmd = ' machinepack exec '+identity;
_.each(result.withInputs, function (configuredInput){
cmd += ' ';
cmd += '--'+configuredInput.name+'='+configuredInput.value;
});
return cmd;
})()));
console.log();
}
});

7

bin/machinepack.js

@@ -9,2 +9,3 @@ #!/usr/bin/env node

var chalk = require('chalk');
var _ = require('lodash');

@@ -14,4 +15,6 @@

.version(require('../package.json').version)
.usage(chalk.gray('[options]')+' '+chalk.bold('<command>'))
.command('init', 'initialize the current module as a machinepack')
// Allow unknown options.
.unknownOption = function NOOP(){};
program.usage(chalk.gray('[options]')+' '+chalk.bold('<command>'))
.command('init', 'make this a machinepack')
.command('ls', 'list machines')

@@ -18,0 +21,0 @@ .command('add', 'add a new machine')

{
"name": "machinepack",
"version": "1.1.0",
"version": "2.0.0",
"description": "CLI tool for working with machinepacks and their machines.",

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

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