From 0c20ef5d172d417f12cef13bccffb0bd4528e521 Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 14 Jan 2022 18:46:03 +0300 Subject: [PATCH] refactor a complex ternary --- tools/build-vendor.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tools/build-vendor.js b/tools/build-vendor.js index c4d50ba3..1ee5da32 100644 --- a/tools/build-vendor.js +++ b/tools/build-vendor.js @@ -105,14 +105,7 @@ async function buildFiles(pkg, flatPkg, patterns) { fse.copySync(file, dest ? `vendor/${flatPkg}/${dest}` : `vendor/${path.relative('node_modules', file).replace(pkg + '/', flatPkg + '/')}`); - const relSrc = path.relative(`node_modules/${pkg}`, file).replace(/\\/g, '/'); - copied += dest && dest !== relSrc - ? `* ${dest}: ${ - keepDirs || getFileName(dest) !== getFileName(relSrc) - ? relSrc - : relSrc.replace(/[^/]+$/, '*') - }\n` - : `* ${relSrc}\n`; + copied += `* ${reportFile(pkg, file, dest)}\n`; } } } @@ -165,3 +158,14 @@ function deindent(str) { function getFileName(path) { return path.split('/').pop(); } + +function reportFile(pkg, file, dest) { + file = path.relative(`node_modules/${pkg}`, file).replace(/\\/g, '/'); + if (!dest || dest === file) { + return file; + } + if (file.includes('/') && getFileName(dest) === getFileName(file)) { + file = file.replace(/[^/]+$/, '*'); + } + return `${dest}: ${file}`; +}