Skip to content

jbangdev/jbang-npm

Repository files navigation

jbang-npm - Java Script in your JavaScript

Install and use JBang from NPM based projects.

Lets you use your own local scripts, JBang AppStore alias or any network reachable jar or Maven artifact.

Table of Contents

Installation

npm i @jbangdev/jbang --save

Prefer installing the package globally if you want to use it as a CLI wrapper of JBang:

npm i -g @jbangdev/jbang

Usage

You can find the complete documentation about arguments you can pass to the jbang executable here: https://www.jbang.dev/documentation/guide/latest/cli/jbang.html.

As a library

const jbang = require('@jbangdev/jbang');

jbang is an object exposing the following.

exec(string)

The jbang.exec() function accepts a string that will be passed as the command-line arguments to the jbang executable.

Example:

jbang.exec('app install --name karate-core com.intuit.karate:karate-core:RELEASE:all');

spawnSync(string)

Use spawnSync to run the command in the same process/stdin/signals.

await jbang.spawnSync('app install --name karate-core com.intuit.karate:karate-core:RELEASE:all');

Primarily used by the jbang-npm CLI.

As a CLI

Package preferably installed globally, you can run in a shell the command named jbang-npm. jbang-npm is a simple wrapper of the installed jbang executable which prevents you to manually add the command to your path.

Example:

jbang-npm app install --name karate-core com.intuit.karate:karate-core:RELEASE:all

You can also use npx:

npx jbang quarkus@quarkusio

Behind the scenes

This will look for jbang in path and if not available install it before executing jbang.

Using as a dependency

In most cases you should be able to use JBang directly in node scripts.

But if you want to provide more customization you can create your own "wrapper" NPM package. One of the advantages is that you can pre-install the library dependencies needed at the time of npm install (just by calling --help or a similar "no op" command) so that the user-experience when running the first command after install is better.

For an example, refer to the @karatelabs/karate NPM package.