badmfck-api-server 4.1.31 → 4.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Deploy = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const __1 = require("../..");
|
|
11
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
12
|
+
async function Deploy(opt) {
|
|
13
|
+
if (typeof opt === "string") {
|
|
14
|
+
if (!fs_1.default.existsSync(opt)) {
|
|
15
|
+
throw new Error(`File not found: ${opt}`);
|
|
16
|
+
}
|
|
17
|
+
opt = JSON.parse(fs_1.default.readFileSync(opt).toString("utf-8"));
|
|
18
|
+
if (!opt.name || !opt.token || !opt.host || !opt.username || !opt.password) {
|
|
19
|
+
throw new Error(`Invalid deploy config file: ${opt}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const archiveName = __1.UID.sha256(opt.name.replaceAll(".", "_")) + ".tar.gz";
|
|
23
|
+
console.log("Changing Config to live");
|
|
24
|
+
const config = path_1.default.resolve("src", "Config.ts");
|
|
25
|
+
let configSrc = fs_1.default.readFileSync(config).toString("utf-8");
|
|
26
|
+
if (configSrc.indexOf("static scheme:Scheme = local;") !== -1) {
|
|
27
|
+
configSrc = configSrc.replace("static scheme:Scheme = local;", "static scheme:Scheme = live;");
|
|
28
|
+
fs_1.default.writeFileSync(config, configSrc);
|
|
29
|
+
}
|
|
30
|
+
const pkgPath = path_1.default.resolve("package.json");
|
|
31
|
+
const pkg = JSON.parse(fs_1.default.readFileSync(pkgPath).toString("utf-8"));
|
|
32
|
+
const parts = String(pkg.version || "0.0.0").split(".").map(p => parseInt(p, 10) || 0);
|
|
33
|
+
while (parts.length < 3)
|
|
34
|
+
parts.push(0);
|
|
35
|
+
parts[parts.length - 1] += 1;
|
|
36
|
+
const newVersion = parts.join(".");
|
|
37
|
+
console.log(`Bumping version: ${pkg.version} -> ${newVersion}`);
|
|
38
|
+
pkg.version = newVersion;
|
|
39
|
+
fs_1.default.writeFileSync(pkgPath, JSON.stringify(pkg, null, "\t") + "\n");
|
|
40
|
+
if (fs_1.default.existsSync(path_1.default.resolve(archiveName))) {
|
|
41
|
+
fs_1.default.rmSync(path_1.default.resolve(archiveName));
|
|
42
|
+
console.log("Removing old archive");
|
|
43
|
+
}
|
|
44
|
+
console.log("Build");
|
|
45
|
+
var execResult = run("npm run build");
|
|
46
|
+
console.log(execResult);
|
|
47
|
+
console.log("Archiving");
|
|
48
|
+
execResult = run("tar -czvf " + archiveName + " ./bin package.json");
|
|
49
|
+
console.log(execResult);
|
|
50
|
+
if (!fs_1.default.existsSync(path_1.default.resolve(archiveName))) {
|
|
51
|
+
console.error("ARCHIVE NOT CREATED!");
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
const cmd = `curl \
|
|
55
|
+
-H "Authorization: Bearer ${crypto_1.default.createHash("sha256").update(opt.username + ":" + opt.password).digest("hex")}" \
|
|
56
|
+
-F "token=${opt.token}" \
|
|
57
|
+
-F "name=${opt.name}" \
|
|
58
|
+
-F "file=@${archiveName}" \
|
|
59
|
+
"${opt.host}"`;
|
|
60
|
+
console.log("Deploying: \n" + cmd);
|
|
61
|
+
execResult = run(cmd);
|
|
62
|
+
console.log(execResult);
|
|
63
|
+
const deployedAt = new Date();
|
|
64
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
65
|
+
const stamp = `${deployedAt.getFullYear()}-${pad(deployedAt.getMonth() + 1)}-${pad(deployedAt.getDate())} ${pad(deployedAt.getHours())}:${pad(deployedAt.getMinutes())}:${pad(deployedAt.getSeconds())}`;
|
|
66
|
+
console.log(`\nDeployed v${newVersion} at ${stamp}\n`);
|
|
67
|
+
return archiveName;
|
|
68
|
+
}
|
|
69
|
+
exports.Deploy = Deploy;
|
|
70
|
+
function run(cmd) {
|
|
71
|
+
try {
|
|
72
|
+
return (0, child_process_1.execSync)(cmd, { encoding: "utf-8" });
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
console.error(`\nCommand failed: ${cmd}\n`);
|
|
76
|
+
const out = (err.stdout || "").toString().trim();
|
|
77
|
+
const errOut = (err.stderr || "").toString().trim();
|
|
78
|
+
if (out)
|
|
79
|
+
console.error(out);
|
|
80
|
+
if (errOut)
|
|
81
|
+
console.error(errOut);
|
|
82
|
+
process.exit(typeof err.status === "number" ? err.status : 1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -495,11 +495,6 @@ class DeployerService extends BaseService_1.BaseService {
|
|
|
495
495
|
}
|
|
496
496
|
async unpack(destination, uploadedFile, install, ignoreDirectoryClean) {
|
|
497
497
|
return new Promise((resolve) => {
|
|
498
|
-
if (!this._isDestinationSafe(destination)) {
|
|
499
|
-
(0, LogService_1.logError)("Refusing to unpack: destination outside projects_path", destination);
|
|
500
|
-
resolve({ code: 19, message: "Destination outside projects root", httpStatus: 500 });
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
498
|
try {
|
|
504
499
|
const tmp = path_1.default.resolve(destination, "__tmp");
|
|
505
500
|
if (fs_1.default.existsSync(tmp))
|
package/dist/index.d.ts
CHANGED
|
@@ -16,4 +16,5 @@ import { ZipUtils } from "./apiServer/helper/ZipUtils";
|
|
|
16
16
|
import { Http } from "./apiServer/http/Http";
|
|
17
17
|
import { MicroserviceHost } from "./apiServer/external/MicroserviceHost";
|
|
18
18
|
import { MicroserviceClient } from "./apiServer/external/MicroserviceClient";
|
|
19
|
-
|
|
19
|
+
import { Deploy } from "./apiServer/deployment/Deploy";
|
|
20
|
+
export { MicroserviceHost, MicroserviceClient, Http, ZipUtils, UID, YYYYMMDDHH, JSONStableStringify, APIService, Initializer, LocalRequest, ValidationModel, MysqlService, TimeframeService, Validator, LogService, DataProvider, ErrorUtils, ExternalService, DBService, Deploy, S_MONITOR_REGISTRATE_ACTION };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.S_MONITOR_REGISTRATE_ACTION = exports.DBService = exports.ExternalService = exports.ErrorUtils = exports.DataProvider = exports.LogService = exports.Validator = exports.TimeframeService = exports.MysqlService = exports.LocalRequest = exports.Initializer = exports.APIService = exports.JSONStableStringify = exports.YYYYMMDDHH = exports.UID = exports.ZipUtils = exports.Http = exports.MicroserviceClient = exports.MicroserviceHost = void 0;
|
|
3
|
+
exports.S_MONITOR_REGISTRATE_ACTION = exports.Deploy = exports.DBService = exports.ExternalService = exports.ErrorUtils = exports.DataProvider = exports.LogService = exports.Validator = exports.TimeframeService = exports.MysqlService = exports.LocalRequest = exports.Initializer = exports.APIService = exports.JSONStableStringify = exports.YYYYMMDDHH = exports.UID = exports.ZipUtils = exports.Http = exports.MicroserviceClient = exports.MicroserviceHost = void 0;
|
|
4
4
|
const APIService_1 = require("./apiServer/APIService");
|
|
5
5
|
Object.defineProperty(exports, "APIService", { enumerable: true, get: function () { return APIService_1.APIService; } });
|
|
6
6
|
Object.defineProperty(exports, "Initializer", { enumerable: true, get: function () { return APIService_1.Initializer; } });
|
|
@@ -38,3 +38,5 @@ const MicroserviceHost_1 = require("./apiServer/external/MicroserviceHost");
|
|
|
38
38
|
Object.defineProperty(exports, "MicroserviceHost", { enumerable: true, get: function () { return MicroserviceHost_1.MicroserviceHost; } });
|
|
39
39
|
const MicroserviceClient_1 = require("./apiServer/external/MicroserviceClient");
|
|
40
40
|
Object.defineProperty(exports, "MicroserviceClient", { enumerable: true, get: function () { return MicroserviceClient_1.MicroserviceClient; } });
|
|
41
|
+
const Deploy_1 = require("./apiServer/deployment/Deploy");
|
|
42
|
+
Object.defineProperty(exports, "Deploy", { enumerable: true, get: function () { return Deploy_1.Deploy; } });
|