-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcombineService.js
41 lines (29 loc) · 1.02 KB
/
combineService.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
30
31
32
33
34
35
36
37
38
39
40
41
const fs = require('fs');
const path = require('path');
const sourceDir = './utils/definitions/'
const outputDir = './utils'
const outputFileName = 'service-definitions.json';
const outputFile = path.join(outputDir, outputFileName);
const combineJsonFiles = () => {
fs.readdir(sourceDir, (err, files) => {
if (err) {
console.error(`Error reading directory ${sourceDir}: ${err}`);
return;
}
const jsonFiles = files.filter(file => file.endsWith('.json'));
if (jsonFiles.length === 0) {
console.warn(`No JSON files found in ${sourceDir}`);
return;
}
const combinedData = [];
jsonFiles.forEach(file => {
const filePath = path.join(sourceDir, file);
const fileContent = fs.readFileSync(filePath, 'utf-8');
const jsonData = JSON.parse(fileContent);
combinedData.push(jsonData);
});
fs.writeFileSync(outputFile, JSON.stringify(combinedData, null, 2));
console.log(`Combined JSON file created: ${outputFile}`);
});
};
combineJsonFiles();