-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunDev.js
93 lines (85 loc) · 2.92 KB
/
runDev.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
84
85
86
87
88
89
90
91
92
"use strict";
var { execSync, execFile, spawn } = require("child_process");
var fs = require("fs");
var path = require("path");
var processLogger = require("./processLogger");
// var {StringDecoder} = require("string_decoder");
// var decoder = new StringDecoder("utf8");
let go = ["blank-sr", "blank-router", "blank-cron", "blank-filestore"];
let node = ["blank-node-worker"];
let jsPath = "../";
module.exports = function (jsPathArg, update) {
jsPath = jsPathArg || jsPath;
try {
for (let nPackage of node) {
let packagePath = path.resolve(jsPath) + path.sep + nPackage + path.sep;
console.log(`Checking package ${nPackage} in '${packagePath}'`);
fs.accessSync(packagePath, fs.F_OK);
}
} catch (e) {
console.log("Cannot find one or more js packages, check '--js-path' argument");
return;
}
try {
fs.accessSync(process.env.GOPATH, fs.F_OK);
} catch (e) {
console.log("$GOPATH env variable is not accessible. $GOPATH value:", process.env.GOPATH);
return;
}
if (update) {
_update();
} else {
_run();
}
};
function _update() {
let _jsPath = path.resolve(jsPath) + path.sep,
done = false;
try {
execSync("pkill -f blank-");
console.log("All Blank processes stopped");
} catch (err) {
console.error("_update error", err)
}
try {
for (let i = 0; i < go.length; i++) {
let p = go[i];
console.log(`Updating Go package ${i + 1}/${go.length}`);
let _path = `${process.env.GOPATH}/src/github.com/getblank/${p}`;
execSync(`go get -u -d github.com/getblank/${p} && cd ${_path} && go generate && go install`);
console.log(p, "done");
}
for (let i = 0; i < node.length; i++) {
let p = node[i];
console.log(`Updating Node package ${i} of ${node.length}`);
execSync(`cd ${_jsPath + p} && git pull && npm install && npm run prestart`);
console.log(p, "done");
}
done = true;
console.log("Update completed");
} catch (e) {
console.error(`Error while updating packages: ${e}`);
}
if (done) {
_run();
}
}
function _run() {
for (const packageName of go) {
const p = execFile(packageName, {
cwd: `${process.env.GOPATH}/src/github.com/getblank/${packageName}`,
});
processLogger.bindStreams(p, packageName);
}
for (const packageName of node) {
const cwd = path.resolve(jsPath) + path.sep + packageName + path.sep;
const p = spawn("node", ["--harmony_async_await", ".", "--sr", "ws://localhost:2345"], {
cwd: cwd,
env: Object.assign({}, process.env, {
NODE_PATH: "./lib/blank-js-core",
NODE_ENV: "PRODUCTION",
}),
});
processLogger.bindStreams(p, packageName, true);
}
}