-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (31 loc) · 1008 Bytes
/
index.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
'use strict'
let util = require('util');
let yargs = require('yargs');
let merge = require('./lib/merge.js');
let jsonHelper = require('./lib/json.helper.js');
let mergeMethod = yargs.argv.m || 'shallow';
let mergeType = yargs.argv.t || 'spread';
let outputFile = yargs.argv.o;
let inputFiles = yargs.argv._;
doMerge(mergeMethod, mergeType, inputFiles).then((result) => {
if (outputFile) {
jsonHelper.writeJson(result, outputFile);
}
console.log(util.inspect(result, { depth: null }));
}).catch((err) => {
console.error(err);
});
async function doMerge(mergeMethod, mergeType, inputFiles) {
let inputJsonPromises = inputFiles.map((fileName) => {
let absolutePath = require.resolve(fileName);
return jsonHelper.openJson(absolutePath);
});
return Promise.all(inputJsonPromises).then((objects) => {
if (mergeMethod === 'deep') {
return merge.all.deep(objects);
} else {
return merge.all.shallow(objects, mergeType);
}
});
}
module.exports = doMerge;