How to use machine - 10 common examples

To help you get started, we’ve selected a few machine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Karnith / machinepack-sailsgulpify / machines / sails-gulpify.js View on Github external
fn: function(inputs, exits, env) {
    var createGulpFile = require('machine').build(require('./create-gulp-file')),
      createGulpTasks = require('machine').build(require('./create-gulp-tasks')),
      createGulpEngine = require('machine').build(require('./create-gulp-engine')),
      toggleSailsrc = require('machine').build(require('./toggle-sailsrc')),
      installGulpDependencies = require('machine').build(require('./install-gulp-dependencies'));

    Prompts.text({
      message: "For first time configuration, enter yes, otherwise enter no if sails node module was upgraded.",
      exampleValue: 'yes'
    }).exec({
      error: function (err){
        console.error('Unexpected error interpeting interactive prompt input:', err);
        return process.exit(1);
      },
      // OK- got user input.
      success: function (userInput){
        var firstTimeRun = userInput.toLowerCase();
github node-machine / machinepack / bin / machinepack-exec.js View on Github external
// if (!program.args[0]) {
//   console.error('`identity` required');
//   process.exit(1);
// }


var identity = program.args[0];



// exposed via closure simply for convenience
var machinepackVarName;
var machineMethodName;


Machine.build({
  inputs: {
    identity: {
      example: 'do-stuff'
    },
    dir: {
      example: '/Users/mikermcneil/machinepack-foo/'
    }
  },
  defaultExit: 'success',
  exits: {
    success: {
      example: {
        withInputs: [
          {
            name: 'foobar',
            value: 'fiddle diddle'
github sailshq / treeline1 / legacy / treeline-exec.js View on Github external
// Parse command-line argument (i.e. not options)
// which indicates an optional machinepack and/or machine
if (_.isString(program.args[0])){
  if (program.args[0].match(/\//)) {
    machinepackIdentity = program.args[0].split('/')[0];
    machineIdentity = program.args[0].split('/')[1];
  }
  else {
    machinepackIdentity = program.args[0];
  }
}

// Allow unknown options.
program.unknownOption = function NOOP(){};

(Machine.build({
  inputs: {},
  defaultExit: 'success',
  exits: {
    success: {
      example: {
        machinepack: {
          identity: 'machinepack-whatever',
          variableName: 'Whatever'
        },
        machine: {
          identity: 'do-stuff',
          variableName: 'doStuff'
        },
        withInputs: [
          {
            name: 'foobar',
github mikermcneil / machinepack-github / lib / remove-label-from-issue.js View on Github external
fn: function (inputs,exits) {

    var sendGithubApiRequest = require('machine').build(require('./private/send-github-api-request')).customize({
      arginStyle: 'serial',
      execStyle: 'natural'
    });

    // Remove label from issue
    sendGithubApiRequest.with({
      method: 'DELETE',
      url: '/repos/'+encodeURIComponent(inputs.owner)+'/'+encodeURIComponent(inputs.repo)+'/issues/'+encodeURIComponent(inputs.issueNumber)+'/labels/'+encodeURIComponent(inputs.label),
      credentials: inputs.credentials
    }).switch({
      error: exits.error,
      success: function (unusedApiResponse) {
        return exits.success();
      }
    });
github mikermcneil / machinepack-github / lib / private / send-github-api-request.js View on Github external
fn: function (inputs,exits) {
    var _ = require('@sailshq/lodash');
    var Http = require('machinepack-http');

    // Normalize credentials, if any were provided.
    var normalizeCredentials = require('machine').build(require('./normalize-credentials')).customize({
      arginStyle: 'serial',
      execStyle: 'natural'
    });
    inputs.credentials = normalizeCredentials.with(inputs.credentials);
    // Ensure "Accept" and "User-agent" headers exist.
    inputs.credentials.headers['Accept'] = inputs.credentials.headers['Accept'] || 'application/json';
    inputs.credentials.headers['User-Agent'] = inputs.credentials.headers['User-Agent'] || 'machinepack-github';

    // Send API request
    Http.sendHttpRequest({
      baseUrl: 'https://api.github.com',
      url: inputs.url,
      method: inputs.method,
      params: _.merge(inputs.credentials.params, inputs.params),
      body: inputs.body,
      headers: _.merge(inputs.credentials.headers, inputs.headers),
github sailshq / treeline1 / standalone / build-script.js View on Github external
module.exports = function buildScript(opts, exitOverrides){

  // Use either `opts` or `opts.machine` as the machine definition
  var machineDef;
  if (!opts.machine) {
    machineDef = opts;
    opts = { machine: machineDef };
  }
  else {
    machineDef = opts.machine;
  }

  // Build machine, applying defaults
  var wetMachine = Machine.build(_.extend({
    identity: machineDef.identity||machineDef.friendlyName||'anonymous-machine-script',
    defaultExit: 'success',
    inputs: {},
    exits: {
      success: {
        description: 'Done.'
      },
      error: {
        description: 'Unexpected error occurred.'
      }
    },
    fn: function (inputs, exits){
      exits.error(new Error('Not implemented yet!'));
    }
  },machineDef||{}));
github mikermcneil / machinepack-github / helpers / index.js View on Github external
// This is a little helper pack with some private machines.
var _ = require('@sailshq/lodash');
var Machine = require('machine');

module.exports = {
  normalizeCredentials: Machine.build(_.extend({identity: 'normalize-credentials' }, require('./lib/normalize-credentials'))),
  sendGithubApiRequest: Machine.build(_.extend({identity: 'send-github-api-request' }, require('./lib/send-github-api-request'))),
};
github balderdashy / sails-mongo / lib / private / build-std-adapter-method.js View on Github external
module.exports = function buildStdAdapterMethod (machineDef, WET_MACHINES, registeredDsEntries, registeredDryModels) {

  // Build wet machine.
  var performQuery = Machine.build(machineDef);

  // Return function that will be the adapter method.
  return function (datastoreName, s3q, done) {

    // Look up the datastore entry (to get the manager).
    var dsEntry = registeredDsEntries[datastoreName];

    // Sanity check:
    if (_.isUndefined(dsEntry)) {
      return done(new Error('Consistency violation: Cannot do that with datastore (`'+datastoreName+'`) because no matching datastore entry is registered in this adapter!  This is usually due to a race condition (e.g. a lifecycle callback still running after the ORM has been torn down), or it could be due to a bug in this adapter.  (If you get stumped, reach out at http://sailsjs.com/support.)'));
    }

    // Obtain a connection.
    doWithConnection({
      WET_MACHINES: WET_MACHINES,
      manager: dsEntry.manager,
github balderdashy / sails-mongo / lib / private / machines / private / register-datastore.js View on Github external
//  ██╔══██╗██╔══╝  ██║   ██║██║╚════██║   ██║   ██╔══╝  ██╔══██╗
//  ██║  ██║███████╗╚██████╔╝██║███████║   ██║   ███████╗██║  ██║
//  ╚═╝  ╚═╝╚══════╝ ╚═════╝ ╚═╝╚══════╝   ╚═╝   ╚══════╝╚═╝  ╚═╝
//
//  ██████╗  █████╗ ████████╗ █████╗     ███████╗████████╗ ██████╗ ██████╗ ███████╗
//  ██╔══██╗██╔══██╗╚══██╔══╝██╔══██╗    ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
//  ██║  ██║███████║   ██║   ███████║    ███████╗   ██║   ██║   ██║██████╔╝█████╗
//  ██║  ██║██╔══██║   ██║   ██╔══██║    ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝
//  ██████╔╝██║  ██║   ██║   ██║  ██║    ███████║   ██║   ╚██████╔╝██║  ██║███████╗
//  ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚═╝  ╚═╝    ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
//
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// FUTURE: Pull this into Waterline core.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

module.exports = require('machine').build({


  friendlyName: 'Register datastore',


  description: 'Register a new datastore for making connections.',


  inputs: {

    identity: {
      description: 'A unique identitifer for the datastore.',
      example: 'default',
      required: true
    },
github balderdashy / sails-postgresql / helpers / register-data-store.js View on Github external
//  ██████╗ ███████╗ ██████╗ ██╗███████╗████████╗███████╗██████╗
//  ██╔══██╗██╔════╝██╔════╝ ██║██╔════╝╚══██╔══╝██╔════╝██╔══██╗
//  ██████╔╝█████╗  ██║  ███╗██║███████╗   ██║   █████╗  ██████╔╝
//  ██╔══██╗██╔══╝  ██║   ██║██║╚════██║   ██║   ██╔══╝  ██╔══██╗
//  ██║  ██║███████╗╚██████╔╝██║███████║   ██║   ███████╗██║  ██║
//  ╚═╝  ╚═╝╚══════╝ ╚═════╝ ╚═╝╚══════╝   ╚═╝   ╚══════╝╚═╝  ╚═╝
//
//  ██████╗  █████╗ ████████╗ █████╗     ███████╗████████╗ ██████╗ ██████╗ ███████╗
//  ██╔══██╗██╔══██╗╚══██╔══╝██╔══██╗    ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
//  ██║  ██║███████║   ██║   ███████║    ███████╗   ██║   ██║   ██║██████╔╝█████╗
//  ██║  ██║██╔══██║   ██║   ██╔══██║    ╚════██║   ██║   ██║   ██║██╔══██╗██╔══╝
//  ██████╔╝██║  ██║   ██║   ██║  ██║    ███████║   ██║   ╚██████╔╝██║  ██║███████╗
//  ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚═╝  ╚═╝    ╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝╚══════╝
//

module.exports = require('machine').build({


  friendlyName: 'Register Data Store',


  description: 'Register a new datastore for making connections.',


  sync: true,


  inputs: {

    identity: {
      description: 'A unique identitifer for the connection.',
      example: 'localPostgres',

machine

Build functions in standardized containers.

MIT
Latest version published 1 year ago

Package Health Score

54 / 100
Full package analysis

Popular machine functions