serverless/lib/utils/fs/walk-dir-sync.js
Austen 158f644cd0
feat: Refactor logging to reduce complexity (#12432)
* chore: Change logger

* chore: continue refactor

* chore: WIP

* chore: Sync
2024-04-17 13:26:31 -07:00

31 lines
771 B
JavaScript

import path from 'path';
import fs from 'fs';
function walkDirSync(dirPath, opts) {
const options = Object.assign(
{
noLinks: false,
},
opts
);
let filePaths = [];
const list = fs.readdirSync(dirPath);
list.forEach((filePathParam) => {
let filePath = filePathParam;
filePath = path.join(dirPath, filePath);
const stat = options.noLinks ? fs.lstatSync(filePath) : fs.statSync(filePath);
// skipping symbolic links when noLinks option
if (options.noLinks && stat && stat.isSymbolicLink()) {
return;
} else if (stat && stat.isDirectory()) {
filePaths = filePaths.concat(walkDirSync(filePath, opts));
} else {
filePaths.push(filePath);
}
});
return filePaths;
}
export default walkDirSync;