2016-06-28 20:36:00 +03:00
|
|
|
/* global -moment */
|
|
|
|
/* jshint node: true */
|
2016-05-24 15:07:31 +03:00
|
|
|
/* jscs:disable */
|
2016-06-28 20:36:00 +03:00
|
|
|
var _ = require('lodash'),
|
|
|
|
fs = require('fs-extra'),
|
|
|
|
path = require('path'),
|
|
|
|
https = require('https'),
|
|
|
|
getTopContribs = require('top-gh-contribs'),
|
|
|
|
moment = require('moment'),
|
|
|
|
chalk = require('chalk'),
|
2016-08-03 10:54:24 +03:00
|
|
|
Promise = require('bluebird');
|
2016-05-24 15:07:31 +03:00
|
|
|
|
|
|
|
module.exports = function(grunt) {
|
|
|
|
|
|
|
|
// Find all of the task which start with `grunt-` and load them, rather than explicitly declaring them all
|
|
|
|
require('matchdep').filterDev(['grunt-*', '!grunt-cli']).forEach(grunt.loadNpmTasks);
|
|
|
|
|
|
|
|
grunt.initConfig({
|
2016-07-14 14:43:49 +03:00
|
|
|
clean: {
|
|
|
|
built: {
|
|
|
|
src: [
|
|
|
|
'dist/**',
|
|
|
|
'public/assets/img/contributors/**',
|
|
|
|
'app/templates/-contributors.hbs'
|
|
|
|
]
|
|
|
|
},
|
|
|
|
dependencies: {
|
|
|
|
src: [
|
|
|
|
'bower_components/**',
|
|
|
|
'node_modules/**'
|
|
|
|
]
|
|
|
|
},
|
|
|
|
tmp: {
|
|
|
|
src: ['tmp/**']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-05-24 15:07:31 +03:00
|
|
|
jshint: {
|
|
|
|
options: {
|
|
|
|
jshintrc: true,
|
|
|
|
ignores: [
|
|
|
|
'node_modules/**',
|
|
|
|
'bower_components/**',
|
|
|
|
'tmp/**',
|
|
|
|
'dist/**',
|
|
|
|
'vendor/**'
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
all: ['**/*.js']
|
|
|
|
},
|
|
|
|
|
|
|
|
jscs: {
|
|
|
|
app: {
|
|
|
|
options: {
|
|
|
|
config: '.jscsrc',
|
|
|
|
excludeFiles: [
|
|
|
|
'node_modules/**',
|
|
|
|
'bower_components/**',
|
|
|
|
'tests/**',
|
|
|
|
'tmp/**',
|
|
|
|
'dist/**',
|
|
|
|
'vendor/**'
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
files: {
|
|
|
|
src: ['**/*.js']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tests: {
|
|
|
|
options: {
|
|
|
|
config: 'tests/.jscsrc'
|
|
|
|
},
|
|
|
|
|
|
|
|
files: {
|
|
|
|
src: [
|
|
|
|
'tests/**/*.js'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-08-03 10:54:24 +03:00
|
|
|
// ### grunt-bg-shell
|
|
|
|
// Used to run ember-cli watch in the background
|
|
|
|
bgShell: {
|
|
|
|
ember: {
|
|
|
|
cmd: 'npm run build -- --watch',
|
2016-08-06 12:26:24 +03:00
|
|
|
bg: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
csscomb: {
|
|
|
|
files: ['app/styles/**/*.css'],
|
|
|
|
tasks: ['shell:csscombfix']
|
2016-08-03 10:54:24 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-05-24 15:07:31 +03:00
|
|
|
shell: {
|
2016-06-18 20:30:35 +03:00
|
|
|
'npm-install': {
|
|
|
|
command: 'npm install'
|
|
|
|
},
|
|
|
|
|
|
|
|
'bower-install': {
|
2016-08-03 10:54:24 +03:00
|
|
|
command: 'bower install'
|
|
|
|
},
|
|
|
|
|
|
|
|
ember: {
|
|
|
|
command: function (mode) {
|
|
|
|
switch (mode) {
|
|
|
|
case 'prod':
|
|
|
|
return 'npm run build -- --environment=production --silent';
|
|
|
|
|
|
|
|
case 'dev':
|
|
|
|
return 'npm run build';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
execOptions: {
|
|
|
|
stdout: false
|
|
|
|
}
|
|
|
|
}
|
2016-06-18 20:30:35 +03:00
|
|
|
},
|
|
|
|
|
2016-05-24 15:07:31 +03:00
|
|
|
csscombfix: {
|
2016-08-03 10:54:24 +03:00
|
|
|
command: 'csscomb -c app/styles/csscomb.json -v app/styles'
|
2016-05-24 15:07:31 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
csscomblint: {
|
2016-08-03 10:54:24 +03:00
|
|
|
command: 'csscomb -c app/styles/csscomb.json -lv app/styles'
|
|
|
|
},
|
|
|
|
|
|
|
|
test: {
|
|
|
|
command: 'npm test'
|
|
|
|
},
|
|
|
|
|
|
|
|
options: {
|
|
|
|
preferLocal: true
|
2016-05-24 15:07:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-18 20:30:35 +03:00
|
|
|
grunt.registerTask('init', 'Install the client dependencies',
|
2016-10-17 11:58:44 +03:00
|
|
|
['shell:npm-install', 'shell:bower-install']
|
2016-06-18 20:30:35 +03:00
|
|
|
);
|
|
|
|
|
2016-05-24 15:07:31 +03:00
|
|
|
grunt.registerTask('lint', 'Run the code style checks and linter',
|
|
|
|
['jshint', 'jscs', 'shell:csscomblint']
|
|
|
|
);
|
2016-06-28 20:36:00 +03:00
|
|
|
|
|
|
|
// ### 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' +
|
2016-10-08 00:16:26 +03:00
|
|
|
' <img src="{{gh-path "asset" "/img/contributors"}}/<%= name %>" alt="<%= name %>" />\n' +
|
2016-06-28 20:36:00 +03:00
|
|
|
' </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);
|
|
|
|
});
|
|
|
|
});
|
2016-05-24 15:07:31 +03:00
|
|
|
};
|