Skip to content

Instantly share code, notes, and snippets.

@rksm
Created January 9, 2018 21:50
Show Gist options
  • Save rksm/59b4571079cd0e87ba3e8289ceaac279 to your computer and use it in GitHub Desktop.
Save rksm/59b4571079cd0e87ba3e8289ceaac279 to your computer and use it in GitHub Desktop.
build-livelify-node.js
/*global require, __dirname*/
let fs = require("fs"),
path = require("path"),
x = require("child_process").execSync;
if (!fs.existsSync("babel-node.js")) {
console.log("Donwloading babel-standalone");
x("curl -k https://wzrd.in/standalone/babel-standalone > babel-node.js", {stdio: "inherit"});
}
let files = [
require.resolve("systemjs/dist/system.src.js"),
require.resolve("lively.modules/dist/lively.modules.js"),
require.resolve("lively-system-interface/dist/lively-system-interface-only-local.js"),
require.resolve("lively.2lively/dist/lively.2lively_client.node.js"),
],
targetFile = "livelify-node.js",
init = `
var ioPath = process.env.L2L_SESSIONTRACKER_PATH || "/lively-socket.io",
host = process.env.L2L_SESSIONTRACKER_SERVER || "http://localhost:9011",
url = host + ioPath;
lively.l2l.client = lively.l2l.L2LClient.ensure(
{url, namespace: "l2l", info: {type: "lively.next node repl from " + require("os").hostname()}});
lively.l2l.client.whenRegistered(20*1000)
.then(() => console.log("[l2l] online"))
.catch(err => console.error("[l2l] failed:", err));`;
fs.writeFileSync(targetFile,
`(function() {
var module = {exports: {}};
${fs.readFileSync("babel-node.js")}
global.babel = module.exports;
})();\n
(function() {
var module = undefined, exports = undefined;
${files.map(ea => fs.readFileSync(ea)).join("\n\n")}\n
})();\n
${init}
`);
console.log(path.join(__dirname, targetFile) + " written");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment