refactor a complex ternary

This commit is contained in:
tophf 2022-01-14 18:46:03 +03:00
parent ddc09f3511
commit 0c20ef5d17

View File

@ -105,14 +105,7 @@ async function buildFiles(pkg, flatPkg, patterns) {
fse.copySync(file, dest fse.copySync(file, dest
? `vendor/${flatPkg}/${dest}` ? `vendor/${flatPkg}/${dest}`
: `vendor/${path.relative('node_modules', file).replace(pkg + '/', flatPkg + '/')}`); : `vendor/${path.relative('node_modules', file).replace(pkg + '/', flatPkg + '/')}`);
const relSrc = path.relative(`node_modules/${pkg}`, file).replace(/\\/g, '/'); copied += `* ${reportFile(pkg, file, dest)}\n`;
copied += dest && dest !== relSrc
? `* ${dest}: ${
keepDirs || getFileName(dest) !== getFileName(relSrc)
? relSrc
: relSrc.replace(/[^/]+$/, '*')
}\n`
: `* ${relSrc}\n`;
} }
} }
} }
@ -165,3 +158,14 @@ function deindent(str) {
function getFileName(path) { function getFileName(path) {
return path.split('/').pop(); 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}`;
}