mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
To increase the ease of development we are moving @angular/docs into the adev directory within this repo. While we are doing this to improve our development experience in the short term, efforts are also in place to maintain a division between this @angular/docs (shared) code and adev itself, so that it can be extracted back out in the future when components is ready to leverage it as well. PR Close #57132
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
/*!
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.dev/license
|
|
*/
|
|
|
|
import {normalizePath} from './navigation.utils';
|
|
import {FileAndContent} from '../interfaces';
|
|
|
|
interface DirEnt<T> {
|
|
name: T;
|
|
isFile(): boolean;
|
|
isDirectory(): boolean;
|
|
}
|
|
|
|
interface FileSystemAPI {
|
|
readdir(
|
|
path: string,
|
|
options: {
|
|
encoding?:
|
|
| 'ascii'
|
|
| 'utf8'
|
|
| 'utf-8'
|
|
| 'utf16le'
|
|
| 'ucs2'
|
|
| 'ucs-2'
|
|
| 'base64'
|
|
| 'base64url'
|
|
| 'latin1'
|
|
| 'binary'
|
|
| 'hex'
|
|
| null;
|
|
withFileTypes: true;
|
|
},
|
|
): Promise<DirEnt<string>[]>;
|
|
readFile(path: string, encoding?: string): Promise<string>;
|
|
}
|
|
|
|
export const checkFilesInDirectory = async (
|
|
dir: string,
|
|
fs: FileSystemAPI,
|
|
filterFoldersPredicate: (path?: string) => boolean = () => true,
|
|
files: FileAndContent[] = [],
|
|
) => {
|
|
const entries = (await fs.readdir(dir, {withFileTypes: true})) ?? [];
|
|
|
|
for (const entry of entries) {
|
|
const fullPath = normalizePath(`${dir}/${entry.name}`);
|
|
|
|
if (entry.isFile()) {
|
|
const content = await fs.readFile(fullPath, 'utf-8');
|
|
files.push({content, path: fullPath});
|
|
} else if (entry.isDirectory() && filterFoldersPredicate(entry.name)) {
|
|
await checkFilesInDirectory(fullPath, fs, filterFoldersPredicate, files);
|
|
}
|
|
}
|
|
|
|
return files;
|
|
};
|