Skip to content

Commit

Permalink
fix(report): use cwd for more accurate reports (#9)
Browse files Browse the repository at this point in the history
Replaced path resolution from __dirname to process.cwd to have
more control over the destination of report files.

Resolves #8
  • Loading branch information
gregswindle authored Feb 9, 2018
1 parent ad04e43 commit c73d65a
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 268 deletions.
17 changes: 12 additions & 5 deletions lib/cli/index.js → lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const CommonVocabulary = require('../common-vocabulary')
const LexiconFactory = require('../lexicon-factory')
const CommonVocabulary = require('./common-vocabulary')
const LexiconFactory = require('./lexicon-factory')
const meow = require('meow')
const path = require('path')

Expand Down Expand Up @@ -59,7 +59,7 @@ const options = {
'flags': {
'output': {
'alias': 'o',
'default': path.resolve(__dirname, '../../docs/common-vocabulary.md'),
'default': path.resolve(process.cwd(), 'docs/common-vocabulary.md'),
'type': 'string'
}
}
Expand All @@ -69,7 +69,6 @@ const decorator = {
forReports (cli, commonVocabulary) {
commonVocabulary.report = () => {
const destination = cli.flags.output || options.flags.output.default

const lexicon = commonVocabulary.toHtml()
const lexiconFactory = new LexiconFactory()
lexiconFactory.report(destination, lexicon)
Expand All @@ -79,7 +78,15 @@ const decorator = {
forStdout (cli, commonVocabulary) {
const method = cli.input.shift() || 'report'
// eslint-disable-next-line no-console
console.log(commonVocabulary[method](cli.input))
const out = commonVocabulary[method](cli.input)
console.log(decorator.toMessage(out))
},

toMessage (out) {
if (!out) {
return 'Nothing found.'
}
return out
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/lexicon-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class LexiconFactory {
try {
const html = this.commonVocabulary.toHtml()
await fs.writeFile(path.resolve(__dirname, destination), html)
commonVocabLogger.info(`Generated: ${destination}`)
console.log(`Generated: ${destination}`)
} catch (err) {
commonVocabLogger.error(err)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/templates/en/page-template.md.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<blockquote>
<ul>
<% _.forEach(entry.conventionalCommitTypes, (change) => { %>
<li><em>Scope:</em> <code><%- entry.dt %></code>
<p><li><em>Type:</em> <code><%- change %></code>
<li><em>Type:</em> <code><%- change %></code>
<p><li><em>Scope:</em> <code><%- entry.dt %></code>
<p>Sample commit message header:
<pre class="ini"><code><%- change %>(<%- entry.dt %>): lorem ipsum dolor sit amet</code></pre>
<% }) %>
Expand Down
Loading

0 comments on commit c73d65a

Please sign in to comment.