diff --git a/bin/gendiff.js b/bin/gendiff.js index 0deb1d6..07d5a3c 100755 --- a/bin/gendiff.js +++ b/bin/gendiff.js @@ -1,11 +1,30 @@ #!/usr/bin/env node import { Command } from 'commander'; +import * as path from 'node:path'; +import { cwd } from 'node:process'; +import { readFileSync } from 'node:fs'; +import fileParse from '../src/fileParse.js'; const program = new Command(); program .name('gendiff') .description('Compares two configuration files and shows a difference.') - .version('1.0.0'); + .version('1.0.0') + .arguments(' ') + .option('-f, --format [type]', 'output format') + .action((filepath1, filepath2) => { + const absolutePath1 = path.resolve(cwd(), filepath1); + const absolutePath2 = path.resolve(cwd(), filepath2); + + const file1Content = readFileSync(absolutePath1); + const file2Content = readFileSync(absolutePath2); + + const file1Parsed = fileParse(file1Content); + const file2Parsed = fileParse(file2Content); + + console.log(file1Parsed); + console.log(file2Parsed); + }); program.parse(process.argv); diff --git a/file1.json b/file1.json new file mode 100644 index 0000000..6212a97 --- /dev/null +++ b/file1.json @@ -0,0 +1,6 @@ +{ + "host": "hexlet.io", + "timeout": 50, + "proxy": "123.234.53.22", + "follow": false +} \ No newline at end of file diff --git a/file2.json b/file2.json new file mode 100644 index 0000000..194e6f4 --- /dev/null +++ b/file2.json @@ -0,0 +1,5 @@ +{ + "timeout": 20, + "verbose": true, + "host": "hexlet.io" +} diff --git a/src/fileParse.js b/src/fileParse.js new file mode 100644 index 0000000..379e84b --- /dev/null +++ b/src/fileParse.js @@ -0,0 +1,3 @@ +const fileParse = (file) => JSON.parse(file); + +export default fileParse;