| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import config from '../config';
- import path from 'path';
- import gulp from 'gulp';
- import cached from 'gulp-cached';
- import eslint from 'gulp-eslint';
- import gulpif from 'gulp-if';
- import htmlhint from 'gulp-htmlhint';
- import plumber from 'gulp-plumber';
- import sassLint from 'gulp-sass-lint';
- const target = config.currentTarget;
- const isProduction = target === 'production';
- /**
- * Linting of javascript and jsx files
- *
- * @param cb: callback handler passed by gulp, signals task completion when called
- */
- const lintJs = (cb) => {
- gulp.src(
- path.join(
- config.paths.src,
- config.paths.js,
- '/**/*.{js, jsx}'
- ))
- .pipe(plumber())
- .pipe(cached('eslint'))
- .pipe(eslint(config.eslint[target]))
- .pipe(gulpif(!isProduction, eslint.format()))
- .pipe(gulpif(isProduction, eslint.formatEach('stylish', process.stdout)))
- .pipe(gulpif(isProduction, eslint.failOnError()))
- .on('data', gulpif(!isProduction, (file) => {
- if (file.eslint.messages && file.eslint.messages.length) gulp.fail = true;
- }));
- cb();
- };
- /**
- * Linting of sass / scss files
- *
- * @param cb: callback handler passed by gulp, signals task completion when called
- */
- const lintSass = (cb) => {
- gulp.src(
- path.join(
- config.paths.src,
- config.paths.sass,
- '/**/*.scss'
- ))
- .pipe(plumber())
- .pipe(gulpif(!isProduction, cached('sasslint')))
- .pipe(sassLint())
- .pipe(sassLint.format())
- .pipe(gulpif(isProduction, sassLint.failOnError()));
- cb();
- };
- /**
- * Linting of index.html
- *
- * @param cb: callback handler passed by gulp, signals task completion when called
- */
- const lintHtml = (cb) => {
- gulp.src(
- path.join(
- config.paths.src,
- config.paths.html,
- `${config.fileNames.html}.html`
- ))
- .pipe(htmlhint(config.htmlhintrc))
- .pipe(gulpif(!isProduction, htmlhint.reporter()))
- .pipe(gulpif(isProduction, htmlhint.failReporter()));
- cb();
- };
- const lint = (cb) => {
- gulp.parallel(
- lintSass,
- lintJs,
- lintHtml
- );
- cb();
- };
- export {
- lint,
- lintHtml,
- lintJs,
- lintSass
- };
|