machine-as-script
Advanced tools
Comparing version 4.0.0 to 4.0.1
373
index.js
@@ -32,2 +32,24 @@ /** | ||
// ██████╗██╗ ██╗███████╗ ██████╗██╗ ██╗ ██████╗ ██████╗ ████████╗███████╗ | ||
// ██╔════╝██║ ██║██╔════╝██╔════╝██║ ██╔╝ ██╔═══██╗██╔══██╗╚══██╔══╝██╔════╝ | ||
// ██║ ███████║█████╗ ██║ █████╔╝ ██║ ██║██████╔╝ ██║ ███████╗ | ||
// ██║ ██╔══██║██╔══╝ ██║ ██╔═██╗ ██║ ██║██╔═══╝ ██║ ╚════██║ | ||
// ╚██████╗██║ ██║███████╗╚██████╗██║ ██╗ ╚██████╔╝██║ ██║ ███████║ | ||
// ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝ | ||
// | ||
// ██╗ ███████╗███████╗████████╗ ██╗ ██╗██████╗ | ||
// ██║ ██╔════╝██╔════╝╚══██╔══╝ ██║ ██║██╔══██╗ | ||
// ████████╗ ███████╗█████╗ ██║ ██║ ██║██████╔╝ | ||
// ██╔═██╔═╝ ╚════██║██╔══╝ ██║ ██║ ██║██╔═══╝ | ||
// ██████║ ███████║███████╗ ██║ ╚██████╔╝██║ | ||
// ╚═════╝ ╚══════╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ | ||
// | ||
// ██████╗ ███████╗███████╗ █████╗ ██╗ ██╗██╗ ████████╗███████╗ | ||
// ██╔══██╗██╔════╝██╔════╝██╔══██╗██║ ██║██║ ╚══██╔══╝██╔════╝ | ||
// ██║ ██║█████╗ █████╗ ███████║██║ ██║██║ ██║ ███████╗ | ||
// ██║ ██║██╔══╝ ██╔══╝ ██╔══██║██║ ██║██║ ██║ ╚════██║ | ||
// ██████╔╝███████╗██║ ██║ ██║╚██████╔╝███████╗██║ ███████║ | ||
// ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚══════╝ | ||
// | ||
optsOrMachineDef = optsOrMachineDef||{}; | ||
@@ -55,2 +77,52 @@ | ||
// ╦ ╦╔═╗╦ ╦╔╦╗╔═╗╔╦╗╔═╗ ┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐ | ||
// ╚╗╔╝╠═╣║ ║ ║║╠═╣ ║ ║╣ │ │├─┘ │ ││ ││││└─┐ | ||
// ╚╝ ╩ ╩╩═╝╩═╩╝╩ ╩ ╩ ╚═╝ └─┘┴ ┴ ┴└─┘┘└┘└─┘ | ||
// Validate optional things. | ||
_.each(opts, function (optVal, optKey) { | ||
// Ignore opts with undefined values. | ||
if (_.isUndefined(optVal)) { return; } | ||
switch (optKey) { | ||
case 'args': (function (){ | ||
if (!_.isArray(opts.args)) { | ||
throw new Error('Invalid option: If specified, `args` should be provided as an array of strings.'); | ||
} | ||
_.each(opts.args, function (targetInputCodeName){ | ||
var knownInputCodeNames = _.keys(machineDef.inputs||{}); | ||
if (!_.contains(knownInputCodeNames, targetInputCodeName)) { | ||
throw new Error('Invalid option: `args` references an unrecognized input (`'+targetInputCodeName+'`). Each item in `args` should be the code name of a known input defined in this machine!'); | ||
} | ||
}); | ||
})(); break; | ||
case 'envVarNamespace': (function (){ | ||
if (!_.isString(opts.envVarNamespace)) { | ||
throw new Error('Invalid option: If specified, `envVarNamespace` should be provided as a string.'); | ||
} | ||
})(); break; | ||
case 'sails': (function (){ | ||
if (!_.isObject(opts.sails) || opts.sails.constructor.name !== 'Sails') { | ||
throw new Error('Invalid option: The supposed Sails app instance provided as `sails` seems a little sketchy. Make sure you are doing `sails: require(\'sails\')`.'); | ||
} | ||
// Note that we do additional validations below. | ||
// (bcause at this point in the code, we can't yet guarantee the machine's `habitat` will be correct-- | ||
// at least not across all versions of the `machine` runner) | ||
})(); break; | ||
default: | ||
throw new Error('Consistency violation: Internal bug in machine-as-script. An option (`'+optKey+'`) is unrecognized, but we should never have unrecognized opts at this point.'); | ||
} | ||
}); | ||
// ┌─┐┌─┐┌┬┐ ╔╦╗╔═╗╔═╗╔═╗╦ ╦╦ ╔╦╗╔═╗ ┌─┐┌─┐┬─┐ ┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐ | ||
// └─┐├┤ │ ║║║╣ ╠╣ ╠═╣║ ║║ ║ ╚═╗ ├┤ │ │├┬┘ │ │├─┘ │ ││ ││││└─┐ | ||
// └─┘└─┘ ┴ ═╩╝╚═╝╚ ╩ ╩╚═╝╩═╝╩ ╚═╝ └ └─┘┴└─ └─┘┴ ┴ ┴└─┘┘└┘└─┘ | ||
// Set up namespace for environment variables. | ||
@@ -62,2 +134,35 @@ var envVarNamespace = '___'; | ||
// We'll use this local variable (`envToSet`) to hold the `env` dictionary we're building up below. | ||
// At the very end, we'll use this again when we build the dictionary to send to `setEnv`) | ||
// | ||
// > Remember: this `env` is _completely_ different from system "environment variables"! | ||
// > It is more closely related to the notion of "habitat" in the machine spec. | ||
// > See http://node-machine.org for more details. | ||
var envToSet = {}; | ||
// ██████╗ ██╗ ██╗██╗██╗ ██████╗ | ||
// ██╔══██╗██║ ██║██║██║ ██╔══██╗ | ||
// ██████╔╝██║ ██║██║██║ ██║ ██║ | ||
// ██╔══██╗██║ ██║██║██║ ██║ ██║ | ||
// ██████╔╝╚██████╔╝██║███████╗██████╔╝ | ||
// ╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ | ||
// | ||
// ███╗ ███╗ █████╗ ██████╗██╗ ██╗██╗███╗ ██╗███████╗ | ||
// ████╗ ████║██╔══██╗██╔════╝██║ ██║██║████╗ ██║██╔════╝ | ||
// ██╔████╔██║███████║██║ ███████║██║██╔██╗ ██║█████╗ | ||
// ██║╚██╔╝██║██╔══██║██║ ██╔══██║██║██║╚██╗██║██╔══╝ | ||
// ██║ ╚═╝ ██║██║ ██║╚██████╗██║ ██║██║██║ ╚████║███████╗ | ||
// ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚══════╝ | ||
// | ||
// ██╗███╗ ██╗███████╗████████╗ █████╗ ███╗ ██╗ ██████╗███████╗ | ||
// ██║████╗ ██║██╔════╝╚══██╔══╝██╔══██╗████╗ ██║██╔════╝██╔════╝ | ||
// ██║██╔██╗ ██║███████╗ ██║ ███████║██╔██╗ ██║██║ █████╗ | ||
// ██║██║╚██╗██║╚════██║ ██║ ██╔══██║██║╚██╗██║██║ ██╔══╝ | ||
// ██║██║ ╚████║███████║ ██║ ██║ ██║██║ ╚████║╚██████╗███████╗ | ||
// ╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝╚══════╝ | ||
// | ||
// `Machine.build()` tolerates: | ||
@@ -96,28 +201,71 @@ // • machine definitions | ||
// Finally, before moving on, we check the `habitat` and potentially provide | ||
// access to `env.sails`. | ||
var sailsApp; | ||
// ██████╗██╗ ██╗███████╗ ██████╗██╗ ██╗ | ||
// ██╔════╝██║ ██║██╔════╝██╔════╝██║ ██╔╝ | ||
// ██║ ███████║█████╗ ██║ █████╔╝ | ||
// ██║ ██╔══██║██╔══╝ ██║ ██╔═██╗ | ||
// ╚██████╗██║ ██║███████╗╚██████╗██║ ██╗ | ||
// ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═════╝╚═╝ ╚═╝ | ||
// | ||
// ██████╗ ██████╗ ██████╗ ██╗ ██╗██╗██████╗ ███████╗██████╗ | ||
// ██╔══██╗██╔══██╗██╔═══██╗██║ ██║██║██╔══██╗██╔════╝██╔══██╗ | ||
// ██████╔╝██████╔╝██║ ██║██║ ██║██║██║ ██║█████╗ ██║ ██║ | ||
// ██╔═══╝ ██╔══██╗██║ ██║╚██╗ ██╔╝██║██║ ██║██╔══╝ ██║ ██║ | ||
// ██║ ██║ ██║╚██████╔╝ ╚████╔╝ ██║██████╔╝███████╗██████╔╝ | ||
// ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═══╝ ╚═╝╚═════╝ ╚══════╝╚═════╝ | ||
// | ||
// ███████╗ █████╗ ██╗██╗ ███████╗ █████╗ ██████╗ ██████╗ | ||
// ██╔════╝██╔══██╗██║██║ ██╔════╝ ██╔══██╗██╔══██╗██╔══██╗ | ||
// ███████╗███████║██║██║ ███████╗ ███████║██████╔╝██████╔╝ | ||
// ╚════██║██╔══██║██║██║ ╚════██║ ██╔══██║██╔═══╝ ██╔═══╝ | ||
// ███████║██║ ██║██║███████╗███████║ ██║ ██║██║ ██║ | ||
// ╚══════╝╚═╝ ╚═╝╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ | ||
// | ||
// ██╗███╗ ██╗███████╗████████╗ █████╗ ███╗ ██╗ ██████╗███████╗ | ||
// ██║████╗ ██║██╔════╝╚══██╔══╝██╔══██╗████╗ ██║██╔════╝██╔════╝ | ||
// ██║██╔██╗ ██║███████╗ ██║ ███████║██╔██╗ ██║██║ █████╗ | ||
// ██║██║╚██╗██║╚════██║ ██║ ██╔══██║██║╚██╗██║██║ ██╔══╝ | ||
// ██║██║ ╚████║███████║ ██║ ██║ ██║██║ ╚████║╚██████╗███████╗ | ||
// ╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝╚══════╝ | ||
// | ||
// Finally, before moving on, we check the `habitat`. Since we'll potentially | ||
// provide access to `env.sails`, we need to make sure a valid Sails app was | ||
// passed in. | ||
if (wetMachine.habitat === 'request') { | ||
throw new Error('The target machine defintion declares a dependency on the `request` habitat, which cannot be provided via the command-line interface. This machine cannot be run using machine-as-script.'); | ||
} | ||
// If the machine depends on the Sails habitat: | ||
else if (wetMachine.habitat === 'sails') { | ||
// If the machine depends on the Sails habitat, then we'll attempt to use the provided version of `sails`. | ||
if (opts.sails) { | ||
if (!_.isObject(opts.sails) || opts.sails.constructor.name !== 'Sails') { | ||
throw new Error('The supposed Sails app instance provided as `sails` seems a little sketchy. Make sure you are doing `sails: require(\'sails\')`.'); | ||
} | ||
// Down below, we'll attempt to load (but not lift) the Sails app in the current working directory. | ||
// If it works, then we'll run the script, providing it with `env.sails`. After that, regardless of | ||
// how the script exits, we'll call `sails.lower()` to clean up. | ||
sailsApp = opts.sails; | ||
} | ||
// ...then we'll want to attempt to use the provided version of `sails` (a SailsApp instance.) | ||
// If no `sails` was provided to machine-as-script, then we'll throw an error. | ||
else { | ||
if (!opts.sails) { | ||
throw new Error('The target machine defintion declares a dependency on the `sails` habitat, but no `sails` app instance was provided as a top-level option to machine-as-script. Make sure this script module is doing: `sails: require(\'sails\')`'); | ||
} | ||
} | ||
// Down below, we'll attempt to load (but not lift) the Sails app in the current working directory. | ||
// If it works, then we'll run the script, providing it with `env.sails`. After that, regardless of | ||
// how the script exits, we'll call `sails.lower()` to clean up. | ||
// | ||
// In the mean time, we'll go ahead and save a reference to this Sails app on `envToSet`, since we'll | ||
// be passing it into the machine instance's `fn` as `env.sails` (via `.setEnv()`) | ||
envToSet.sails = opts.sails; | ||
}//</if (machine depends on `sails` habitat)> | ||
// ██████╗ ██╗ ██╗██╗██╗ ██████╗ ██╗ ██╗███████╗ █████╗ ██████╗ ███████╗ | ||
// ██╔══██╗██║ ██║██║██║ ██╔══██╗ ██║ ██║██╔════╝██╔══██╗██╔════╝ ██╔════╝ | ||
// ██████╔╝██║ ██║██║██║ ██║ ██║ ██║ ██║███████╗███████║██║ ███╗█████╗ | ||
// ██╔══██╗██║ ██║██║██║ ██║ ██║ ██║ ██║╚════██║██╔══██║██║ ██║██╔══╝ | ||
// ██████╔╝╚██████╔╝██║███████╗██████╔╝ ╚██████╔╝███████║██║ ██║╚██████╔╝███████╗ | ||
// ╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝ | ||
// | ||
// ██╗ ██████╗ ██████╗ ███╗ ███╗███╗ ███╗ █████╗ ███╗ ██╗██████╗ ███████╗██████╗ ██╗ | ||
// ██╔╝██╔════╝██╔═══██╗████╗ ████║████╗ ████║██╔══██╗████╗ ██║██╔══██╗██╔════╝██╔══██╗╚██╗ | ||
// ██║ ██║ ██║ ██║██╔████╔██║██╔████╔██║███████║██╔██╗ ██║██║ ██║█████╗ ██████╔╝ ██║ | ||
// ██║ ██║ ██║ ██║██║╚██╔╝██║██║╚██╔╝██║██╔══██║██║╚██╗██║██║ ██║██╔══╝ ██╔══██╗ ██║ | ||
// ╚██╗╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚═╝ ██║██║ ██║██║ ╚████║██████╔╝███████╗██║ ██║██╔╝ | ||
// ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ | ||
// | ||
// ====================================================================== | ||
@@ -177,6 +325,35 @@ // Now we'll put together the configuration for our wet machine instance. | ||
// Build inputs from CLI options and args | ||
// ██████╗ █████╗ ██████╗ ███████╗███████╗ █████╗ ██████╗ ██████╗ ███╗ ███╗████████╗███████╗ | ||
// ██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔════╝ ██╔══██╗██╔══██╗██╔════╝ ████╗ ████║╚══██╔══╝██╔════╝ | ||
// ██████╔╝███████║██████╔╝███████╗█████╗ ███████║██████╔╝██║ ███╗██╔████╔██║ ██║ ███████╗ | ||
// ██╔═══╝ ██╔══██║██╔══██╗╚════██║██╔══╝ ██╔══██║██╔══██╗██║ ██║██║╚██╔╝██║ ██║ ╚════██║ | ||
// ██║ ██║ ██║██║ ██║███████║███████╗ ██║ ██║██║ ██║╚██████╔╝██║ ╚═╝ ██║ ██║ ███████║ | ||
// ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ | ||
// ██╗ ██████╗ ██████╗ ███╗ ██╗███████╗██╗ ██████╗ ██╗ ██╗██████╗ ███████╗ | ||
// ██║ ██╔════╝██╔═══██╗████╗ ██║██╔════╝██║██╔════╝ ██║ ██║██╔══██╗██╔════╝ | ||
// ████████╗ ██║ ██║ ██║██╔██╗ ██║█████╗ ██║██║ ███╗██║ ██║██████╔╝█████╗ | ||
// ██╔═██╔═╝ ██║ ██║ ██║██║╚██╗██║██╔══╝ ██║██║ ██║██║ ██║██╔══██╗██╔══╝ | ||
// ██████║ ╚██████╗╚██████╔╝██║ ╚████║██║ ██║╚██████╔╝╚██████╔╝██║ ██║███████╗ | ||
// ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ | ||
// | ||
// \│/╔═╗╔═╗╦═╗╔═╗╔═╗ ┬─┐┬ ┬┌┐┌┌┬┐┬┌┬┐┌─┐ ┬ ┬┌─┐┬ ┬ ┬┌─┐┌─┐ ┌─┐┌─┐┬─┐\│/ | ||
// ─ ─╠═╝╠═╣╠╦╝╚═╗║╣ ├┬┘│ ││││ │ ││││├┤ └┐┌┘├─┤│ │ │├┤ └─┐ ├┤ │ │├┬┘─ ─ | ||
// /│\╩ ╩ ╩╩╚═╚═╝╚═╝ ┴└─└─┘┘└┘ ┴ ┴┴ ┴└─┘ └┘ ┴ ┴┴─┘└─┘└─┘└─┘ └ └─┘┴└─/│\ | ||
// ┌─┐┬ ┬ ┌─┐┌─┐┌┬┐┌─┐ ┬ ┌─┐┌─┐┬─┐┬┌─┐┬ ┌─┐┬─┐┌─┐┌─┐ ┬ ┌─┐┌┐┌┬ ┬ ┬ ┬┌─┐┬─┐┌─┐ | ||
// │ │ │ │ │├─┘ │ └─┐ ┌┼─ └─┐├┤ ├┬┘│├─┤│ ├─┤├┬┘│ ┬└─┐ ┌┼─ ├┤ │││└┐┌┘ └┐┌┘├─┤├┬┘└─┐ | ||
// └─┘┴─┘┴ └─┘┴ ┴ └─┘ └┘ └─┘└─┘┴└─┴┴ ┴┴─┘ ┴ ┴┴└─└─┘└─┘ └┘ └─┘┘└┘ └┘ └┘ ┴ ┴┴└─└─┘┘ | ||
// ┌┬┐┬ ┬┌─┐┌┐┌ ╔═╗╔═╗╔╗╔╔═╗╦╔═╗╦ ╦╦═╗╔═╗ ┌┬┐┬ ┬┌─┐ ┬ ┬┌─┐┌┬┐ ┌┬┐┌─┐┌─┐┬ ┬┬┌┐┌┌─┐ | ||
// │ ├─┤├┤ │││ ║ ║ ║║║║╠╣ ║║ ╦║ ║╠╦╝║╣ │ ├─┤├┤ │││├┤ │ │││├─┤│ ├─┤││││├┤ | ||
// ┴ ┴ ┴└─┘┘└┘ ╚═╝╚═╝╝╚╝╚ ╩╚═╝╚═╝╩╚═╚═╝ ┴ ┴ ┴└─┘ └┴┘└─┘ ┴ ┴ ┴┴ ┴└─┘┴ ┴┴┘└┘└─┘ | ||
// ┌┬┐┌─┐ ┌─┐┌─┐┌┬┐ ┌─┐ ╦ ╦╦ ╦╔═╗ ╔╦╗╔═╗╔═╗╦ ╦╦╔╗╔╔═╗ ┬┌┐┌┌─┐┌┬┐┌─┐┌┐┌┌─┐┌─┐ | ||
// │ │ │ │ ┬├┤ │ ├─┤ ║ ║╚╗╔╝║╣ ║║║╠═╣║ ╠═╣║║║║║╣ ││││└─┐ │ ├─┤││││ ├┤ | ||
// ┴ └─┘ └─┘└─┘ ┴ ┴ ┴ ╩═╝╩ ╚╝ ╚═╝ ╩ ╩╩ ╩╚═╝╩ ╩╩╝╚╝╚═╝ ┴┘└┘└─┘ ┴ ┴ ┴┘└┘└─┘└─┘o | ||
// Build runtime input values from CLI options and args. | ||
var inputConfiguration = {}; | ||
// Supply CLI options | ||
// (the ones that start with `-` or `--`) | ||
// ======================================================================================= | ||
_.extend(inputConfiguration, yargs.argv); | ||
@@ -186,3 +363,17 @@ delete inputConfiguration._; | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
// TODO: make the following usage work in the way you would expect: | ||
// ``` | ||
// kit exclaim --verbose 'my sweet code comment' wat --width '37' | ||
// ``` | ||
// Currently, `'my sweet code comment'` is parsed as "verbose", | ||
// even though "verbose" should really be a boolean, and so that | ||
// string should be interpreted as a serial CLI arg (not an opt). | ||
// | ||
// (see https://github.com/yargs/yargs#booleankey for more info) | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
// Supply environment variables | ||
// ======================================================================================= | ||
_.each(wetMachine.inputs, function (inputDef, inputName){ | ||
@@ -199,15 +390,31 @@ var envVarData = process.env[envVarNamespace + inputName]; | ||
// Include a special `args` input for convenience-- | ||
// but note that this is an experimental feature that could change. | ||
if (_.isArray(yargs.argv._)) { | ||
inputConfiguration.args = yargs.argv._; | ||
} | ||
// Supply argv CLI arguments using special `args` notation | ||
// Supply serial CLI arguments | ||
// (the kind that come one after another -- i.e. they don't start with `-` or `--`) | ||
// ======================================================================================= | ||
envToSet.commandLineArgs = _.isArray(yargs.argv._) ? yargs.argv._ : []; | ||
// (^^ Note that we always supply `env.commandLineArgs`.) | ||
// But if `opts.args` was provided, then we ALSO iterate through the serial CLI args | ||
// and provide them as values for the appropriate inputs (i.e. according to the order | ||
// of code names in `opts.args`.) | ||
if (_.isArray(opts.args)) { | ||
_.each(opts.args, function (inputName, i){ | ||
inputConfiguration[inputName] = yargs.argv._[i]; | ||
inputConfiguration[inputName] = envToSet.commandLineArgs[i]; | ||
}); | ||
} | ||
// TODO: deprecate | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
// Include a special `args` input for convenience-- | ||
// but note that this is an experimental feature that could change. | ||
// | ||
// UPDATE: THIS WILL BE DEPRECATED SOON. USE `env.commandLineArgs` INSTEAD!!! | ||
if (_.isArray(envToSet.commandLineArgs)) { | ||
inputConfiguration.args = envToSet.commandLineArgs;// << will be deprecated | ||
} | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
// Finally, loop through each of the input configurations and run `rttc.parseHuman()`. | ||
@@ -235,2 +442,22 @@ inputConfiguration = _.reduce(inputConfiguration, function (memo, val, inputName){ | ||
// console.log('----------------------------------------------------------------------'); | ||
// console.log('serial CLI args: ',envToSet.commandLineArgs); | ||
// console.log('input configuration that was parsed: ',inputConfiguration); | ||
// console.log('----------------------------------------------------------------------'); | ||
// ██████╗ ██╗ ██╗██╗██╗ ██████╗ | ||
// ██╔══██╗██║ ██║██║██║ ██╔══██╗ | ||
// ██████╔╝██║ ██║██║██║ ██║ ██║ | ||
// ██╔══██╗██║ ██║██║██║ ██║ ██║ | ||
// ██████╔╝╚██████╔╝██║███████╗██████╔╝ | ||
// ╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ | ||
// | ||
// ██████╗ █████╗ ██╗ ██╗ ██████╗ █████╗ ██████╗██╗ ██╗███████╗ | ||
// ██╔════╝██╔══██╗██║ ██║ ██╔══██╗██╔══██╗██╔════╝██║ ██╔╝██╔════╝ | ||
// ██║ ███████║██║ ██║ ██████╔╝███████║██║ █████╔╝ ███████╗ | ||
// ██║ ██╔══██║██║ ██║ ██╔══██╗██╔══██║██║ ██╔═██╗ ╚════██║ | ||
// ╚██████╗██║ ██║███████╗███████╗██████╔╝██║ ██║╚██████╗██║ ██╗███████║ | ||
// ╚═════╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝ | ||
// | ||
// Now build up a default handler callback for each exit. | ||
@@ -284,2 +511,33 @@ // (Note that these can be overridden though!) | ||
// ███╗ ███╗ ██████╗ ███╗ ██╗██╗ ██╗███████╗██╗ ██╗ ██████╗ █████╗ ████████╗ ██████╗██╗ ██╗ | ||
// ████╗ ████║██╔═══██╗████╗ ██║██║ ██╔╝██╔════╝╚██╗ ██╔╝ ██╔══██╗██╔══██╗╚══██╔══╝██╔════╝██║ ██║ | ||
// ██╔████╔██║██║ ██║██╔██╗ ██║█████╔╝ █████╗ ╚████╔╝█████╗██████╔╝███████║ ██║ ██║ ███████║ | ||
// ██║╚██╔╝██║██║ ██║██║╚██╗██║██╔═██╗ ██╔══╝ ╚██╔╝ ╚════╝██╔═══╝ ██╔══██║ ██║ ██║ ██╔══██║ | ||
// ██║ ╚═╝ ██║╚██████╔╝██║ ╚████║██║ ██╗███████╗ ██║ ██║ ██║ ██║ ██║ ╚██████╗██║ ██║ | ||
// ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ | ||
// | ||
// ██╗███████╗ ██████╗ ██████╗ ███████╗ █████╗ ██╗██╗ ███████╗ | ||
// ██╔╝██╔════╝██╔═══██╗██╔══██╗ ██╔════╝██╔══██╗██║██║ ██╔════╝ | ||
// ██║ █████╗ ██║ ██║██████╔╝ ███████╗███████║██║██║ ███████╗ | ||
// ██║ ██╔══╝ ██║ ██║██╔══██╗ ╚════██║██╔══██║██║██║ ╚════██║ | ||
// ╚██╗██║ ╚██████╔╝██║ ██║ ███████║██║ ██║██║███████╗███████║ | ||
// ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝╚══════╝╚══════╝ | ||
// | ||
// ██╗ ██╗███████╗███████╗ ██████╗██╗ ██╗ ██████╗██╗ ███████╗██╗ | ||
// ██║ ██║██╔════╝██╔════╝██╔════╝╚██╗ ██╔╝██╔════╝██║ ██╔════╝╚██╗ | ||
// ██║ ██║█████╗ █████╗ ██║ ╚████╔╝ ██║ ██║ █████╗ ██║ | ||
// ██║ ██║██╔══╝ ██╔══╝ ██║ ╚██╔╝ ██║ ██║ ██╔══╝ ██║ | ||
// ███████╗██║██║ ███████╗╚██████╗ ██║ ╚██████╗███████╗███████╗██╔╝ | ||
// ╚══════╝╚═╝╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═════╝╚══════╝╚══════╝╚═╝ | ||
// | ||
// | ||
// ╔═╗╦ ╦╔═╗╦═╗╦═╗╦╔╦╗╔═╗ ╔═╗═╗ ╦╔═╗╔═╗ | ||
// ║ ║╚╗╔╝║╣ ╠╦╝╠╦╝║ ║║║╣ ║╣ ╔╩╦╝║╣ ║ | ||
// ╚═╝ ╚╝ ╚═╝╩╚═╩╚═╩═╩╝╚═╝ o╚═╝╩ ╚═╚═╝╚═╝ | ||
// ┌─ ┌─┐┬─┐┌─┐┌┬┐ ┌┬┐┬ ┬┌─┐ ┌┬┐┌─┐┌─┐┬ ┬┬┌┐┌┌─┐ ┬─┐┬ ┬┌┐┌┌┐┌┌─┐┬─┐ ─┐ | ||
// │─── ├┤ ├┬┘│ ││││ │ ├─┤├┤ │││├─┤│ ├─┤││││├┤ ├┬┘│ │││││││├┤ ├┬┘ ───│ | ||
// └─ └ ┴└─└─┘┴ ┴ ┴ ┴ ┴└─┘ ┴ ┴┴ ┴└─┘┴ ┴┴┘└┘└─┘ ┴└─└─┘┘└┘┘└┘└─┘┴└─ ─┘ | ||
// | ||
// Now intercept `.exec()` to take care of sails.lower(), if relevant. | ||
@@ -292,3 +550,3 @@ // (we have to do this because any of the callbacks above _could_ be overridden!) | ||
// If we're not managing a Sails app instance for this script, then just do the normal thing. | ||
if (_.isUndefined(sailsApp)) { | ||
if (_.isUndefined(envToSet.sails)) { | ||
if (_.isObject(args[0])) { | ||
@@ -307,5 +565,10 @@ var combinedCbs = _.extend({}, callbacks, args[0]); | ||
// --• Otherwise, we need to load Sails first, then lower it afterwards. | ||
// --• | ||
// Otherwise, we need to load Sails first, then lower it afterwards. | ||
// ┬ ┌─┐┌─┐┌┬┐ ┌─┐┌─┐┬┬ ┌─┐ | ||
// │ │ │├─┤ ││ └─┐├─┤││ └─┐ | ||
// ┴─┘└─┘┴ ┴─┴┘ └─┘┴ ┴┴┴─┘└─┘ | ||
// Load the Sails app. | ||
sailsApp.load(function (err){ | ||
envToSet.sails.load(function (err){ | ||
if (err) { | ||
@@ -315,5 +578,12 @@ throw new Error('This script relies on access to Sails, but when attempting to load this Sails app automatically, an error occurred. Details: '+err.stack); | ||
// ┬─┐┬ ┬┌┐┌ ┬ ┬┌┐┌┌┬┐┌─┐┬─┐┬ ┬ ┬┬┌┐┌┌─┐ ╔═╗═╗ ╦╔═╗╔═╗ | ||
// ├┬┘│ ││││ │ ││││ ││├┤ ├┬┘│ └┬┘│││││ ┬ ║╣ ╔╩╦╝║╣ ║ | ||
// ┴└─└─┘┘└┘ └─┘┘└┘─┴┘└─┘┴└─┴─┘┴ ┴┘└┘└─┘ o╚═╝╩ ╚═╚═╝╚═╝ | ||
// Run underlying .exec(), but intercept it to tear down the Sails app. | ||
_originalExecBeforeItWasChangedForUseByMachineAsScript.apply(liveMachine, [function (sbErr, successResult){ | ||
sailsApp.lower(function (sailsLowerErr) { | ||
// ┬ ┌─┐┬ ┬┌─┐┬─┐ ┌─┐┌─┐┬┬ ┌─┐ | ||
// │ │ ││││├┤ ├┬┘ └─┐├─┤││ └─┐ | ||
// ┴─┘└─┘└┴┘└─┘┴└─ └─┘┴ ┴┴┴─┘└─┘ | ||
envToSet.sails.lower(function (sailsLowerErr) { | ||
if (sailsLowerErr) { | ||
@@ -356,7 +626,48 @@ console.warn('This script relies on access to Sails, but when attempting to lower this Sails app automatically after running the script, an error occurred. Details:',sailsLowerErr.stack); | ||
// If we're managing a Sails app instance for this script, then pass through `env.sails`. | ||
if (!_.isUndefined(sailsApp)) { | ||
liveMachine.setEnv({ sails: sailsApp }); | ||
} | ||
// ███████╗███████╗████████╗███████╗███╗ ██╗██╗ ██╗ ██╗██╗ | ||
// ██╔════╝██╔════╝╚══██╔══╝██╔════╝████╗ ██║██║ ██║ ██╔╝╚██╗ | ||
// ███████╗█████╗ ██║ █████╗ ██╔██╗ ██║██║ ██║ ██║ ██║ | ||
// ╚════██║██╔══╝ ██║ ██╔══╝ ██║╚██╗██║╚██╗ ██╔╝ ██║ ██║ | ||
// ██╗███████║███████╗ ██║ ███████╗██║ ╚████║ ╚████╔╝ ╚██╗██╔╝ | ||
// ╚═╝╚══════╝╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝ ╚═══╝ ╚═╝╚═╝ | ||
// | ||
// ┌─┐┬─┐┌─┐┬ ┬┬┌┬┐┌─┐ ╔═╗╔╗╔╦ ╦ ┌┬┐┌─┐ ┌┬┐┌─┐┌─┐┬ ┬┬┌┐┌┌─┐ ┌─┐┌┐┌ | ||
// ├─┘├┬┘│ │└┐┌┘│ ││├┤ ║╣ ║║║╚╗╔╝ │ │ │ │││├─┤│ ├─┤││││├┤ ├┤ │││ | ||
// ┴ ┴└─└─┘ └┘ ┴─┴┘└─┘ ╚═╝╝╚╝ ╚╝ ┴ └─┘ ┴ ┴┴ ┴└─┘┴ ┴┴┘└┘└─┘ └ ┘└┘ | ||
// | ||
// Now provide `env. | ||
// | ||
// This allows us to provide access to special variables for this | ||
// particular machine runtime (i.e. `machine-as-script`), as well | ||
// as any other scope specific to the machine's habitat. | ||
// | ||
// For example, if this machine declares the "sails" habitat, then we | ||
// must be managing a Sails app instance for this script. So we pass | ||
// through that Sails app instance as `env.sails`. | ||
// | ||
// Similarly, since `machine-as-script` parses serial command-line | ||
// arguments, it _always_ provides ``env.commandLineArgs`. | ||
liveMachine.setEnv(envToSet); | ||
// ██████╗ ███████╗████████╗██╗ ██╗██████╗ ███╗ ██╗ | ||
// ██╔══██╗██╔════╝╚══██╔══╝██║ ██║██╔══██╗████╗ ██║ | ||
// ██████╔╝█████╗ ██║ ██║ ██║██████╔╝██╔██╗ ██║ | ||
// ██╔══██╗██╔══╝ ██║ ██║ ██║██╔══██╗██║╚██╗██║ | ||
// ██║ ██║███████╗ ██║ ╚██████╔╝██║ ██║██║ ╚████║ | ||
// ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ | ||
// | ||
// ┬ ┬┬ ┬┌─┐ ╔╦╗╔═╗╔═╗╦ ╦╦╔╗╔╔═╗ ╦╔╗╔╔═╗╔╦╗╔═╗╔╗╔╔═╗╔═╗ | ||
// │ │└┐┌┘├┤ ║║║╠═╣║ ╠═╣║║║║║╣ ║║║║╚═╗ ║ ╠═╣║║║║ ║╣ | ||
// ┴─┘┴ └┘ └─┘ ╩ ╩╩ ╩╚═╝╩ ╩╩╝╚╝╚═╝ ╩╝╚╝╚═╝ ╩ ╩ ╩╝╚╝╚═╝╚═╝ | ||
// ┌─ ┬ ┬┬┌┬┐┬ ┬ ┌─┐┌─┐┌─┐┌─┐┬┌─┐┬ ╔╦╗╔═╗╦ ╦ ╔╦╗╔═╗╦ ╔═╗ ┌─┐┬─┐┌─┐┌─┐ ─┐ | ||
// │─── ││││ │ ├─┤ └─┐├─┘├┤ │ │├─┤│ ║ ║╣ ║ ║ ║ ╠═╣║ ║╣ ├─┘├┬┘│ │├─┘ ───│ | ||
// └─ └┴┘┴ ┴ ┴ ┴ └─┘┴ └─┘└─┘┴┴ ┴┴─┘ ────╩ ╚═╝╩═╝╩═╝╩ ╩ ╩╩═╝╚═╝ ┴ ┴└─└─┘┴ ─┘ | ||
// Set a telltale property to allow `bin/machine-as-script` to be more | ||
@@ -363,0 +674,0 @@ // intelligent about catching wet machine instances which are already wrapped |
{ | ||
"name": "machine-as-script", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Run a machine as a command-line script.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64622
676