@iobroker/legacy-testing 1.0.5 → 1.0.7

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.
Files changed (3) hide show
  1. package/README.md +6 -0
  2. package/package.json +1 -1
  3. package/setup.js +35 -5
package/README.md CHANGED
@@ -14,6 +14,12 @@ Set process.env.JS_CONTROLLER_VERSION to version e.g. `5.0.5-alpha.0-20230617-46
14
14
 
15
15
  ## Changelog
16
16
  <!-- ### **WORK IN PROGRESS** -->
17
+ ### 1.0.7 (2023-12-19)
18
+ * (foxriver76) allow re-initialization after config change
19
+
20
+ ### 1.0.6 (2023-12-19)
21
+ * (foxriver76) allow to specify the `rootDir`
22
+
17
23
  ### 1.0.5 (2023-12-15)
18
24
  * (bluefox) Added support for vis-1 testing
19
25
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.5",
2
+ "version": "1.0.7",
3
3
  "name": "@iobroker/legacy-testing",
4
4
  "main": "setup.js",
5
5
  "files": [
package/setup.js CHANGED
@@ -18,8 +18,7 @@ if (adapterName[adapterName.length - 2] === 'vis-2-widgets-testing') {
18
18
  }
19
19
  adapterName = adapterName[adapterName.length - 2];
20
20
 
21
- let pkg = require(`${rootDir}package.json`);
22
- pkg.main = pkg.main || 'main.js';
21
+ let pkg;
23
22
 
24
23
  const adaptersStarted = {};
25
24
  const pids = {};
@@ -28,6 +27,16 @@ let objects;
28
27
  let states;
29
28
  let systemConfig = null;
30
29
 
30
+ initialize();
31
+
32
+ /**
33
+ * Initialize logic, you can re-trigger it after config has changed
34
+ */
35
+ function initialize() {
36
+ pkg = require(`${rootDir}package.json`);
37
+ pkg.main = pkg.main || 'main.js';
38
+ }
39
+
31
40
  function getAppName() {
32
41
  const parts = rootDir.replace(/\\/g, '/').split('/');
33
42
  parts.pop();
@@ -400,7 +409,7 @@ async function installJsController(preInstalledAdapters, cb) {
400
409
  if (!fs.existsSync(`${rootDir}tmp/node_modules/${appName}.js-controller`)) {
401
410
  console.log('installJsController: no js-controller => install dev build from npm');
402
411
 
403
- cp.execSync(`npm install ${appName}.js-controller@${process.env.JS_CONTROLLER_VERSION || 'dev'} --prefix ./ --production`, {
412
+ cp.execSync(`npm install ${appName}.js-controller@${process.env.JS_CONTROLLER_VERSION || 'dev'} --prefix ./ --omit=dev`, {
404
413
  cwd: `${rootDir}tmp/`,
405
414
  stdio: [0, 1, 2],
406
415
  });
@@ -473,7 +482,7 @@ function copyAdapterToController() {
473
482
  stdio: [0, 1, 2],
474
483
  });
475
484
  copyFileSync(`${rootDir}${pkg.name}-${pkg.version}.tgz`, `${rootDir}tmp/${pkg.name}-${pkg.version}.tgz`);
476
- cp.execSync(`npm install ${pkg.name}-${pkg.version}.tgz --prefix ./ --production`, {
485
+ cp.execSync(`npm install ${pkg.name}-${pkg.version}.tgz --prefix ./ --omit=dev`, {
477
486
  cwd: `${rootDir}tmp`,
478
487
  stdio: [0, 1, 2],
479
488
  });
@@ -483,7 +492,7 @@ function copyAdapterToController() {
483
492
  function installCustomAdapter(adapterName) {
484
493
  if (!fs.existsSync(`${rootDir}tmp/node_modules/${adapterName}`)) {
485
494
  console.log(`Install ${adapterName}`);
486
- cp.execSync(`npm install ${adapterName} --prefix ./ --production`, {
495
+ cp.execSync(`npm install ${adapterName} --prefix ./ --omit=dev`, {
487
496
  cwd: `${rootDir}tmp/`,
488
497
  stdio: [0, 1, 2],
489
498
  });
@@ -548,6 +557,25 @@ function clearDB() {
548
557
  }
549
558
  }
550
559
 
560
+ /** @typedef {{ rootDir?: string }} LegacyTestingOptions */
561
+
562
+ /**
563
+ * Override options
564
+ *
565
+ * @param {LegacyTestingOptions} options specify attributes which should be overridden
566
+ */
567
+ function setOptions(options) {
568
+ if (options.rootDir) {
569
+ rootDir = options.rootDir
570
+ }
571
+ }
572
+
573
+ /**
574
+ * Install js-controller and setup the adapter
575
+ *
576
+ * @param {string[]} preInstalledAdapters list of adapters which need to be installed additionally
577
+ * @param {(systemConfig: Record<string, any>) => void} cb callback
578
+ */
551
579
  function setupController(preInstalledAdapters, cb) {
552
580
  if (typeof preInstalledAdapters === 'function') {
553
581
  cb = preInstalledAdapters;
@@ -960,4 +988,6 @@ if (typeof module !== undefined && module.parent) {
960
988
  module.exports.installCustomAdapter = installCustomAdapter;
961
989
  module.exports.getObject = getObject;
962
990
  module.exports.setObject = setObject;
991
+ module.exports.setOptions = setOptions;
992
+ module.exports.initialize = initialize;
963
993
  }