loopback-run

Run Loopback model method through a single command in a non-interactive way.

Usage no npm install needed!

<script type="module">
  import loopbackRun from 'https://cdn.skypack.dev/loopback-run';
</script>

README

Loopback-run

A tool to launch Loopback method with a single command in a non-interactive way.

A complementary tool of Loopback-console.

Usage

In your loopback project

  1. npm install --save-dev loopback-run
  2. npx loopback-run UserAccount.find
  3. npx loopback-run UserAccount.create --username test --email test@localhost --password test123

Options

You can path all the options for loopback-run before a -- if you need to use options for the method itself

npx loopback-run UserAccount.findOne --exit -- --where.username=test

If you dont have method options you can do npx loopback-run UserAccount.findOne --exit

--exit

Close all opened datasource and force exit Needed if you open persistent connection outside of loopback datasources

--loopbackPath

Define a custom path for loopback entry point.

You can use the environnement variable LOOPBACK_PATH as well.

--argsFile

Provide a javascript file with exported options, will be merge with other options provided

--json

All output will be serialize with JSON.stringify

--argsAsJson

Parse a json string as args for the loopback method npx loopback-run MyModel.task --argsAsJson '{"where": {"prop.subprod": "value"}}'

Progress

You can provide a EventEmitter in the promise to display progress

const _ = require('lodash');
const Promise = require('bluebird');

SampleModel.task = function(){
  const eventEmitter = new EventEmitter();
  let done = 0;
  const promise = Promise.mapSeries(_.times(100), async () => {
     await Promise.delay(_.random(10, 500));
     eventEmitter.emit('progress', {done: ++done, total: 100});
  });
  promise.events = eventEmitter;
  return promise;
}

Debug

DEBUG=loopback-run npx loopback-run MyModel.task