function parseFolder (folder) { const profileFiles = glob.sync(`icongenie-*.json`, { cwd: folder, deep: 1, absolute: true }) const numberOfFiles = profileFiles.length if (numberOfFiles === 0) { warn(`No icongenie-*.json files detected in "${folder}" folder!`) process.exit(1) } console.log(` Detected ${numberOfFiles} JSON profile file(s):\n`) console.log(` * ${folder}`) profileFiles.forEach((file, index) => { const prefix = index + 1 < profileFiles.length ? `├──` : `└──` console.log(` ${prefix} ${basename(file)}`) }) console.log() return profileFiles }
/** * Creates a dictionary map of all files and directories under a path. */ function mapDirectory (rootDir, subDir, include, exclude) { const pathToMap = path.join(rootDir, subDir); return fastGlob.sync(include, { fs, // we pass in fs here, to be able to mock it in our tests dot: true, stats: true, onlyFiles: false, cwd: pathToMap, ignore: exclude }) .map(({ path: p, stats }) => ({ [path.normalize(p)]: { subDir, stats } })) .reduce( (dirMap, fragment) => Object.assign(dirMap, fragment), { '': { subDir, stats: fs.statSync(pathToMap) } } ); }