Skip to content

Commit

Permalink
Merge pull request #7 from bidoubiwa/refactor
Browse files Browse the repository at this point in the history
Refactor code
  • Loading branch information
bidoubiwa authored May 22, 2021
2 parents 1921097 + 5fe4b19 commit 7d25934
Show file tree
Hide file tree
Showing 17 changed files with 283 additions and 99 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# top-most EditorConfig file
root = true

# all files
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
max_line_length = 80

[*.{js,ts}]
quote_type = single
curly_bracket_next_line = false
spaces_around_brackets = inside
indent_brace_style = BSD KNF

# HTML
[*.html]
quote_type = double
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ lerna-debug.log
.DS_Store
Thumbs.db

combined.json
combined.json
6 changes: 3 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Combine-json

Combine-json is a CLI tool that combines all json files found in a directory into one big json file.
Combine-json is a CLI tool that combines all json files found in a directory into one big json file using streaming.

It takes as argument a directory in which to find the json files and a output file name in which the json files will combined.
The json file will be created in the directory where the CLI is used.
Expand All @@ -14,15 +14,15 @@ npm i
npm run link
```

## Usage
## Usage
`combine-json [inputDir] [outputFile(optionnal)]`
```bash
combine-json directory
```
default output file is combined.json at the root of where you execute the cli.

## Try it out
Go at the root of the CLI
Go at the root of the CLI
```bash
combine-json misc
```
Expand Down
58 changes: 56 additions & 2 deletions combined.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,61 @@
{ "name": "Hello" },
{ "name": "Hello" },
{ "name": "Hello" }
,{
,
{
"id": "106678",
"title": "Jungle Erotic",
"poster": "https://image.tmdb.org/t/p/w1280/rkMHlp42CDJUEB4GKsn3LC5znGC.jpg",
"overview": "Young women have an adventure in the African jungle - where they are harassed by gentle men, and wild monkeys.",
"release_date": 26265600,
"genre": [
"Adventure",
"Drama"
]
},
{
"id": "490410",
"title": "48 Christmas Wishes",
"poster": "https://image.tmdb.org/t/p/w1280/mrcA62O9j8y4gsSpftMKVcvrzCI.jpg",
"overview": "Holiday magic has never gleamed brighter as Santa’s Elves head out on an adventure to bring every boy and girl their Christmas wish while also bringing a family back together in this heartfelt Christmas movie from Gaumont. After accidentally destroying a bag of Christmas wishes from a small town on the eve of Christmas Eve, two junior elves learn that if even one wish goes unfulfilled, Christmas could be extinguished forever. For the first time in their lives, the elves Mindy and Cam venture out of the North Pole and sneak into Minnedoza to collect the lost wishes. Along the way they enlist the help of young Blake, whose family has a difficult time celebrating Christmas since his father died. With their deadline fast approaching, Mindy and Cam have only one more wish to find…but whose could it be? It’s up to Mindy and Cam to find out and save Christmas!",
"release_date": 1512086400,
"genre": [
"Family",
"Adventure",
"Comedy",
"TV Movie"
]
},
{
"id": "285841",
"title": "Elephant Song",
"poster": "https://image.tmdb.org/t/p/w1280/9pHl6RmMIDyPmQW1XUJ2Mahsr3M.jpg",
"overview": "A psychiatrist is drawn into a complex mind game when he questions a disturbed patient about the disappearance of a colleague.",
"release_date": 1409792400,
"genre": []
}
,
{
"id": "481370",
"title": "Bigger",
"poster": "https://image.tmdb.org/t/p/w1280/f6rmiFTfT3Rf9XDrXfLO6XcAgWn.jpg",
"overview": "The inspirational tale of the grandfathers of the fitness movement as we now know it, Joe & Ben Weider. Battling anti-Semitism, racism and extreme poverty, the brothers beat all odds to build an empire & inspire future generations.",
"release_date": 1539392400,
"genre": [
"Drama"
]
},
{
"id": "31357",
"title": "Waiting to Exhale",
"poster": "https://image.tmdb.org/t/p/w1280/4wjGMwPsdlvi025ZqR4rXnFDvBz.jpg",
"overview": "Cheated on, mistreated and stepped on, the women are holding their breath, waiting for the elusive 'good man' to break a string of less-than-stellar lovers. Friends and confidants Vannah, Bernie, Glo and Robin talk it all out, determined to find a better way to breathe.",
"release_date": 819590400,
"genre": [
"Comedy",
"Drama",
"Romance"
,{
"name": "not an array"
},
1,
Expand All @@ -20,4 +74,4 @@
{ "name": "world" },
{ "name": "world" },
{ "name": "world" }
]
]
2 changes: 1 addition & 1 deletion misc/far_away.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
{
"name": "far away"
}
]
]
2 changes: 1 addition & 1 deletion misc/hello.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
{ "name": "Hello" },
{ "name": "Hello" },
{ "name": "Hello" }
]
]
34 changes: 34 additions & 0 deletions misc/nested_array.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"id": "106678",
"title": "Jungle Erotic",
"poster": "https://image.tmdb.org/t/p/w1280/rkMHlp42CDJUEB4GKsn3LC5znGC.jpg",
"overview": "Young women have an adventure in the African jungle - where they are harassed by gentle men, and wild monkeys.",
"release_date": 26265600,
"genre": [
"Adventure",
"Drama"
]
},
{
"id": "490410",
"title": "48 Christmas Wishes",
"poster": "https://image.tmdb.org/t/p/w1280/mrcA62O9j8y4gsSpftMKVcvrzCI.jpg",
"overview": "Holiday magic has never gleamed brighter as Santa’s Elves head out on an adventure to bring every boy and girl their Christmas wish while also bringing a family back together in this heartfelt Christmas movie from Gaumont. After accidentally destroying a bag of Christmas wishes from a small town on the eve of Christmas Eve, two junior elves learn that if even one wish goes unfulfilled, Christmas could be extinguished forever. For the first time in their lives, the elves Mindy and Cam venture out of the North Pole and sneak into Minnedoza to collect the lost wishes. Along the way they enlist the help of young Blake, whose family has a difficult time celebrating Christmas since his father died. With their deadline fast approaching, Mindy and Cam have only one more wish to find…but whose could it be? It’s up to Mindy and Cam to find out and save Christmas!",
"release_date": 1512086400,
"genre": [
"Family",
"Adventure",
"Comedy",
"TV Movie"
]
},
{
"id": "285841",
"title": "Elephant Song",
"poster": "https://image.tmdb.org/t/p/w1280/9pHl6RmMIDyPmQW1XUJ2Mahsr3M.jpg",
"overview": "A psychiatrist is drawn into a complex mind game when he questions a disturbed patient about the disappearance of a colleague.",
"release_date": 1409792400,
"genre": []
}
]
24 changes: 24 additions & 0 deletions misc/nested_array_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"id": "481370",
"title": "Bigger",
"poster": "https://image.tmdb.org/t/p/w1280/f6rmiFTfT3Rf9XDrXfLO6XcAgWn.jpg",
"overview": "The inspirational tale of the grandfathers of the fitness movement as we now know it, Joe & Ben Weider. Battling anti-Semitism, racism and extreme poverty, the brothers beat all odds to build an empire & inspire future generations.",
"release_date": 1539392400,
"genre": [
"Drama"
]
},
{
"id": "31357",
"title": "Waiting to Exhale",
"poster": "https://image.tmdb.org/t/p/w1280/4wjGMwPsdlvi025ZqR4rXnFDvBz.jpg",
"overview": "Cheated on, mistreated and stepped on, the women are holding their breath, waiting for the elusive 'good man' to break a string of less-than-stellar lovers. Friends and confidants Vannah, Bernie, Glo and Robin talk it all out, determined to find a better way to breathe.",
"release_date": 819590400,
"genre": [
"Comedy",
"Drama",
"Romance"
]
}
]
2 changes: 1 addition & 1 deletion misc/not_array.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"name": "not an array"
}
}
2 changes: 1 addition & 1 deletion misc/number.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
1,
2,
3
]
]
2 changes: 1 addition & 1 deletion misc/world.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
{ "name": "world" },
{ "name": "world" },
{ "name": "world" }
]
]
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"name": "combine-json",
"version": "1.0.0",
"description": "",
"main": "src/combine-json.js",
"main": "src/index.js",
"preferGlobal": true,
"bin": "./src/combine-json.js",
"bin": "./src/cli.js",
"scripts": {
"link": "npm link",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "./src/cli.js misc"
},
"author": "",
"license": "ISC",
Expand Down
18 changes: 18 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node
const combineJson = require('./combine-json');

(async () => {
console.log(combineJson);
try {
if (process.argv.length === 2) {
console.log(chalk.red('Error: Missing path argument'));
}
else {
await combineJson(process.argv[2], process.argv[3])
}
}
catch(e) {
console.error(e);
throw(e)
}
})()
Loading

0 comments on commit 7d25934

Please sign in to comment.