redput 2.0.0 β 2.1.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 +15 -0
- package/README.md +16 -0
- package/lib/parse-plugin/apply-strings-tuple/README.md +42 -0
- package/lib/parse-plugin/apply-strings-tuple/index.js +17 -0
- package/lib/parse-plugin/parse-plugin.js +59 -0
- package/lib/redput.js +1 -1
- package/package.json +7 -8
- package/lib/parse-plugin.js +0 -30
package/ChangeLog
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
2023.12.19, v2.1.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 59c9e8e redput: add ability to convert to string tuple
|
|
5
|
+
|
|
6
|
+
2023.12.13, v2.0.1
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 500158f redput: escover v4.0.1
|
|
10
|
+
- 0939e42 redput: @putout/test v8.0.0
|
|
11
|
+
- c38a03f redput: @putout/plugin-putout v18.0.0
|
|
12
|
+
- 2b18949 redput: @putout/plugin-remove-unused-variables v8.0.0
|
|
13
|
+
- 06ee597 redput: eslint-plugin-putout v22.1.0
|
|
14
|
+
- 4c16df5 redput: supertape v9.0.0
|
|
15
|
+
|
|
1
16
|
2023.12.10, v2.0.0
|
|
2
17
|
|
|
3
18
|
feature:
|
package/README.md
CHANGED
|
@@ -28,6 +28,22 @@ GITHUB_TOKEN=github-token redput [putout-editor-url]
|
|
|
28
28
|
- if it finds `index.js` - creates rule inside nested plugin;
|
|
29
29
|
- creates directory with a plugin name and fills directories `lib`, `test` and `fixture`;
|
|
30
30
|
|
|
31
|
+
example of input:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
// ["off", "write-all-files"]
|
|
35
|
+
export const report = () => `Write all files`;
|
|
36
|
+
|
|
37
|
+
export const fix = (file) => {
|
|
38
|
+
const content = readFileContent(file);
|
|
39
|
+
writeFileContent(file, content);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const scan = (root, {push}) => {
|
|
43
|
+
findFile(root, ['*']).map(push);
|
|
44
|
+
};
|
|
45
|
+
```
|
|
46
|
+
|
|
31
47
|
## License
|
|
32
48
|
|
|
33
49
|
MIT
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# @putout/plugin-apply-strings-tuple [![NPM version][NPMIMGURL]][NPMURL]
|
|
2
|
+
|
|
3
|
+
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-apply-strings-tuple.svg?style=flat&longCache=true
|
|
4
|
+
[NPMURL]: https://npmjs.org/package/@putout/plugin-apply-strings-tuple "npm"
|
|
5
|
+
|
|
6
|
+
π[**Putout**](https://github.com/coderaiser/putout) plugin adds abilit to apply strings tuple. Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/34ea476503a1ffd981abd85882383ba5/67774fba230669fd88cf6b1d870743e051706f8b).
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm i @putout/plugin-apply-strings-tuple
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Rule
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"rules": {
|
|
19
|
+
"apply-strings-tuple": "on"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## β Example of incorrect code
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
[off, remove-useless];
|
|
28
|
+
['off', remove-useless];
|
|
29
|
+
['off', 'remove-useless'];
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## β
Example of correct code
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
['off', 'remove-useless'];
|
|
36
|
+
['off', 'remove-useless'];
|
|
37
|
+
['off', 'remove-useless'];
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
MIT
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {types} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {isStringLiteral} = types;
|
|
4
|
+
|
|
5
|
+
export const report = () => `Apply strings tuple`;
|
|
6
|
+
|
|
7
|
+
export const replace = () => ({
|
|
8
|
+
'[__a, __b]': ({__a, __b}, path) => {
|
|
9
|
+
const [__aPath, __bPath] = path.get('elements');
|
|
10
|
+
const status = isStringLiteral(__a) ? __a.value : __aPath.toString();
|
|
11
|
+
const name = isStringLiteral(__b) ? __b.value : __bPath
|
|
12
|
+
.toString()
|
|
13
|
+
.replace(/\s/g, '') + '';
|
|
14
|
+
|
|
15
|
+
return `["${status}", "${name}"]`;
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import tryCatch from 'try-catch';
|
|
2
|
+
import {
|
|
3
|
+
parse,
|
|
4
|
+
transform,
|
|
5
|
+
print,
|
|
6
|
+
} from 'putout';
|
|
7
|
+
import * as applyStringsTuple from './apply-strings-tuple/index.js';
|
|
8
|
+
|
|
9
|
+
export const parsePlugin = (raw) => {
|
|
10
|
+
const [comment, ...lines] = raw.split('\n');
|
|
11
|
+
const [options, name] = parseComment(comment);
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
name,
|
|
15
|
+
lines,
|
|
16
|
+
options,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function parseComment(comment) {
|
|
21
|
+
const raw = comment
|
|
22
|
+
.replace('//', '')
|
|
23
|
+
.trimStart();
|
|
24
|
+
|
|
25
|
+
const [error, data] = tryCatch(JSON.parse, raw);
|
|
26
|
+
|
|
27
|
+
if (!error)
|
|
28
|
+
return data;
|
|
29
|
+
|
|
30
|
+
const [parseError, ast] = tryCatch(parse, raw);
|
|
31
|
+
|
|
32
|
+
if (parseError)
|
|
33
|
+
return ['', raw];
|
|
34
|
+
|
|
35
|
+
transform(ast, raw, {
|
|
36
|
+
plugins: [
|
|
37
|
+
['apply-strings-tuple', applyStringsTuple],
|
|
38
|
+
],
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const json = print(ast, {
|
|
42
|
+
printer: ['putout', {
|
|
43
|
+
format: {
|
|
44
|
+
quote: '"',
|
|
45
|
+
},
|
|
46
|
+
semantics: {
|
|
47
|
+
encodeDoubleQuote: false,
|
|
48
|
+
trailingComma: false,
|
|
49
|
+
},
|
|
50
|
+
}],
|
|
51
|
+
}).slice(0, -2);
|
|
52
|
+
|
|
53
|
+
const [secondError, result] = tryCatch(JSON.parse, json);
|
|
54
|
+
|
|
55
|
+
if (secondError)
|
|
56
|
+
return ['', raw];
|
|
57
|
+
|
|
58
|
+
return result;
|
|
59
|
+
}
|
package/lib/redput.js
CHANGED
|
@@ -3,7 +3,7 @@ import {getReport} from './get-report/get-report.js';
|
|
|
3
3
|
import {readGist} from './read-gist/read-gist.js';
|
|
4
4
|
import {writePlugin} from './write/index.js';
|
|
5
5
|
import {parseLink} from './parse-link.js';
|
|
6
|
-
import {parsePlugin} from './parse-plugin.js';
|
|
6
|
+
import {parsePlugin} from './parse-plugin/parse-plugin.js';
|
|
7
7
|
|
|
8
8
|
const SUCCESS = [null, 'Done'];
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redput",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "CLI tool to convert source from πPutout Editor to files",
|
|
5
5
|
"main": "lib/redput.js",
|
|
6
6
|
"bin": {
|
|
@@ -59,8 +59,8 @@
|
|
|
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": "^
|
|
63
|
-
"@putout/plugin-remove-unused-variables": "^
|
|
62
|
+
"@putout/plugin-putout": "^18.0.0",
|
|
63
|
+
"@putout/plugin-remove-unused-variables": "^8.0.0",
|
|
64
64
|
"node-fetch": "^3.3.2",
|
|
65
65
|
"octokit": "^3.1.0",
|
|
66
66
|
"putout": "^34.0.0",
|
|
@@ -69,17 +69,16 @@
|
|
|
69
69
|
"try-to-catch": "^3.0.1"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@putout/test": "^
|
|
72
|
+
"@putout/test": "^8.0.0",
|
|
73
73
|
"c8": "^8.0.0",
|
|
74
|
-
"escover": "^
|
|
74
|
+
"escover": "^4.0.1",
|
|
75
75
|
"eslint": "^8.0.0",
|
|
76
76
|
"eslint-plugin-n": "^16.0.1",
|
|
77
|
-
"eslint-plugin-putout": "^
|
|
77
|
+
"eslint-plugin-putout": "^22.1.0",
|
|
78
78
|
"madrun": "^10.0.0",
|
|
79
79
|
"montag": "^1.2.1",
|
|
80
80
|
"nodemon": "^3.0.1",
|
|
81
|
-
"
|
|
82
|
-
"supertape": "^8.1.0"
|
|
81
|
+
"supertape": "^9.0.0"
|
|
83
82
|
},
|
|
84
83
|
"publishConfig": {
|
|
85
84
|
"access": "public"
|
package/lib/parse-plugin.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import tryCatch from 'try-catch';
|
|
2
|
-
|
|
3
|
-
const {parse} = JSON;
|
|
4
|
-
|
|
5
|
-
export const parsePlugin = (raw) => {
|
|
6
|
-
const [comment, ...lines] = raw.split('\n');
|
|
7
|
-
const [options, name] = parseComment(comment);
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
name,
|
|
11
|
-
lines,
|
|
12
|
-
options,
|
|
13
|
-
};
|
|
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 [
|
|
27
|
-
data[0],
|
|
28
|
-
data[1],
|
|
29
|
-
];
|
|
30
|
-
}
|