lint gulpfile, add eslint config and ignore file for those that using eslint

This commit is contained in:
Lukas Juhas 2017-11-21 17:55:18 +00:00
parent 4296b41faf
commit fa5afe879e
3 changed files with 135 additions and 95 deletions

2
.eslintignore Normal file
View File

@ -0,0 +1,2 @@
js/**/*.js
node_modules/**/*.js

39
.eslintrc.js Normal file
View File

@ -0,0 +1,39 @@
module.exports = {
"root": true,
"parserOptions": {
"parser": "babel-eslint",
"ecmaVersion": 2017,
"sourceType": "module"
},
"env": {
"browser": true,
"node": true,
"es6": true
},
"globals": {
"window": true,
"location": true
},
"extends": [
"airbnb-base",
],
// custom rules here
"rules": {
// don"t require .vue extension when importing
"import/extensions": ["error", "always", {
"js": "never",
"vue": "js",
"mjs": "never"
}],
"no-param-reassign": ["error", {
"props": true,
"ignorePropertyModificationsFor": [
"event", // for e.returnvalue
"response", // for Express responses
"item", // for item usually within each loops
]
}],
// allow debugger during development
"no-debugger": process.env.NODE_ENV === "production" ? 2 : 0
}
}

View File

@ -1,4 +1,3 @@
/* eslint-disable no-console */
import gulp from 'gulp'; import gulp from 'gulp';
import clean from 'gulp-clean'; import clean from 'gulp-clean';
import sass from 'gulp-sass'; import sass from 'gulp-sass';
@ -20,7 +19,7 @@ import notify from 'gulp-notify';
import runSequence from 'run-sequence'; import runSequence from 'run-sequence';
import path from 'path'; import path from 'path';
const log = console.log; const { log } = console;
let production = false; let production = false;
let error = false; let error = false;
@ -28,8 +27,8 @@ let error = false;
* Config * Config
*/ */
const config = { const config = {
src: './assets', src: './assets',
public: './', public: './',
}; };
/** /**
@ -44,140 +43,140 @@ const tasks = ['styles', 'scripts', 'images'];
* @param {string} status * @param {string} status
*/ */
function notification(message = '', status = 'success') { function notification(message = '', status = 'success') {
return gulp.src('./node_modules/gulp-notify/test/fixtures/1.txt') return gulp.src('./node_modules/gulp-notify/test/fixtures/1.txt')
.pipe(notify({ .pipe(notify({
title: 'Barebones', title: 'Barebones',
message, message,
icon: path.join(__dirname, `assets/icons/${status}.png`), icon: path.join(__dirname, `assets/icons/${status}.png`),
})); }));
} }
/** /**
* Styles * Styles
*/ */
gulp.task('clean-styles', () => ( gulp.task('clean-styles', () => (
gulp.src(`${config.public}/css`, { gulp.src(`${config.public}/css`, {
read: false, read: false,
}) })
.pipe(clean()) .pipe(clean())
)); ));
gulp.task('styles', ['clean-styles'], () => ( gulp.task('styles', ['clean-styles'], () => (
gulp.src([`${config.src}/styles/*.scss`]) gulp.src([`${config.src}/styles/*.scss`])
.pipe(gulpif(!production, sourcemaps.init())) .pipe(gulpif(!production, sourcemaps.init()))
.pipe(sass({ .pipe(sass({
outputStyle: production ? 'compressed' : 'nested', outputStyle: production ? 'compressed' : 'nested',
}).on('error', (err) => { }).on('error', (err) => {
notification('Failed to compile styles. 😱', 'error'); notification('Failed to compile styles. 😱', 'error');
log(err.stack); log(err.stack);
error = true; error = true;
})) }))
.pipe(autoprefixer({ .pipe(autoprefixer({
browsers: ['last 10 versions'], browsers: ['last 10 versions'],
})) }))
.pipe(rename({ .pipe(rename({
suffix: '.min', suffix: '.min',
})) }))
.pipe(gulpif(!production, sourcemaps.write('.'))) .pipe(gulpif(!production, sourcemaps.write('.')))
.pipe(gulp.dest(`${config.public}/css`)) .pipe(gulp.dest(`${config.public}/css`))
)); ));
/** /**
* Scripts * Scripts
*/ */
gulp.task('clean-scripts', () => ( gulp.task('clean-scripts', () => (
gulp.src(`${config.public}/js`, { gulp.src(`${config.public}/js`, {
read: false, read: false,
}) })
.pipe(clean()) .pipe(clean())
)); ));
gulp.task('scripts', ['clean-scripts'], () => { gulp.task('scripts', ['clean-scripts'], () => {
let env = 'development'; let env = 'development';
if (production) { if (production) {
env = 'production'; env = 'production';
} }
rollup({ rollup({
entry: `${config.src}/scripts/scripts.js`, entry: `${config.src}/scripts/scripts.js`,
plugins: [ plugins: [
multiEntry(), multiEntry(),
buble(), buble(),
nodeResolve({ nodeResolve({
browser: true, browser: true,
main: true, main: true,
jsnext: true, jsnext: true,
}), }),
commonjs({ commonjs({
include: [ include: [
'node_modules/**', 'node_modules/**',
`${config.src}/**`, `${config.src}/**`,
],
}),
json(),
replace({
'process.env.NODE_ENV': JSON.stringify(env),
}),
production ? uglify({}, minify) : '',
], ],
}).then((bundle) => { }),
bundle.write({ json(),
format: 'iife', replace({
moduleName: 'BarebonesBundle', 'process.env.NODE_ENV': JSON.stringify(env),
sourceMap: !production, }),
dest: `${config.public}/js/script.min.js`, production ? uglify({}, minify) : '',
}); ],
}).catch(err => { }).then((bundle) => {
notification('Failed to compile scripts. 😱', 'error'); bundle.write({
log(err.stack); format: 'iife',
error = true; moduleName: 'BarebonesBundle',
sourceMap: !production,
dest: `${config.public}/js/script.min.js`,
}); });
}).catch((err) => {
notification('Failed to compile scripts. 😱', 'error');
log(err.stack);
error = true;
});
}); });
/** /**
* Watch * Watch
*/ */
gulp.task('watch-files', tasks, () => { gulp.task('watch-files', tasks, () => {
gulp.watch(`${config.src}/styles/**/*.scss`, ['styles']); gulp.watch(`${config.src}/styles/**/*.scss`, ['styles']);
gulp.watch(`${config.src}/scripts/**/*.js`, ['scripts']); gulp.watch(`${config.src}/scripts/**/*.js`, ['scripts']);
gulp.watch(`${config.src}/images/**/*.*`, ['images']); gulp.watch(`${config.src}/images/**/*.*`, ['images']);
}); });
/** /**
* Images * Images
*/ */
gulp.task('images', () => { gulp.task('images', () => {
// hadle all images that are not svg // hadle all images that are not svg
gulp.src(`${config.src}/images/**/*.*`) gulp.src(`${config.src}/images/**/*.*`)
.pipe(imagemin({ .pipe(imagemin({
progressive: true, progressive: true,
svgoPlugins: [{ svgoPlugins: [{
removeViewBox: false, removeViewBox: false,
}], }],
})) }))
.pipe(gulp.dest(`${config.public}/img`)); .pipe(gulp.dest(`${config.public}/img`));
}); });
/** /**
* Main Tasks * Main Tasks
*/ */
gulp.task('watch', () => ( gulp.task('watch', () => (
runSequence(tasks, 'watch-files', () => { runSequence(tasks, 'watch-files', () => {
if (!error) { if (!error) {
notification('Watching files... 👀'); notification('Watching files... 👀');
} }
}) })
)); ));
gulp.task('build', () => { gulp.task('build', () => {
production = true; production = true;
runSequence(tasks, () => { runSequence(tasks, () => {
if(!error) { if (!error) {
notification('Build complete! 🍻'); notification('Build complete! 🍻');
} }
}); });
}); });
gulp.task('default', () => ( gulp.task('default', () => (
runSequence(tasks) runSequence(tasks)
)); ));