Provides access to shell and OS processes.

You can access these tools on the @weex-cli/core, via const { system } = require('@weex-cli/core').

run

This is an async function.

Runs a shell command and returns the output as a string.

The first parameter commandLine is the shell command to run. It can have pipes! The second parameter is options, object. This is a promise wrapped around node.js child-process.exec api call.

You can also pass trim: true inside the options parameter to have the output automatically trim all starting and trailing spaces.

Should the process fail, an error will be thrown with properties such as:

propertytypepurpose
codenumberthe exit code
cmdstringthe command we asked to run
stderrstringany information the process wrote to stderr
killedboolif the process was killed or not
signalnumberthe signal number used to off the process (if killed)
const nodeVersion = context.system.run('node -v', { trim: true })

which

Returns the full path to a command on your system if located on your path.

const whereIsIt = context.system.which('npm')

startTimer

Returns a function. When this is called, the number of milliseconds will be returned.

const timer = context.system.startTimer()

// time passes...
console.log(`that just took ${timer()} ms.`)

Caveat: Due to the event loop scheduler in Node.JS, they don't guarantee millisecond accuracy when invoking async functions. For that reason, expect a up to a 4ms overage.

Note that this lag doesn't apply to synchronous code.