Skip to content

Commit 5eefffd

Browse files
committed
Add quiet option
1 parent e7a5ad4 commit 5eefffd

File tree

6 files changed

+116
-15
lines changed

6 files changed

+116
-15
lines changed

lib/_options.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ module.exports = {
134134
short: '-m',
135135
name: 'only-milestones',
136136
description: 'Add to the release bodies only the issues that have a milestone'
137+
},
138+
{
139+
short: '-q',
140+
name: 'quiet',
141+
description: 'Run command without console logs.'
137142
}
138143
],
139144
releaseOptions: [

lib/src/Gren.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const defaults = {
1313
template: templateConfig,
1414
prerelease: false,
1515
generate: false,
16+
quiet: false,
1617
override: false,
1718
debug: false,
1819
ignoreLabels: false,
@@ -75,7 +76,7 @@ class Gren {
7576
* @return {Promise}
7677
*/
7778
async release() {
78-
utils.printTask('Generate release notes');
79+
utils.printTask(this.options.quiet, 'Generate release notes');
7980

8081
await this._hasNetwork();
8182
const blocks = await this._getReleaseBlocks();
@@ -92,7 +93,7 @@ class Gren {
9293
* @return {Promise}
9394
*/
9495
async changelog() {
95-
utils.printTask('Generate changelog file');
96+
utils.printTask(this.options.quiet, 'Generate changelog file');
9697

9798
await this._hasNetwork();
9899
this._checkChangelogFile();
@@ -133,11 +134,12 @@ class Gren {
133134
* @param {string} body The body of the file
134135
*/
135136
_createChangelog(body) {
137+
const loaded = utils.task(this, `Creating ${this.options.changelogFilename}`);
136138
const filePath = process.cwd() + '/' + this.options.changelogFilename;
137139

138140
fs.writeFileSync(filePath, this.options.template.changelogTitle + body);
139141

140-
console.log(chalk.green(`\nChangelog created in ${filePath}`));
142+
loaded(chalk.green(`\nChangelog created in ${filePath}`));
141143
}
142144

143145
/**
@@ -164,9 +166,7 @@ class Gren {
164166
const loaded = utils.task(this, 'Updating latest release');
165167
const { data: release } = await this.repo.updateRelease(releaseId, releaseOptions);
166168

167-
loaded(chalk.green(`${release.name} has been successfully updated!`));
168-
169-
console.log(chalk.blue(`\nSee the results here: ${release.html_url}`));
169+
loaded(chalk.green(`${release.name} has been successfully updated!`) + chalk.blue(`\nSee the results here: ${release.html_url}`));
170170

171171
return release;
172172
}
@@ -193,9 +193,7 @@ class Gren {
193193
const loaded = utils.task(this, 'Preparing the release');
194194
const { data: release } = await this.repo.createRelease(releaseOptions);
195195

196-
loaded(chalk.green(`\n${release.name} has been successfully created!`));
197-
198-
console.log(chalk.blue(`See the results here: ${release.html_url}`));
196+
loaded(chalk.green(`\n${release.name} has been successfully created!`) + chalk.blue(`See the results here: ${release.html_url}`));
199197

200198
return release;
201199
}

lib/src/_utils.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ function sortObject(object) {
3030
*
3131
* @param {string} name The name of the task
3232
*/// istanbul ignore next
33-
function printTask(name) {
33+
function printTask(isQuiet, name) {
34+
if (isQuiet) {
35+
return;
36+
}
37+
3438
process.stdout.write(chalk.blue(`\n🤖 - ${name}:\n===================================\n`));
3539
}
3640

@@ -45,6 +49,11 @@ function printTask(name) {
4549
* @return {Function} The function to be fired when is loaded
4650
*/// istanbul ignore next
4751
function task(gren, taskName) {
52+
if (gren.options.quiet) {
53+
gren.tasks[taskName] = {};
54+
55+
return noop;
56+
}
4857
const spinner = ora(taskName);
4958
gren.tasks[taskName] = spinner;
5059

@@ -205,6 +214,11 @@ function getFileNameFromPath(path) {
205214
return path.split('\\').pop().split('/').pop();
206215
}
207216

217+
/**
218+
* Just a noop function
219+
*/
220+
function noop() {}
221+
208222
// Allow nodeunit to work. Has to be fixed.
209223
module.exports = {
210224
sortObject,
@@ -217,5 +231,5 @@ module.exports = {
217231
formatDate,
218232
requireConfig,
219233
getConfigFromFile,
220-
noop: () => {}
234+
noop
221235
};

package-lock.json

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "./github-release-notes.js",
66
"scripts": {
77
"start": "node github-release-notes.js",
8-
"test": "nyc mocha --compilers=js:babel-register",
8+
"test": "nyc mocha --reporter=nyan --compilers=js:babel-register",
99
"coverage": "nyc --reporter=lcov --reporter=text mocha --compilers=js:babel-register",
1010
"options": "node tasks/_generate-options.js",
1111
"examples": "node tasks/_generate-examples.js",
@@ -82,6 +82,7 @@
8282
"jsdoc": "^3.4.3",
8383
"minami": "^1.2.3",
8484
"nyc": "^11.2.1",
85+
"tap-nyan": "^1.1.0",
8586
"yamljs": "^0.3.0"
8687
}
8788
}

test/Gren.spec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ describe('Gren', () => {
1515
const gren = new Gren({
1616
token: TOKEN,
1717
username: 'github-tools',
18-
repo: 'github-release-notes'
18+
repo: 'github-release-notes',
19+
quiet: true
1920
});
2021

2122
it('Should throw an error', () => {
2223
process.env.GREN_GITHUB_TOKEN = null;
2324

24-
const gren = () => new Gren();
25-
assert.throws(gren, chalk.red('You must provide the TOKEN'), 'No token passed');
25+
const grenWithoutToken = () => new Gren();
26+
assert.throws(grenWithoutToken, chalk.red('You must provide the TOKEN'), 'No token passed');
2627
});
2728

2829
it('Should generate the options', () => {

0 commit comments

Comments
 (0)