Skip to content

Commit

Permalink
support user server main exporting a function
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Apr 11, 2018
1 parent 837a87c commit 8bdb189
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/electrode-archetype-react-app/support/babel-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,27 @@ const Path = require("path");

const serverDir = process.argv[2] || "src/server";

let start;

try {
// Try to load user's dev.js under src/server
require(Path.resolve(serverDir, "dev.js"));
start = require(Path.resolve(serverDir, "dev.js"));
} catch (e) {
const cwdNM = Path.resolve("node_modules");
const cwd = process.cwd();

// fallback to default action that loads babel-register and then requires
// src/server, under which there should be an index.js file.
require("babel-register")({ only: x => {
x = Path.normalize(x);
return x.startsWith(cwd) && !x.startsWith(cwdNM);
}});
require(Path.resolve(serverDir));
require("babel-register")({
only: x => {
x = Path.normalize(x);
return x.startsWith(cwd) && !x.startsWith(cwdNM);
}
});
const fullServerDir = Path.resolve(serverDir);
start = require(fullServerDir);
}

if (typeof start === "function") {
start();
}

0 comments on commit 8bdb189

Please sign in to comment.