<commit_before># Getting Started with ElixirScript


The intent of this guide is to get you started with ElixirScript. It will give you instructions on using ElixirScript. I will go over the three ways you can use ElixirScript:

* As an escript
* As a mix task
* As a library in your application

### Escript

* Step 1: Get escript

    You can download the elixirscript escript from the [releases page on github](https://github.com/bryanjos/elixirscript/releases). It is a tar file named elixirscript.tar.gz.

* Step 2: Untar

    Next, untar elixirscript.tar.gz

    ```bash
    tar -xvzf elixirscript.tar.gz
    ```

    You will want to put the bin folder from the uncompressed folder into your path. This should allow you to use the elixirscript escript.

* Step 3: Use

    This is the help output of elixirscript

    ```bash
      usage: elixirscript <input> [options]

      <input> path to elixir files or
              the elixir code string if the -ex flag is used

      options:
      -o  --output [path]   places output at the given path
      -ex --elixir          read input as elixir code string
      -r  --root [path]     root path for standard libs
      -h  --help            this message
    ```

    the `<input>` is the elixir code string or file path you want to convert from elixir to javascript. Below is an example of using a code string and turning it into JavaScript

    ```bash
    $ elixirscript ":atom" -ex
    Symbol.for('atom')
    ```

    The elixirscript escript changed the elixir code, `:atom` into the JavaScript code `Symbol.for('atom')`. The `-ex` parameter lets the script know that the input is an Elixir code string instead of a file.

    What if we wanted to give it a file? You would simply do the following:

    ```bash
    $ elixirscript "example.exjs"
    Symbol.for('atom')
    ```

    What you will have noticed by now is that it has output everything we've done so far to the terminal. What about if we want to place the output to a path? The next example takes a file as input and outputs the result in another directory.

    ```bash
    $ elixirscript "example.exjs" -o "dist"
    ```

    If you look in the dist folder, you should see example.js as well as elixir.js. elixir.js is the JavaScript file that contains the Elixir Standard library. In example.js, the first line should be an import statement importing elixir.js for use.

    wildcards are also accepted:

    ```bash
    $ elixirscript "src/**/*.exjs" -o "dist"
    ```

    The last option we will show is the root option. This option is for defining a root path for the import statements. By default your import statement will not have anything prepended to it. For example, the elixir import will look like this:

    ```javascript
    import * as Elixir from 'elixir';
    ```

    If we wanted to prepend "js" to the root, we can like this:

    ```
    $ elixirscript "example.ex" -o "dist" -r "js"
    ```

    Now the import will look like this:

    ```javascript
    import * as Elixir from 'js/elixir';
    ```

    That concludes the walkthrough on options, as well as the walkthrough on using the elixirscript escript.

### mix elixirscript

* Step 1: Get dependency

    The first step is getting the dependency. In your mix.exs file for your elixir project, add elixir_script to your deps.

    ```elixir
    {:elixir_script, "~> 0.16"}
    ```

* Step 2: Now download the dep

    ```bash
    $ mix deps.get
    ```

    Now you should have the mix task, elixirscript.

* Step 3: Use
    ```bash
    $ mix elixirscript "example.ex" -o "dist" -r "js"
    ```

    What you will notice is that the parameters are exactly the same as the escript.

### ElixirScript module
* Step 1: Get dependency

    The first step is getting the dependency. In your mix.exs file for your elixir project, add elixir_script to your deps.

    ```elixir
    {:elixir_script, "~> 0.15"}
    ```

* Step 2: Now download the dep

    ```bash
    $ mix deps.get
    ```

* Step 3: Use
    Now you will be able to use the ElixirScript module within your code.

    ```elixir
    ElixirScript.compile(":atom")
    ```

    The is also compile_path/2 and compile_quoted/2. Each of the functions take an options keyword list.

     * `:root` - a binary path prepended to the path of the standard lib imports if needed
    * `:env` - a Macro.env struct to use. This is most useful when using macros. Make sure that the  given env has the macros required. Defaults to `__ENV__`.

    You may notice the mention of macros. Using the module in your code allows you to use macros. As long as you pass in an environment with the macros loaded. By default, it uses the current environment.

    For example, if I have a module with a macro in it

    ```elixir
    defmodule ElixirScript.Math do
      defmacro squared(x) do
        quote do
          unquote(x) * unquote(x)
        end<commit_msg>Updated docs<commit_after># Getting Started with ElixirScript


The intent of this guide is to get you started with ElixirScript. It will give you instructions on using ElixirScript. I will go over the three ways you can use ElixirScript:

* As an escript
* As a mix task
* As a library in your application

### Escript

* Step 1: Get escript

    You can download the elixirscript escript from the [releases page on github](https://github.com/bryanjos/elixirscript/releases). It is a tar file named elixirscript.tar.gz.

* Step 2: Untar

    Next, untar elixirscript.tar.gz

    ```bash
    tar -xvzf elixirscript.tar.gz
    ```

    You will want to put the bin folder from the uncompressed folder into your path. This should allow you to use the elixirscript escript.

* Step 3: Use

    This is the help output of elixirscript

    ```bash
    usage: elixirscript <input> [options]
    <input> path to elixir files or the elixir code string if the -ex flag is used

    options:
    -o  --output [path]   places output at the given path
    -ex --elixir          read input as elixir code string
    -r  --root [path]     root import path for all exported modules
    --std-lib [path]      outputs the elixirscript standard library JavaScript files to the specified path
    --full-build          informs the compiler to do a full build instead of an incremental one
    only used when output is specified
    --core-path    es6 import path to the elixirscript standard lib
    only used with the [output] option. When used, Elixir.js is not exported
    -v  --version         the current version number
    -h  --help            this message
    ```

    the `<input>` is the elixir code string or file path you want to convert from elixir to javascript. Below is an example of using a code string and turning it into JavaScript

    ```bash
    $ elixirscript ":atom" -ex
    Symbol.for('atom')
    ```

    The elixirscript escript changed the elixir code, `:atom` into the JavaScript code `Symbol.for('atom')`. The `-ex` parameter lets the script know that the input is an Elixir code string instead of a file.

    What if we wanted to give it a file? You would simply do the following:

    ```bash
    $ elixirscript "example.exjs"
    Symbol.for('atom')
    ```

    What you will have noticed by now is that it has output everything we've done so far to the terminal. What about if we want to place the output to a path? The next example takes a file as input and outputs the result in another directory.

    ```bash
    $ elixirscript "example.exjs" -o "dist"
    ```

    If you look in the dist folder, you should see example.js as well as elixir.js. elixir.js is the JavaScript file that contains the Elixir Standard library. In example.js, the first line should be an import statement importing elixir.js for use.

    wildcards are also accepted:

    ```bash
    $ elixirscript "src/**/*.exjs" -o "dist"
    ```

    The last option we will show is the root option. This option is for defining a root path for the import statements. By default your import statement will not have anything prepended to it. For example, the elixir import will look like this:

    ```javascript
    import * as Elixir from 'elixir';
    ```

    If we wanted to prepend "js" to the root, we can like this:

    ```
    $ elixirscript "example.ex" -o "dist" -r "js"
    ```

    Now the import will look like this:

    ```javascript
    import * as Elixir from 'js/elixir';
    ```

    That concludes the walkthrough on options, as well as the walkthrough on using the elixirscript escript.

### mix elixirscript

* Step 1: Get dependency

    The first step is getting the dependency. In your mix.exs file for your elixir project, add elixir_script to your deps.

    ```elixir
    {:elixir_script, "~> 0.17"}
    ```

* Step 2: Now download the dep

    ```bash
    $ mix deps.get
    ```

    Now you should have the mix task, elixirscript.

* Step 3: Use
    ```bash
    $ mix elixirscript "example.ex" -o "dist" -r "js"
    ```

    What you will notice is that the parameters are exactly the same as the escript.

### ElixirScript module
* Step 1: Get dependency

    The first step is getting the dependency. In your mix.exs file for your elixir project, add elixir_script to your deps.

    ```elixir
    {:elixir_script, "~> 0.17"}
    ```

* Step 2: Now download the dep

    ```bash
    $ mix deps.get
    ```

* Step 3: Use
    Now you will be able to use the ElixirScript module within your code.

    ```elixir
    ElixirScript.compile(":atom")
    ```

    The is also compile_path/2 and compile_quoted/2. Each of the functions take an options keyword list.

     * `:root` - a binary path prepended to the path of the standard lib imports if needed
    * `:env` - a Macro.env struct to use. This is most useful when using macros. Make sure that the  given env has the macros required. Defaults to `__ENV__`.

    You may notice the mention of macros. Using the module in your code allows you to use macros. As long as you pass in an environment with the macros loaded. By default, it uses the current environment.

    For example, if I have a module with a macro in it

    ```elixir
    defmodule ElixirScript.Math do
      defmacro squared(x) do
        quote do
          unquote(x) * unquote(x)
        end
{'fraction_non_alphanumeric': 0.07413557335417073, 'fraction_numerical': 0.0034186364524321157, 'mean_word_length': 2.782415958625785, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4072115', 'n_tokens_mistral': 3106, 'n_tokens_neox': 2928, 'n_words': 1460}