Skip to content

Commit

Permalink
Tool Config files: Run Prettier/ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
zowesiouff committed Jun 30, 2017
1 parent 227200b commit 7930ab3
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 164 deletions.
131 changes: 66 additions & 65 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,134 +4,135 @@
* Apache 2.0 Licensed
*/


"use strict";
const babel = require('gulp-babel');
const del = require('del');
const eslint = require('gulp-eslint');
const fs = require('fs');
const gulp = require('gulp');
const gutil = require('gulp-util');
const KarmaServer = require('karma').Server;
const webpack = require('webpack');
const webpack_config = require('./webpack.config.js');
const WebpackDevServer = require('webpack-dev-server');
const _ = require('lodash');

const del = require("del");
const eslint = require("gulp-eslint");
const fs = require("fs");
const gulp = require("gulp");
const gutil = require("gulp-util");
const KarmaServer = require("karma").Server;
const webpack = require("webpack");
const webpack_config = require("./webpack.config.js");
const WebpackDevServer = require("webpack-dev-server");
const _ = require("lodash");

/**
* Environments configuration
*/
const chalk = require('chalk');
const ALLOWED_ENVS = ['dev', 'prod', 'preprod'];
const chalk = require("chalk");

const ALLOWED_ENVS = ["dev", "prod", "preprod"];
const env_name = process.env.NODE_ENV;
if (ALLOWED_ENVS.indexOf(env_name) != -1) {
if (ALLOWED_ENVS.indexOf(env_name) !== -1) {
console.log(`Running environment ${chalk.green(env_name)}`);
} else {
console.error(chalk.red(`Environment ${chalk.blue(env_name)} not in ${chalk.yellow(ALLOWED_ENVS)}`));
console.error(
chalk.red(`Environment ${chalk.blue(env_name)} not in ${chalk.yellow(ALLOWED_ENVS)}`)
);
process.exit(1);
}


/**
* Globbing expressions
*/
const client_files = 'src/client/**/*.js?(x)';
const test_files = 'test/**/*.js';

const client_files = "src/client/**/*.js?(x)";
const test_files = "test/**/*.js";

/**
* Main tasks
*/
gulp.task('lint', () => {
return gulp.src([
client_files,
test_files,
'!src/client/rollbar.umd.nojson.min.js',
])
gulp.task("lint", () => {
return gulp
.src([client_files, test_files, "!src/client/rollbar.umd.nojson.min.js"])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('webpack', (callback) => {
gulp.task("webpack", callback => {
const config = webpack_config({
env: env_name,
env: env_name
});
webpack(config, (error, stats) => {
if (error) {
throw new gutil.PluginError('webpack', error)
};
gutil.log("[webpack]", stats.toString({
'colors': true,
}));
throw new gutil.PluginError("webpack", error);
}
gutil.log(
"[webpack]",
stats.toString({
colors: true
})
);
callback();
});
});

gulp.task('webpack-dev-server', (callback) => {
const host = 'dev.kin.today';
gulp.task("webpack-dev-server", () => {
const host = "dev.kin.today";
const port = 8080;

const config = webpack_config({
env: env_name,
env: env_name
});

// FIXME: Webpack dev server's inline mode seems to auto-reload the page in rare
// occasions (first install iOS simulator -> first connector),
// might need further investigations
_.forEach(config.entry, entry => {
entry.unshift('webpack-dev-server/client?https://' + host + ':' + port + '/');
entry.unshift(`webpack-dev-server/client?https://${host}:${port}/`);
});

// Start a webpack-dev-server
new WebpackDevServer(webpack(config), {
key: fs.readFileSync('./certs/localhost-key.pem'),
cert: fs.readFileSync('./certs/localhost-cert.pem'),
key: fs.readFileSync("./certs/localhost-key.pem"),
cert: fs.readFileSync("./certs/localhost-cert.pem"),
https: true,
stats: {
colors: true
},
}).listen(port, host, (error) => {
}
}).listen(port, host, error => {
if (error) {
throw new gutil.PluginError('webpack-dev-server', error);
throw new gutil.PluginError("webpack-dev-server", error);
}
gutil.log('[webpack-dev-server]', 'https://' + host + ':' + port + '/index.html');
gutil.log("[webpack-dev-server]", `https://${host}:${port}/index.html`);
});
});


/**
* Test tasks
*/
gulp.task('test', ['_set-test-node-env'], (done) => {
new KarmaServer({
configFile: `${__dirname}/karma.config.js`,
singleRun: true,
}, done).start();
gulp.task("test", ["_set-test-node-env"], done => {
new KarmaServer(
{
configFile: `${__dirname}/karma.config.js`,
singleRun: true
},
done
).start();
});

gulp.task('test-watch', ['_set-test-node-env'], (done) => {
new KarmaServer({
configFile: `${__dirname}/karma.config.js`,
}, done).start();
gulp.task("test-watch", ["_set-test-node-env"], done => {
new KarmaServer(
{
configFile: `${__dirname}/karma.config.js`
},
done
).start();
});

gulp.task('_set-test-node-env', function() {
return process.env.NODE_ENV = 'test';
gulp.task("_set-test-node-env", () => {
return (process.env.NODE_ENV = "test");
});


/**
* Utils tasks
*/
gulp.task('clean', () => {
gulp.task("clean", () => {
del([
'./public/*.otf',
'./public/*.html',
'./public/*.css',
'./public/*.map',
'./public/*.js',
'./public/*.png',
"./public/*.otf",
"./public/*.html",
"./public/*.css",
"./public/*.map",
"./public/*.js",
"./public/*.png"
]);
});
39 changes: 18 additions & 21 deletions karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,37 @@
* Apache 2.0 Licensed
*/


var webpack_config = require('./webpack.config.js')({
env: 'test',
const webpack_config = require("./webpack.config.js")({
env: "test"
});
webpack_config.devtool = 'inline-source-map';

webpack_config.devtool = "inline-source-map";

module.exports = function(config) {
module.exports = function karma_config(config) {
config.set({
frameworks: ['mocha', 'sinon-chai'],
reporters: ['mocha', 'coverage'],
browsers: ['ChromeHeadless'],
frameworks: ["mocha", "sinon-chai"],
reporters: ["mocha", "coverage"],
browsers: ["ChromeHeadless"],

files: [
'./test/index.js',
],
files: ["./test/index.js"],

preprocessors: {
'./test/index.js': ['webpack', 'sourcemap'],
"./test/index.js": ["webpack", "sourcemap"]
},

webpack: webpack_config,
webpackMiddleware: {
noInfo: true,
noInfo: true
},

plugins: [
'karma-chrome-launcher',
'karma-coverage',
'karma-mocha-reporter',
'karma-mocha',
'karma-sinon-chai',
'karma-sourcemap-loader',
'karma-webpack',
],
"karma-chrome-launcher",
"karma-coverage",
"karma-mocha-reporter",
"karma-mocha",
"karma-sinon-chai",
"karma-sourcemap-loader",
"karma-webpack"
]
});
};
6 changes: 4 additions & 2 deletions postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
* Apache 2.0 Licensed
*/

// NOTE: eslint-config-base-airbnb's config for `import/no-extraneous-dependencies` doesn't support PostCSS config files
const autoprefixer = require("autoprefixer"); // eslint-disable-line import/no-extraneous-dependencies

module.exports = {
plugins: [
require('autoprefixer')({
browsers: ['last 2 versions'],
autoprefixer({
browsers: ["last 2 versions"]
})
]
};
Loading

0 comments on commit 7930ab3

Please sign in to comment.