1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import path from "path"; 16import fs from "fs"; 17 18export function scanFiles(filepath: string, fileList: Set<string>) { 19 if (!fs.existsSync(filepath)) { 20 return; 21 } 22 const files = fs.readdirSync(filepath); 23 files.forEach((file) => { 24 const child = path.join(filepath, file); 25 const stat = fs.statSync(child); 26 if (stat.isDirectory()) { 27 scanFiles(child, fileList); 28 } else { 29 if (child.includes("mock")) { 30 return; 31 } 32 fileList.add(child); 33 } 34 }); 35} 36 37export function scanFileNames(filepath: string, fileList: Set<string>) { 38 if (!fs.existsSync(filepath)) { 39 return; 40 } 41 const files = fs.readdirSync(filepath); 42 files.forEach((file) => { 43 const child = path.join(filepath, file); 44 const stat = fs.statSync(child); 45 if (stat.isDirectory()) { 46 scanFiles(child, fileList); 47 } else { 48 if (child.includes("mock")) { 49 return; 50 } 51 fileList.add(path.basename(child)); 52 } 53 }); 54} 55