-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move code from spasdk/tasks repo and rework
- Loading branch information
0 parents
commit 8d1bc46
Showing
8 changed files
with
270 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* @author Stanislav Kalashnik <[email protected]> | ||
* @license GNU GENERAL PUBLIC LICENSE Version 3 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// public | ||
module.exports = { | ||
// base rules | ||
extends: require.resolve('@cjssdk/eslint-config/.eslintrc.js') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Contributing | ||
============ | ||
|
||
## Issues ## | ||
|
||
Try to be the most specific possible. Give your OS, Node.js, application, database and packages info. | ||
Give an example that will help other people to replicate your problem. | ||
|
||
|
||
## Pull Requests ## | ||
|
||
They are always welcomed but with respect to the adopted [code style](https://github.com/DarkPark/jscs) and included [ESLint](http://eslint.org/) rules. | ||
Your patches must pass all the tests. If adding a new feature, don't forget about adding it to documentation (readme.md) and add tests for it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.eslintrc.js | ||
.github | ||
.idea | ||
.travis.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- "10" | ||
- "8" | ||
- "6" | ||
cache: | ||
directories: | ||
- node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* @author Stanislav Kalashnik <[email protected]> | ||
* @license GNU GENERAL PUBLIC LICENSE Version 3 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var name = 'eslint', | ||
log = require('@runner/logger').wrap(name); | ||
|
||
|
||
function watch ( config, done ) { | ||
var path = require('path'), | ||
chokidar = require('chokidar'), | ||
CLIEngine = require('eslint').CLIEngine, | ||
failCount = {}, | ||
engine, watcher; | ||
|
||
function handler ( name ) { | ||
var report = engine.executeOnFiles([name]); | ||
|
||
report.results.forEach(function ( result ) { | ||
result.messages.forEach(function ( message ) { | ||
log.fail( | ||
'%s %s [%s:%s] %s', | ||
log.colors.bold(path.relative('.', result.filePath)), | ||
message.message, | ||
message.line, | ||
message.column, | ||
log.colors.grey(message.ruleId) | ||
); | ||
}); | ||
|
||
// no more errors? | ||
if ( result.messages.length === 0 && failCount[result.filePath] > 0 ) { | ||
log.info('%s fixed', log.colors.bold(path.relative('.', result.filePath))); | ||
} | ||
|
||
// remember each check errors amount | ||
failCount[result.filePath] = result.messages.length; | ||
}); | ||
} | ||
|
||
engine = new CLIEngine(config.options); | ||
|
||
watcher = chokidar.watch(config.watch, config.watchOptions || runner.watch.config); | ||
watcher | ||
.on('change', handler) | ||
.on('unlink', handler) | ||
.on('add', handler); | ||
|
||
return { | ||
engine: engine, | ||
watcher: watcher, | ||
done: done | ||
}; | ||
} | ||
|
||
|
||
function unwatch ( instance ) { | ||
if ( instance ) { | ||
instance.watcher.close(); | ||
instance.done(); | ||
} | ||
} | ||
|
||
|
||
function generator ( config, options ) { | ||
var tasks = {}, | ||
instance; | ||
|
||
// sanitize and extend defaults | ||
options = Object.assign(generator.options, options || {}); | ||
|
||
tasks[options.prefix + 'config' + options.suffix] = function () { | ||
log.inspect(config, log); | ||
}; | ||
|
||
tasks[options.prefix + 'watch' + options.suffix] = function ( done ) { | ||
instance = watch(config, done); | ||
}; | ||
|
||
tasks[options.prefix + 'unwatch' + options.suffix] = function () { | ||
unwatch(instance); | ||
instance = null; | ||
}; | ||
|
||
return tasks; | ||
} | ||
|
||
|
||
// defaults | ||
generator.options = { | ||
prefix: name + ':', | ||
suffix: '' | ||
}; | ||
|
||
|
||
// export main actions | ||
generator.methods = { | ||
watch: watch, | ||
unwatch: unwatch | ||
}; | ||
|
||
|
||
// public | ||
module.exports = generator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "@runner/generator-eslint", | ||
"version": "1.0.0", | ||
"description": "Tasks generator for ESLint.", | ||
"author": { | ||
"name": "Stanislav Kalashnik", | ||
"email": "[email protected]" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/runner/generator-eslint" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"lint": "eslint .", | ||
"test": "npm run lint" | ||
}, | ||
"dependencies": { | ||
"@runner/logger": "^1.0.0", | ||
"chokidar": "^2.0.3", | ||
"eslint": "^4.19.1" | ||
}, | ||
"devDependencies": { | ||
"@cjssdk/eslint-config": "^1.1.2" | ||
}, | ||
"keywords": [ | ||
"task", | ||
"runner", | ||
"generator", | ||
"eslint" | ||
], | ||
"license": "GPL-3.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
Tasks generator for ESLint | ||
========================== | ||
|
||
[](https://travis-ci.org/runner/generator-eslint) | ||
[](https://www.npmjs.com/package/@runner/generator-eslint) | ||
[](https://david-dm.org/runner/generator-eslint) | ||
[](https://david-dm.org/runner/generator-eslint?type=dev) | ||
[](https://gitter.im/DarkPark/runner) | ||
[](https://npm.runkit.com/@runner/generator-eslint) | ||
|
||
|
||
## Installation ## | ||
|
||
```bash | ||
npm install @runner/generator-eslint | ||
``` | ||
|
||
|
||
## Usage ## | ||
|
||
Add to the scope: | ||
|
||
```js | ||
var generator = require('@runner/generator-eslint'); | ||
``` | ||
|
||
Add generated tasks to the runner instance: | ||
|
||
```js | ||
var runner = require('@runner/core'); | ||
|
||
runner.tasks( | ||
generator({ | ||
watch: ['src/js/**/*.js'] | ||
}) | ||
); | ||
``` | ||
|
||
The following tasks will become available: | ||
|
||
Task name | Description | ||
----------------|------------- | ||
eslint:config | prints the current configuration used for generated tasks | ||
eslint:watch | starts file changes monitoring, prints warnings on errors | ||
eslint:unwatch | stops monitoring | ||
|
||
Generator configuration object: | ||
|
||
Name | Description | ||
--------------|------------- | ||
watch | file, dir, glob, or array passed to `watch` in [chokidar](https://www.npmjs.com/package/chokidar#api) | ||
watchOptions | optional watcher config object [parameters](https://www.npmjs.com/package/chokidar#api) | ||
options | optional config object passed to [ESLint CLIEngine](https://eslint.org/docs/developer-guide/nodejs-api#cliengine) | ||
|
||
Additional generator options: | ||
|
||
Name | Description | ||
--------|------------- | ||
prefix | an affix placed before a task name (default is `eslint:`) | ||
suffix | a string added at the end of a task name (empty by default) | ||
|
||
So it's possible to change generated tasks names: | ||
|
||
```js | ||
runner.tasks( | ||
generator(config, { | ||
prefix: 'lint:', | ||
suffix: ':develop' | ||
}) | ||
); | ||
``` | ||
|
||
This will create the following tasks: | ||
|
||
* lint:config:develop | ||
* lint:watch:develop | ||
* lint:unwatch:develop | ||
|
||
|
||
## Contribution ## | ||
|
||
If you have any problems or suggestions please open an [issue](https://github.com/runner/generator-eslint/issues) | ||
according to the contribution [rules](.github/contributing.md). | ||
|
||
|
||
## License ## | ||
|
||
`@runner/generator-eslint` is released under the [GPL-3.0 License](http://opensource.org/licenses/GPL-3.0). |