Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build tools in Elm #2

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ instance/**/*.js
run_with_credentials.sh
file
users.db
bootstrap.js
22 changes: 22 additions & 0 deletions bootstrapper/Bootstrapper.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Bootstrapper where
{-|
This is a very naughty module indeed.

Swap out the two arguments to bootstrap with the name of your module
and the name of the output file.

That output file will then be ran whenever you call this script.

This script is also self-bootstrapping, simply run node on it and it will
handle the rest.

-}
import Native.Bootstrapper

bootstrap : String -> String -> ()
bootstrap =
Native.Bootstrapper.bootstrap

port run : ()
port run =
bootstrap "instance/server/Main" "instance/server/main.js"
55 changes: 55 additions & 0 deletions bootstrapper/Native/Bootstrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

var bootstrap = function(fs, exec, compiler){
var compile = function(file, outFile, onClose){
compiler.compile([file + '.elm'], {
output: outFile,
yes: true
}).on('close', onClose);
};

return function(filename, output){
console.log("here");
compile(filename, output, function(){
var dirIndex = filename.lastIndexOf('/');
var lastFileName = filename.substr(dirIndex + 1);

fs.appendFileSync(output, "\nElm.worker(Elm." + lastFileName + ");")
var child = exec('node ' + output);

child.stdout.on('data', console.log);
child.stderr.on('data', console.error);
child.on('close', function(code) {
console.log('closing code: ' + code);
});
});
};
};

var make = function make(localRuntime) {
localRuntime.Native = localRuntime.Native || {};
localRuntime.Native.Bootstrapper = localRuntime.Native.Bootstrapper || {};

if (localRuntime.Native.Bootstrapper.values) {
return localRuntime.Native.Bootstrapper.values;
}
var fs = require('fs');
var exec = require('child_process').exec;
var compiler = require('node-elm-compiler');


return {
bootstrap: F2(bootstrap(fs, exec, compiler))
};
};

Elm.Native.Bootstrapper = {};
Elm.Native.Bootstrapper.make = make;

if (typeof window === "undefined") {
window = global;
}

setTimeout(function() {
console.log("starting elm..");
Elm.worker(Elm.Bootstrapper);
}, 1000);
15 changes: 15 additions & 0 deletions bootstrapper/elm-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "1.0.0",
"summary": "helpful summary of your project, less than 80 characters",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"."
],
"exposed-modules": [],
"native-modules": true,
"dependencies": {
"elm-lang/core": "3.0.0 <= v < 4.0.0"
},
"elm-version": "0.16.0 <= v < 0.17.0"
}
4 changes: 0 additions & 4 deletions instance/server/run.sh

This file was deleted.