@putout/engine-reporter 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +16 -0
- package/lib/formatter/formatter.cjs +28 -0
- package/lib/index.js +54 -0
- package/lib/report.cjs +54 -0
- package/lib/simple-import.cjs +6 -0
- package/lib/subscribe.js +26 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) coderaiser
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @putout/engine-reporter [![NPM version][NPMIMGURL]][NPMURL]
|
|
2
|
+
|
|
3
|
+
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/engine-reporter.svg?style=flat&longCache=true
|
|
4
|
+
[NPMURL]: https://npmjs.org/package/@putout/engine-reporter "npm"
|
|
5
|
+
|
|
6
|
+
Run 🐊[**Putout**](https://github.com/coderaiser/putout) formatters.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm i @putout/engine-reporter
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## License
|
|
15
|
+
|
|
16
|
+
MIT
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {simpleImport} = require('../simple-import.cjs');
|
|
4
|
+
const {createAsyncLoader} = require('@putout/engine-loader');
|
|
5
|
+
|
|
6
|
+
const tryToCatch = require('try-to-catch');
|
|
7
|
+
const {
|
|
8
|
+
NO_FORMATTER,
|
|
9
|
+
CANNOT_LOAD_FORMATTER,
|
|
10
|
+
} = require('putout/exit-codes/cjs');
|
|
11
|
+
|
|
12
|
+
const {isArray} = Array;
|
|
13
|
+
const maybeArray = (a) => isArray(a) ? a : [a, {}];
|
|
14
|
+
|
|
15
|
+
module.exports.getFormatter = async (formatterOptional, exit) => {
|
|
16
|
+
const [formatterName, formatterOptions] = maybeArray(formatterOptional);
|
|
17
|
+
const loadFormatter = createAsyncLoader('formatter');
|
|
18
|
+
|
|
19
|
+
const [error, formatter] = await tryToCatch(loadFormatter, formatterName, simpleImport);
|
|
20
|
+
|
|
21
|
+
if (formatter)
|
|
22
|
+
return [formatter, formatterOptions];
|
|
23
|
+
|
|
24
|
+
if (error.code === 'ERR_MODULE_NOT_FOUND')
|
|
25
|
+
return exit(NO_FORMATTER, error);
|
|
26
|
+
|
|
27
|
+
exit(CANNOT_LOAD_FORMATTER, error);
|
|
28
|
+
};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import module from 'node:module';
|
|
2
|
+
import tryCatch from 'try-catch';
|
|
3
|
+
import getOptions from 'putout/cli/get-options';
|
|
4
|
+
import {
|
|
5
|
+
INTERACTIVE_CANCELED,
|
|
6
|
+
INVALID_CONFIG,
|
|
7
|
+
} from 'putout/exit-codes';
|
|
8
|
+
|
|
9
|
+
import {getFormatter} from './formatter/formatter.cjs';
|
|
10
|
+
import Report from './report.cjs';
|
|
11
|
+
|
|
12
|
+
const {createRequire} = module;
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
const {formatter: defaultFormatter} = require('putout/putout.json');
|
|
15
|
+
const {dependencies} = require('putout/package.json');
|
|
16
|
+
|
|
17
|
+
const {keys} = Object;
|
|
18
|
+
|
|
19
|
+
export const createReport = async ({args, cwd, exit}) => {
|
|
20
|
+
const {interactive, format} = args;
|
|
21
|
+
|
|
22
|
+
const report = Report();
|
|
23
|
+
const noConfig = !args.config;
|
|
24
|
+
|
|
25
|
+
const [configError, config] = tryCatch(getOptions, {
|
|
26
|
+
name: `${cwd()}/*`,
|
|
27
|
+
noConfig,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (configError)
|
|
31
|
+
exit(INVALID_CONFIG, configError);
|
|
32
|
+
|
|
33
|
+
const {formatter} = config;
|
|
34
|
+
|
|
35
|
+
let newFormatter;
|
|
36
|
+
|
|
37
|
+
if (interactive) {
|
|
38
|
+
const {chooseFormatter} = await import('@putout/cli-choose-formatter');
|
|
39
|
+
|
|
40
|
+
[newFormatter] = await chooseFormatter(defaultFormatter, keys(dependencies));
|
|
41
|
+
|
|
42
|
+
if (!newFormatter)
|
|
43
|
+
exit(INTERACTIVE_CANCELED);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const [currentFormat, formatterOptions] = await getFormatter(newFormatter || format || formatter, exit);
|
|
47
|
+
|
|
48
|
+
return async (a) => {
|
|
49
|
+
return await report(currentFormat, {
|
|
50
|
+
...a,
|
|
51
|
+
formatterOptions,
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
};
|
package/lib/report.cjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {isArray} = Array;
|
|
4
|
+
const noop = () => {};
|
|
5
|
+
|
|
6
|
+
module.exports = () => {
|
|
7
|
+
let filesCount = 0;
|
|
8
|
+
let errorsCount = 0;
|
|
9
|
+
|
|
10
|
+
return async (formatter, options) => {
|
|
11
|
+
const {
|
|
12
|
+
name,
|
|
13
|
+
rule,
|
|
14
|
+
source,
|
|
15
|
+
places,
|
|
16
|
+
index = 0,
|
|
17
|
+
count = 1,
|
|
18
|
+
trace = noop,
|
|
19
|
+
formatterOptions = {},
|
|
20
|
+
} = options;
|
|
21
|
+
|
|
22
|
+
if (!isArray(places))
|
|
23
|
+
throw Error(`☝️ Looks like for 'places: Places[]' you passed the wrong type: '${typeof places}'`);
|
|
24
|
+
|
|
25
|
+
if (places.length)
|
|
26
|
+
++filesCount;
|
|
27
|
+
|
|
28
|
+
errorsCount += places.length;
|
|
29
|
+
|
|
30
|
+
trace('progress', {
|
|
31
|
+
rule,
|
|
32
|
+
name,
|
|
33
|
+
options: formatterOptions,
|
|
34
|
+
source,
|
|
35
|
+
places,
|
|
36
|
+
index,
|
|
37
|
+
count,
|
|
38
|
+
filesCount,
|
|
39
|
+
errorsCount,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return await formatter({
|
|
43
|
+
rule,
|
|
44
|
+
name,
|
|
45
|
+
options: formatterOptions,
|
|
46
|
+
source,
|
|
47
|
+
places,
|
|
48
|
+
index,
|
|
49
|
+
count,
|
|
50
|
+
filesCount,
|
|
51
|
+
errorsCount,
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
};
|
package/lib/subscribe.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import keyPress from '@putout/cli-keypress';
|
|
2
|
+
import {createReport} from './index.js';
|
|
3
|
+
|
|
4
|
+
export const subscribe = async ({write, cwd, args, worker, exit}) => {
|
|
5
|
+
const {isStop} = keyPress();
|
|
6
|
+
const report = await createReport({
|
|
7
|
+
args,
|
|
8
|
+
cwd,
|
|
9
|
+
exit,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
worker.on('exit', exit);
|
|
13
|
+
worker.on('message', async ([event, data]) => {
|
|
14
|
+
if (event !== 'progress')
|
|
15
|
+
return;
|
|
16
|
+
|
|
17
|
+
//if (isStop())
|
|
18
|
+
// data.index = data.count - 1;
|
|
19
|
+
const line = await report(data);
|
|
20
|
+
|
|
21
|
+
write(line || '');
|
|
22
|
+
|
|
23
|
+
if (isStop())
|
|
24
|
+
worker.postMessage(['stop']);
|
|
25
|
+
});
|
|
26
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@putout/engine-reporter",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
|
+
"description": "Run 🐊Putout formatters",
|
|
7
|
+
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-reporter#readme",
|
|
8
|
+
"main": "./lib/index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./lib/index.js",
|
|
11
|
+
"./subscribe": "./lib/subscribe.js",
|
|
12
|
+
"./report": "./lib/report.cjs",
|
|
13
|
+
"./formatter": "./lib/formatter/formatter.cjs"
|
|
14
|
+
},
|
|
15
|
+
"release": false,
|
|
16
|
+
"tag": false,
|
|
17
|
+
"changelog": false,
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git://github.com/coderaiser/putout.git"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "madrun test",
|
|
24
|
+
"watch:test": "madrun watch:test",
|
|
25
|
+
"lint": "madrun lint",
|
|
26
|
+
"fresh:lint": "madrun fresh:lint",
|
|
27
|
+
"lint:fresh": "madrun lint:fresh",
|
|
28
|
+
"fix:lint": "madrun fix:lint",
|
|
29
|
+
"coverage": "madrun coverage",
|
|
30
|
+
"report": "madrun report"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@putout/cli-choose-formatter": "^3.0.0",
|
|
34
|
+
"@putout/cli-keypress": "^2.0.0",
|
|
35
|
+
"@putout/engine-loader": "^13.0.0",
|
|
36
|
+
"fullstore": "^3.0.0",
|
|
37
|
+
"try-catch": "^3.0.1",
|
|
38
|
+
"try-to-catch": "^3.0.1"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"putout",
|
|
42
|
+
"putout-engine"
|
|
43
|
+
],
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@putout/formatter-progress": "^4.0.0",
|
|
46
|
+
"c8": "^9.0.0",
|
|
47
|
+
"eslint": "^9.0.0-alpha.0",
|
|
48
|
+
"eslint-plugin-n": "^17.0.0-0",
|
|
49
|
+
"eslint-plugin-putout": "^22.0.0",
|
|
50
|
+
"just-camel-case": "^4.0.2",
|
|
51
|
+
"lerna": "^6.0.1",
|
|
52
|
+
"madrun": "^10.0.0",
|
|
53
|
+
"mock-require": "^3.0.3",
|
|
54
|
+
"montag": "^1.0.0",
|
|
55
|
+
"nodemon": "^3.0.1",
|
|
56
|
+
"putout": "*",
|
|
57
|
+
"supertape": "^9.0.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"putout": "*"
|
|
61
|
+
},
|
|
62
|
+
"license": "MIT",
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=18"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
}
|
|
69
|
+
}
|