Fix eslint issues

This commit is contained in:
radswiat 2017-04-12 22:32:39 +01:00
parent 2a38901fae
commit 17f28004df
11 changed files with 973 additions and 955 deletions

View file

@ -13,6 +13,7 @@
"components": "./components" "components": "./components"
} }
}], }],
"transform-class-properties",
"transform-runtime" "transform-runtime"
] ]
} }

View file

@ -37,6 +37,7 @@
], ],
"rules": { "rules": {
"no-unneeded-ternary" : "off", "no-unneeded-ternary" : "off",
"no-console": "off",
"object-curly-spacing": ["error", "always", { "object-curly-spacing": ["error", "always", {
"objectsInObjects": false, "objectsInObjects": false,
"arraysInObjects": false "arraysInObjects": false

File diff suppressed because it is too large Load diff

View file

@ -10,10 +10,8 @@
"author": "Radoslaw Swiat", "author": "Radoslaw Swiat",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"bluebird": "^3.4.6",
"chalk": "^1.1.3", "chalk": "^1.1.3",
"lodash": "^4.17.4", "lodash": "^4.17.4",
"minimist": "^1.2.0",
"optimist": "^0.6.1", "optimist": "^0.6.1",
"semver": "^5.3.0", "semver": "^5.3.0",
"babel-cli": "^6.10.1", "babel-cli": "^6.10.1",
@ -26,15 +24,14 @@
"babel-preset-node5": "^11.0.1", "babel-preset-node5": "^11.0.1",
"babel-preset-react": "^6.5.0", "babel-preset-react": "^6.5.0",
"babel-preset-stage-2": "^6.22.0", "babel-preset-stage-2": "^6.22.0",
"gutil": "^1.6.4",
"webpack": "^2.3.3",
"webpack-node-externals": "^1.5.4",
"eslint": "^2.7.0", "eslint": "^2.7.0",
"eslint-config-airbnb": "^6.2.0", "eslint-config-airbnb": "^6.2.0",
"eslint-loader": "^1.5.0", "eslint-loader": "^1.5.0",
"eslint-plugin-babel": "^3.2.0", "eslint-plugin-babel": "^3.2.0",
"gutil": "^1.6.4", "eslint-plugin-jsx-control-statements": "^2.1.1",
"webpack": "^2.3.3", "eslint-plugin-react": "^4.2.3"
"webpack-node-externals": "^1.5.4"
},
"dependencies": {
} }
} }

View file

@ -1,12 +1,10 @@
import semver from 'semver'; import semver from 'semver';
import config from 'config';
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
import { isArgv } from 'core/utils'; import { isArgv } from 'core/utils';
import chalk from 'chalk';
import log from 'core/log'; import log from 'core/log';
export default class AutoIncreaseVersion{ export default class AutoIncreaseVersion {
static componentName = 'AutoIncreaseVersion'; static componentName = 'AutoIncreaseVersion';
@ -14,6 +12,11 @@ export default class AutoIncreaseVersion{
this.context = context; this.context = context;
} }
/**
* Apply will be called from main class
* @protected
* @returns {Promise}
*/
apply() { apply() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.resolve = resolve; this.resolve = resolve;
@ -28,14 +31,13 @@ export default class AutoIncreaseVersion{
*/ */
start() { start() {
this.packageFile = this.openPackageFile(); this.packageFile = this.openPackageFile();
if( isArgv('major') ) { if (isArgv('major')) {
this.major(); this.major();
} } else if (isArgv('minor')) {
else if( isArgv('minor') ) {
this.minor(); this.minor();
}else if( isArgv('patch') ) { } else if (isArgv('patch')) {
this.patch(); this.patch();
}else { } else {
this.reject(); this.reject();
} }
} }
@ -56,13 +58,17 @@ export default class AutoIncreaseVersion{
this.packageFile.version = newVersion; this.packageFile.version = newVersion;
fs.writeFile( fs.writeFile(
path.resolve(this.context.config.PACKAGE_JSON_PATH), path.resolve(this.context.config.PACKAGE_JSON_PATH),
JSON.stringify(this.packageFile, null, 4 JSON.stringify(this.packageFile, null, 4), (err) => {
), (err) => { if (err) {
if(err) {this.reject(err); return console.log(err);} this.reject(err);
console.log(err);
return false;
}
log.info(`autoIncVersion : new version : ${newVersion}`); log.info(`autoIncVersion : new version : ${newVersion}`);
log.info('package.json updated!'); log.info('package.json updated!');
this.context.version = newVersion; this.context.version = newVersion;
this.resolve(); this.resolve();
return true;
}); });
} }

View file

@ -1,4 +1,3 @@
import chalk from 'chalk';
import path from 'path'; import path from 'path';
import config from 'config'; import config from 'config';
import log from 'core/log'; import log from 'core/log';
@ -10,7 +9,7 @@ const endOfLine = require('os').EOL;
* - done by parsing html file, * - done by parsing html file,
* > replace: <{version}> * > replace: <{version}>
*/ */
export default class InjectAsComment{ export default class InjectAsComment {
static componentName = 'InjectAsComment'; static componentName = 'InjectAsComment';
@ -18,12 +17,17 @@ export default class InjectAsComment{
this.context = context; this.context = context;
} }
/**
* Apply will be called from main class
* @protected
* @returns {Promise}
*/
apply() { apply() {
this.context.compiler.plugin('emit', (compilation, cb) => { this.context.compiler.plugin('emit', (compilation, cb) => {
for ( var basename in compilation.assets ) { for (let basename in compilation.assets) {
let ext = path.extname(basename); let ext = path.extname(basename);
let asset = compilation.assets[basename]; let asset = compilation.assets[basename];
switch(ext) { switch (ext) {
case '.js' : case '.js' :
this.injectIntoJs(asset); this.injectIntoJs(asset);
break; break;
@ -33,27 +37,31 @@ export default class InjectAsComment{
case '.css' : case '.css' :
this.injectIntoCss(asset); this.injectIntoCss(asset);
break; break;
case 'default': break; default:
break;
} }
log.info(`InjectAsComment : match : ${basename} : injected : ${this.context.version}`); log.info(`InjectAsComment : match : ${basename} : injected : ${this.context.version}`);
} }
cb(); cb();
}); });
return new Promise((resolve, reject) => { resolve(); }) return new Promise((resolve) => { resolve(); });
} }
injectIntoCss(asset) { injectIntoCss(asset) {
let modAsset = `/** [${config.SHORT}] Build version: ${this.context.version} **/ ${endOfLine} ${asset.source()} `; let modAsset = `/** [${config.SHORT}] Build version: ${this.context.version} **/ `;
modAsset += `${endOfLine} ${asset.source()} `;
asset.source = () => modAsset; asset.source = () => modAsset;
} }
injectIntoHtml(asset) { injectIntoHtml(asset) {
let modAsset = `<!-- [${config.SHORT}] Build version: ${this.context.version} --> ${endOfLine} ${asset.source()} `; let modAsset = `<!-- [${config.SHORT}] Build version: ${this.context.version} --> `;
modAsset += `${endOfLine} ${asset.source()} `;
asset.source = () => modAsset; asset.source = () => modAsset;
} }
injectIntoJs(asset) { injectIntoJs(asset) {
let modAsset = `// [${config.SHORT}] Build version: ${this.context.version} ${endOfLine} ${asset.source()} `; let modAsset = `// [${config.SHORT}] Build version: ${this.context.version} `;
modAsset = `${endOfLine} ${asset.source()} `;
asset.source = () => modAsset; asset.source = () => modAsset;
} }
} }

View file

@ -1,11 +1,11 @@
import log from 'core/log'; import log from 'core/log';
import chalk from 'chalk';
/** /**
* Inject version number into HTML * Inject version number into HTML
* - done by parsing html file, * - done by parsing html file,
* > replace: <{version}> * > replace: <{version}>
*/ */
export default class InjectByTag{ export default class InjectByTag {
static componentName = 'InjectByTag'; static componentName = 'InjectByTag';
@ -13,12 +13,17 @@ export default class InjectByTag{
this.context = context; this.context = context;
} }
/**
* Apply will be called from main class
* @protected
* @returns {Promise}
*/
apply() { apply() {
this.context.compiler.plugin('emit', (compilation, cb) => { this.context.compiler.plugin('emit', (compilation, cb) => {
// for every output file // for every output file
for ( let basename in compilation.assets ) { for (let basename in compilation.assets) {
// only if match regex // only if match regex
if(this.context.config.componentsOptions.InjectByTag.fileRegex.test(basename)) { if (this.context.config.componentsOptions.InjectByTag.fileRegex.test(basename)) {
let replaced = 0; let replaced = 0;
let asset = compilation.assets[basename]; let asset = compilation.assets[basename];
@ -38,7 +43,6 @@ export default class InjectByTag{
} }
cb(); cb();
}); });
return new Promise((resolve) => { resolve(); });
return new Promise((resolve, reject) => { resolve(); })
} }
} }

View file

@ -3,7 +3,7 @@ import chalk from 'chalk';
import { isArgv } from 'core/utils'; import { isArgv } from 'core/utils';
const endOfLine = require('os').EOL; const endOfLine = require('os').EOL;
class Log{ class Log {
logLevel = 3; // default 1 logLevel = 3; // default 1
@ -12,9 +12,9 @@ class Log{
} }
getLogLevel() { getLogLevel() {
if(isArgv('aiv-log-full')){ if (isArgv('aiv-log-full')) {
this.logLevel = 3; this.logLevel = 3;
}else if(isArgv('aiv-log-none')) { } else if (isArgv('aiv-log-none')) {
this.logLevel = 0; this.logLevel = 0;
} }
} }
@ -24,7 +24,7 @@ class Log{
* @returns {string} * @returns {string}
*/ */
getHead() { getHead() {
return endOfLine + chalk.bgYellow.black('[AIV] : ') return endOfLine + chalk.bgYellow.black('[AIV] : ');
} }
/** /**
@ -40,27 +40,25 @@ class Log{
* @param msg * @param msg
*/ */
call(type, msgId) { call(type, msgId) {
if(typeof this[type] === 'function') { if (typeof this[type] === 'function') {
this[type](this.getText(msgId)); this[type](this.getText(msgId));
} }
} }
error (msg) { error(msg) {
if(this.logLevel < 3) return; if (this.logLevel < 3) return;
console.log(`${this.getHead()} ${chalk.red('error')} : ${msg}`); console.log(`${this.getHead()} ${chalk.red('error')} : ${msg}`);
} }
info(msg) {
info (msg) { if (!this.logLevel) return;
if(!this.logLevel) return;
console.log(`${this.getHead()} ${chalk.blue('info')} : ${msg}`); console.log(`${this.getHead()} ${chalk.blue('info')} : ${msg}`);
} }
warn (msg) { warn(msg) {
if(!this.logLevel) return; if (!this.logLevel) return;
console.log(`${this.getHead()} ${chalk.yellow('warn')} : ${msg}`); console.log(`${this.getHead()} ${chalk.yellow('warn')} : ${msg}`);
} }
} }
export default new Log(); export default new Log();

View file

@ -18,17 +18,3 @@ export function isArgv(arg) {
return Boolean(argv.env[arg]); return Boolean(argv.env[arg]);
} }
/**
* Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1
* @param obj1
* @param obj2
* @returns obj3 a new object based on obj1 and obj2
*/
export function merge(obj1,obj2){
var obj3 = {};
for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
return obj3;
}

View file

@ -1,4 +1,4 @@
import chalk from 'chalk'; /* global define */
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import config from 'config'; import config from 'config';
@ -10,11 +10,15 @@ import AutoIncreaseVersion from 'components/auto-increase-version';
import InjectAsComment from 'components/inject-as-comment'; import InjectAsComment from 'components/inject-as-comment';
import InjectByTag from 'components/inject-by-tag'; import InjectByTag from 'components/inject-by-tag';
export default class WebpackAutoInject{ export default class WebpackAutoInject {
/**
* Protected config
* @type {{NAME: string, SHORT: string}}
*/
static protectedConfig = { static protectedConfig = {
NAME: 'Auto Inject Version', NAME: 'Auto Inject Version',
SHORT: 'AIV', SHORT: 'AIV'
}; };
/** /**
@ -32,11 +36,17 @@ export default class WebpackAutoInject{
this.executeNoneWebpackComponents(); this.executeNoneWebpackComponents();
} }
/**
* Set config
* - merge userConfig with default config
* - merge above with a protected config
* @param userConfig
*/
setConfig(userConfig) { setConfig(userConfig) {
this.config = merge(config, userConfig); this.config = merge(config, userConfig);
// lets convert all components names to lowercase - to prevent issues // lets convert all components names to lowercase - to prevent issues
this.config.components = transform(this.config.components, function (result, val, key) { this.config.components = transform(this.config.components, (result, val, key) => {
result[key.toLowerCase()] = val; result[key.toLowerCase()] = val;
}); });
@ -48,6 +58,7 @@ export default class WebpackAutoInject{
* when webpack is initialized and * when webpack is initialized and
* plugin has been called by webpack * plugin has been called by webpack
* @param compiler * @param compiler
* @protected
*/ */
async apply(compiler) { async apply(compiler) {
this.compiler = compiler; this.compiler = compiler;
@ -78,10 +89,9 @@ export default class WebpackAutoInject{
* - used for both, webpack and non webpack comp * - used for both, webpack and non webpack comp
*/ */
async executeComponent(components) { async executeComponent(components) {
// no more components, // no more components,
// finish // finish
if(!components.length) { if (!components.length) {
return; return;
} }

View file

@ -1,10 +1,7 @@
import path from 'path'; import path from 'path';
const webpack = require('webpack');
// import nodeExternals from 'webpack-node-externals';
export default { export default {
target: 'node', target: 'node',
// externals: [nodeExternals()],
entry: ['babel-polyfill', './src/main.js'], entry: ['babel-polyfill', './src/main.js'],
resolve: { resolve: {
extensions: ['.js'] extensions: ['.js']
@ -26,7 +23,10 @@ export default {
loaders: [ loaders: [
{ {
test: /\.js$/, test: /\.js$/,
loader: 'babel-loader', use: [
'babel-loader',
'eslint-loader'
],
include: [ include: [
path.resolve('src') path.resolve('src')
] ]