Skip to content

Commit

Permalink
Print only the url when being piped/scripted.
Browse files Browse the repository at this point in the history
This ensures that something akin to `ember-source-channel-url >
some-file.txt` writes only the URL (not the verbose console message).
  • Loading branch information
rwjblue committed May 16, 2019
1 parent da4d191 commit 569cd10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions bin/ember-source-channel-url
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
11 changes: 11 additions & 0 deletions tests/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 569cd10

Please sign in to comment.