// For every type in bundle.types creates a new bundle obj.
const bundles = [
{
name: 'banana',
input: 'src/banana.js',
dir: 'dist',
types: ['esm', 'umd']
},
{
name: 'apple',
input: 'src/apple.js',
dir: 'dist',
types: ['umd']
}
]
/* =>
[
{
name: 'banana',
input: 'src/banana.js',
dir: 'dist',
type: 'esm'
},
{
name: 'banana',
input: 'src/banana.js',
dir: 'dist',
type: 'umd'
},
{
name: 'apple',
input: 'src/apple.js',
dir: 'dist',
type: 'umd'
}
]
*/
let allBundles = R.chain(R.converge(
R.pipe(R.xprod, R.map(R.mergeAll)),
[
R.pipe(R.dissoc('types'), R.of),
R.pipe(R.prop('types'), R.map(R.objOf('type')))
]
), bundles);
console.log('ramda');
console.log(JSON.stringify(allBundles, null, 2));
allBundles = bundles.reduce((acc, b) => {
return acc.concat(b.types.map((type) => {
const bundle = { ...b, type };
delete bundle.types;
return bundle;
}));
}, []);
console.log('lamda')
console.log(JSON.stringify(allBundles, null, 2));
<script src="https://cdn.jsdelivr.net/npm/ramda@0.25.0/dist/ramda.min.js"></script>