chore: prettify non-source files

This commit is contained in:
Julien Fontanet 2017-12-06 13:52:12 +01:00
parent eb37c7d7d8
commit 8178de8a6b
3 changed files with 75 additions and 83 deletions

View File

@ -1,13 +1,10 @@
module.exports = {
'extends': [
'standard',
'standard-jsx',
],
'globals': {
'__DEV__': true
extends: ['standard', 'standard-jsx'],
globals: {
__DEV__: true
},
'parser': 'babel-eslint',
'rules': {
parser: 'babel-eslint',
rules: {
'comma-dangle': ['error', 'always-multiline'],
'no-var': 'error',
'prefer-const': 'error'

View File

@ -2,17 +2,17 @@
// ===================================================================
var SRC_DIR = __dirname + '/src' // eslint-disable-line no-path-concat
var DIST_DIR = __dirname + '/dist' // eslint-disable-line no-path-concat
const SRC_DIR = __dirname + '/src' // eslint-disable-line no-path-concat
const DIST_DIR = __dirname + '/dist' // eslint-disable-line no-path-concat
// Port to use for the livereload server.
//
// It must be available and if possible unique to not conflict with other projects.
// http://www.random.org/integers/?num=1&min=1024&max=65535&col=1&base=10&format=plain&rnd=new
var LIVERELOAD_PORT = 26242
const LIVERELOAD_PORT = 26242
var PRODUCTION = process.env.NODE_ENV === 'production'
var DEVELOPMENT = !PRODUCTION
const PRODUCTION = process.env.NODE_ENV === 'production'
const DEVELOPMENT = !PRODUCTION
if (!process.env.XOA_PLAN) {
process.env.XOA_PLAN = '5' // Open Source
@ -20,12 +20,12 @@ if (!process.env.XOA_PLAN) {
// ===================================================================
var gulp = require('gulp')
const gulp = require('gulp')
// ===================================================================
function lazyFn (factory) {
var fn = function () {
let fn = function () {
fn = factory()
return fn.apply(this, arguments)
}
@ -37,19 +37,19 @@ function lazyFn (factory) {
// -------------------------------------------------------------------
var livereload = lazyFn(function () {
var livereload = require('gulp-refresh')
const livereload = lazyFn(function () {
const livereload = require('gulp-refresh')
livereload.listen({
port: LIVERELOAD_PORT
port: LIVERELOAD_PORT,
})
return livereload
})
var pipe = lazyFn(function () {
var current
const pipe = lazyFn(function () {
let current
function pipeCore (streams) {
var i, n, stream
let i, n, stream
for (i = 0, n = streams.length; i < n; ++i) {
stream = streams[i]
if (!stream) {
@ -57,14 +57,12 @@ var pipe = lazyFn(function () {
} else if (stream instanceof Array) {
pipeCore(stream)
} else {
current = current
? current.pipe(stream)
: stream
current = current ? current.pipe(stream) : stream
}
}
}
var push = Array.prototype.push
const push = Array.prototype.push
return function (streams) {
try {
if (!(streams instanceof Array)) {
@ -81,7 +79,7 @@ var pipe = lazyFn(function () {
}
})
var resolvePath = lazyFn(function () {
const resolvePath = lazyFn(function () {
return require('path').resolve
})
@ -89,37 +87,35 @@ var resolvePath = lazyFn(function () {
// Similar to `gulp.src()` but the pattern is relative to `SRC_DIR`
// and files are automatically watched when not in production mode.
var src = lazyFn(function () {
const src = lazyFn(function () {
function resolve (path) {
return path
? resolvePath(SRC_DIR, path)
: SRC_DIR
return path ? resolvePath(SRC_DIR, path) : SRC_DIR
}
return PRODUCTION
? function src (pattern, opts) {
var base = resolve(opts && opts.base)
const base = resolve(opts && opts.base)
return gulp.src(pattern, {
base: base,
cwd: base,
passthrough: opts && opts.passthrough,
sourcemaps: opts && opts.sourcemaps
sourcemaps: opts && opts.sourcemaps,
})
}
: function src (pattern, opts) {
var base = resolve(opts && opts.base)
const base = resolve(opts && opts.base)
return pipe(
gulp.src(pattern, {
base: base,
cwd: base,
passthrough: opts && opts.passthrough,
sourcemaps: opts && opts.sourcemaps
sourcemaps: opts && opts.sourcemaps,
}),
require('gulp-watch')(pattern, {
base: base,
cwd: base
cwd: base,
}),
require('gulp-plumber')()
)
@ -129,17 +125,15 @@ var src = lazyFn(function () {
// Similar to `gulp.dest()` but the output directory is relative to
// `DIST_DIR` and default to `./`, and files are automatically live-
// reloaded when not in production mode.
var dest = lazyFn(function () {
const dest = lazyFn(function () {
function resolve (path) {
return path
? resolvePath(DIST_DIR, path)
: DIST_DIR
return path ? resolvePath(DIST_DIR, path) : DIST_DIR
}
var opts = {
const opts = {
sourcemaps: {
path: '.'
}
path: '.',
},
}
return PRODUCTION
@ -147,7 +141,7 @@ var dest = lazyFn(function () {
return gulp.dest(resolve(path), opts)
}
: function dest (path) {
var stream = gulp.dest(resolve(path), opts)
const stream = gulp.dest(resolve(path), opts)
stream.pipe(livereload())
return stream
}
@ -160,7 +154,7 @@ function browserify (path, opts) {
opts = {}
}
var bundler = require('browserify')(path, {
let bundler = require('browserify')(path, {
basedir: SRC_DIR,
debug: true,
extensions: opts.extensions,
@ -170,12 +164,12 @@ function browserify (path, opts) {
// Required by Watchify.
cache: {},
packageCache: {}
packageCache: {},
})
var plugins = opts.plugins
for (var i = 0, n = plugins && plugins.length; i < n; ++i) {
var plugin = plugins[i]
const plugins = opts.plugins
for (let i = 0, n = plugins && plugins.length; i < n; ++i) {
const plugin = plugins[i]
bundler.plugin(require(plugin[0]), plugin[1])
}
@ -186,7 +180,7 @@ function browserify (path, opts) {
bundler = require('watchify')(bundler, {
// do not watch in `node_modules`
// https://github.com/browserify/watchify#options
ignoreWatch: true
ignoreWatch: true,
})
}
@ -196,11 +190,11 @@ function browserify (path, opts) {
}
path = resolvePath(SRC_DIR, path)
var stream = new (require('readable-stream'))({
objectMode: true
let stream = new (require('readable-stream'))({
objectMode: true,
})
var write
let write
function bundle () {
bundler.bundle(function onBundle (error, buffer) {
if (error) {
@ -208,11 +202,13 @@ function browserify (path, opts) {
return
}
write(new (require('vinyl'))({
base: SRC_DIR,
contents: buffer,
path: path
}))
write(
new (require('vinyl'))({
base: SRC_DIR,
contents: buffer,
path: path,
})
)
})
}
@ -244,9 +240,10 @@ gulp.task(function buildPages () {
return pipe(
src('index.pug', { sourcemaps: true }),
require('gulp-pug')(),
DEVELOPMENT && require('gulp-embedlr')({
port: LIVERELOAD_PORT
}),
DEVELOPMENT &&
require('gulp-embedlr')({
port: LIVERELOAD_PORT,
}),
dest()
)
})
@ -256,10 +253,13 @@ gulp.task(function buildScripts () {
browserify('./index.js', {
plugins: [
// ['css-modulesify', {
['modular-css/browserify', {
css: DIST_DIR + '/modules.css'
}]
]
[
'modular-css/browserify',
{
css: DIST_DIR + '/modules.css',
},
],
],
}),
require('gulp-sourcemaps').init({ loadMaps: true }),
PRODUCTION && require('gulp-uglify/composer')(require('uglify-es'))(),
@ -271,10 +271,7 @@ gulp.task(function buildStyles () {
return pipe(
src('index.scss', { sourcemaps: true }),
require('gulp-sass')(),
require('gulp-autoprefixer')([
'last 1 version',
'> 1%'
]),
require('gulp-autoprefixer')(['last 1 version', '> 1%']),
PRODUCTION && require('gulp-csso')(),
dest()
)
@ -285,22 +282,20 @@ gulp.task(function copyAssets () {
src(['assets/**/*', 'favicon.*']),
src('fontawesome-webfont.*', {
base: __dirname + '/node_modules/font-awesome/fonts', // eslint-disable-line no-path-concat
passthrough: true
passthrough: true,
}),
src(['!*.css', 'font-mfizz.*'], {
base: __dirname + '/node_modules/font-mfizz/dist', // eslint-disable-line no-path-concat
passthrough: true
passthrough: true,
}),
dest()
)
})
gulp.task('build', gulp.parallel(
'buildPages',
'buildScripts',
'buildStyles',
'copyAssets'
))
gulp.task(
'build',
gulp.parallel('buildPages', 'buildScripts', 'buildStyles', 'copyAssets')
)
// -------------------------------------------------------------------

View File

@ -2,25 +2,25 @@
require('babel-register')
var Benchmark = require('benchmark')
var globby = require('globby')
var resolve = require('path').resolve
const Benchmark = require('benchmark')
const globby = require('globby')
const resolve = require('path').resolve
// ===================================================================
function bench (path) {
var fn = require(resolve(path))
let fn = require(resolve(path))
if (typeof fn !== 'function') {
fn = fn.default
}
var benchmarks = []
const benchmarks = []
function benchmark (name, fn) {
benchmarks.push(new Benchmark(name, fn))
}
fn({
benchmark: benchmark
benchmark: benchmark,
})
benchmarks.forEach(function (benchmark) {
@ -38,7 +38,7 @@ function main (args) {
throw new Error('no files to run')
}
for (var i = 0, n = paths.length; i < n; ++i) {
for (let i = 0, n = paths.length; i < n; ++i) {
bench(paths[i])
}
})