1 | "use strict";
|
2 |
|
3 | var _a;
|
4 | Object.defineProperty(exports, "__esModule", { value: true });
|
5 | exports.Adapter = exports.adapter = exports.getConfig = exports.controllerDir = void 0;
|
6 | const fs = require("fs");
|
7 | const path = require("path");
|
8 | const helpers_1 = require("./helpers");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function getControllerDir(isInstall) {
|
14 |
|
15 | const possibilities = ["iobroker.js-controller", "ioBroker.js-controller"];
|
16 |
|
17 | let controllerDir = (0, helpers_1.tryResolvePackage)(possibilities);
|
18 |
|
19 |
|
20 | if (controllerDir)
|
21 | return controllerDir;
|
22 |
|
23 | controllerDir = (0, helpers_1.scanForPackage)(possibilities);
|
24 | if (controllerDir)
|
25 | return controllerDir;
|
26 | if (!isInstall) {
|
27 | console.log("Cannot find js-controller");
|
28 | return process.exit(10);
|
29 | }
|
30 | else {
|
31 | return process.exit();
|
32 | }
|
33 | }
|
34 |
|
35 | exports.controllerDir = getControllerDir(!!((_a = process === null || process === void 0 ? void 0 : process.argv) === null || _a === void 0 ? void 0 : _a.includes("--install")));
|
36 | function resolveAdapterConstructor() {
|
37 |
|
38 | let adapterPath = (0, helpers_1.tryResolvePackage)(["@iobroker/js-controller-adapter"]);
|
39 | if (adapterPath) {
|
40 | try {
|
41 | const { Adapter } = require(adapterPath);
|
42 | if (Adapter)
|
43 | return Adapter;
|
44 | }
|
45 | catch (_a) {
|
46 |
|
47 | }
|
48 | }
|
49 |
|
50 | adapterPath = (0, helpers_1.tryResolvePackage)(["@iobroker/js-controller-adapter"], [path.join(exports.controllerDir, "node_modules")]);
|
51 | if (adapterPath) {
|
52 | try {
|
53 | const { Adapter } = require(adapterPath);
|
54 | if (Adapter)
|
55 | return Adapter;
|
56 | }
|
57 | catch (_b) {
|
58 |
|
59 | }
|
60 | }
|
61 |
|
62 | adapterPath = path.join(exports.controllerDir, "lib/adapter.js");
|
63 | try {
|
64 |
|
65 | const Adapter = require(adapterPath);
|
66 | if (Adapter)
|
67 | return Adapter;
|
68 | }
|
69 | catch (_c) {
|
70 |
|
71 | }
|
72 |
|
73 | adapterPath = path.join(exports.controllerDir, "build/lib/adapter.js");
|
74 | try {
|
75 |
|
76 | const Adapter = require(adapterPath);
|
77 | if (Adapter)
|
78 | return Adapter;
|
79 | }
|
80 | catch (_d) {
|
81 |
|
82 | }
|
83 | throw new Error("Cannot resolve adapter class");
|
84 | return process.exit(10);
|
85 | }
|
86 |
|
87 | function getConfig() {
|
88 | return JSON.parse(fs.readFileSync(path.join(exports.controllerDir, "conf/iobroker.json"), "utf8"));
|
89 | }
|
90 | exports.getConfig = getConfig;
|
91 |
|
92 | exports.adapter = resolveAdapterConstructor();
|
93 |
|
94 | exports.Adapter = exports.adapter;
|