From 7e5ac17fc410f335e4a63f52a693faddf1e67442 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 11 Nov 2015 16:20:02 +0000 Subject: [PATCH 1/6] Update header text --- lib/deploy.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/deploy.js b/lib/deploy.js index 575fdd2f..d33e1807 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -72,7 +72,7 @@ module.exports = function(config) { } } - console.log('Deploying "' + commitMessage + '"'); + console.log('Deploying "' + commitMessage + '" to GitHub Pages…'); if (cloneDir) { ghPagesConfig.clone = cloneDir; @@ -94,7 +94,9 @@ module.exports = function(config) { // We can't log on Travis because it would leak the GitHub token. // We can't use the gh-pages silent option because it makes error messages // less informative (https://github.com/mozilla/oghliner/pull/58#issuecomment-147550610). - ghPagesConfig.logger = ('GH_TOKEN' in process.env) ? function() {} : console.log; + ghPagesConfig.logger = ('GH_TOKEN' in process.env) ? function() {} : function(message) { + console.log(chalk.bold.green('✓ ') + message + '… done!'); + }; if ('GH_TOKEN' in process.env) { // We're using a token to authenticate with GitHub, so we have to embed From 3b17fff868f49fa78253ccb7d7e1c80a55b173a5 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 11 Nov 2015 16:33:17 +0000 Subject: [PATCH 2/6] Print spinner while performing the gh-pages operations --- lib/deploy.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/deploy.js b/lib/deploy.js index d33e1807..8e45d3cf 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -28,6 +28,7 @@ var fse = require('fs-extra'); var path = require('path'); var glob = require('glob'); var temp = require('temp').track(); +var cli = require('cli'); function getCommitMessage() { var spawn = childProcess.spawnSync('git', ['log', '--format=%B', '-n', '1']); @@ -41,6 +42,16 @@ function getCommitMessage() { return spawn.stdout.toString().trim(); } +var lastMessage; +function ghPagesLogger(message) { + if (lastMessage) { + cli.spinner(chalk.bold.green('✓ ') + lastMessage + '… done!', true); + } + + cli.spinner(' ' + message); + lastMessage = message; +} + module.exports = function(config) { return new Promise(function(resolve, reject) { config = config || {}; @@ -94,9 +105,7 @@ module.exports = function(config) { // We can't log on Travis because it would leak the GitHub token. // We can't use the gh-pages silent option because it makes error messages // less informative (https://github.com/mozilla/oghliner/pull/58#issuecomment-147550610). - ghPagesConfig.logger = ('GH_TOKEN' in process.env) ? function() {} : function(message) { - console.log(chalk.bold.green('✓ ') + message + '… done!'); - }; + ghPagesConfig.logger = ('GH_TOKEN' in process.env) ? function() {} : ghPagesLogger; if ('GH_TOKEN' in process.env) { // We're using a token to authenticate with GitHub, so we have to embed @@ -117,6 +126,10 @@ module.exports = function(config) { } ghPages.publish(rootDir, ghPagesConfig, function(err) { + if (lastMessage) { + cli.spinner(chalk.bold.green('✓ ') + lastMessage + '… done!', true); + } + if (err) { reject(err); } else { From 6f85021bf5798114ecbcc675c4d6ac1f49500dff Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 11 Nov 2015 16:51:25 +0000 Subject: [PATCH 3/6] Only print the first line of a multiline commit --- lib/deploy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/deploy.js b/lib/deploy.js index 8e45d3cf..79f4d74c 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -83,7 +83,7 @@ module.exports = function(config) { } } - console.log('Deploying "' + commitMessage + '" to GitHub Pages…'); + console.log('Deploying "' + commitMessage.split('\n')[0] + '" to GitHub Pages…'); if (cloneDir) { ghPagesConfig.clone = cloneDir; From 903b799d16025af6e69be3ee9e596a5d71ea4922 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 11 Nov 2015 17:06:31 +0000 Subject: [PATCH 4/6] Test commit message printing --- test/testDeploy.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/testDeploy.js b/test/testDeploy.js index de5f9925..6b1dacfb 100644 --- a/test/testDeploy.js +++ b/test/testDeploy.js @@ -5,6 +5,7 @@ var path = require('path'); var temp = require('temp').track(); var ghPages = require('gh-pages'); var deploy = require('../lib/deploy'); +var childProcess = require('child_process'); describe('Deploy', function() { var oldWD = process.cwd(); @@ -254,4 +255,47 @@ describe('Deploy', function() { }); }); }); + + function checkCommitMessage(message, expected) { + return new Promise(function(resolve, reject) { + var dir = temp.mkdirSync('oghliner'); + + process.chdir(dir); + + childProcess.execSync('git init'); + fs.writeFileSync('file', 'data'); + childProcess.execSync('git add file'); + childProcess.execSync('git commit -m "' + message + '"'); + + var output = ''; + var write = process.stdout.write; + process.stdout.write = function(chunk, encoding, fd) { + write.apply(process.stdout, arguments); + output += chunk; + + if (output.indexOf('Deploying "' + expected + '" to GitHub Pages…') !== -1) { + process.stdout.write = write; + resolve(); + } + }; + }); + } + + it('should prasd', function() { + return Promise.all([ + checkCommitMessage('Do. Or do not.', 'Do. Or do not.'), + deploy({ + cloneDir: '.gh-pages-cache', + }).catch(function() {}), + ]); + }); + + it('should print only the first line of a multiline commit', function() { + return Promise.all([ + checkCommitMessage('Do. Or do not.\nThere is no try.', 'Do. Or do not.'), + deploy({ + cloneDir: '.gh-pages-cache', + }).catch(function() {}), + ]); + }); }); From 8c4fea741c91d6afc4d8bbf57de4bf29581da16f Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 11 Nov 2015 17:19:56 +0000 Subject: [PATCH 5/6] Add white line after header and after the command output --- lib/deploy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/deploy.js b/lib/deploy.js index 79f4d74c..5e6a684d 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -83,7 +83,7 @@ module.exports = function(config) { } } - console.log('Deploying "' + commitMessage.split('\n')[0] + '" to GitHub Pages…'); + console.log('Deploying "' + commitMessage.split('\n')[0] + '" to GitHub Pages…\n'); if (cloneDir) { ghPagesConfig.clone = cloneDir; @@ -127,7 +127,7 @@ module.exports = function(config) { ghPages.publish(rootDir, ghPagesConfig, function(err) { if (lastMessage) { - cli.spinner(chalk.bold.green('✓ ') + lastMessage + '… done!', true); + cli.spinner(chalk.bold.green('✓ ') + lastMessage + '… done!\n', true); } if (err) { From 8503a7f4f0dd612a147ed0121ff2f0c17cdc46c8 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Fri, 13 Nov 2015 00:03:16 +0000 Subject: [PATCH 6/6] Update test description --- test/testDeploy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testDeploy.js b/test/testDeploy.js index 6b1dacfb..916c143e 100644 --- a/test/testDeploy.js +++ b/test/testDeploy.js @@ -281,7 +281,7 @@ describe('Deploy', function() { }); } - it('should prasd', function() { + it('should print the commit message', function() { return Promise.all([ checkCommitMessage('Do. Or do not.', 'Do. Or do not.'), deploy({