-
Notifications
You must be signed in to change notification settings - Fork 3
/
magic-ws.js
61 lines (50 loc) · 1.62 KB
/
magic-ws.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var path = require("path");
var getPackageDescriptions = require("./get-package-descriptions");
var options = require("commander")
.usage("magic-ws [commands]")
.option("-w, --workspace [workspace]", "Workspace location", collect, [])
.option("-p, --package [package]", "Package location", collect, [])
.option("-b, --babel", "Turn on automatic Babel transpilation")
.parse(getBootstrappedArgv());
var cwd = process.cwd();
var workspaces = options.workspace;
var packages = options.package;
var descriptions = getPackageDescriptions(workspaces, packages);
require("./modify-resolve-lookup-paths")(descriptions);
if (options.babel)
{
try
{
var presetPath = require.resolve("@isomorphic/babel-preset");
var node = process.versions.node;
var registrations = require("./get-registrations")(node, descriptions, presetPath);
require("./babel-register")(registrations);
}
catch (e)
{
throw new Error("--babel is not yet supported.");
}
}
function resolve(relative)
{
return path.resolve(cwd, relative);
}
function collect(val, memo)
{
memo.push(val);
return memo;
}
function getBootstrappedArgv()
{
var bootstrapArgs = process.env["MAGIC_WS_BOOTSTRAP_ARGS"];
var bootstrapArgv = [process.argv0, __filename];
var index = 0;
while (index < bootstrapArgs.length)
{
var semicolon = bootstrapArgs.indexOf(";", index);
var length = +bootstrapArgs.substring(index, semicolon);
bootstrapArgv.push(bootstrapArgs.substr(semicolon + 1, length));
index = semicolon + length + 1;
}
return bootstrapArgv;
}