sq / JSIL

CIL to Javascript Compiler
http://jsil.org/
Other
1.73k stars 241 forks source link

Simple "hello world" .NET console app for use in NodeJS #716

Open cookch10 opened 9 years ago

cookch10 commented 9 years ago

Overview

I am trying to create a simple JavaScript file for use in a NodeJS environment from a C# Console application (the end goal is to create a simple image processing utility, this is my starting point).

I have successfully cloned and built the JSIL solution (disabling XNA projects), added the JSIL bin directory to my path so that I am able to call JSILc.exe "path/to/myConsoleApp.exe".

Program.cs:

using System;

namespace NodeImageUtilities {
    static class Program {
        static void Main(string[] args) {
            args = args.Length > 0 ? args : new[] { "noop" };

            Console.WriteLine(string.Join(",", args));
        }
    }
}

After compiling my C# app, I run JSILc.exe to convert my executable to JavaScript which completes without error, generating the following files:

At this point I would employ an additional series of build tasks (like grunt) to concatenate / minify the JS files.

Issue

This is where I'm a bit hazy on JSIL library dependencies. In the generated JavaScript, the JSIL object itself is not actually constructed. It appears that this happens in the projects/JSIL/Libraries/JSIL.js file (and possibly other files within projects/JSIL/Libraries/*.js).

Most of the examples I've found are showing JSIL in use within the browser, which I am guessing facilitates loading the JSIL library along with any necessary dependencies. My need is the opposite: I do not plan on running this in the browser, this library will be run server-side only (NodeJS).

Are there any recommendations for automatically including JSIL dependencies in this type of application (anything out of the box)? I wanted to ask before I start crafting some elaborate build process.

Thanks!

kg commented 9 years ago

JSIL can be used in a shell environment, you just want to load JSIL.js with manifest(s) available like in the browser. For node you may need to add a variation on the spidermonkey shell environment that's already in JSIL.js to map things to node's APIs for stuff like stdout and script loading.

cookch10 commented 9 years ago

Thanks @kg, this is helpful. I'll update this issue with any helpful information and questions as I continue to try integrating with Node for anyone else that may be trying to do the same thing.