|
@@ -13,31 +13,48 @@ const gutil = require( 'gulp-util' );
|
|
|
module.exports = ( config ) => {
|
|
module.exports = ( config ) => {
|
|
|
const src = [ '**/*.js' ].concat( config.IGNORED_FILES.map( i => '!' + i ), getGitIgnore() );
|
|
const src = [ '**/*.js' ].concat( config.IGNORED_FILES.map( i => '!' + i ), getGitIgnore() );
|
|
|
|
|
|
|
|
- gulp.task( 'lint', () => {
|
|
|
|
|
- return gulp.src( src )
|
|
|
|
|
- .pipe( lint() );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- gulp.task( 'pre-commit', () => {
|
|
|
|
|
- return guppy.stream( 'pre-commit' )
|
|
|
|
|
- .pipe( gulpFilter( src ) )
|
|
|
|
|
- .pipe( lint() )
|
|
|
|
|
-
|
|
|
|
|
- // Error reporting for gulp.
|
|
|
|
|
- .pipe( jscs.reporter( 'fail' ) )
|
|
|
|
|
- .on( 'error', errorHandler )
|
|
|
|
|
- .pipe( jshint.reporter( 'fail' ) )
|
|
|
|
|
- .on( 'error', errorHandler );
|
|
|
|
|
|
|
+ const tasks = {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Returns stream containing jshint and jscs reporters.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @returns { Stream }
|
|
|
|
|
+ */
|
|
|
|
|
+ lint() {
|
|
|
|
|
+ return gulp.src( src )
|
|
|
|
|
+ .pipe( lint() );
|
|
|
|
|
+ },
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Handles error from jscs and jshint fail reporters. Stops node process with error code
|
|
|
|
|
- * and prints error message to the console.
|
|
|
|
|
|
|
+ * This method is executed on pre-commit hook, linting only files staged for current commit.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @returns { Stream }
|
|
|
*/
|
|
*/
|
|
|
- function errorHandler() {
|
|
|
|
|
- gutil.log( gutil.colors.red( 'Linting failed, commit aborted' ) );
|
|
|
|
|
- process.exit( 1 );
|
|
|
|
|
|
|
+ preCommit() {
|
|
|
|
|
+ return guppy.stream( 'pre-commit' )
|
|
|
|
|
+ .pipe( gulpFilter( src ) )
|
|
|
|
|
+ .pipe( lint() )
|
|
|
|
|
+
|
|
|
|
|
+ // Error reporting for gulp.
|
|
|
|
|
+ .pipe( jscs.reporter( 'fail' ) )
|
|
|
|
|
+ .on( 'error', errorHandler )
|
|
|
|
|
+ .pipe( jshint.reporter( 'fail' ) )
|
|
|
|
|
+ .on( 'error', errorHandler );
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Handles error from jscs and jshint fail reporters. Stops node process with error code
|
|
|
|
|
+ * and prints error message to the console.
|
|
|
|
|
+ */
|
|
|
|
|
+ function errorHandler() {
|
|
|
|
|
+ gutil.log( gutil.colors.red( 'Linting failed, commit aborted' ) );
|
|
|
|
|
+ process.exit( 1 );
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- } );
|
|
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ gulp.task( 'lint', tasks.lint );
|
|
|
|
|
+ gulp.task( 'pre-commit', tasks.preCommit );
|
|
|
|
|
+
|
|
|
|
|
+ return tasks;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Gets the list of ignores from `.gitignore`.
|
|
* Gets the list of ignores from `.gitignore`.
|