Files
threshold-ui/ui/desktop/electron-app/src/cli/path.js
T

39 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
const path = require('path');
const { isWindows } = require('../helpers/platform.js');
const isDev = require('electron-is-dev');
2024-10-04 16:35:18 +02:00
const { existsSync } = require('node:fs');
const which = require('which');
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;
2024-10-04 16:35:18 +02:00
module.exports = {
path: pathBoundary,
isBuiltInCli,
};