Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated from jshint -> eslint #1930

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
/src/js/vendor
12 changes: 12 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "airbnb",
"env": {
"browser": true,
"mocha": true,
"es6": true
},
"rules": {
"no-plusplus": "off",
"no-cond-assign": "off"
}
}
68 changes: 0 additions & 68 deletions .jscsrc

This file was deleted.

32 changes: 0 additions & 32 deletions .jshintrc

This file was deleted.

31 changes: 15 additions & 16 deletions dist/js/plugins.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
// Avoid `console` errors in browsers that lack a console.
(function() {

This comment was marked as abuse.

var method;
var noop = function () {};
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn'
];
var length = methods.length;
var console = (window.console = window.console || {});
(function () {
let method;
const noop = function () {};
const methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn',
];
let length = methods.length;

while (length--) {
method = methods[length];
while (length--) {
method = methods[length];

// Only stub undefined methods.
if (!console[method]) {
console[method] = noop;
}
if (!console[method]) {
console[method] = noop;
}
}
}());

// Place any jQuery/helper plugins in here.
135 changes: 59 additions & 76 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import runSequence from 'run-sequence';
import archiver from 'archiver';
import glob from 'glob';
import del from 'del';
import sri from 'node-sri'
import sri from 'node-sri';

import pkg from './package.json';

Expand All @@ -25,102 +25,97 @@ const dirs = pkg['h5bp-configs'].directories;
// ---------------------------------------------------------------------

gulp.task('archive:create_archive_dir', () => {
fs.mkdirSync(path.resolve(dirs.archive), '0755');
fs.mkdirSync(path.resolve(dirs.archive), '0755');
});

gulp.task('archive:zip', (done) => {
const archiveName = path.resolve(dirs.archive, `${pkg.name}_v${pkg.version}.zip`);
const zip = archiver('zip');
const files = glob.sync('**/*.*', {
cwd: dirs.dist,
dot: true, // include hidden files
});
const output = fs.createWriteStream(archiveName);

const archiveName = path.resolve(dirs.archive, `${pkg.name}_v${pkg.version}.zip`);
const zip = archiver('zip');
const files = glob.sync('**/*.*', {
'cwd': dirs.dist,
'dot': true // include hidden files
});
const output = fs.createWriteStream(archiveName);

zip.on('error', (error) => {
done();
throw error;
});
zip.on('error', (error) => {
done();
throw error;
});

output.on('close', done);
output.on('close', done);

files.forEach( (file) => {

const filePath = path.resolve(dirs.dist, file);
files.forEach((file) => {
const filePath = path.resolve(dirs.dist, file);

// `zip.bulk` does not maintain the file
// permissions, so we need to add files individually
zip.append(fs.createReadStream(filePath), {
'name': file,
'mode': fs.statSync(filePath).mode
});

zip.append(fs.createReadStream(filePath), {
name: file,
mode: fs.statSync(filePath).mode,
});
});

zip.pipe(output);
zip.finalize();

zip.pipe(output);
zip.finalize();
});

gulp.task('clean', (done) => {
del([
dirs.archive,
dirs.dist
]).then( () => {
done();
});
del([
dirs.archive,
dirs.dist,
]).then(() => {
done();
});
});

gulp.task('copy', [
'copy:.htaccess',
'copy:index.html',
'copy:jquery',
'copy:license',
'copy:main.css',
'copy:misc',
'copy:normalize'
'copy:.htaccess',
'copy:index.html',
'copy:jquery',
'copy:license',
'copy:main.css',
'copy:misc',
'copy:normalize',
]);

gulp.task('copy:.htaccess', () =>
gulp.src('node_modules/apache-server-configs/dist/.htaccess')
.pipe(plugins().replace(/# ErrorDocument/g, 'ErrorDocument'))
.pipe(gulp.dest(dirs.dist))
.pipe(gulp.dest(dirs.dist)),
);

gulp.task('copy:index.html', (done) =>
gulp.task('copy:index.html', done =>
sri.hash('node_modules/jquery/dist/jquery.min.js', (err, hash) => {
if (err) throw err
if (err) throw err;

let version = pkg.devDependencies.jquery;
gulp.src(`${dirs.src}/index.html`)
const version = pkg.devDependencies.jquery;
gulp.src(`${dirs.src}/index.html`)
.pipe(plugins().replace(/{{JQUERY_VERSION}}/g, version))
.pipe(plugins().replace(/{{JQUERY_SRI_HASH}}/g, hash))
.pipe(gulp.dest(dirs.dist));
done();
})
done();
}),
);

gulp.task('copy:jquery', () =>
gulp.src(['node_modules/jquery/dist/jquery.min.js'])
.pipe(plugins().rename(`jquery-${pkg.devDependencies.jquery}.min.js`))
.pipe(gulp.dest(`${dirs.dist}/js/vendor`))
.pipe(gulp.dest(`${dirs.dist}/js/vendor`)),
);

gulp.task('copy:license', () =>
gulp.src('LICENSE.txt')
.pipe(gulp.dest(dirs.dist))
.pipe(gulp.dest(dirs.dist)),
);

gulp.task('copy:main.css', () => {
const banner = `/*! HTML5 Boilerplate v${pkg.version} | ${pkg.license} License | ${pkg.homepage} */\n\n`;

const banner = `/*! HTML5 Boilerplate v${pkg.version} | ${pkg.license} License | ${pkg.homepage} */\n\n`;

gulp.src(`${dirs.src}/css/main.css`)
gulp.src(`${dirs.src}/css/main.css`)
.pipe(plugins().header(banner))
.pipe(plugins().autoprefixer({
browsers: ['last 2 versions', 'ie >= 8', '> 1%'],
cascade: false
browsers: ['last 2 versions', 'ie >= 8', '> 1%'],
cascade: false,
}))
.pipe(gulp.dest(`${dirs.dist}/css`));
});
Expand All @@ -129,55 +124,43 @@ gulp.task('copy:misc', () =>
gulp.src([

// Copy all files
`${dirs.src}/**/*`,
`${dirs.src}/**/*`,

// Exclude the following files
// (other tasks will handle the copying of these files)
`!${dirs.src}/css/main.css`,
`!${dirs.src}/index.html`
`!${dirs.src}/css/main.css`,
`!${dirs.src}/index.html`,

], {

// Include hidden files by default
dot: true
dot: true,

}).pipe(gulp.dest(dirs.dist))
}).pipe(gulp.dest(dirs.dist)),
);

gulp.task('copy:normalize', () =>
gulp.src('node_modules/normalize.css/normalize.css')
.pipe(gulp.dest(`${dirs.dist}/css`))
);

gulp.task('lint:js', () =>
gulp.src([
'gulpfile.js',
`${dirs.src}/js/*.js`,
`${dirs.test}/*.js`
]).pipe(plugins().jscs())
.pipe(plugins().jshint())
.pipe(plugins().jshint.reporter('jshint-stylish'))
.pipe(plugins().jshint.reporter('fail'))
.pipe(gulp.dest(`${dirs.dist}/css`)),
);


// ---------------------------------------------------------------------
// | Main tasks |
// ---------------------------------------------------------------------

gulp.task('archive', (done) => {
runSequence(
runSequence(
'build',
'archive:create_archive_dir',
'archive:zip',
done)
done);
});

gulp.task('build', (done) => {
runSequence(
['clean', 'lint:js'],
runSequence(
['clean'],
'copy',
done)
done);
});

gulp.task('default', ['build']);
Loading