|
1 |
| -// Copyright (c) Microsoft Corporation. All rights reserved. |
2 |
| -// Licensed under the MIT license. |
3 |
| - |
4 |
| -import * as childProcess from "child_process"; |
5 |
| -import * as path from "path"; |
6 |
| -import { directoryExistsSync, fileExistsSync, resolveMacArduinoAppPath } from "../util"; |
7 |
| - |
8 |
| -export function resolveArduinoPath(): string { |
9 |
| - let result; |
10 |
| - |
11 |
| - const defaultCommonPaths = [path.join(process.env.HOME, "Applications"), "/Applications"]; |
12 |
| - for (const scanPath of defaultCommonPaths) { |
13 |
| - if (directoryExistsSync(path.join(scanPath, "Arduino.app"))) { |
14 |
| - result = scanPath; |
15 |
| - break; |
16 |
| - } |
17 |
| - } |
18 |
| - return result || ""; |
19 |
| -} |
20 |
| - |
21 |
| -export function validateArduinoPath(arduinoPath: string, useArduinoCli = false): boolean { |
22 |
| - return fileExistsSync(path.join(resolveMacArduinoAppPath(arduinoPath), useArduinoCli ? "arduino-cli" : "/Contents/MacOS/Arduino")); |
23 |
| - |
24 |
| -} |
25 |
| - |
26 |
| -export function findFile(fileName: string, cwd: string): string { |
27 |
| - let pathString; |
28 |
| - try { |
29 |
| - pathString = childProcess.execSync(`find ${cwd} -name ${fileName} -type f`, { encoding: "utf8" }).split("\n"); |
30 |
| - |
31 |
| - if (pathString && pathString[0] && fileExistsSync(pathString[0].trim())) { |
32 |
| - pathString = path.normalize(pathString[0].trim()); |
33 |
| - } else { |
34 |
| - pathString = null; |
35 |
| - } |
36 |
| - } catch (ex) { |
37 |
| - // Ignore the errors. |
38 |
| - } |
39 |
| - return pathString; |
40 |
| -} |
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +import * as childProcess from "child_process"; |
| 5 | +import * as path from "path"; |
| 6 | +import { directoryExistsSync, fileExistsSync, resolveMacArduinoAppPath } from "../util"; |
| 7 | + |
| 8 | +export function resolveArduinoPath(): string { |
| 9 | + let result; |
| 10 | + |
| 11 | + const defaultCommonPaths = [path.join(process.env.HOME, "Applications"), "/Applications"]; |
| 12 | + for (const scanPath of defaultCommonPaths) { |
| 13 | + if (directoryExistsSync(path.join(scanPath, "Arduino.app"))) { |
| 14 | + result = scanPath; |
| 15 | + break; |
| 16 | + } |
| 17 | + } |
| 18 | + return result || ""; |
| 19 | +} |
| 20 | + |
| 21 | +export function validateArduinoPath(arduinoPath: string, useArduinoCli = false): boolean { |
| 22 | + return fileExistsSync(path.join(resolveMacArduinoAppPath(arduinoPath, useArduinoCli), useArduinoCli ? "arduino-cli" : "/Contents/MacOS/Arduino")); |
| 23 | +} |
| 24 | + |
| 25 | +export function findFile(fileName: string, cwd: string): string { |
| 26 | + let pathString; |
| 27 | + try { |
| 28 | + pathString = childProcess.execSync(`find ${cwd} -name ${fileName} -type f`, { encoding: "utf8" }).split("\n"); |
| 29 | + |
| 30 | + if (pathString && pathString[0] && fileExistsSync(pathString[0].trim())) { |
| 31 | + pathString = path.normalize(pathString[0].trim()); |
| 32 | + } else { |
| 33 | + pathString = null; |
| 34 | + } |
| 35 | + } catch (ex) { |
| 36 | + // Ignore the errors. |
| 37 | + } |
| 38 | + return pathString; |
| 39 | +} |
0 commit comments