Skip to content

Commit

Permalink
ready to deploy!
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed May 9, 2018
1 parent aba1179 commit 0c91994
Show file tree
Hide file tree
Showing 55 changed files with 3,425 additions and 144 deletions.
6 changes: 0 additions & 6 deletions dist/bin/apt_get_installer.d.ts

This file was deleted.

82 changes: 0 additions & 82 deletions dist/bin/apt_get_installer.js

This file was deleted.

3 changes: 3 additions & 0 deletions dist/bin/build_dist_tarball.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare const module_dir_path: string;
export declare function execSyncInherit(cmd: string, options?: any): void;
export declare function find_module_path(module_name: string, root_module_path: string): string;
113 changes: 113 additions & 0 deletions dist/bin/build_dist_tarball.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr/bin/env node
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __values = (this && this.__values) || function (o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
};
Object.defineProperty(exports, "__esModule", { value: true });
require("rejection-tracker").main(__dirname, "..", "..");
var child_process = require("child_process");
var scriptLib = require("../tools/scriptLib");
var path = require("path");
exports.module_dir_path = path.join(__dirname, "..", "..");
function execSyncInherit(cmd, options) {
if (options === void 0) { options = {}; }
console.log(scriptLib.colorize("$ " + cmd, "YELLOW") + "\n");
child_process.execSync(cmd, __assign({ "stdio": "inherit" }, options));
}
exports.execSyncInherit = execSyncInherit;
function find_module_path(module_name, root_module_path) {
var cmd = [
"dirname $(",
"find " + path.join(root_module_path, "node_modules") + " ",
"-type f -path \\*/node_modules/" + module_name + "/package.json",
")"
].join("");
var match = child_process
.execSync(cmd, { "stdio": [] })
.toString("utf8")
.split("\n");
match.pop();
if (!match.length) {
throw new Error("Not found");
}
else {
return match.sort(function (a, b) { return a.length - b.length; })[0];
}
}
exports.find_module_path = find_module_path;
var working_directory_path = path.join(exports.module_dir_path, "working_directory");
if (require.main === module) {
var dist_dir_name_1 = [
"dongle",
"v" + require(path.join(exports.module_dir_path, "package.json"))["version"],
child_process.execSync("uname -m").toString("utf8").replace("\n", "")
].join("_");
console.log({ dist_dir_name: dist_dir_name_1 });
var dist_dir_path_1 = path.join(working_directory_path, dist_dir_name_1);
(function () {
var tmp_dir_path = path.join("/tmp", dist_dir_name_1);
execSyncInherit("rm -rf " + tmp_dir_path);
execSyncInherit("cp -r " + exports.module_dir_path + " " + tmp_dir_path);
execSyncInherit("rm -rf " + dist_dir_path_1);
execSyncInherit("mv " + tmp_dir_path + " " + dist_dir_path_1);
})();
execSyncInherit("cp " + path.join(working_directory_path, "node") + " " + dist_dir_path_1);
(function () {
var node_python_messaging_path = find_module_path("node-python-messaging", dist_dir_path_1);
execSyncInherit("rm -r " + path.join(node_python_messaging_path, "dist", "virtual"));
})();
(function () {
var udev_module_path = find_module_path("udev", dist_dir_path_1);
execSyncInherit("rm -r " + path.join(udev_module_path, "build"));
})();
try {
for (var _a = __values([".git", ".gitignore", "src", "tsconfig.json"]), _b = _a.next(); !_b.done; _b = _a.next()) {
var name = _b.value;
execSyncInherit("rm -r " + path.join(dist_dir_path_1, name));
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_1) throw e_1.error; }
}
try {
for (var _d = __values(["@types", "typescript"]), _e = _d.next(); !_e.done; _e = _d.next()) {
var name = _e.value;
execSyncInherit("rm -r " + path.join(dist_dir_path_1, "node_modules", name));
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
}
finally { if (e_2) throw e_2.error; }
}
execSyncInherit("find " + path.join(dist_dir_path_1, "node_modules") + " -type f -name \"*.ts\" -exec rm -rf {} \\;");
execSyncInherit("rm -r " + path.join(dist_dir_path_1, path.basename(working_directory_path)));
execSyncInherit("tar -czf " + path.join(working_directory_path, dist_dir_name_1 + ".tar.gz") + " -C " + dist_dir_path_1 + " .");
execSyncInherit("rm -r " + dist_dir_path_1);
console.log("---DONE---");
//mkdir foo
//tar -xzf bar.tar.gz -C foo
// /usr/share
}
var e_1, _c, e_2, _f;
Empty file modified dist/bin/cli.js
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions dist/bin/configure_dist.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
88 changes: 88 additions & 0 deletions dist/bin/configure_dist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env node
"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
var __values = (this && this.__values) || function (o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
};
Object.defineProperty(exports, "__esModule", { value: true });
var path = require("path");
var build_dist_tarball_1 = require("./build_dist_tarball");
var fs = require("fs");
var node_path = path.join(build_dist_tarball_1.module_dir_path, "node");
var bin_dir_path = path.join(build_dist_tarball_1.module_dir_path, "dist", "bin");
var args = (function () {
var out = __spread(process.argv);
out.shift();
out.shift();
return out.map(function (v) { return "\"" + v + "\""; }).join(" ");
})();
var runInstaller = function () { return build_dist_tarball_1.execSyncInherit(node_path + " " + path.join(bin_dir_path, "installer.js") + " install " + args); };
if (!!args.match(/\-\-help/) || !!args.match(/\-h/)) {
runInstaller();
process.exit(0);
}
build_dist_tarball_1.execSyncInherit(node_path + " " + path.join(bin_dir_path, "install_prereq"));
(function build_udev() {
var udev_dir_path = build_dist_tarball_1.find_module_path("udev", build_dist_tarball_1.module_dir_path);
if (fs.existsSync(path.join(udev_dir_path, "build"))) {
return;
}
var pre_gyp_dir_path = "";
try {
for (var _a = __values([udev_dir_path, build_dist_tarball_1.module_dir_path]), _b = _a.next(); !_b.done; _b = _a.next()) {
var root_module_path = _b.value;
try {
pre_gyp_dir_path = build_dist_tarball_1.find_module_path("node-pre-gyp", root_module_path);
break;
}
catch (_c) { }
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
}
finally { if (e_1) throw e_1.error; }
}
build_dist_tarball_1.execSyncInherit([
"PATH=" + path.join(build_dist_tarball_1.module_dir_path) + ":$PATH",
"node " + path.join(pre_gyp_dir_path, "bin", "node-pre-gyp") + " install",
"--fallback-to-build"
].join(" "), { "cwd": udev_dir_path });
var e_1, _d;
})();
(function postinstall_node_python_messaging() {
var node_python_messaging_dir_path = build_dist_tarball_1.find_module_path("node-python-messaging", build_dist_tarball_1.module_dir_path);
if (fs.existsSync(path.join(node_python_messaging_dir_path, "dist", "virtual"))) {
return;
}
build_dist_tarball_1.execSyncInherit("./install-python-dep.sh", { "cwd": node_python_messaging_dir_path });
})();
runInstaller();
Empty file modified dist/bin/install_prereq.js
100755 → 100644
Empty file.
25 changes: 16 additions & 9 deletions dist/bin/installer.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ require("rejection-tracker").main(__dirname, "..", "..");
var program = require("commander");
var child_process = require("child_process");
var execSync = function (cmd) { return child_process.execSync(cmd).toString("utf8"); };
var execSyncSilent = function (cmd) { return child_process.execSync(cmd, { stdio: [] }).toString("utf8"); };
var execSyncSilent = function (cmd) { return child_process.execSync(cmd, { "stdio": [] }).toString("utf8"); };
var fs = require("fs");
var path = require("path");
var scriptLib = require("../tools/scriptLib");
var readline = require("readline");
var localsManager = require("../lib/localsManager");
var node_path = process.argv[0];
var module_path = path.join(__dirname, "..", "..");
var _a = __read(["cli.js", "main.js"].map(function (f) { return path.join(module_path, "dist", "bin", f); }), 2), cli_js_path = _a[0], main_js_path = _a[1];
var working_directory_path = path.join(module_path, "working_directory");
var stop_sh_path = path.join(working_directory_path, "stop.sh");
var wait_ast_sh_path = path.join(working_directory_path, "wait_ast.sh");
var node_path = path.join(working_directory_path, "node");
var _install = program.command("install");
for (var key in localsManager.Locals.defaults) {
var value = localsManager.Locals.defaults[key];
Expand Down Expand Up @@ -166,23 +166,26 @@ _install.action(function (options) { return __awaiter(_this, void 0, void 0, fun
case 2:
_b.sent();
console.log("DONE");
_b.label = 3;
return [3 /*break*/, 4];
case 3:
_b.trys.push([3, 5, , 7]);
return [4 /*yield*/, install(locals, astdirs)];
execSyncSilent("pkill -u " + locals.service_name + " -SIGUSR2 || true");
_b.label = 4;
case 4:
_b.sent();
return [3 /*break*/, 7];
_b.trys.push([4, 6, , 8]);
return [4 /*yield*/, install(locals, astdirs)];
case 5:
_b.sent();
return [3 /*break*/, 8];
case 6:
_a = _b.sent();
process.stdout.write(scriptLib.colorize("Rollback install ...", "YELLOW"));
return [4 /*yield*/, uninstall(locals, astdirs)];
case 6:
case 7:
_b.sent();
console.log("DONE");
process.exit(-1);
return [2 /*return*/];
case 7:
case 8:
console.log("---DONE---");
process.exit(0);
return [2 /*return*/];
Expand Down Expand Up @@ -218,6 +221,7 @@ function install(locals, astdirs) {
astetcdir = astdirs.astetcdir, astsbindir = astdirs.astsbindir, astmoddir = astdirs.astmoddir, astrundir = astdirs.astrundir;
unixUser.create(locals.service_name);
workingDirectory.create(locals.service_name);
execSync("cp $(readlink -e " + process.argv[0] + ") " + node_path);
(function () {
var local_path = path.join(working_directory_path, localsManager.file_name);
fs.writeFileSync(local_path, Buffer.from(JSON.stringify(locals, null, 2), "utf8"));
Expand Down Expand Up @@ -541,6 +545,8 @@ var unixUser;
(function (unixUser) {
function create(service_name) {
process.stdout.write("Creating unix user '" + service_name + "' ... ");
execSyncSilent("pkill -u " + service_name + " -SIGUSR2 || true");
execSyncSilent("userdel " + service_name + " || true");
execSync("useradd -M " + service_name + " -s /bin/false -d " + working_directory_path);
console.log(scriptLib.colorize("OK", "GREEN"));
}
Expand Down Expand Up @@ -630,6 +636,7 @@ var systemd;
fs.writeFileSync(service_path, Buffer.from(service, "utf8"));
execSync("systemctl daemon-reload");
execSync("systemctl enable " + service_name + " --quiet");
execSync("systemctl start " + service_name);
console.log(scriptLib.colorize("OK", "GREEN"));
}
systemd.create = create;
Expand Down
Empty file modified dist/bin/main.js
100755 → 100644
Empty file.
3 changes: 0 additions & 3 deletions dist/lib/bridge.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions dist/src/bin/build_dist_tarball.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
Loading

0 comments on commit 0c91994

Please sign in to comment.