Files
threshold-ui/ui/desktop/electron-app/src/cli/path.js
T
Lisbet Alvarez c5353d6e5e Icu 16547 upgrade ember desktop UI (#2796)
* v4.12.2...v5.12.0

* chore: 🤖 yarn.lock file changes

* chore: 🤖 ember init blueprint updates

* chore: 🤖 yarn.lock changes

* style: 💄 run linter and formatter

* chore: 🤖 yarn.lock file changes

* chore: 🤖 remove ember-cli-app-version

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-16547
2025-04-29 15:32:50 -07:00

40 lines
1.4 KiB
JavaScript

/**
* 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');
const { existsSync } = require('node:fs');
const which = require('which');
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.
// 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;
module.exports = {
path: pathBoundary,
isBuiltInCli,
};