redput 1.2.1 → 1.3.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 +8 -0
- package/lib/get-report/plugin-get-report/index.js +0 -4
- package/lib/redput.js +4 -4
- package/lib/write/index.js +8 -13
- package/lib/write/nested/add-rule/plugin-insert-get-rule/index.js +40 -0
- package/lib/write/nested/insert-test/insert-test.js +18 -0
- package/lib/write/nested/insert-test/plugin-insert-test/index.js +31 -0
- package/lib/write/{nested.js → nested/nested.js} +24 -1
- package/package.json +1 -1
- package/lib/add-rule/plugin-insert-get-rule/index.js +0 -47
- /package/lib/{add-rule → write/nested/add-rule}/add-rule.js +0 -0
package/ChangeLog
CHANGED
package/lib/redput.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import tryToCatch from 'try-to-catch';
|
|
2
|
-
import {exists} from 'fs';
|
|
3
|
-
import {access} from 'fs/promises';
|
|
4
2
|
import {getReport} from './get-report/get-report.js';
|
|
5
3
|
import {readGist} from './read-gist/read-gist.js';
|
|
6
4
|
import {writePlugin} from './write/index.js';
|
|
@@ -34,12 +32,14 @@ export const redput = async (link, {token}) => {
|
|
|
34
32
|
const rule = lines.join('\n');
|
|
35
33
|
const report = getReport(rule);
|
|
36
34
|
|
|
37
|
-
await writePlugin
|
|
35
|
+
const [errorWrite] = await tryToCatch(writePlugin, name, {
|
|
38
36
|
rule,
|
|
39
37
|
fixture,
|
|
40
38
|
report,
|
|
41
39
|
});
|
|
42
40
|
|
|
41
|
+
if (errorWrite)
|
|
42
|
+
return [errorWrite];
|
|
43
|
+
|
|
43
44
|
return SUCCESS;
|
|
44
45
|
};
|
|
45
|
-
|
package/lib/write/index.js
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
readFile,
|
|
4
|
-
writeFile,
|
|
5
|
-
mkdir,
|
|
6
|
-
access,
|
|
7
|
-
} from 'fs/promises';
|
|
8
|
-
import {
|
|
9
|
-
dirname,
|
|
10
|
-
basename,
|
|
11
|
-
join,
|
|
12
|
-
} from 'path';
|
|
1
|
+
import {access} from 'fs/promises';
|
|
13
2
|
import {
|
|
3
|
+
updateNestedIndex,
|
|
4
|
+
updateOverallNestedFixtures,
|
|
5
|
+
updateOverallNestedTest,
|
|
14
6
|
writeNestedFixtures,
|
|
15
7
|
writeNestedRule,
|
|
16
8
|
writeNestedTests,
|
|
17
|
-
} from './nested.js';
|
|
9
|
+
} from './nested/nested.js';
|
|
18
10
|
import {
|
|
19
11
|
writeFixtures,
|
|
20
12
|
writeRule,
|
|
@@ -44,6 +36,9 @@ export const writeNested = async (name, {rule, fixture, report}) => {
|
|
|
44
36
|
await writeNestedRule(name, rule);
|
|
45
37
|
await writeNestedFixtures(name, fixture);
|
|
46
38
|
await writeNestedTests(name, report);
|
|
39
|
+
await updateNestedIndex(name);
|
|
40
|
+
await updateOverallNestedFixtures(name, fixture);
|
|
41
|
+
await updateOverallNestedTest(name);
|
|
47
42
|
};
|
|
48
43
|
|
|
49
44
|
export const writeSimple = async (name, {rule, fixture, report}) => {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
types,
|
|
3
|
+
operator,
|
|
4
|
+
template,
|
|
5
|
+
} from 'putout';
|
|
6
|
+
|
|
7
|
+
const {StringLiteral, SpreadElement} = types;
|
|
8
|
+
const {traverse} = operator;
|
|
9
|
+
|
|
10
|
+
export const report = () => `Insert 'getRule()'`;
|
|
11
|
+
|
|
12
|
+
const createRule = template('getRule(%%name%%)');
|
|
13
|
+
|
|
14
|
+
export const match = ({options}) => ({
|
|
15
|
+
'module.exports.rules = __object': ({__object}) => {
|
|
16
|
+
let exists = false;
|
|
17
|
+
const {name} = options;
|
|
18
|
+
|
|
19
|
+
traverse(__object, {
|
|
20
|
+
[`getRule('${name}')`]: () => {
|
|
21
|
+
exists = true;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return !exists;
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const replace = ({options}) => ({
|
|
30
|
+
'module.exports.rules = __object': ({__object}, path) => {
|
|
31
|
+
const {name} = options;
|
|
32
|
+
const node = SpreadElement(createRule({
|
|
33
|
+
name: StringLiteral(name),
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
__object.properties.push(node);
|
|
37
|
+
|
|
38
|
+
return path;
|
|
39
|
+
},
|
|
40
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import putout from 'putout';
|
|
2
|
+
import * as insertTestPlugin from './plugin-insert-test/index.js';
|
|
3
|
+
|
|
4
|
+
export const insertTest = (rule, plugin, source) => {
|
|
5
|
+
const {code} = putout(source, {
|
|
6
|
+
rules: {
|
|
7
|
+
'insert-test': ['on', {
|
|
8
|
+
rule,
|
|
9
|
+
plugin,
|
|
10
|
+
}],
|
|
11
|
+
},
|
|
12
|
+
plugins: [
|
|
13
|
+
['insert-test', insertTestPlugin],
|
|
14
|
+
],
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return code;
|
|
18
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {template} from 'putout';
|
|
2
|
+
|
|
3
|
+
export const report = () => 'Insert test';
|
|
4
|
+
|
|
5
|
+
export const fix = ({path, nodeTest}) => {
|
|
6
|
+
path.node.body.push(nodeTest);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const traverse = ({push, pathStore, options}) => {
|
|
10
|
+
const {plugin = 'github', rule = 'insert-test'} = options;
|
|
11
|
+
const strTest = `
|
|
12
|
+
test('plugin-${plugin}: transform: ${rule}', (t) => {
|
|
13
|
+
t.transform('${rule}');
|
|
14
|
+
t.end();
|
|
15
|
+
});
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
const nodeTest = template.ast(strTest);
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
[strTest]: pathStore,
|
|
22
|
+
Program: {
|
|
23
|
+
exit(path) {
|
|
24
|
+
!pathStore().length && push({
|
|
25
|
+
path,
|
|
26
|
+
nodeTest,
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
join,
|
|
10
10
|
} from 'path';
|
|
11
11
|
import rendy from 'rendy';
|
|
12
|
+
import {addRule} from './add-rule/add-rule.js';
|
|
13
|
+
import {insertTest} from './insert-test/insert-test.js';
|
|
12
14
|
|
|
13
15
|
export const writeNestedRule = async (name, data) => {
|
|
14
16
|
await mkdir(`./${name}`, {
|
|
@@ -28,7 +30,7 @@ export const writeNestedFixtures = async (name, data) => {
|
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
export const writeNestedTests = async (name, report) => {
|
|
31
|
-
const templatePath = new URL('
|
|
33
|
+
const templatePath = new URL('../../../templates/plugin.js', import.meta.url).pathname;
|
|
32
34
|
const template = await readFile(templatePath, 'utf8');
|
|
33
35
|
const nestedPluginName = basename(dirname(join(process.cwd(), '..')));
|
|
34
36
|
const nested = nestedPluginName.replace('plugin-', '');
|
|
@@ -40,3 +42,24 @@ export const writeNestedTests = async (name, report) => {
|
|
|
40
42
|
importPath: '.',
|
|
41
43
|
}));
|
|
42
44
|
};
|
|
45
|
+
|
|
46
|
+
export const updateNestedIndex = async (name) => {
|
|
47
|
+
const source = await readFile('./index.js', 'utf8');
|
|
48
|
+
const code = addRule(name, source);
|
|
49
|
+
await writeFile(`./index.js`, code);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const updateOverallNestedTest = async (name) => {
|
|
53
|
+
const nestedPluginName = basename(dirname(join(process.cwd())));
|
|
54
|
+
const plugin = nestedPluginName.replace('plugin-', '');
|
|
55
|
+
|
|
56
|
+
const source = await readFile(`../test/${plugin}.js`, 'utf8');
|
|
57
|
+
const code = insertTest(name, plugin, source);
|
|
58
|
+
|
|
59
|
+
await writeFile(`../test/${plugin}.js`, code);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const updateOverallNestedFixtures = async (name, data) => {
|
|
63
|
+
await writeFile(`../test/fixture/${name}.js`, data);
|
|
64
|
+
await writeFile(`../test/fixture/${name}-fix.js`, data);
|
|
65
|
+
};
|
package/package.json
CHANGED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
operator,
|
|
3
|
-
types,
|
|
4
|
-
template,
|
|
5
|
-
} from 'putout';
|
|
6
|
-
|
|
7
|
-
const {getTemplateValues} = operator;
|
|
8
|
-
const {StringLiteral, SpreadElement} = types;
|
|
9
|
-
const RULES = 'module.exports.rules = __object';
|
|
10
|
-
const GET_RULE = template('getRule(%%name%%)');
|
|
11
|
-
|
|
12
|
-
export const report = () => `Insert 'getRule()'`;
|
|
13
|
-
|
|
14
|
-
export const fix = ({__object}, {options}) => {
|
|
15
|
-
const {name} = options;
|
|
16
|
-
const getRuleNode = SpreadElement(GET_RULE({
|
|
17
|
-
name: StringLiteral(name),
|
|
18
|
-
}));
|
|
19
|
-
|
|
20
|
-
__object.properties.push(getRuleNode);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const traverse = ({push, options}) => ({
|
|
24
|
-
[RULES](path) {
|
|
25
|
-
const {__object} = getTemplateValues(path, RULES);
|
|
26
|
-
const {name} = options;
|
|
27
|
-
|
|
28
|
-
if (!check(name, __object))
|
|
29
|
-
return;
|
|
30
|
-
|
|
31
|
-
push({
|
|
32
|
-
path,
|
|
33
|
-
__object,
|
|
34
|
-
});
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
function check(name, {properties}) {
|
|
39
|
-
for (const {argument} of properties) {
|
|
40
|
-
const [first] = argument.arguments;
|
|
41
|
-
|
|
42
|
-
if (first.value === name)
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
File without changes
|