Skip to content

Commit

Permalink
feat: set an exit code if js check fails (#18)
Browse files Browse the repository at this point in the history
* feat: set an exit code if js check fails

* chore: use js check in travis build
  • Loading branch information
amcgee authored and varl committed Mar 5, 2019
1 parent 498ab10 commit 3833bea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ node_js:
before_script:
- npm install --global @dhis2/deploy-build
script:
- echo "We don't have any tests yet..."
- ./bin/d2-style js check --all
deploy:
- provider: script
script: publish-build
Expand Down
21 changes: 15 additions & 6 deletions src/cmds/js_cmds/check.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const path = require('path')
const { collectFiles } = require('../../files.js')
const log = require('@dhis2/cli-helpers-engine').reporter

const { check_fmt } = require('../../prettier.js')
const { staged_files } = require('../../git.js')

const configure = require('../../config.js')

const whitelist = [ '.js', '.jsx', '.ts',]
const whitelist = ['.js', '.jsx', '.ts']

function whitelisted(file) {
return whitelist.includes(path.extname(file))
Expand Down Expand Up @@ -44,7 +43,17 @@ exports.handler = argv => {

const prettyFiles = check_fmt(codeFiles)

prettyFiles.length > 0
? log.info(`Files to style:\n${prettyFiles.join('\n')}`)
: log.info('No files to style.')
const success = prettyFiles.length > 0

if (success) {
log.info(`Files to style:`)
prettyFiles.forEach(f =>
log.print(`\t${path.relative(process.cwd(), f)}`)
)
log.error('One or more files failed the style check')
process.exit(1)
} else {
log.info('No files to style.')
process.exit(0)
}
}

0 comments on commit 3833bea

Please sign in to comment.