Skip to content

Commit

Permalink
Step #3
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAven committed Jul 29, 2024
1 parent 86ab53e commit 096363e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
21 changes: 20 additions & 1 deletion bin/gendiff.js
Original file line number Diff line number Diff line change
@@ -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('<filepath1> <filepath2>')
.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);
6 changes: 6 additions & 0 deletions file1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"host": "hexlet.io",
"timeout": 50,
"proxy": "123.234.53.22",
"follow": false
}
5 changes: 5 additions & 0 deletions file2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"timeout": 20,
"verbose": true,
"host": "hexlet.io"
}
3 changes: 3 additions & 0 deletions src/fileParse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const fileParse = (file) => JSON.parse(file);

export default fileParse;

0 comments on commit 096363e

Please sign in to comment.