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"
}
}],
"transform-class-properties",
"transform-runtime"
]
}
}

View file

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

File diff suppressed because it is too large Load diff

View file

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

View file

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

View file

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

View file

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

View file

@ -3,7 +3,7 @@ import chalk from 'chalk';
import { isArgv } from 'core/utils';
const endOfLine = require('os').EOL;
class Log{
class Log {
logLevel = 3; // default 1
@ -12,9 +12,9 @@ class Log{
}
getLogLevel() {
if(isArgv('aiv-log-full')){
if (isArgv('aiv-log-full')) {
this.logLevel = 3;
}else if(isArgv('aiv-log-none')) {
} else if (isArgv('aiv-log-none')) {
this.logLevel = 0;
}
}
@ -24,7 +24,7 @@ class Log{
* @returns {string}
*/
getHead() {
return endOfLine + chalk.bgYellow.black('[AIV] : ')
return endOfLine + chalk.bgYellow.black('[AIV] : ');
}
/**
@ -40,27 +40,25 @@ class Log{
* @param msg
*/
call(type, msgId) {
if(typeof this[type] === 'function') {
if (typeof this[type] === 'function') {
this[type](this.getText(msgId));
}
}
error (msg) {
if(this.logLevel < 3) return;
error(msg) {
if (this.logLevel < 3) return;
console.log(`${this.getHead()} ${chalk.red('error')} : ${msg}`);
}
info (msg) {
if(!this.logLevel) return;
info(msg) {
if (!this.logLevel) return;
console.log(`${this.getHead()} ${chalk.blue('info')} : ${msg}`);
}
warn (msg) {
if(!this.logLevel) return;
warn(msg) {
if (!this.logLevel) return;
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]);
}
/**
* 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 path from 'path';
import config from 'config';
@ -10,11 +10,15 @@ import AutoIncreaseVersion from 'components/auto-increase-version';
import InjectAsComment from 'components/inject-as-comment';
import InjectByTag from 'components/inject-by-tag';
export default class WebpackAutoInject{
export default class WebpackAutoInject {
/**
* Protected config
* @type {{NAME: string, SHORT: string}}
*/
static protectedConfig = {
NAME: 'Auto Inject Version',
SHORT: 'AIV',
SHORT: 'AIV'
};
/**
@ -32,11 +36,17 @@ export default class WebpackAutoInject{
this.executeNoneWebpackComponents();
}
/**
* Set config
* - merge userConfig with default config
* - merge above with a protected config
* @param userConfig
*/
setConfig(userConfig) {
this.config = merge(config, userConfig);
// 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;
});
@ -48,6 +58,7 @@ export default class WebpackAutoInject{
* when webpack is initialized and
* plugin has been called by webpack
* @param compiler
* @protected
*/
async apply(compiler) {
this.compiler = compiler;
@ -78,10 +89,9 @@ export default class WebpackAutoInject{
* - used for both, webpack and non webpack comp
*/
async executeComponent(components) {
// no more components,
// finish
if(!components.length) {
if (!components.length) {
return;
}

View file

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