-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmerge.js
29 lines (21 loc) · 895 Bytes
/
merge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// https://stackoverflow.com/a/40022630
const fs = require('fs');
const glob = require('glob');
const output = {};
const outputPath = './snippets/';
glob('src/**/*.json', (error, files) => {
try {
fs.existsSync(outputPath) || fs.mkdirSync(outputPath);
fs.accessSync(outputPath, fs.constants.R_OK | fs.constants.W_OK)
// console.log(`${outputPath} exists, and it is writable`);
files.forEach((filename) => {
const contents = JSON.parse(fs.readFileSync(filename, 'utf8'));
Object.assign(output, contents);
});
fs.writeFileSync(outputPath + 'javascript.json', JSON.stringify(output));
console.log(`Complete! :)`);
} catch (err) {
console.error(`${outputPath} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`);
console.log('Failed! :(')
}
});