From 97ca61f15ba9f6049ef0f5766824d3c412de3e32 Mon Sep 17 00:00:00 2001 From: Deight Date: Tue, 28 Jan 2025 13:45:26 +0300 Subject: [PATCH] Fix approve command with custom fileNameFormatter --- packages/runner/src/commands/approve/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/runner/src/commands/approve/index.js b/packages/runner/src/commands/approve/index.js index b316df24..3c2a5ffe 100644 --- a/packages/runner/src/commands/approve/index.js +++ b/packages/runner/src/commands/approve/index.js @@ -8,6 +8,17 @@ const getConfig = require('../../config'); const isPNG = (file) => file.substr(-4) === '.png'; +function getFiles(dir, subdir = '') { + const parentDir = path.resolve(dir, subdir); + const files = fs.readdirSync(parentDir); + + return files.flatMap((file) => { + const res = path.resolve(parentDir, file); + const filePath = path.join(subdir, file); + return fs.statSync(res).isDirectory() ? getFiles(dir, filePath) : filePath; + }) +} + function approve(args) { const config = getConfig(); const { outputDir, differenceDir, referenceDir, diffOnly } = parseOptions( @@ -17,7 +28,7 @@ function approve(args) { // If diff only is active, only copy over the files that were changed const inputDir = diffOnly ? differenceDir : outputDir; - const files = fs.readdirSync(inputDir).filter(isPNG); + const files = getFiles(inputDir).filter(isPNG); if (!files.length) { die(