Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 3d04365

Browse files
filter folders when parsing libraries
1 parent b9e9b1d commit 3d04365

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/arduino/boardManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,11 @@ export class BoardManager {
348348

349349
private loadInstalledPlatforms(): void {
350350
this._installedPlatforms = [];
351-
let rootPacakgesPath = path.join(path.join(this._settings.packagePath, "packages"));
352-
if (!util.directoryExistsSync(rootPacakgesPath)) {
351+
let rootPackagePath = path.join(path.join(this._settings.packagePath, "packages"));
352+
if (!util.directoryExistsSync(rootPackagePath)) {
353353
return;
354354
}
355-
const dirs = util.filterJunk(fs.readdirSync(rootPacakgesPath)); // in Mac, filter .DS_Store file.
355+
const dirs = util.filterJunk(util.readdirSync(rootPackagePath, true)); // in Mac, filter .DS_Store file.
356356
dirs.forEach((packageName) => {
357357
let archPath = path.join(this._settings.packagePath, "packages", packageName, "hardware");
358358
if (!util.directoryExistsSync(archPath)) {

src/arduino/libraryManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class LibraryManager {
8787
if (os.platform() === "darwin") {
8888
ideLibraryPath = path.join(arduinoPath, "Arduino.app/Contents/Java/libraries");
8989
}
90-
const ideLibraries = util.filterJunk(fs.readdirSync(ideLibraryPath));
90+
const ideLibraries = util.filterJunk(util.readdirSync(ideLibraryPath, true));
9191
for (let libDir of ideLibraries) {
9292
if (util.fileExistsSync(path.join(ideLibraryPath, libDir, "library.properties"))) {
9393
const properties = <any>await util.parseProperties(path.join(ideLibraryPath, libDir, "library.properties"));
@@ -112,7 +112,7 @@ export class LibraryManager {
112112
return;
113113
}
114114

115-
let installedLibDirs = util.filterJunk(fs.readdirSync(libRoot));
115+
let installedLibDirs = util.filterJunk(util.readdirSync(libRoot, true));
116116
for (let libDir of installedLibDirs) {
117117
if (util.fileExistsSync(path.join(libRoot, libDir, "library.properties"))) {
118118
const properties = <any>await util.parseProperties(path.join(libRoot, libDir, "library.properties"));
@@ -147,7 +147,7 @@ export class LibraryManager {
147147
let builtInLib = [];
148148
let builtInLibPath = path.join(rootBoardPath, "libraries");
149149
if (util.directoryExistsSync(builtInLibPath)) {
150-
let libDirs = util.filterJunk(fs.readdirSync(builtInLibPath));
150+
let libDirs = util.filterJunk(util.readdirSync(builtInLibPath, true));
151151
if (!libDirs || !libDirs.length) {
152152
return builtInLib;
153153
}

src/common/util.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ export function directoryExistsSync(dirPath: string): boolean {
5151
}
5252
}
5353

54+
/**
55+
* This function will implement same function as fs.readdirSync,
56+
* besides it could filter folders when the second argument is true.
57+
* @function readdirSync
58+
* @argument {string} dirPath
59+
* @argument {boolean} folderOnly
60+
*/
61+
export function readdirSync(dirPath: string, folderOnly: boolean = false): string[] {
62+
const dirs = fs.readdirSync(dirPath);
63+
if (folderOnly) {
64+
return dirs.filter((subdir) => {
65+
return directoryExistsSync(path.join(dirPath, subdir));
66+
});
67+
} else {
68+
return dirs;
69+
}
70+
}
71+
5472
export function mkdirRecursivelySync(dirPath: string): void {
5573
if (directoryExistsSync(dirPath)) {
5674
return ;

0 commit comments

Comments
 (0)