mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[tasks/lintStagedFiles] 🎶 promises are a devs best friend
This commit is contained in:
parent
8ca53bdd00
commit
81cda9179b
3 changed files with 35 additions and 28 deletions
|
@ -29,7 +29,7 @@
|
|||
"test": "grunt test",
|
||||
"start": "node ./src/server/bin/kibana.js",
|
||||
"server": "node ./src/server/bin/kibana.js",
|
||||
"precommit": "grunt hintStagedFiles"
|
||||
"precommit": "grunt lintStagedFiles"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
var path = require('path');
|
||||
var workingPath = path.resolve(__dirname, '..');
|
||||
var simplegit = require('simple-git')(workingPath);
|
||||
module.exports = function (grunt) {
|
||||
grunt.registerTask('hintStagedFiles', 'JSHint staged filed', function () {
|
||||
grunt.log.debug('git working path', workingPath);
|
||||
|
||||
var done = this.async();
|
||||
var files = simplegit.diff('--name-only --cached', function (err, files) {
|
||||
// match these patterns
|
||||
var patterns = grunt.config.get('lintThese');
|
||||
files = files.split('\n').filter(Boolean).map(function (file) {
|
||||
return path.join(workingPath, file);
|
||||
});
|
||||
|
||||
files = grunt.file.match(patterns, files);
|
||||
grunt.log.debug(files);
|
||||
|
||||
grunt.config.set('jshint.staged.files.src', files);
|
||||
grunt.config.set('jscs.staged.files.src', files);
|
||||
|
||||
grunt.task.run(['jshint:staged', 'jscs:staged']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
34
tasks/lintStagedFiles.js
Normal file
34
tasks/lintStagedFiles.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
var resolve = require('path').resolve;
|
||||
var root = resolve(__dirname, '..');
|
||||
var simpleGit = require('simple-git')(root);
|
||||
var diff = require('bluebird').promisify(simpleGit.diff, simpleGit);
|
||||
|
||||
module.exports = function (grunt) {
|
||||
|
||||
grunt.registerTask(
|
||||
'lintStagedFiles',
|
||||
'Run staged files through JSHint/JSCS',
|
||||
function () {
|
||||
|
||||
diff('--name-only --cached')
|
||||
.then(function (files) {
|
||||
// match these patterns
|
||||
var patterns = grunt.config.get('lintThese');
|
||||
files = files.split('\n').filter(Boolean).map(function (file) {
|
||||
return resolve(root, file);
|
||||
});
|
||||
|
||||
files = grunt.file.match(patterns, files);
|
||||
grunt.log.debug(files);
|
||||
|
||||
grunt.config.set('jshint.staged.files.src', files);
|
||||
grunt.config.set('jscs.staged.files.src', files);
|
||||
|
||||
grunt.task.run(['jshint:staged', 'jscs:staged']);
|
||||
})
|
||||
.nodeify(this.async());
|
||||
|
||||
}
|
||||
);
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue