This repository was archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathlinux.ts
49 lines (42 loc) · 1.73 KB
/
linux.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as childProcess from "child_process";
import * as path from "path";
import { IHostPlatform } from "../i-host-platform";
import { fileExistsSync } from "../util";
export class LinuxPlatform implements IHostPlatform {
public resolveArduinoPath(useArduinoCli?: boolean): string {
let pathString;
try {
const appName = useArduinoCli ? 'arduino-cli' : 'arduino'
pathString = childProcess.execSync(`readlink -f $(which ${appName})`, { encoding: "utf8" });
pathString = path.resolve(pathString).trim();
if (fileExistsSync(pathString)) {
pathString = path.dirname(path.resolve(pathString));
}
} catch (ex) {
// Ignore the errors.
}
return pathString || "";
}
public validateArduinoPath(arduinoPath: string, useArduinoCli?: boolean) {
return fileExistsSync(path.join(arduinoPath, useArduinoCli ? "arduino-cli" : "arduino"));
}
public findFile(fileName: string, cwd: string): string {
let pathString;
try {
pathString = childProcess.execSync(`find ${cwd} -name ${fileName} -type f`, { encoding: "utf8" }).split("\n");
if (pathString && pathString[0] && fileExistsSync(pathString[0].trim())) {
pathString = path.normalize(pathString[0].trim());
} else {
pathString = null;
}
} catch (ex) {
// Ignore the errors.
}
return pathString;
}
public getExecutableFileName(fileName: string): string {
return fileName;
}
}