redput 1.12.0 → 1.14.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/ChangeLog +12 -0
- package/lib/get-report/plugin-get-report/index.js +8 -3
- package/lib/parse-plugin.js +19 -3
- package/lib/redput.js +6 -7
- package/lib/write/index.js +7 -5
- package/lib/write/nested/add-rule/add-rule.js +2 -1
- package/lib/write/nested/add-rule/plugin-insert-get-rule/index.js +15 -1
- package/lib/write/nested/nested.js +2 -2
- package/package.json +4 -3
package/ChangeLog
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
2023.11.28, v1.14.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- daae14d redput: add ability to pass options
|
|
5
|
+
|
|
6
|
+
2023.11.21, v1.13.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 8ecf9d3 redput: @putout/plugin-putout v16.7.0
|
|
10
|
+
- afce39c redput: putout v33.9.1
|
|
11
|
+
- 3a70560 redput: get-report: improve support of template literals
|
|
12
|
+
|
|
1
13
|
2023.11.02, v1.12.0
|
|
2
14
|
|
|
3
15
|
feature:
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
operator,
|
|
3
3
|
types,
|
|
4
|
+
print,
|
|
4
5
|
} from 'putout';
|
|
5
6
|
|
|
6
7
|
const {isStringLiteral} = types;
|
|
7
8
|
const {getTemplateValues} = operator;
|
|
8
9
|
|
|
9
|
-
const REPORT = 'export const report = () => __a';
|
|
10
|
-
const REPORT_COMMONJS = 'module.exports.report = () => __a';
|
|
10
|
+
const REPORT = 'export const report = (__args) => __a';
|
|
11
|
+
const REPORT_COMMONJS = 'module.exports.report = (__args) => __a';
|
|
11
12
|
const ASSIGN = 'export const report = __a';
|
|
12
13
|
|
|
13
14
|
const templates = [
|
|
@@ -47,5 +48,9 @@ function parseValue(a) {
|
|
|
47
48
|
if (isStringLiteral(a))
|
|
48
49
|
return a.value;
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
const value = print(a);
|
|
52
|
+
|
|
53
|
+
return value
|
|
54
|
+
.slice(1, -3)
|
|
55
|
+
.replaceAll('${', '{');
|
|
51
56
|
}
|
package/lib/parse-plugin.js
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
|
+
import tryCatch from 'try-catch';
|
|
2
|
+
|
|
3
|
+
const {parse} = JSON;
|
|
4
|
+
|
|
1
5
|
export const parsePlugin = (raw) => {
|
|
2
6
|
const [comment, ...lines] = raw.split('\n');
|
|
3
|
-
const name = comment
|
|
4
|
-
.replace('//', '')
|
|
5
|
-
.trimStart();
|
|
7
|
+
const [options, name] = parseComment(comment);
|
|
6
8
|
|
|
7
9
|
return {
|
|
8
10
|
name,
|
|
9
11
|
lines,
|
|
12
|
+
options,
|
|
10
13
|
};
|
|
11
14
|
};
|
|
15
|
+
|
|
16
|
+
function parseComment(comment) {
|
|
17
|
+
const raw = comment
|
|
18
|
+
.replace('//', '')
|
|
19
|
+
.trimStart();
|
|
20
|
+
|
|
21
|
+
const [error, data] = tryCatch(parse, raw);
|
|
22
|
+
|
|
23
|
+
if (error)
|
|
24
|
+
return ['', raw];
|
|
25
|
+
|
|
26
|
+
return [data[0], data[1]];
|
|
27
|
+
}
|
package/lib/redput.js
CHANGED
|
@@ -21,17 +21,16 @@ export const redput = async (link, {token}) => {
|
|
|
21
21
|
const raw = result.data.files['transform.js'].content;
|
|
22
22
|
const fixture = result.data.files['source.js'].content;
|
|
23
23
|
|
|
24
|
-
const {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
];
|
|
30
|
-
|
|
24
|
+
const {
|
|
25
|
+
name,
|
|
26
|
+
options,
|
|
27
|
+
lines,
|
|
28
|
+
} = parsePlugin(raw);
|
|
31
29
|
const rule = lines.join('\n');
|
|
32
30
|
const report = getReport(rule);
|
|
33
31
|
|
|
34
32
|
const [errorWrite] = await tryToCatch(writePlugin, name, {
|
|
33
|
+
options,
|
|
35
34
|
rule,
|
|
36
35
|
fixture,
|
|
37
36
|
report,
|
package/lib/write/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from './simple.js';
|
|
15
15
|
import tryToCatch from 'try-to-catch';
|
|
16
16
|
|
|
17
|
-
export const writePlugin = async (name, {rule, fixture, report}) => {
|
|
17
|
+
export const writePlugin = async (name, {rule, fixture, report, options}) => {
|
|
18
18
|
const [isNested] = await tryToCatch(access, './package.json');
|
|
19
19
|
|
|
20
20
|
if (isNested)
|
|
@@ -22,6 +22,7 @@ export const writePlugin = async (name, {rule, fixture, report}) => {
|
|
|
22
22
|
rule,
|
|
23
23
|
fixture,
|
|
24
24
|
report,
|
|
25
|
+
options,
|
|
25
26
|
});
|
|
26
27
|
|
|
27
28
|
await writeSimple(name, {
|
|
@@ -31,18 +32,19 @@ export const writePlugin = async (name, {rule, fixture, report}) => {
|
|
|
31
32
|
});
|
|
32
33
|
};
|
|
33
34
|
|
|
34
|
-
export const writeNested = async (name, {rule, fixture, report}) => {
|
|
35
|
-
await writeNestedRule(name, rule);
|
|
35
|
+
export const writeNested = async (name, {rule, fixture, report, options}) => {
|
|
36
|
+
await writeNestedRule(name, rule, options);
|
|
36
37
|
await writeNestedFixtures(name, fixture);
|
|
37
38
|
await writeNestedTests(name, report);
|
|
38
39
|
|
|
39
40
|
await tryToCatch(writeNestedOptional, name, {
|
|
41
|
+
options,
|
|
40
42
|
fixture,
|
|
41
43
|
});
|
|
42
44
|
};
|
|
43
45
|
|
|
44
|
-
export const writeNestedOptional = async (name, {fixture}) => {
|
|
45
|
-
await updateNestedIndex(name);
|
|
46
|
+
export const writeNestedOptional = async (name, {options, fixture}) => {
|
|
47
|
+
await updateNestedIndex(name, options);
|
|
46
48
|
await updateOverallNestedFixtures(name, fixture);
|
|
47
49
|
await updateOverallNestedTest(name);
|
|
48
50
|
};
|
|
@@ -3,11 +3,12 @@ import * as insertGetRulePlugin from './plugin-insert-get-rule/index.js';
|
|
|
3
3
|
import pluginPutout from '@putout/plugin-putout';
|
|
4
4
|
import removeUnusedVariables from '@putout/plugin-remove-unused-variables';
|
|
5
5
|
|
|
6
|
-
export const addRule = (name, source) => {
|
|
6
|
+
export const addRule = (name, source, ruleOptions) => {
|
|
7
7
|
const {code} = putout(source, {
|
|
8
8
|
rules: {
|
|
9
9
|
'add-rule': ['on', {
|
|
10
10
|
name,
|
|
11
|
+
ruleOptions,
|
|
11
12
|
}],
|
|
12
13
|
},
|
|
13
14
|
plugins: [
|
|
@@ -10,6 +10,7 @@ const {traverse} = operator;
|
|
|
10
10
|
export const report = () => `Insert 'getRule()'`;
|
|
11
11
|
|
|
12
12
|
const createRule = template('getRule(%%name%%)');
|
|
13
|
+
const createRuleWithOptions = template('getRule(%%name%%, "off")');
|
|
13
14
|
|
|
14
15
|
export const match = ({options}) => ({
|
|
15
16
|
'module.exports.rules = __object': ({__object}) => {
|
|
@@ -20,6 +21,9 @@ export const match = ({options}) => ({
|
|
|
20
21
|
[`getRule('${name}')`]: () => {
|
|
21
22
|
exists = true;
|
|
22
23
|
},
|
|
24
|
+
[`getRule('${name}', 'off')`]: () => {
|
|
25
|
+
exists = true;
|
|
26
|
+
},
|
|
23
27
|
});
|
|
24
28
|
|
|
25
29
|
return !exists;
|
|
@@ -28,7 +32,17 @@ export const match = ({options}) => ({
|
|
|
28
32
|
|
|
29
33
|
export const replace = ({options}) => ({
|
|
30
34
|
'module.exports.rules = __object': ({__object}, path) => {
|
|
31
|
-
const {name} = options;
|
|
35
|
+
const {name, ruleOptions} = options;
|
|
36
|
+
|
|
37
|
+
if (ruleOptions) {
|
|
38
|
+
const node = SpreadElement(createRuleWithOptions({
|
|
39
|
+
name: StringLiteral(name),
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
__object.properties.push(node);
|
|
43
|
+
return path;
|
|
44
|
+
}
|
|
45
|
+
|
|
32
46
|
const node = SpreadElement(createRule({
|
|
33
47
|
name: StringLiteral(name),
|
|
34
48
|
}));
|
|
@@ -47,9 +47,9 @@ export const writeNestedTests = async (name, report) => {
|
|
|
47
47
|
}));
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
export const updateNestedIndex = async (name) => {
|
|
50
|
+
export const updateNestedIndex = async (name, options) => {
|
|
51
51
|
const source = await readFile('./index.js', 'utf8');
|
|
52
|
-
const code = addRule(name, source);
|
|
52
|
+
const code = addRule(name, source, options);
|
|
53
53
|
await writeFile(`./index.js`, code);
|
|
54
54
|
};
|
|
55
55
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redput",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "CLI tool to convert source from 🐊Putout Editor to files",
|
|
5
5
|
"main": "lib/redput.js",
|
|
6
6
|
"bin": {
|
|
@@ -59,12 +59,13 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@putout/plugin-convert-esm-to-commonjs": "^6.0.0",
|
|
61
61
|
"@putout/plugin-declare": "^2.0.1",
|
|
62
|
-
"@putout/plugin-putout": "^
|
|
62
|
+
"@putout/plugin-putout": "^16.7.0",
|
|
63
63
|
"@putout/plugin-remove-unused-variables": "^7.0.0",
|
|
64
64
|
"node-fetch": "^3.3.2",
|
|
65
65
|
"octokit": "^3.1.0",
|
|
66
|
-
"putout": "^
|
|
66
|
+
"putout": "^33.9.1",
|
|
67
67
|
"rendy": "^4.1.3",
|
|
68
|
+
"try-catch": "^3.0.1",
|
|
68
69
|
"try-to-catch": "^3.0.1"
|
|
69
70
|
},
|
|
70
71
|
"devDependencies": {
|