Skip to content

Commit c73d65a

Browse files
authored
fix(report): use cwd for more accurate reports (#9)
Replaced path resolution from __dirname to process.cwd to have more control over the destination of report files. Resolves #8
1 parent ad04e43 commit c73d65a

5 files changed

Lines changed: 91 additions & 268 deletions

File tree

lib/cli/index.js renamed to lib/cli.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

3-
const CommonVocabulary = require('../common-vocabulary')
4-
const LexiconFactory = require('../lexicon-factory')
3+
const CommonVocabulary = require('./common-vocabulary')
4+
const LexiconFactory = require('./lexicon-factory')
55
const meow = require('meow')
66
const path = require('path')
77

@@ -59,7 +59,7 @@ const options = {
5959
'flags': {
6060
'output': {
6161
'alias': 'o',
62-
'default': path.resolve(__dirname, '../../docs/common-vocabulary.md'),
62+
'default': path.resolve(process.cwd(), 'docs/common-vocabulary.md'),
6363
'type': 'string'
6464
}
6565
}
@@ -69,7 +69,6 @@ const decorator = {
6969
forReports (cli, commonVocabulary) {
7070
commonVocabulary.report = () => {
7171
const destination = cli.flags.output || options.flags.output.default
72-
7372
const lexicon = commonVocabulary.toHtml()
7473
const lexiconFactory = new LexiconFactory()
7574
lexiconFactory.report(destination, lexicon)
@@ -79,7 +78,15 @@ const decorator = {
7978
forStdout (cli, commonVocabulary) {
8079
const method = cli.input.shift() || 'report'
8180
// eslint-disable-next-line no-console
82-
console.log(commonVocabulary[method](cli.input))
81+
const out = commonVocabulary[method](cli.input)
82+
console.log(decorator.toMessage(out))
83+
},
84+
85+
toMessage (out) {
86+
if (!out) {
87+
return 'Nothing found.'
88+
}
89+
return out
8390
}
8491
}
8592

lib/lexicon-factory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class LexiconFactory {
1212
try {
1313
const html = this.commonVocabulary.toHtml()
1414
await fs.writeFile(path.resolve(__dirname, destination), html)
15-
commonVocabLogger.info(`Generated: ${destination}`)
15+
console.log(`Generated: ${destination}`)
1616
} catch (err) {
1717
commonVocabLogger.error(err)
1818
}

lib/templates/en/page-template.md.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
<blockquote>
3232
<ul>
3333
<% _.forEach(entry.conventionalCommitTypes, (change) => { %>
34-
<li><em>Scope:</em> <code><%- entry.dt %></code>
35-
<p><li><em>Type:</em> <code><%- change %></code>
34+
<li><em>Type:</em> <code><%- change %></code>
35+
<p><li><em>Scope:</em> <code><%- entry.dt %></code>
3636
<p>Sample commit message header:
3737
<pre class="ini"><code><%- change %>(<%- entry.dt %>): lorem ipsum dolor sit amet</code></pre>
3838
<% }) %>

0 commit comments

Comments
 (0)