mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 21:46:29 +00:00
feat: added a JSON handler/fixer (#165)
* 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 https://github.com/all-contributors/all-contributors-bot/issues/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`
This commit is contained in:
parent
93a910a375
commit
ebff1e8b88
3 changed files with 9 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -10,3 +10,5 @@ dist
|
||||||
# when working with contributors
|
# when working with contributors
|
||||||
package-lock.json
|
package-lock.json
|
||||||
yarn.lock
|
yarn.lock
|
||||||
|
.vscode
|
||||||
|
cache
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
"chalk": "^2.3.0",
|
"chalk": "^2.3.0",
|
||||||
"didyoumean": "^1.2.1",
|
"didyoumean": "^1.2.1",
|
||||||
"inquirer": "^6.2.1",
|
"inquirer": "^6.2.1",
|
||||||
|
"json-fixer": "^1.3.1-0",
|
||||||
"lodash": "^4.11.2",
|
"lodash": "^4.11.2",
|
||||||
"pify": "^4.0.1",
|
"pify": "^4.0.1",
|
||||||
"request": "^2.72.0",
|
"request": "^2.72.0",
|
||||||
|
|
|
@ -1,16 +1,21 @@
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const pify = require('pify')
|
const pify = require('pify')
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
|
const jf = require('json-fixer')
|
||||||
|
|
||||||
function readConfig(configPath) {
|
function readConfig(configPath) {
|
||||||
try {
|
try {
|
||||||
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'))
|
const {data: config, changed} = jf(fs.readFileSync(configPath, 'utf-8'))
|
||||||
if (!('repoType' in config)) {
|
if (!('repoType' in config)) {
|
||||||
config.repoType = 'github'
|
config.repoType = 'github'
|
||||||
}
|
}
|
||||||
if (!('commitConvention' in config)) {
|
if (!('commitConvention' in config)) {
|
||||||
config.commitConvention = 'none'
|
config.commitConvention = 'none'
|
||||||
}
|
}
|
||||||
|
if (changed) {
|
||||||
|
//Updates the file with fixes
|
||||||
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2))
|
||||||
|
}
|
||||||
return config
|
return config
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof SyntaxError) {
|
if (error instanceof SyntaxError) {
|
||||||
|
|
Loading…
Reference in a new issue