@actions-kit/exec
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Actions Kit - Exec

npm version build status

A command execution library of Actions Kit, an additional toolkit for developing GitHub Actions.

Installation

npm install @actions-kit/exec

Usage

Run a Command

Use run(command, args...) to run a command.

const exec = require('@actions-kit/exec');

await exec.run("node", "index.js");

It will returns a RunResult object which contains an exit code of the command run.

const res = await exec.run("node", "-c", "index.js");
if (!res.isOk()) {
  console.log(`Failed with exit code: ${res.code}`);
}

Run a Command and Get the Output

Use output(command, args...) to run a command and get the output. It will returns an OutputResult object which contains an exit code and the log output of the command run.

const exec = require('@actions-kit/exec');

const res = await exec.output("node", "--version");
if (!res.isOk()) {
  console.log(`Failed with exit code: ${res.code}`);
} else {
  console.log(`Node version: ${res.output}`);
}

Run a Command Silently

Use runSilently(command, args...) to run a command silently without printing anything to the console.

const exec = require('@actions-kit/exec');

await exec.runSilently("node", "-c", "index.js");

Or use outputSilently(command, args...) to run a command and get the output silently without printing anything to the console.

const res = await exec.outputSilently("node", "--version");
console.log(`Node version: ${res.output}`);

Construct a Command Helper

Construct a command helper using Command class to simplify the command run.

const exec = require('@actions-kit/exec');

const node = new exec.Command("node", "-e");
await node.run("process.exit();");

All command run functions are available in the Command class and are behaving the same.

await node.runSilently("process.exit();");

const res = node.output("console.log('Hello world!');");
console.log(`output: ${res.output}`);

License

This project is licensed under the terms of the MIT License.

Copyright © 2023 Alfi Maulana

Readme

Keywords

Package Sidebar

Install

npm i @actions-kit/exec

Weekly Downloads

2

Version

0.2.0

License

MIT

Unpacked Size

18.4 kB

Total Files

15

Last publish

Collaborators

  • threeal