2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-01 09:39:41 -06:00
|
|
|
*/
|
|
|
|
|
|
2021-06-05 22:11:47 -04:00
|
|
|
const path = require('path');
|
|
|
|
|
const { isWindows } = require('../helpers/platform.js');
|
2023-09-26 16:36:13 -04:00
|
|
|
const isDev = require('electron-is-dev');
|
2024-10-04 16:35:18 +02:00
|
|
|
const { existsSync } = require('node:fs');
|
|
|
|
|
const which = require('which');
|
2021-06-05 22:11:47 -04:00
|
|
|
|
2024-10-04 16:35:18 +02:00
|
|
|
const binaryName = isWindows() ? 'boundary.exe' : 'boundary';
|
|
|
|
|
const builtInCliPath = isDev
|
|
|
|
|
? path.resolve(__dirname, '..', '..', 'cli', binaryName)
|
|
|
|
|
: path.resolve(process.resourcesPath, 'cli', binaryName);
|
|
|
|
|
|
|
|
|
|
// Return true if the CLI in usage is the built in. False if relies on system CLI.
|
|
|
|
|
const isBuiltInCli = existsSync(builtInCliPath);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns Boundary CLI path if the CLI is built in or the Boundary binary name
|
|
|
|
|
* if not, so we assume boundary is available within user $PATH.
|
|
|
|
|
*/
|
|
|
|
|
const pathBoundary = isBuiltInCli
|
|
|
|
|
? builtInCliPath
|
|
|
|
|
: // On Windows, we need to filter out the path that is within the current working directory.
|
2025-04-29 15:32:50 -07:00
|
|
|
// This is necessary because the spawn methods may not always find the correct binary path.
|
|
|
|
|
// The `which` module returns an array of all available paths for the 'boundary' binary.
|
|
|
|
|
// We then filter out the path that is within the current working directory.
|
|
|
|
|
isWindows()
|
|
|
|
|
? which
|
|
|
|
|
.sync(binaryName, { nothrow: true, all: true })
|
|
|
|
|
.filter((binary) => !binary.startsWith(process.cwd()))[0]
|
|
|
|
|
: binaryName;
|
2023-09-26 16:36:13 -04:00
|
|
|
|
2024-10-04 16:35:18 +02:00
|
|
|
module.exports = {
|
|
|
|
|
path: pathBoundary,
|
|
|
|
|
isBuiltInCli,
|
2021-06-05 22:11:47 -04:00
|
|
|
};
|