Skip to content

Commit

Permalink
Added support of JSON5 and YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
Anantachai Saothong (Manta) committed May 10, 2018
1 parent 3b7da79 commit 289735d
Show file tree
Hide file tree
Showing 5 changed files with 566 additions and 41 deletions.
2 changes: 2 additions & 0 deletions docs/index.html

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions edge/commandLineProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const fp = require('path')
const ps = require('process')
const glob = require('glob')
const _ = require('lodash')
const JSONWithComments = require('comment-json')
const JSON5 = require('json5')
const YAML = require('js-yaml')

const format = require('./format')
const createFormattingOptions = require('./createFormattingOptions')
Expand Down Expand Up @@ -37,7 +38,12 @@ function process(command, params = [], Console = console) {
}

try {
formattingOptions = JSONWithComments.parse(fs.readFileSync(optionFilePathParams[1], 'utf8'), null, true)
const fileText = fs.readFileSync(optionFilePathParams[1], 'utf8')
if (optionFilePathParams[1].endsWith('.yaml') || optionFilePathParams[1].endsWith('.yml')) {
formattingOptions = YAML.safeLoad(fileText, { json: true })
} else {
formattingOptions = JSON5.parse(fileText)
}
} catch (ex) {
throw new Error('The given option file could not be parsed as JSON.')
}
Expand Down
Loading

0 comments on commit 289735d

Please sign in to comment.