Skip to content

Commit

Permalink
ESLint CGL
Browse files Browse the repository at this point in the history
  • Loading branch information
begner authored and bastianccm committed Apr 2, 2019
1 parent e5cb2de commit 3491f90
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 84 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ docs
tmp
node_modules
test
babel.config.js
babel.config.js
webpackConfig.js
25 changes: 11 additions & 14 deletions packages/flamingo-carotene-behavior/src/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*
*/
class Behavior {

/**
* @param listOfBehaviourClasses
*
Expand All @@ -22,7 +21,7 @@ class Behavior {
* ...
* }
*/
constructor(behaviourClasses) {
constructor (behaviourClasses) {
/**
* List of all registered behaviors
* @type {{}}
Expand All @@ -44,8 +43,7 @@ class Behavior {
if (behaviorClassObject.hasOwnProperty('default')) {
behaviorClass = behaviorClassObject.default
}
}
else {
} else {
// Support for globbing: import * as behaviorModules from '...'
behaviorClass = behaviorClassObject
}
Expand All @@ -65,7 +63,7 @@ class Behavior {
* Attachs a Behavior to given domElement (and all children)
* @param domElement|null
*/
attachBehaviors(domElement) {
attachBehaviors (domElement) {
domElement = domElement || document
const allElements = domElement.querySelectorAll('[data-behavior]')

Expand All @@ -78,7 +76,7 @@ class Behavior {
* Detach all Behaviors to given domElement (and all children)
* @param domElement
*/
detachBehaviors(domElement) {
detachBehaviors (domElement) {
domElement = domElement || document
const allElements = domElement.querySelectorAll('[data-behavior]')
for (let behaviorElement of allElements) {
Expand All @@ -91,7 +89,7 @@ class Behavior {
* @param domElement
* @returns {*}
*/
getBehaviorFromElement(domElement) {
getBehaviorFromElement (domElement) {
let instance = null

if (domElement.hasOwnProperty('nodeType')) {
Expand All @@ -111,7 +109,7 @@ class Behavior {
* Attachs a behavior to a given dom element
* @param domElement
*/
_attachBehaviorToDom(domElement) {
_attachBehaviorToDom (domElement) {
const instance = this.getBehaviorFromElement(domElement)
if (instance) {
if (this.debug) {
Expand All @@ -129,22 +127,22 @@ class Behavior {
return
}

const behaviorClass = this.behaviors[behaviorName]
const BehaviorClass = this.behaviors[behaviorName]
if (this.debug) {
console.info(`Behavior: attachBehaviorToElement: Initialize behavior "${behaviorName}" on domElement`, domElement)
}

domElement.behaviorInstance = {
name: behaviorName,
behavior: new behaviorClass(domElement)
behavior: new BehaviorClass(domElement)
}
}

/**
* Detach a behavior from a given dom element
* @param domElement
*/
_detachBehaviorsToDom(domElement) {
_detachBehaviorsToDom (domElement) {
const instance = this.getBehaviorFromElement(domElement)
if (!instance) {
if (this.debug) {
Expand Down Expand Up @@ -186,18 +184,17 @@ class Behavior {
* @param {string} behaviorName
* @returns {string}
*/
_sanitizeName(behaviorName) {
_sanitizeName (behaviorName) {
return behaviorName.toLowerCase()
}

/**
* Enables Debug Mode
* @param state {boolean}
*/
setDebug(state) {
setDebug (state) {
this.debug = state
}

}

module.exports = Behavior
1 change: 0 additions & 1 deletion packages/flamingo-carotene-core/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ let modules = null
let errors = []

class Core {

getConfig () {
if (config !== null) {
return config
Expand Down
16 changes: 5 additions & 11 deletions packages/flamingo-carotene-core/lib/flamingoCarotene.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#!/usr/bin/env node

const shell = require('shelljs')

const core = require('./core')


const cliTools = core.getCliTools()
const config = core.getConfig()
const dispatcher = core.getDispatcher()

const command = cliTools.getCommand()

if (!command || command.charAt(0) === '-') {
Expand All @@ -27,13 +22,12 @@ if (command !== 'config') {
}

// check reported core-errors - and exit
process.on("exit", () => {
process.on('exit', () => {
if (core.hasErrors()) {
const error = core.getErrors().join('\n');
cliTools.info(`Flamingo carotene finished - with errors:\n${error}`);
const error = core.getErrors().join('\n')
cliTools.info(`Flamingo carotene finished - with errors:\n${error}`)
cliTools.exit(1)
}
else {
cliTools.info('Flamingo carotene finished - successfully');
} else {
cliTools.info('Flamingo carotene finished - successfully')
}
})
6 changes: 3 additions & 3 deletions packages/flamingo-carotene-dev-server/caroteneModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CaroteneDevServer {
{
command: 'dev',
handler: (core) => {
const watcherConfigList = this.getWatcherConfiguration();
const watcherConfigList = this.getWatcherConfiguration()

io.on('connection', (client) => {
// console.info(`Connected to client: ${client.id}`)
Expand All @@ -46,7 +46,7 @@ class CaroteneDevServer {
for (const module of modules) {
if (typeof module.getWatcherForDevServer === 'function') {
const watcher = module.getWatcherForDevServer()
watcherList = [...watcherList, ...watcher];
watcherList = [...watcherList, ...watcher]
}
}
return watcherList
Expand All @@ -62,4 +62,4 @@ class CaroteneDevServer {
}
}

module.exports = CaroteneDevServer
module.exports = CaroteneDevServer
23 changes: 10 additions & 13 deletions packages/flamingo-carotene-dev-server/lib/flamingoWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const fs = require('fs')
* This class is a wrapper for a watcher instance
*/
class FlamingoWatcher {

/**
*
* @param core - flamingo carotene core
Expand All @@ -15,16 +14,15 @@ class FlamingoWatcher {
* @param command - flamingo carotene command, that will be triggered
* @param callbackKey - key of config[KEY].callback function, that will be called
*/
constructor (watcherCaroteneModule, core, watchId, watchPaths, command, callbackKey)
{
constructor (watcherCaroteneModule, core, watchId, watchPaths, command, callbackKey) {
this.watcherCaroteneModule = watcherCaroteneModule
this.watchId = watchId
this.watchPaths = watchPaths
this.callbackKey = callbackKey
this.command = command

// instance of chokidar
this.watcher = null;
this.watcher = null

// flag, if this watcher is currently running a build
this.buildInProgress = false
Expand Down Expand Up @@ -64,10 +62,10 @@ class FlamingoWatcher {
initialize () {
// setup watcher
console.log(process.platform)
const isWindows = (process.platform === "win32" || process.platform === "linux");
const usePolling = (process.platform === 'win32' || process.platform === 'linux')
this.watcher = chokidar.watch(this.watchPaths, {
ignored: /(^|[\/\\])\../, // dot files or folders
usePolling: isWindows,
ignored: /(^|[/\\])\../, // dot files or folders
usePolling: usePolling
})

// start watcher
Expand Down Expand Up @@ -133,16 +131,15 @@ class FlamingoWatcher {
* @param changedPath
*/
buildOnChange (changedPath) {
this.currentChangedPath = changedPath;
this.currentChangedPath = changedPath
this.cliTools.info(`Watcher-${this.watchId}: Change detected...`)

// if there is a build in progress - que the change and do nothing.
if (this.isBuildInProgress()) {
this.cliTools.info(`Watcher-${this.watchId}: Change detected, but build is in Progress, will rebuild after finish`)
this.rerunAfterBuild = true
}
// no build in progress? so - build it!
else {
} else {
// no build in progress? so - build it!
const config = this.core.getConfig()

// save original callback...
Expand All @@ -167,7 +164,7 @@ class FlamingoWatcher {
const config = this.core.getConfig()

// restore old, original callback...
config[this.callbackKey].callback = this.oldCallback;
config[this.callbackKey].callback = this.oldCallback

this.buildInProgress = false

Expand All @@ -183,4 +180,4 @@ class FlamingoWatcher {
}
}

module.exports = FlamingoWatcher
module.exports = FlamingoWatcher
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ socket.on('connect', function onConnect () {
console.info(`Connected socket with id: ${socket.id}`)
})

socket.on('built', () => location.reload())
socket.on('built', () => window.location.reload())
3 changes: 1 addition & 2 deletions packages/flamingo-carotene-es-lint/caroteneModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const buildHandler = require('./lib/handler/build')
// class CarotenePug extends CaroteneModule {
class ESLint {
constructor (core) {

// super(core)
this.listeners = [
{
Expand All @@ -29,7 +28,7 @@ class ESLint {
},
{
command: 'build',
handler: function(core) {
handler: function (core) {
const config = core.getConfig()
config.eslint.breakOnError = true
buildHandler(core)
Expand Down
24 changes: 10 additions & 14 deletions packages/flamingo-carotene-es-lint/lib/handler/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { spawn } = require('child_process');
const { spawn } = require('child_process')
const path = require('path')
const fs = require('fs')

Expand All @@ -7,13 +7,12 @@ const fs = require('fs')
* @param core
*/
const esLint = (core) => {

const cliTools = core.getCliTools()
const config = core.getConfig()

// trying to find es lint in project folder..
let rulesConfigFilePath = loadConfigPath('.eslintrc.js', config)
let ignoreConfigFilePath = loadConfigPath('.eslintignore',config)
let ignoreConfigFilePath = loadConfigPath('.eslintignore', config)

const cmd = `yarn`
const parameters = ['eslint', '--config', rulesConfigFilePath, '--ignore-path', ignoreConfigFilePath, '--ext', '.js', '.']
Expand All @@ -27,7 +26,7 @@ const esLint = (core) => {
cmd,
parameters,
{
env : spawnEnv
env: spawnEnv
}
)

Expand All @@ -40,37 +39,34 @@ const esLint = (core) => {
let skipLine = false

// Don't need current cmd
if (data.toString().trim().search('\/\.bin\/eslint') !== -1) {
skipLine = true
if (data.toString().trim().search('/.bin/eslint') !== -1) {
skipLine = true
}

if (!skipLine) {
results.push(data)
}
});
})

childProcess.stderr.on('data', function (data) {
errors.push(data)
})


childProcess.on('exit', (code) => {

let output = 'ESLint - end\n'
output += results.join('\n').trim()
output += errors.join('\n').trim()

if (code !== 0) {
cliTools.warn(output)
}
else {
} else {
cliTools.info(output)
}

if (config.eslint.breakOnError && errors.length > 0) {
core.reportError(`ESLint report errors.`);
core.reportError(`ESLint report errors.`)
}
});
})
}

/**
Expand All @@ -84,7 +80,7 @@ const loadConfigPath = (configName, config) => {

// if not exists, take standard one
if (!fs.existsSync(configFilePath)) {
configFilePath = path.join(config.paths.esLint, configName)
configFilePath = path.join(config.paths.esLint, configName)
}

return configFilePath
Expand Down
Loading

0 comments on commit 3491f90

Please sign in to comment.