@iobroker/legacy-testing 0.2.3 → 0.2.4
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.
- package/README.md +1 -1
- package/package.json +1 -1
- package/setup.js +89 -27
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Legacy test modules for ioBroker
|
|
|
11
11
|
|
|
12
12
|
## Changelog
|
|
13
13
|
<!-- ### **WORK IN PROGRESS** -->
|
|
14
|
-
### 0.2.
|
|
14
|
+
### 0.2.4 (2023-05-07)
|
|
15
15
|
* (bluefox) Added possibility to install additional adapters at start
|
|
16
16
|
* (bluefox) Added setOfflineState/getOfflineState
|
|
17
17
|
|
package/package.json
CHANGED
package/setup.js
CHANGED
|
@@ -15,7 +15,12 @@ let JSONLDB;
|
|
|
15
15
|
|
|
16
16
|
let adapterName = path.normalize(rootDir).replace(/\\/g, '/').split('/');
|
|
17
17
|
adapterName = adapterName[adapterName.length - 2];
|
|
18
|
-
|
|
18
|
+
const adaptersStarted = {};
|
|
19
|
+
const pids = {};
|
|
20
|
+
|
|
21
|
+
let objects;
|
|
22
|
+
let states;
|
|
23
|
+
let systemConfig = null;
|
|
19
24
|
|
|
20
25
|
function getAppName() {
|
|
21
26
|
const parts = rootDir.replace(/\\/g, '/').split('/');
|
|
@@ -23,6 +28,8 @@ function getAppName() {
|
|
|
23
28
|
return parts.pop().split('.')[0];
|
|
24
29
|
}
|
|
25
30
|
|
|
31
|
+
const appName = getAppName().toLowerCase();
|
|
32
|
+
|
|
26
33
|
function loadJSONLDB() {
|
|
27
34
|
if (!JSONLDB) {
|
|
28
35
|
const dbPath = require.resolve('@alcalzone/jsonl-db', {
|
|
@@ -38,15 +45,6 @@ function loadJSONLDB() {
|
|
|
38
45
|
}
|
|
39
46
|
}
|
|
40
47
|
|
|
41
|
-
const appName = getAppName().toLowerCase();
|
|
42
|
-
|
|
43
|
-
let objects;
|
|
44
|
-
let states;
|
|
45
|
-
|
|
46
|
-
let pid = null;
|
|
47
|
-
|
|
48
|
-
let systemConfig = null;
|
|
49
|
-
|
|
50
48
|
function copyFileSync(source, target) {
|
|
51
49
|
let targetFile = target;
|
|
52
50
|
|
|
@@ -668,24 +666,25 @@ function encrypt (key, value) {
|
|
|
668
666
|
}
|
|
669
667
|
|
|
670
668
|
function startAdapter(objects, states, callback) {
|
|
671
|
-
|
|
669
|
+
const id = `${pkg.name}.0`;
|
|
670
|
+
if (adaptersStarted[id]) {
|
|
672
671
|
console.log('Adapter already started ...');
|
|
673
672
|
callback && callback(objects, states);
|
|
674
673
|
return;
|
|
675
674
|
}
|
|
676
|
-
|
|
675
|
+
adaptersStarted[id] = true;
|
|
677
676
|
console.log('startAdapter...');
|
|
678
677
|
if (fs.existsSync(`${rootDir}tmp/node_modules/${pkg.name}/${pkg.main}`)) {
|
|
679
678
|
try {
|
|
680
679
|
if (debug) {
|
|
681
680
|
// start controller
|
|
682
|
-
|
|
681
|
+
pids[id] = child_process.exec(`node node_modules/${pkg.name}/${pkg.main} --console silly`, {
|
|
683
682
|
cwd: `${rootDir}tmp`,
|
|
684
683
|
stdio: [0, 1, 2]
|
|
685
684
|
});
|
|
686
685
|
} else {
|
|
687
686
|
// start controller
|
|
688
|
-
|
|
687
|
+
pids[id] = child_process.fork(`node_modules/${pkg.name}/${pkg.main}`, ['--console', 'silly'], {
|
|
689
688
|
cwd: `${rootDir}tmp`,
|
|
690
689
|
stdio: [0, 1, 2, 'ipc']
|
|
691
690
|
});
|
|
@@ -699,6 +698,39 @@ function startAdapter(objects, states, callback) {
|
|
|
699
698
|
callback && callback(objects, states);
|
|
700
699
|
}
|
|
701
700
|
|
|
701
|
+
function startCustomAdapter(adapterName, adapterInstance) {
|
|
702
|
+
adapterInstance = adapterInstance || 0;
|
|
703
|
+
const id = `${adapterName}.${adapterInstance}`;
|
|
704
|
+
if (adaptersStarted[id]) {
|
|
705
|
+
console.log(`Adapter ${id} already started ...`);
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
adaptersStarted[`${id}`] = true;
|
|
709
|
+
console.log(`startAdapter ${id} ...`);
|
|
710
|
+
const _pkg = require(`${rootDir}tmp/node_modules/iobroker.${adapterName}/package.json`);
|
|
711
|
+
if (fs.existsSync(`${rootDir}tmp/node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'}`)) {
|
|
712
|
+
try {
|
|
713
|
+
if (debug) {
|
|
714
|
+
// start controller
|
|
715
|
+
pids[`${pkg.name}.0`] = child_process.exec(`node node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'} ${adapterInstance} --console silly`, {
|
|
716
|
+
cwd: `${rootDir}tmp`,
|
|
717
|
+
stdio: [0, 1, 2]
|
|
718
|
+
});
|
|
719
|
+
} else {
|
|
720
|
+
// start controller
|
|
721
|
+
pids[`${pkg.name}.0`] = child_process.fork(`node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'}`, [adapterInstance, '--console', 'silly'], {
|
|
722
|
+
cwd: `${rootDir}tmp`,
|
|
723
|
+
stdio: [0, 1, 2, 'ipc']
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
} catch (error) {
|
|
727
|
+
console.error(JSON.stringify(error));
|
|
728
|
+
}
|
|
729
|
+
} else {
|
|
730
|
+
console.error(`Cannot find: ${rootDir}tmp/node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'}`);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
|
|
702
734
|
function startController(isStartAdapter, onObjectChange, onStateChange, callback) {
|
|
703
735
|
if (typeof isStartAdapter === 'function') {
|
|
704
736
|
callback = onStateChange;
|
|
@@ -712,14 +744,14 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
|
|
|
712
744
|
onObjectChange = undefined;
|
|
713
745
|
}
|
|
714
746
|
|
|
715
|
-
if (
|
|
747
|
+
if (pids[`${pkg.name}.0`]) {
|
|
716
748
|
console.error('Controller is already started!');
|
|
717
749
|
} else {
|
|
718
750
|
console.log('startController...');
|
|
719
751
|
try {
|
|
720
752
|
const config = require(`${rootDir}tmp/${appName}-data/${appName}.json`);
|
|
721
753
|
|
|
722
|
-
|
|
754
|
+
adaptersStarted[`${pkg.name}.0`] = false;
|
|
723
755
|
let isObjectConnected;
|
|
724
756
|
let isStatesConnected;
|
|
725
757
|
|
|
@@ -819,27 +851,56 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
|
|
|
819
851
|
}
|
|
820
852
|
|
|
821
853
|
function stopAdapter(cb) {
|
|
822
|
-
|
|
854
|
+
const id = `${pkg.name}.0`;
|
|
855
|
+
if (!pids[id]) {
|
|
823
856
|
console.error('Controller is not running!');
|
|
824
857
|
cb && setTimeout(() => cb(false), 0);
|
|
825
858
|
} else {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
if (
|
|
859
|
+
adaptersStarted[id] = false;
|
|
860
|
+
pids[id].on('exit', (code, signal) => {
|
|
861
|
+
if (pids[id]) {
|
|
829
862
|
console.log(`child process terminated due to receipt of signal ${signal}`);
|
|
830
863
|
cb && cb();
|
|
831
|
-
|
|
864
|
+
pids[id] = null;
|
|
832
865
|
}
|
|
833
866
|
});
|
|
834
867
|
|
|
835
|
-
|
|
836
|
-
if (
|
|
868
|
+
pids[id].on('close', (/* code, signal */) => {
|
|
869
|
+
if (pids[id]) {
|
|
837
870
|
cb && cb();
|
|
838
|
-
|
|
871
|
+
pids[id] = null;
|
|
839
872
|
}
|
|
840
873
|
});
|
|
841
874
|
|
|
842
|
-
|
|
875
|
+
pids[id].kill('SIGTERM');
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
function stopCustomAdapter(adapterName, adapterInstance) {
|
|
880
|
+
const id = `${pkg.name}.0`;
|
|
881
|
+
if (!pids[id]) {
|
|
882
|
+
console.error('Controller is not running!');
|
|
883
|
+
return Promise.resolve()
|
|
884
|
+
} else {
|
|
885
|
+
adaptersStarted[id] = false;
|
|
886
|
+
return new Promise(resolve => {
|
|
887
|
+
pids[id].on('exit', (code, signal) => {
|
|
888
|
+
if (pids[id]) {
|
|
889
|
+
console.log(`child process terminated due to receipt of signal ${signal}`);
|
|
890
|
+
pids[id] = null;
|
|
891
|
+
resolve();
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
pids[id].on('close', (/* code, signal */) => {
|
|
896
|
+
if (pids[id]) {
|
|
897
|
+
pids[id] = null;
|
|
898
|
+
resolve();
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
pids[id].kill('SIGTERM');
|
|
903
|
+
});
|
|
843
904
|
}
|
|
844
905
|
}
|
|
845
906
|
|
|
@@ -889,7 +950,7 @@ function stopController(cb) {
|
|
|
889
950
|
cb(false);
|
|
890
951
|
cb = null;
|
|
891
952
|
}
|
|
892
|
-
|
|
953
|
+
pids[`${pkg.name}.0`] = null;
|
|
893
954
|
}, 5000);
|
|
894
955
|
}
|
|
895
956
|
|
|
@@ -993,9 +1054,10 @@ if (typeof module !== undefined && module.parent) {
|
|
|
993
1054
|
module.exports.installAdapter = installAdapter;
|
|
994
1055
|
module.exports.appName = appName;
|
|
995
1056
|
module.exports.adapterName = adapterName;
|
|
996
|
-
module.exports.adapterStarted = adapterStarted;
|
|
997
1057
|
module.exports.getSecret = getSecret;
|
|
998
1058
|
module.exports.encrypt = encrypt;
|
|
999
1059
|
module.exports.setOfflineState = setOfflineState;
|
|
1000
1060
|
module.exports.getOfflineState = getOfflineState;
|
|
1061
|
+
module.exports.stopCustomAdapter = stopCustomAdapter;
|
|
1062
|
+
module.exports.startCustomAdapter = startCustomAdapter;
|
|
1001
1063
|
}
|