Fail buildAboutPage task on error

No Issue
- If buildAboutPage encounters a problem, fail the task so
  the entire test suite doesn't run only to fail because the
  template partial is missing.
- Cleaned up task.
This commit is contained in:
Jason Williams 2014-12-25 00:51:29 +00:00
parent ddaf19c5c5
commit 8af41b8aee

View File

@ -1024,6 +1024,7 @@ var _ = require('lodash'),
grunt.registerTask('buildAboutPage', 'Compile assets for the About Ghost page', function () { grunt.registerTask('buildAboutPage', 'Compile assets for the About Ghost page', function () {
var done = this.async(), var done = this.async(),
templatePath = 'core/client/templates/-contributors.hbs', templatePath = 'core/client/templates/-contributors.hbs',
imagePath = 'core/client/assets/img/contributors/',
ninetyDaysAgo = Date.now() - (1000 * 60 * 60 * 24 * 90); ninetyDaysAgo = Date.now() - (1000 * 60 * 60 * 24 * 90);
if (fs.existsSync(templatePath) && !grunt.option('force')) { if (fs.existsSync(templatePath) && !grunt.option('force')) {
@ -1033,15 +1034,29 @@ var _ = require('lodash'),
} }
grunt.verbose.writeln('Downloading release and contributor information from GitHub'); grunt.verbose.writeln('Downloading release and contributor information from GitHub');
getTopContribs({
user: 'tryghost', return Promise.join(
repo: 'ghost', Promise.promisify(fs.mkdirs)(imagePath),
releaseDate: ninetyDaysAgo, getTopContribs({
count: 20 user: 'tryghost',
}).then(function makeContributorTemplate(contributors) { repo: 'ghost',
var contributorTemplate = '<li>\n <a href="<%githubUrl%>" title="<%name%>">\n' + releaseDate: ninetyDaysAgo,
count: 20
})
).then(function (results) {
var contributors = results[1],
contributorTemplate = '<li>\n <a href="<%githubUrl%>" title="<%name%>">\n' +
' <img src="{{gh-path "admin" "/img/contributors"}}/<%name%>" alt="<%name%>">\n' + ' <img src="{{gh-path "admin" "/img/contributors"}}/<%name%>" alt="<%name%>">\n' +
' </a>\n</li>'; ' </a>\n</li>',
downloadImagePromise = function (url, name) {
return new Promise(function (resolve, reject) {
request(url)
.pipe(fs.createWriteStream(imagePath + name))
.on('close', resolve)
.on('error', reject);
});
};
grunt.verbose.writeln('Creating contributors template.'); grunt.verbose.writeln('Creating contributors template.');
grunt.file.write(templatePath, grunt.file.write(templatePath,
@ -1052,25 +1067,15 @@ var _ = require('lodash'),
.replace(/<%name%>/g, contributor.name); .replace(/<%name%>/g, contributor.name);
}).join('\n') }).join('\n')
); );
grunt.verbose.writeln('Downloading images for top contributors'); grunt.verbose.writeln('Downloading images for top contributors');
return Promise.promisify(fs.mkdirs)('core/client/assets/img/contributors').then(function () {
return contributors;
});
}).then(function downloadContributorImages(contributors) {
var downloadImagePromise = function (url, name) {
return new Promise(function (resolve, reject) {
request(url)
.pipe(fs.createWriteStream('core/client/assets/img/contributors/' + name))
.on('close', resolve)
.on('error', reject);
});
};
return Promise.all(_.map(contributors, function (contributor) { return Promise.all(_.map(contributors, function (contributor) {
return downloadImagePromise(contributor.avatarUrl + '&s=60', contributor.name); return downloadImagePromise(contributor.avatarUrl + '&s=60', contributor.name);
})); }));
}).catch(function (error) { }).then(done).catch(function (error) {
grunt.log.error(error); grunt.log.error(error.stack || error);
}).finally(done); done(false);
});
}); });
// ### Init assets // ### Init assets
// `grunt init` - will run an initial asset build for you // `grunt init` - will run an initial asset build for you