<commit_before>## DynJS addon

> Addon that allow to develop a [forge addon](http://forge.jboss.org/addons) using [DynJS javascript engine](http://dynjs.org/).

### Available Commands

| Command       | Description  |
| ------------- |:-------------|
| eval          | *Evaluate a script* |
| evalinproject | *Evaluate a script in project's scope* |  
| installmodule | *Install a new common module* |

### > eval
>  Evaluate a script
#### Parameters
| param        | Description |
| ------------- |:-------------|
| --script      | *script's full path* |
#### Implicit Object(s)
Object(s) Available in the script

>| object        | Description |
| ------------- |:-------------|
| self          | the current [command](http://bsorrentino.github.io/forge-addon/dynjs-addon/apidocs/org/bsc/commands/Eval.html) instance |


### > evalinproject
>  Evaluate a script in project's scope
#### Parameters
| param        | Description |
| ------------- |:-------------|
| --script      | *script's full path* |
#### Implicit Object(s)
Object(s) Available in the script

>| object       | Description |
| ------------- |:-------------|
| self          | the current [command](http://bsorrentino.github.io/forge-addon/dynjs-addon/apidocs/org/bsc/commands/EvalInProject.html) instance |
| project       | the current [project](http://docs.jboss.org/forge/javadoc/2.6.1-SNAPSHOT/org/jboss/forge/addon/projects/Project.html) instance |

### > installmodule
>  Install a new common module. After installation such module will be available to script using **require** command
#### Parameters
| param        | Description |
| ------------- |:-------------|
| --script      | *script's full path* |

### Getting started

#### Install

`> forge --install org.bsc:dynjs-addon,2.7.2.Final`

*Older versions* 

`> forge --install org.bsc:dynjs-addon,2.6.0.Final`



All available version [here](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.bsc%22%20AND%20a%3A%22dynjs-addon%22)

#### Javascript basic template
```javascript
var input = {}; // object containing the UIInput(s)

function initializeUI( builder ) { // Initialize UI & fill input object

  print( "initialize UI");

}

function execute( context ) { // perform task using the input values

  print( "executeJS " );
}

```

### Examples

#### Print the values of required inputs
```javascript
var String = java.lang.String;
var Boolean = java.lang.Boolean;

print( "addon loaded!");

var input = {};

// initialize an UIInput (String)
input.string0 = self.componentFactory.createInput("string0", String );
input.string0.label = "Give me a string";
input.string0.required = true;

// initialize an UIInput (Boolean)
input.bool0 = self.componentFactory.createInput("bool0", Boolean );
input.bool0.label = "Give me boolean";
input.bool0.DefaultValue = true;

function initializeUI( builder ) {

	print( "initialize UI");
	for( m in input ) {
		builder.add( input[m] );
	}
	print( "UI initialized!")

}

function execute( context ) {

	print( "executeJS " );

	return "OK " +  
         input.string0.value +
         " - " +
         input.bool0.value;
}
```

#### Require module(s)
```javascript


var facets = require("facets")(); // facets is a built-in module
// Other modules can be shared using 'installModule' command

print( "addon loaded!");


function initializeUI( builder ) {

}

function execute( context ) {

  // Perform clean,package on current open project
  facets.mavenfacet.executeMaven( ["clean",  "package"] );
}
```

#### Develop a Module
```javascript

/**
Simple module that provide pwd & cd functions

install from cli:
=================

> installmodule --script <full script path>

Usage within script:
====================

var shell = require("shell");

*/

var OSUtils = org.jboss.forge.furnace.util.OperatingSystemUtils;
var System = java.lang.System;

module.exports = {

		pwd:function() {
			return OSUtils.getWorkingDir();
		},
		cd:function( dir ) {
			return System.setProperty("user.dir", dir);
		}


}

```

### Example
> Checkout more examples from [here](samples)<commit_msg>convert md to asciidoc<commit_after>[[dynjs-addon]]
DynJS addon
~~~~~~~~~~~

__________________________________________________________________________________________________________________________
Addon that allow to develop a http://forge.jboss.org/addons[forge addon]
using http://dynjs.org/[DynJS javascript engine].
__________________________________________________________________________________________________________________________

[[available-commands]]
Available Commands
^^^^^^^^^^^^^^^^^^

[cols=",<",options="header",]
|=====================================================
|Command |Description
|eval |_Evaluate a script_
|evalinproject |_Evaluate a script in project’s scope_
|installmodule |_Install a new common module_
|=====================================================

[[eval]]
> eval
^^^^^^

_______________________________________________________________________________________________________________________________________________________________________
Evaluate a script #### Parameters | param | Description | | ————-
|:————-| | –script | _script’s full path_ | #### Implicit Object(s)
Object(s) Available in the script
_______________________________________________________________________________________________________________________________________________________________________

[cols=",<",options="header",]
|=======================================================================
|> |object |Description
|self |the current
http://bsorrentino.github.io/forge-addon/dynjs-addon/apidocs/org/bsc/commands/Eval.html[command]
instance
|=======================================================================

[[evalinproject]]
> evalinproject
^^^^^^^^^^^^^^^

__________________________________________________________________________________________________________________________________________________________________________________________
Evaluate a script in project’s scope #### Parameters | param |
Description | | ————- |:————-| | –script | _script’s full path_ | ####
Implicit Object(s) Object(s) Available in the script
__________________________________________________________________________________________________________________________________________________________________________________________

[cols=",<",options="header",]
|=======================================================================
|> |object |Description
|self |the current
http://bsorrentino.github.io/forge-addon/dynjs-addon/apidocs/org/bsc/commands/EvalInProject.html[command]
instance

|project |the current
http://docs.jboss.org/forge/javadoc/2.6.1-SNAPSHOT/org/jboss/forge/addon/projects/Project.html[project]
instance
|=======================================================================

[[installmodule]]
> installmodule
^^^^^^^^^^^^^^^

___________________________________________________________________________________________________________________________________________________________________________________________________________
Install a new common module. After installation such module will be
available to script using *require* command #### Parameters | param |
Description | | ————- |:————-| | –script | _script’s full path_ |
___________________________________________________________________________________________________________________________________________________________________________________________________________

[[getting-started]]
Getting started
^^^^^^^^^^^^^^^

[[install]]
Install
+++++++

`> forge --install org.bsc:dynjs-addon,2.7.2.Final`

_Older versions_

`> forge --install org.bsc:dynjs-addon,2.6.0.Final`

All available version
http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.bsc%22%20AND%20a%3A%22dynjs-addon%22[here]

[[javascript-basic-template]]
Javascript basic template
+++++++++++++++++++++++++

code,javascript-----------------------------------------------------------------------
code,javascript
var input = {}; // object containing the UIInput(s)

function initializeUI( builder ) { // Initialize UI & fill input object

  print( "initialize UI");

}

function execute( context ) { // perform task using the input values

  print( "executeJS " );
}
-----------------------------------------------------------------------

[[examples]]
Examples
^^^^^^^^

[[print-the-values-of-required-inputs]]
Print the values of required inputs
+++++++++++++++++++++++++++++++++++

```javascript var String = java.lang.String; var Boolean =
java.lang.Boolean;

print( ``addon loaded!'');

var input = \{};

// initialize an UIInput (String) input.string0 =
self.componentFactory.createInput(``string0'', String );
input.string0.label = ``Give me a string''; input.string0.required =
true;

// initialize an UIInput (Boolean) input.bool0 =
self.componentFactory.createInput(``bool0'', Boolean );
input.bool0.label = ``Give me boolean''; input.bool0.DefaultValue =
true;

function initializeUI( builder ) \{

----------------------------
print( "initialize UI");
for( m in input ) {
    builder.add( input[m] );
}
print( "UI initialized!")
----------------------------

}

function execute( context ) \{

----------------------
print( "executeJS " );

return "
----------------------
{'fraction_non_alphanumeric': 0.22138147227326777, 'fraction_numerical': 0.0077829423846070694, 'mean_word_length': 4.233031674208145, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1494770', 'n_tokens_mistral': 2468, 'n_tokens_neox': 2329, 'n_words': 573}