@em-cli/shared
Version:
脚手架工具方法包
30 lines (29 loc) • 703 B
JavaScript
import path from 'path';
import fg from 'fast-glob';
/**
* 扫描指定目录和文件
*/
export async function scanFiles(workInDir, glob = '*', mapping = val => val) {
const files = await fg(`${workInDir}/${glob}`, {
onlyFiles: true,
ignore: ['node_modules/**/*']
});
return files.map(file => {
return {
fullPath: file,
file: path.basename(file)
};
}).map(mapping);
}
export async function scanDirs(workInDir, mapping = val => val) {
const dirs = await fg(`${workInDir}/*`, {
onlyDirectories: true,
ignore: ['node_modules/**/*']
});
return dirs.map(dir => {
return {
fullPath: dir,
dir: path.basename(dir)
};
}).map(mapping);
}