fix(nx-dev): update course API to ignore system OS Metadata file (#28886)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
This commit is contained in:
Nicholas Cunningham 2024-11-12 02:29:40 -07:00 committed by GitHub
parent c21b039dd0
commit 1e1cd3a0c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,7 @@
import { readFile, readdir } from 'fs/promises';
import { join } from 'path';
import { extractFrontmatter } from '@nx/nx-dev/ui-markdoc';
import { readFileSync } from 'fs';
import { readFileSync, lstatSync } from 'fs';
import { Course, Lesson } from './course.types';
import { calculateTotalDuration } from './duration.utils';
@ -22,7 +22,12 @@ export class CoursesApi {
async getAllCourses(): Promise<Course[]> {
const courseFolders = await readdir(this.options.coursesRoot);
const courses = await Promise.all(
courseFolders.map((folder) => this.getCourse(folder))
courseFolders
.filter((directory) => {
const stat = lstatSync(join(this.options.coursesRoot, directory));
return stat.isDirectory();
})
.map((folder) => this.getCourse(folder))
);
return courses;
}
@ -40,7 +45,10 @@ export class CoursesApi {
const lessonFolders = await readdir(coursePath);
const lessons = await Promise.all(
lessonFolders
.filter((folder) => folder !== 'course.md')
.filter((folder) => {
const stat = lstatSync(join(coursePath, folder));
return stat.isDirectory();
})
.map((folder) => this.getLessons(folderName, folder))
);
const flattenedLessons = lessons.flat();