From 569cd105b8e9f1b1988a07a0bc2cb717f9d31a90 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Thu, 16 May 2019 10:43:41 -0400 Subject: [PATCH] Print only the url when being piped/scripted. This ensures that something akin to `ember-source-channel-url > some-file.txt` writes only the URL (not the verbose console message). --- bin/ember-source-channel-url | 10 +++++++--- tests/index-test.js | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/bin/ember-source-channel-url b/bin/ember-source-channel-url index f4d7d57..f3a14d8 100755 --- a/bin/ember-source-channel-url +++ b/bin/ember-source-channel-url @@ -42,9 +42,13 @@ if (['release', 'beta', 'canary'].indexOf(channel) === -1) { process.exitCode = 1; } else { getChannelURL(channel).then(url => { - console.log( - `The URL for the latest tarball from ember-source's ${channel} channel is:\n\n\t${url}\n` - ); + if (process.stdout.isTTY) { + console.log( + `The URL for the latest tarball from ember-source's ${channel} channel is:\n\n\t${url}\n` + ); + } else { + process.stdout.write(url); + } if (shouldUpdatePackage) { if (!fs.existsSync('package.json')) { diff --git a/tests/index-test.js b/tests/index-test.js index 654b4c8..3b5c8f1 100644 --- a/tests/index-test.js +++ b/tests/index-test.js @@ -62,6 +62,17 @@ QUnit.module('ember-source-channel-url', function(hooks) { }); }); + QUnit.test('when the terminal is not a TTY return only the URL', function(assert) { + let file = tmp.fileSync(); + return execa(EXECUTABLE_PATH, ['canary'], { stdout: file.fd }).then(() => { + assert.equal( + fs.readFileSync(file.name, { encoding: 'utf8' }), + this.expectedURL, + 'stdout is the URL' + ); + }); + }); + QUnit.test('updates local package.json when -w is passed (dependencies)', function(assert) { fs.writeFileSync( 'package.json',