1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.commonTools = exports.resolveNamedModule = exports.controllerToolsInternal = exports.controllerCommonModulesInternal = void 0;
|
4 | const path = require("path");
|
5 | const helpers_1 = require("./helpers");
|
6 | const utils = require("./utils");
|
7 | function resolveControllerTools() {
|
8 |
|
9 | let importPath = (0, helpers_1.tryResolvePackage)(["@iobroker/js-controller-common"]);
|
10 | if (importPath) {
|
11 | try {
|
12 | exports.controllerCommonModulesInternal = require(importPath);
|
13 | const { tools } = exports.controllerCommonModulesInternal;
|
14 | if (tools)
|
15 | return tools;
|
16 | }
|
17 | catch (_a) {
|
18 |
|
19 | }
|
20 | }
|
21 |
|
22 | importPath = (0, helpers_1.tryResolvePackage)(["@iobroker/js-controller-common"], [path.join(utils.controllerDir, "node_modules")]);
|
23 | if (importPath) {
|
24 | try {
|
25 | exports.controllerCommonModulesInternal = require(importPath);
|
26 | const { tools } = exports.controllerCommonModulesInternal;
|
27 | if (tools)
|
28 | return tools;
|
29 | }
|
30 | catch (_b) {
|
31 |
|
32 | }
|
33 | }
|
34 |
|
35 | importPath = path.join(utils.controllerDir, "lib");
|
36 | try {
|
37 |
|
38 | const tools = require(path.join(importPath, "tools"));
|
39 | if (tools)
|
40 | return tools;
|
41 | }
|
42 | catch (_c) {
|
43 |
|
44 | }
|
45 | throw new Error("Cannot resolve tools module");
|
46 | return process.exit(10);
|
47 | }
|
48 |
|
49 | exports.controllerToolsInternal = resolveControllerTools();
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | function resolveNamedModule(name, exportName = name) {
|
57 |
|
58 | if (exports.controllerCommonModulesInternal === null || exports.controllerCommonModulesInternal === void 0 ? void 0 : exports.controllerCommonModulesInternal[exportName])
|
59 | return exports.controllerCommonModulesInternal[exportName];
|
60 |
|
61 |
|
62 | let importPath = path.join(utils.controllerDir, "build/lib", name);
|
63 | try {
|
64 |
|
65 | const module = require(importPath);
|
66 | if (module)
|
67 | return module;
|
68 | }
|
69 | catch (_a) {
|
70 |
|
71 | }
|
72 |
|
73 | importPath = path.join(utils.controllerDir, "lib", name);
|
74 | try {
|
75 |
|
76 | const module = require(importPath);
|
77 | if (module)
|
78 | return module;
|
79 | }
|
80 | catch (_b) {
|
81 |
|
82 | }
|
83 | throw new Error(`Cannot resolve JS-Controller module ${name}.js`);
|
84 | return process.exit(10);
|
85 | }
|
86 | exports.resolveNamedModule = resolveNamedModule;
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | function pattern2RegEx(pattern) {
|
93 | return exports.controllerToolsInternal.pattern2RegEx(pattern);
|
94 | }
|
95 | exports.commonTools = {
|
96 | pattern2RegEx,
|
97 |
|
98 | password: resolveNamedModule("password"),
|
99 | letsEncrypt: resolveNamedModule("letsencrypt"),
|
100 | session: resolveNamedModule("session"),
|
101 | zipFiles: resolveNamedModule("zipFiles"),
|
102 |
|
103 | };
|