Skip to content

Commit

Permalink
feat: added a JSON handler/fixer (#165)
Browse files Browse the repository at this point in the history
* feat: added a JSON handler/fixer [wip]

Added a module that will check JSON files and give a good level of details for errors while
attempting to fix it

re all-contributors/app#102

* refactor: consolidated the fix handler

Made the fixer a bit more concise and added the fields to allow for an auto-update of the config
file (if it was changed)

* chore(package): use another `jsonlint`

* refactor(config-file): use `json-fixer`

* chore(package): bump `json-fixer` to 1.3

* chore(package): bumped `json-fixer`
  • Loading branch information
Berkmann18 authored May 20, 2019
1 parent 93a910a commit ebff1e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ dist
# when working with contributors
package-lock.json
yarn.lock
.vscode
cache
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"chalk": "^2.3.0",
"didyoumean": "^1.2.1",
"inquirer": "^6.2.1",
"json-fixer": "^1.3.1-0",
"lodash": "^4.11.2",
"pify": "^4.0.1",
"request": "^2.72.0",
Expand Down
7 changes: 6 additions & 1 deletion src/util/config-file.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
const fs = require('fs')
const pify = require('pify')
const _ = require('lodash/fp')
const jf = require('json-fixer')

function readConfig(configPath) {
try {
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'))
const {data: config, changed} = jf(fs.readFileSync(configPath, 'utf-8'))
if (!('repoType' in config)) {
config.repoType = 'github'
}
if (!('commitConvention' in config)) {
config.commitConvention = 'none'
}
if (changed) {
//Updates the file with fixes
fs.writeFileSync(configPath, JSON.stringify(config, null, 2))
}
return config
} catch (error) {
if (error instanceof SyntaxError) {
Expand Down

0 comments on commit ebff1e8

Please sign in to comment.