<commit_before># Netjs

Netjs is a .NET to TypeScript and JavaScript compiler. It uses multiple stages to produce JavaScript for your web apps.

<img src="Images/Explanation.png" />

You start by compiling whatever code you want into its own assembly. Portable Class Libraries work great for this, but it really doesn't matter. You can even pass EXEs.

    netjs Library.dll

This produces a TypeScript file. You can use this file as is if the rest of your app is written in TypeScript.

If you want JavaScript (with no dependencies), then pass this file along with a tiny mscorlib to the TypeScript compiler:

    tsc -t ES5 mscorlib.ts Library.ts --out Library.js

You can now include Library.js in any app because it is fully linked (you will get build errors if anything is missing).

    <script src="Library.js" type="text/javascript"></script>

And that's it. You can write apps and reuse the portable parts in web apps!


## Installation

### Install Netjs

Download it:

    git clone https://github.com/praeclarum/Netjs.git

#### Mac

    sudo make install

This will install a soft link called `netjs` in `/usr/bin` to the script `netjs.sh`.

#### Windows

    msbuild

`Netjs.exe` will be built in `Netjs\bin\Debug`. You can copy this executable to someplace in your PATH to make it readily available.


### Install Node

[http://nodejs.org/download/](http://nodejs.org/download/)

Node is needed by the TypeScript compiler.

### Install TypeScript

    sudo npm install -g typescript




## Compiling Code

Netjs works with .NET assemblies built with any compiler ([limitations][Limitations] not withstanding).

### Compile to TypeScript

    netjs Library.dll

This will output a TypeScript file named `Library.ts` containing all the code from `Library.dll` and any other assemblies referenced in its directory.

### Compile to JavaScript

    tsc -t ES5 mscorlib.ts Library.ts --out Library.js 

This compiles the library code along with a small implementation of mscorlib. The files are merged and output as a single JavaScript file `Library.js`.

### ECMAScript 3 Compatibility

In case you need your code to run in es3 environment (like, well, IE8), you have to get rid of accessors as they are not supported.
Passing `--es3` as an argument would result in creating of getter/setter methods instead of fields with accessors.

    netjs Library.dll --es3
    
Library.dll:

    class Person
    {
        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
    }

Library.ts:

    class Person extends NObject
    {
        name: string;<commit_msg>Add build badge and other cleanups<commit_after># Netjs

[![Build Status](https://app.bitrise.io/app/fa94597fdbce95b1/status.svg?token=<KEY>)](https://app.bitrise.io/app/fa94597fdbce95b1)

Netjs is a .NET to TypeScript and JavaScript compiler. It uses multiple stages to produce JavaScript for your web apps.

<img src="Images/Explanation.png" />

You start by compiling whatever code you want into its own assembly. Portable Class Libraries work great for this, but it really doesn't matter. You can even pass EXEs.

```bash
netjs Library.dll
```

This produces a TypeScript file. You can use this file as is if the rest of your app is written in TypeScript.

If you want JavaScript (with no dependencies), then pass this file along with a tiny mscorlib to the TypeScript compiler:

```bash
tsc -t ES5 mscorlib.ts Library.ts --out Library.js
```

You can now include Library.js in any app because it is fully linked (you will get build errors if anything is missing).

```html
<script src="Library.js" type="text/javascript"></script>
```

And that's it. You can write apps and reuse the portable parts in web apps!


## Installation

```bash
dotnet install tool -g Netjs
```

### Install Node

[http://nodejs.org/download/](http://nodejs.org/download/)

### Install TypeScript

[Node](http://nodejs.org/download/) is needed by the TypeScript compiler.

```bash
sudo npm install -g typescript
```


## Compiling Code

Netjs works with .NET assemblies built with any compiler ([limitations][Limitations] not withstanding).

### Compile to TypeScript

```bash
netjs Library.dll
```

This will output a TypeScript file named `Library.ts` containing all the code from `Library.dll` and any other assemblies referenced in its directory.

### Compile to JavaScript

```
tsc -t ES5 mscorlib.ts Library.ts --out Library.js
```

This compiles the library code along with a small implementation of mscorlib. The files are merged and output as a single JavaScript file `Library.js`.

### ECMAScript 3 Compatibility

In case you need your code to run in es3 environment (like, well, IE8), you have to get rid of accessors as they are not supported.
Passing `--es3` as an argument would result in creating of getter/setter methods instead of fields with accessors.

```
netjs Library.dll --es3
```
    
Library.dll:

```csharp
class Person
{
    private string name;
    public string Name
    {
        get { return name; }
        set { name = value; }
    }
}
```

Library.ts:

    class Person extends NObject
    {
        name: string;
{'fraction_non_alphanumeric': 0.08381614522981846, 'fraction_numerical': 0.005793742757821553, 'mean_word_length': 3.5034782608695654, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 3, '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': '6752753', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1444, 'n_words': 682}