Created
August 24, 2016 16:18
-
-
Save dtothefp/07a37838f9891b3f5f64e6151aaef4da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import path from 'path'; | |
import glob from 'globby'; | |
import {readJson, outputJson} from 'fs-extra'; | |
const cwd = process.cwd(); | |
const read = (fp) => { | |
return new Promise((res, rej) => { | |
readJson(fp, (err, data) => { | |
if (err) return rej(err); | |
res(data); | |
}); | |
}); | |
}; | |
const write = (data) => { | |
return new Promise((res, rej) => { | |
const dest = path.join(cwd, 'dist', 'combined.json'); | |
outputJson(dest, data, (err) => { | |
if (err) return rej(err); | |
res(); | |
}); | |
}); | |
}; | |
glob('mocks/*.json', {cwd}).then(fps => { | |
const proms = fps.reduce((list, fp) => ([ | |
...list, | |
read(fp) | |
]), []); | |
return Promise.all(proms); | |
}).then(data => { | |
const combined = data.reduce((acc, json) => ({ | |
...acc, | |
...json | |
}), {}); | |
return write(combined); | |
}).catch(console.log.bind(console, '**ERR**')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment