Standalone usage

Maven Artifact

1
2
3
4
5
<dependency>
  <groupId>org.kevoree</groupId>
  <artifactId>org.kevoree.tools.kevscript</artifactId>
  <version>${kevoree.version}</version>
</dependency>

Usage example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
KevScriptEngine kevs = new KevScriptEngine(new KevoreeConfig.Builder().useDefault().build());
try {
  final String script = "add node: JavaNode";
  final KevoreeFactory factory = new DefaultKevoreeFactory(); // a factory to create models
  final ContainerRoot model = factory.createContainerRoot(); // create an empty model
  factory.root(model); // ignore this but make sure you do it :p

  kevs.execute(script, model);
  // in Java, the KevScript engine mutates the given model directly
  assert (model.getNodes().get(0).getName().equals("node"));
} catch (KevScriptException ex) {
  // something went wrong while executing the script
  ex.printStackTrace();
}

NPM module

1
npm i kevoree-kevscript -S

  You will also need tiny-conf & kevoree-commons

Usage example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const config = require('tiny-conf');
const KevScript = require('kevoree-kevscript');
const loggerFactory = require('kevoree-logger');
const assert = require('assert');

// kevoree-kevscript uses tiny-conf under the hood to retrieve
// its registry settings, so we have to define them before instantiation
config.set('registry', {
  host: 'registry.kevoree.org',
  port: 443,
  ssl: true
});

const kevs = new KevScript(loggerFactory.create('KevScript'));
const script = 'add node: JavascriptNode';

kevs.parse(script, (err, model) => {
  if (err) {
    console.error('Something went wrong while executing script', err.message);
  } else {
    assert.equal(model.nodes.array[0].name, 'node');
  }
});