mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
🔥 Remove grunt contributor (#331)
refs TryGhost/Ghost#7427 Removes unneccessary grunt dependencies from `package.json` and deletes contributor part in `Gruntfile.js`
This commit is contained in:
parent
4d896e6bca
commit
dc4a1cde86
2 changed files with 1 additions and 120 deletions
|
@ -4,7 +4,6 @@ var _ = require('lodash'),
|
|||
fs = require('fs-extra'),
|
||||
path = require('path'),
|
||||
https = require('https'),
|
||||
getTopContribs = require('top-gh-contribs'),
|
||||
moment = require('moment'),
|
||||
chalk = require('chalk'),
|
||||
Promise = require('bluebird');
|
||||
|
@ -18,9 +17,7 @@ module.exports = function(grunt) {
|
|||
clean: {
|
||||
built: {
|
||||
src: [
|
||||
'dist/**',
|
||||
'public/assets/img/contributors/**',
|
||||
'app/templates/-contributors.hbs'
|
||||
'dist/**'
|
||||
]
|
||||
},
|
||||
dependencies: {
|
||||
|
@ -96,116 +93,4 @@ module.exports = function(grunt) {
|
|||
grunt.registerTask('init', 'Install the client dependencies',
|
||||
['shell:npm-install', 'shell:bower-install']
|
||||
);
|
||||
|
||||
// ### Build About Page *(Utility Task)*
|
||||
// Builds the github contributors partial template used on the about page,
|
||||
// and downloads the avatar for each of the users.
|
||||
// Run by any task that compiles ember assets or manually via `grunt buildAboutPage`.
|
||||
// Only builds if the template does not exist.
|
||||
// To force a build regardless, supply the --force option.
|
||||
// `grunt buildAboutPage --force`
|
||||
grunt.registerTask('buildAboutPage', 'Compile assets for the About Ghost page', function () {
|
||||
var done = this.async(),
|
||||
templatePath = 'app/templates/-contributors.hbs',
|
||||
imagePath = 'public/assets/img/contributors',
|
||||
timeSpan = moment().subtract(90, 'days').format('YYYY-MM-DD'),
|
||||
oauthKey = process.env.GITHUB_OAUTH_KEY,
|
||||
contribNumber = 18;
|
||||
|
||||
if (fs.existsSync(templatePath) && !grunt.option('force')) {
|
||||
grunt.log.writeln('Contributors template already exists.');
|
||||
grunt.log.writeln(chalk.bold('Skipped'));
|
||||
return done();
|
||||
}
|
||||
|
||||
grunt.verbose.writeln('Downloading release and contributor information from Github');
|
||||
|
||||
function mergeContribs(first, second) {
|
||||
_.each(second, function (contributor) {
|
||||
var contributorInFirst = _.find(first, ['name', contributor.name]);
|
||||
|
||||
if (contributorInFirst) {
|
||||
contributorInFirst.commitCount += contributor.commitCount;
|
||||
} else {
|
||||
first.push(contributor);
|
||||
}
|
||||
});
|
||||
|
||||
return _(first)
|
||||
.filter(function (contributor) {
|
||||
// remove greenkeeper from contributor list
|
||||
return contributor.name !== 'greenkeeperio-bot';
|
||||
})
|
||||
.sortBy('commitCount')
|
||||
.reverse()
|
||||
.take(contribNumber)
|
||||
.value();
|
||||
}
|
||||
|
||||
return Promise.join(
|
||||
Promise.promisify(fs.mkdirs)(imagePath),
|
||||
getTopContribs({
|
||||
user: 'tryghost',
|
||||
repo: 'ghost',
|
||||
oauthKey: oauthKey,
|
||||
sinceDate: timeSpan,
|
||||
count: contribNumber,
|
||||
retry: true
|
||||
}),
|
||||
getTopContribs({
|
||||
user: 'tryghost',
|
||||
repo: 'ghost-admin',
|
||||
oauthKey: oauthKey,
|
||||
sinceDate: timeSpan,
|
||||
count: contribNumber,
|
||||
retry: true
|
||||
})
|
||||
).then(function (results) {
|
||||
var contributors = mergeContribs(results[1], results[2]),
|
||||
contributorTemplate = '<article>\n <a href="<%= githubUrl %>" title="<%= name %>">\n'
|
||||
+ ' <img src="{{gh-path "asset" "/img/contributors"}}/<%= name %>" alt="<%= name %>" />\n'
|
||||
+ ' </a>\n</article>',
|
||||
|
||||
downloadImagePromise = function (url, name) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var file = fs.createWriteStream(path.join(__dirname, imagePath, name));
|
||||
|
||||
https.get(url, function (response) {
|
||||
response.pipe(file);
|
||||
file.on('finish', function () {
|
||||
file.close();
|
||||
resolve();
|
||||
});
|
||||
}).on('error', reject);
|
||||
});
|
||||
};
|
||||
|
||||
grunt.verbose.writeln('Creating contributors template');
|
||||
grunt.file.write(
|
||||
templatePath,
|
||||
_.map(contributors, function (contributor) {
|
||||
var compiled = _.template(contributorTemplate);
|
||||
|
||||
return compiled(contributor);
|
||||
}).join('\n')
|
||||
);
|
||||
|
||||
grunt.verbose.writeln('Downloading images for top contributors');
|
||||
return Promise.all(_.map(contributors, function (contributor) {
|
||||
return downloadImagePromise(contributor.avatarUrl + '&s=60', contributor.name);
|
||||
}));
|
||||
}).then(done).catch(function (error) {
|
||||
grunt.log.error(error);
|
||||
|
||||
if (error.http_status) {
|
||||
grunt.log.writeln('GitHub API request returned status: ' + error.http_status);
|
||||
}
|
||||
|
||||
if (error.ratelimit_limit) {
|
||||
grunt.log.writeln('Rate limit data: limit: %d, remaining: %d, reset: %s', error.ratelimit_limit, error.ratelimit_remaining, moment.unix(error.ratelimit_reset).fromNow());
|
||||
}
|
||||
|
||||
done(false);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
@ -79,8 +79,6 @@
|
|||
"glob": "7.1.1",
|
||||
"grunt": "1.0.1",
|
||||
"grunt-bg-shell": "2.3.3",
|
||||
"grunt-contrib-clean": "1.0.0",
|
||||
"grunt-contrib-watch": "1.0.0",
|
||||
"grunt-shell": "1.3.1",
|
||||
"jquery-deparam": "0.5.2",
|
||||
"liquid-fire": "0.26.4",
|
||||
|
@ -104,8 +102,6 @@
|
|||
"ignore": [
|
||||
"grunt",
|
||||
"grunt-bg-shell",
|
||||
"grunt-contrib-clean",
|
||||
"grunt-contrib-watch",
|
||||
"grunt-shell"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue