Skip to content

Lena05k/frontend-project-lvl2

Repository files navigation

Actions Status Node.js Package Maintainability Test Coverage

Difference Calculator

Project Description

Difference generator is a cli program. It compares two configuration files and shows a difference. Command-line utility for comparing differences between two data structures (JSON or YAML format files).

Acquired Skills

  • Practice of test-driven development (TDD), writing automated tests for the project using Jest
  • Integration of third-party libraries to solve various tasks
  • Implementation of package's ability to work as a library
  • Working with higher-order functions
  • Building internal representation for tree-like structures
  • Recursive traversal of tree-like structures
  • Hierarchical design, identifying the right abstractions, moving side effects to the top level.

Technology Stack: JavaScript, Node.js, ESLint, GitHub Actions (CI), Jest, Lodash, commander.js

Utility features:

  • Support for different input formats: yaml, json.
  • Report generation as plain text, stylish and json.

Example:

# stylish format
gendiff ./__fixtures__/file1.json ./__fixtures__/file2.json

{
  + follow: false
    setting1: Value 1
  - setting2: 200
  - setting3: true
  + setting3: {
        key: value
    }
  + setting4: blah blah
  + setting5: {
        key5: value5
    }
}

# plain format
gendiff -f plain ./__fixtures__/file1.json ./__fixtures__/file2.json

Property 'common.follow' was added with value: false
Property 'group1.baz' was updated. From 'bas' to 'bars'
Property 'group2' was removed

Launching the program:

Launch scheme:

1. Fork this repo by SSH key:

git@github.com:Lena05k/frontend-project-lvl2.git

2. Install depencies:

make install

3. Link the package to execute gendiff function:

make link

4. Display help:

gendiff -h

Usage: gendiff [options] <filepath1> <filepath2>
Compares two configuration files and shows a difference.
Options:
  -V, --version        output the version number
  -f, --format <type>  output format
  -h, --help           output usage information
      
Video

Video

5. Running a quick command

gendiff filepath1 filepath2
  • gendiff - quick command to compare a file.
  • filepath1 - the path to the first file you want to compare.

Specify the directory: ./__fixtures__/file1.json, ./__fixtures__/file1.yml

  • filepath2 - the path to the second file to be compared with.

Specify the directory: ./__fixtures__/file2.json, ./__fixtures__/file1.yml

Example: gendiff ./__fixtures__/file1.json ./__fixtures__/file2.json

Style:

Difference generator after implementation returns the difference in one of the three styles.

  • 'stylish' - when the comparison is made line by line and all the differences between the first file and the second will be marked with "+" or "-".
  • 'plain' - a text description of the attributes in the format of what was added/changed/deleted and where.
  • 'json' - translation of the difference between files in JSON format.

Launch:

By default, the output style is 'stylish', so the two call options listed below are equivalent:

gendiff ./__fixtures__/file1.json ./__fixtures__/file2.json
gendiff -f stylish ./__fixtures__/file1.json ./__fixtures__/file2.json
Video

Video

Output in 'plain' format:

gendiff -f plain ./__fixtures__/file1.json ./__fixtures__/file2.json
Video

Video

Output in 'json' format:

gendiff -f json ./__fixtures__/file1.json ./__fixtures__/file2.json
Video

Video

Run tests:

  1. Run linter:
make lint
  1. Run test:
make test
Video

Video

  1. Get test coverage:
make test-coverage
Video

Video