-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathleo-cli-test.js
83 lines (74 loc) · 2.11 KB
/
leo-cli-test.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env node
var path = require('path');
var program = require('commander');
var colors = require('colors');
const utils = require("./lib/utils.js");
const watch = require("node-watch");
const fork = require("child_process").fork;
program
.version('0.0.1')
.option("-e, --env [env]", "Environment")
.option("--region [region]", "Region to run cloudformation")
.usage('<dir> [options]')
.action(function(dir) {
let rootDir = path.resolve(process.cwd(), dir);
let watchDir = utils.findFirstPackageValue(rootDir, ["microservice"], "__directory");
var pkg = require(path.resolve(rootDir, "package.json"));
var reactRunner = require("./lib/react.js");
var buildConfig = require("./lib/build-config").build;
if (pkg.config && pkg.config.leo && pkg.config.leo.type == "microservice") {
let c = buildConfig(rootDir);
reactRunner(rootDir, c, c);
} else {
let child = null;
function run() {
function f() {
child = fork(__dirname + "/lib/runner.js", process.argv, {
cwd: rootDir,
env: Object.assign({}, process.env, {
LEO_ENV: program.env || "dev",
LEO_REGION: program.region,
LEO_CONFIG: JSON.stringify(buildConfig(rootDir)),
LEO_PREVENT_RUN_AGAIN: "true"
}),
//execArgv: ["--inspect", "--debug-brk"]
});
//process.kill(child.pid, 'USR1');
child.once("exit", () => {
child = null;
});
}
if (child) {
child.once("exit", f);
child.kill();
} else {
f();
}
}
process.on('SIGINT', () => {
if (child) {
console.log("closing child process. Ctrl-c again to cancel test");
child.kill();
} else {
watcher.close();
process.exit();
}
});
run();
let watchDirs = (watchDir ? [watchDir] : []).concat(pkg.config.test ? pkg.config.test.watch : []);
console.log(watchDirs);
var watcher = watch(watchDirs, {
recursive: true,
filter: (f) => {
return !/node_modules/.test(f)
}
}, (eventType, filename) => {
console.log("new file");
run();
});
}
})
.parse(process.argv);
if (!process.argv.slice(2).length) {
program.outputHelp(colors.red);
}