@itentialopensource/adapter-meraki 0.8.0 → 0.8.3

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/utils/tbUtils.js CHANGED
@@ -352,13 +352,7 @@ module.exports = {
352
352
 
353
353
  // get database connection and existing adapter config
354
354
  getAdapterConfig: async function getAdapterConfig() {
355
- const newDirname = this.getDirname();
356
- let iapDir;
357
- if (this.withinIAP(newDirname)) { // when this script is called from IAP
358
- iapDir = newDirname;
359
- } else {
360
- iapDir = path.join(this.getDirname(), 'utils', '../../../../');
361
- }
355
+ const iapDir = this.getIAPHome();
362
356
  const pronghornProps = this.getPronghornProps(iapDir);
363
357
  console.log('Connecting to Database...');
364
358
  const database = await this.connect(iapDir, pronghornProps);
@@ -434,6 +428,25 @@ module.exports = {
434
428
  return stdout.trim();
435
429
  },
436
430
 
431
+ /**
432
+ * @summary Obtain the IAP installation directory depending on how adapter is used:
433
+ * by IAP, or by npm run CLI interface
434
+ * @returns IAP installation directory
435
+ * @function getIAPHome
436
+ */
437
+ getIAPHome: function getIAPHome() {
438
+ // if adapter started via IAP, use path injected by core
439
+ if (process.env.iap_home) return process.env.iap_home;
440
+ // adapter started via CLI `npm run <command>` so we have to be located under
441
+ // <IAP_HOME>/node_modules/@itentialopensource/<adapter>/ directory,
442
+ // use `pwd` command wihout option -P(resolving symlinks) https://linux.die.net/man/1/pwd
443
+ const { stdout } = this.systemSync('pwd', true);
444
+ if (stdout.indexOf('/node_modules') >= 0) {
445
+ return stdout.trim().split('/node_modules')[0];
446
+ }
447
+ return path.join(stdout.trim(), '../../../');
448
+ },
449
+
437
450
  /**
438
451
  * @summary connect to mongodb
439
452
  *