spacedrive/scripts/which.mjs
Vítor Vasconcellos bd0a7ff434
[ENG-265] Improve setup scripts (#1368)
* Setup script revamp

* Move toml to dev dep + CI runs the postinstall in debug mode

* Fix windows CI

* chmod +x scripts/setup.sh

* Fix eslint and ts CI

* Remove binstall + Fix trying to read input in CI

* Doesn't need to check pnpm and rust in CI

* Run postinstall script for Clippy CI

* Attempt to fix windows CI not running postinstall
 - Ignore cache when running postinstall on CI

* commited generated config.toml by mistake

* Pass GITHUB_TOKEN to `pnpm i`

* Update archive-wasm + Increase minimum node version to 18.17

* CI: Move rust setup after post-install script

* Revert: CI: Move rust setup after post-install script

* Fix CI, generate dummy cargo config.toml to fix prisma generation

* Fix windows CI

* CI: Fix wrong command

---------

Co-authored-by: Utku <74243531+utkubakir@users.noreply.github.com>
2023-09-28 10:03:46 +00:00

42 lines
876 B
JavaScript

import { exec as execCb } from 'node:child_process';
import * as fs from 'node:fs/promises';
import * as os from 'node:os';
import * as path from 'node:path';
import { env } from 'node:process';
import { promisify } from 'node:util';
const exec = promisify(execCb);
/**
* @param {string} progName
* @returns {Promise<boolean>}
*/
async function where(progName) {
// Reject paths
if (/[\\]/.test(progName)) return false;
try {
await exec(`where "${progName}"`);
} catch {
return false;
}
return true;
}
/**
* @param {string} progName
* @returns {Promise<boolean>}
*/
export async function which(progName) {
return os.type() === 'Windows_NT'
? where(progName)
: Promise.any(
Array.from(new Set(env.PATH?.split(':'))).map((dir) =>
fs.access(path.join(dir, progName), fs.constants.X_OK)
)
).then(
() => true,
() => false
);
}