redlint 3.8.0 β†’ 3.9.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 CHANGED
@@ -1,3 +1,9 @@
1
+ 2024.01.15, v3.9.0
2
+
3
+ feature:
4
+ - f627e79 redlint: c8 v9.1.0
5
+ - 29d0f34 redlint: convert: add
6
+
1
7
  2023.12.29, v3.8.0
2
8
 
3
9
  feature:
package/README.md CHANGED
@@ -13,9 +13,9 @@
13
13
  >
14
14
  > **(c) The Book of Kon, PoKon and ZaKon**
15
15
 
16
- ![image](https://github.com/putoutjs/redlint/assets/1573141/3f239180-a378-48b7-9e68-9cc66e762e2b)
16
+ ![image](https://github.com/putoutjs/redlint/assets/1573141/c990a94f-3ea5-42b0-a43f-42caadaad649)
17
17
 
18
- What if **Filesystem** was a simple **JSON** file [`.filesystem.json`](https://github.com/putoutjs/redlint/blob/master/.filesystem.json). What if you can transform **JSON** file with 🐊[**Putout**](https://github.com/coderaiser/putout) code transformer and this changes modify **Filesystem**?
18
+ What if **Filesystem** was a simple **JSON** file [`.filesystem.json`](https://github.com/putoutjs/redlint/blob/v2.0.0/.filesystem.json). What if you can transform **JSON** file with 🐊[**Putout**](https://github.com/coderaiser/putout) code transformer and this changes modify **Filesystem**?
19
19
 
20
20
  What if I tell you it is possible? 😱 Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/0614c2da35a1864b59ac284f18656328/695a9960c401d4e8f6744f58eac591d8f9185235).
21
21
 
@@ -31,7 +31,7 @@ npm i redlint -g
31
31
 
32
32
  You can choose interactively when run `redlint`:
33
33
 
34
- <img width="375" alt="image" src="https://github.com/putoutjs/redlint/assets/1573141/910c85bc-f36d-4ad1-be8a-37935bf9c33a">
34
+ ![image](https://github.com/putoutjs/redlint/assets/1573141/906061ba-a5b3-44be-a7ad-40464a9122f6)
35
35
 
36
36
  ## Scan
37
37
 
@@ -39,6 +39,13 @@ To scan your files use `redlint scan`:
39
39
 
40
40
  <img width="718" alt="image" src="https://github.com/putoutjs/redlint/assets/1573141/58672a61-4408-4c1e-ab75-2fbcca7f225d">
41
41
 
42
+ ## Convert
43
+
44
+ To convert file to **JSON** or **JavaScript** use:
45
+
46
+ ![image](https://github.com/putoutjs/redlint/assets/1573141/2a2df8f7-ea3b-4158-b3f3-d30522dbdd7e)
47
+ ![image](https://github.com/putoutjs/redlint/assets/1573141/847622e9-cfa5-47fd-9503-f526214dcf23)
48
+
42
49
  ## Fix
43
50
 
44
51
  To fix your files use `redlint fix`:
package/bin/redlint.js CHANGED
@@ -6,10 +6,12 @@ import {
6
6
  readFile,
7
7
  writeFile,
8
8
  } from 'node:fs/promises';
9
+ import tryToCatch from 'try-to-catch';
9
10
  import {lintJSON} from 'putout/lint/json';
10
11
  import formatterCodeFrame from '@putout/formatter-codeframe';
11
12
  import formatterDump from '@putout/formatter-dump';
12
13
  import ora from 'ora';
14
+ import enq from 'enquirer';
13
15
  import {help} from '../lib/help/help.js';
14
16
  import {choose} from '../lib/choose.js';
15
17
  import {buildTree} from '../lib/redlint.js';
@@ -23,6 +25,9 @@ import {extract} from '../lib/extract/extract.js';
23
25
  import {debug} from '../lib/debug.js';
24
26
  import {logo} from '../lib/help/logo.js';
25
27
  import {version} from '../lib/cli/version.js';
28
+ import {chooseConvert} from '../lib/convert/index.js';
29
+ import {convert} from '../lib/convert/convert.js';
30
+ import {masterConvert} from '../lib/convert/master.js';
26
31
  import {
27
32
  isScan,
28
33
  isScanDebug,
@@ -37,12 +42,16 @@ import {
37
42
  isHelp,
38
43
  isVersion,
39
44
  isDebug,
45
+ isConvert,
46
+ isConvertChosen,
47
+ isConvertChosenDebug,
40
48
  isBack,
41
49
  isExit,
42
50
  } from '../lib/menu.js';
43
51
 
44
52
  const {log} = console;
45
53
  const {exit} = process;
54
+ const {prompt} = enq;
46
55
 
47
56
  const {stringify} = JSON;
48
57
 
@@ -67,16 +76,6 @@ async function uiLoop(arg) {
67
76
  header = false;
68
77
  }
69
78
 
70
- if (isDebug(arg)) {
71
- arg = await debug();
72
-
73
- if (isBack(arg))
74
- return await uiLoop();
75
- }
76
-
77
- if (isExit(arg))
78
- process.exit();
79
-
80
79
  if (isVersion(arg))
81
80
  return version({
82
81
  log,
@@ -88,9 +87,24 @@ async function uiLoop(arg) {
88
87
  help({
89
88
  header,
90
89
  });
91
- process.exit();
90
+ return process.exit();
92
91
  }
93
92
 
93
+ if (isConvert(arg))
94
+ arg = await chooseConvert();
95
+
96
+ if (isDebug(arg))
97
+ arg = await debug();
98
+
99
+ if (isBack(arg))
100
+ return await uiLoop();
101
+
102
+ if (isExit(arg))
103
+ return process.exit();
104
+
105
+ if (!arg)
106
+ return;
107
+
94
108
  log('Running:');
95
109
  const spinner = ora('index filesystem').start();
96
110
  const CWD = process.cwd();
@@ -105,6 +119,32 @@ async function uiLoop(arg) {
105
119
 
106
120
  const filesystem = lintJSON(stringify(result));
107
121
 
122
+ if (isConvertChosen(arg)) {
123
+ const [e, result] = await tryToCatch(prompt, {
124
+ type: 'input',
125
+ name: 'filename',
126
+ message: 'Filename:',
127
+ });
128
+
129
+ if (!e && result?.filename)
130
+ await masterConvert(result.filename, arg, filesystem);
131
+
132
+ return;
133
+ }
134
+
135
+ if (isConvertChosenDebug(arg)) {
136
+ const [e, result] = await tryToCatch(prompt, {
137
+ type: 'input',
138
+ name: 'filename',
139
+ message: 'Filename:',
140
+ });
141
+
142
+ if (!e && result?.filename)
143
+ await convert(result.filename, arg, filesystem);
144
+
145
+ return;
146
+ }
147
+
108
148
  if (isScan(arg)) {
109
149
  const places = await masterLint(filesystem, {
110
150
  fix: false,
package/lib/choose.js CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  GENERATE_SIMPLE,
9
9
  HELP,
10
10
  VERSION,
11
+ CONVERT,
11
12
  DEBUG,
12
13
  EXIT,
13
14
  } from './menu.js';
@@ -20,6 +21,7 @@ export const choose = async () => {
20
21
  EXTRACT,
21
22
  GENERATE,
22
23
  GENERATE_SIMPLE,
24
+ CONVERT,
23
25
  HELP,
24
26
  VERSION,
25
27
  DEBUG,
@@ -0,0 +1,67 @@
1
+ import {
2
+ parse,
3
+ transform,
4
+ print,
5
+ } from 'putout';
6
+ import {createProgress} from '@putout/engine-runner/progress';
7
+ import * as pluginFilesystem from '@putout/plugin-filesystem';
8
+ import {
9
+ branch as originalBranch,
10
+ merge as originalMerge,
11
+ } from '@putout/processor-filesystem';
12
+ import {
13
+ isConvertToJs,
14
+ isConvertToJson,
15
+ } from '../menu.js';
16
+
17
+ const [, pluginConvertJsonToJs] = pluginFilesystem.rules['convert-json-to-js'];
18
+ const [, pluginConvertJsToJson] = pluginFilesystem.rules['convert-js-to-json'];
19
+
20
+ export const convert = (filename, type, filesystem, {
21
+ progress = createProgress(),
22
+ branch = originalBranch,
23
+ merge = originalMerge,
24
+ } = {}) => {
25
+ const [{source}] = branch(filesystem);
26
+ const ast = parse(source);
27
+ const options = createOptions(filename, type);
28
+
29
+ transform(ast, filesystem, {
30
+ fix: true,
31
+ fixCount: 1,
32
+ progress,
33
+ ...options,
34
+ });
35
+
36
+ const code = print(ast);
37
+
38
+ return merge(filesystem, [code]);
39
+ };
40
+
41
+ function createOptions(filename, type) {
42
+ if (isConvertToJs(type))
43
+ return {
44
+ rules: {
45
+ 'filesystem/convert-json-to-js': ['on', {
46
+ filename,
47
+ }],
48
+ },
49
+ plugins: [
50
+ ['filesystem/convert-json-to-js', pluginConvertJsonToJs],
51
+ ],
52
+ };
53
+
54
+ if (isConvertToJson(type))
55
+ return {
56
+ rules: {
57
+ 'filesystem/convert-js-to-json': ['on', {
58
+ filename,
59
+ }],
60
+ },
61
+ plugins: [
62
+ ['filesystem/convert-js-to-json', pluginConvertJsToJson],
63
+ ],
64
+ };
65
+
66
+ return {};
67
+ }
@@ -0,0 +1,19 @@
1
+ import {choose as chooseDialog} from '@putout/cli-choose';
2
+ import {
3
+ CONVERT_JS_TO_JSON,
4
+ CONVERT_JSON_TO_JS,
5
+ BACK,
6
+ EXIT,
7
+ } from '../menu.js';
8
+
9
+ export * from './convert.js';
10
+ export const chooseConvert = async () => {
11
+ const command = await chooseDialog('Convert:', [
12
+ CONVERT_JS_TO_JSON,
13
+ CONVERT_JSON_TO_JS,
14
+ BACK,
15
+ EXIT,
16
+ ]);
17
+
18
+ return command;
19
+ };
@@ -0,0 +1,37 @@
1
+ import {run} from '../run.js';
2
+ import {
3
+ setStart,
4
+ setEnd,
5
+ setPush,
6
+ setFail,
7
+ setSuccess,
8
+ setSuffixText,
9
+ } from '../spinner.js';
10
+
11
+ export function masterConvert(filename, type, filesystem, {
12
+ start = setStart,
13
+ end = setEnd,
14
+ push = setPush,
15
+ fail = setFail,
16
+ success = setSuccess,
17
+ suffix = setSuffixText,
18
+ } = {}) {
19
+ const slave = new URL('./slave.js', import.meta.url);
20
+ const workerData = {
21
+ filename,
22
+ type,
23
+ filesystem,
24
+ };
25
+
26
+ return run({
27
+ fix: true,
28
+ start,
29
+ end,
30
+ push,
31
+ fail,
32
+ success,
33
+ slave,
34
+ workerData,
35
+ suffix,
36
+ });
37
+ }
@@ -0,0 +1,26 @@
1
+ import {
2
+ parentPort,
3
+ workerData,
4
+ } from 'node:worker_threads';
5
+ import {createProgress} from '@putout/engine-runner/progress';
6
+ import {convert} from './convert.js';
7
+ import {createSlave} from '../slave.js';
8
+
9
+ const {
10
+ filename,
11
+ type,
12
+ filesystem,
13
+ } = workerData;
14
+
15
+ const progress = createProgress();
16
+
17
+ await createSlave(runPack, {
18
+ progress,
19
+ parentPort,
20
+ });
21
+
22
+ async function runPack() {
23
+ return await convert(filename, type, filesystem, {
24
+ progress,
25
+ });
26
+ }
package/lib/debug.js CHANGED
@@ -3,6 +3,8 @@ import {
3
3
  SCAN_DEBUG,
4
4
  PACK_DEBUG,
5
5
  FIX_DEBUG,
6
+ CONVERT_JS_TO_JSON_DEBUG,
7
+ CONVERT_JSON_TO_JS_DEBUG,
6
8
  BACK,
7
9
  EXIT,
8
10
  } from './menu.js';
@@ -12,6 +14,8 @@ export const debug = async () => {
12
14
  SCAN_DEBUG,
13
15
  FIX_DEBUG,
14
16
  PACK_DEBUG,
17
+ CONVERT_JS_TO_JSON_DEBUG,
18
+ CONVERT_JSON_TO_JS_DEBUG,
15
19
  BACK,
16
20
  EXIT,
17
21
  ]);
package/lib/help/help.js CHANGED
@@ -15,6 +15,7 @@ export const help = ({header = true}) => {
15
15
  fix - fix files according to 🐊Putout rules
16
16
  pack - pack 'filesystem.red' with directory contents
17
17
  extract - extract directory contents from 'filesystem.red'
18
+ convert - convert one file type to another according to selected choice from menu
18
19
  help - show help screen and exit
19
20
  generate - generate .filesystem.json file and exit
20
21
  generate:simple - generate simple .filesystem.json file and exit
package/lib/menu.js CHANGED
@@ -3,7 +3,7 @@ export const SCAN_DEBUG = 'πŸ” scan: debug';
3
3
  export const FIX = 'πŸ”¨ fix';
4
4
  export const FIX_DEBUG = 'πŸ”¨ fix: debug';
5
5
  export const PACK = 'πŸ”¬ pack';
6
- export const PACK_DEBUG = 'πŸ”¬ pack';
6
+ export const PACK_DEBUG = 'πŸ”¬ pack: debug';
7
7
  export const EXTRACT = 'πŸ”­ extract';
8
8
  export const EXTRACT_DEBUG = 'πŸ”­ extract: debug';
9
9
  export const GENERATE = `🐊 generate '.filesystem.json'`;
@@ -11,9 +11,15 @@ export const GENERATE_SIMPLE = `🐊 generate simple '.filesystem.json'`;
11
11
  export const HELP = 'οΈ– help';
12
12
  export const VERSION = 'πŸ“¦ version';
13
13
  export const DEBUG = 'πŸ”§ debug';
14
+ export const CONVERT = '🐌 convert';
14
15
  export const BACK = 'πŸ”™ back';
15
16
  export const EXIT = 'πŸšͺ exit';
16
17
 
18
+ export const CONVERT_JS_TO_JSON = '🦏 convert js to json';
19
+ export const CONVERT_JSON_TO_JS = '🦏 convert json to js';
20
+ export const CONVERT_JS_TO_JSON_DEBUG = '🦏 convert js to json: debug';
21
+ export const CONVERT_JSON_TO_JS_DEBUG = '🦏 convert json to js: debug';
22
+
17
23
  export const isScan = (a) => a === SCAN || a === 'scan';
18
24
  export const isScanDebug = (a) => a === SCAN_DEBUG || a === 'scan:debug';
19
25
  export const isFix = (a) => a === FIX || a === 'fix';
@@ -29,3 +35,9 @@ export const isVersion = (a) => a === VERSION || a === 'version';
29
35
  export const isDebug = (a) => a === DEBUG || a === 'debug';
30
36
  export const isBack = (a) => a === BACK || a === 'back';
31
37
  export const isExit = (a) => a === EXIT || a === 'exit';
38
+ export const isConvert = (a) => a === CONVERT || a === 'convert';
39
+ export const isConvertChosen = (a) => a === CONVERT_JS_TO_JSON || a === CONVERT_JSON_TO_JS;
40
+ export const isConvertChosenDebug = (a) => a === CONVERT_JS_TO_JSON_DEBUG || a === CONVERT_JSON_TO_JS_DEBUG;
41
+
42
+ export const isConvertToJson = (a) => a === CONVERT_JS_TO_JSON || a === CONVERT_JSON_TO_JS_DEBUG;
43
+ export const isConvertToJs = (a) => a === CONVERT_JSON_TO_JS || a === CONVERT_JSON_TO_JS_DEBUG;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redlint",
3
- "version": "3.8.0",
3
+ "version": "3.9.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Lint Filesystem with 🐊Putout",
@@ -38,11 +38,13 @@
38
38
  "@putout/plugin-filesystem": "^3.6.0",
39
39
  "@putout/processor-filesystem": "^3.0.0",
40
40
  "chalk": "^5.3.0",
41
+ "enquirer": "^2.4.1",
41
42
  "fullstore": "^3.0.0",
42
43
  "ignore": "^5.2.4",
43
44
  "ora": "^8.0.1",
44
45
  "putout": "^34.0.0",
45
- "strip-ansi": "^7.1.0"
46
+ "strip-ansi": "^7.1.0",
47
+ "try-to-catch": "^3.0.1"
46
48
  },
47
49
  "keywords": [
48
50
  "putout",
@@ -54,7 +56,7 @@
54
56
  "generate"
55
57
  ],
56
58
  "devDependencies": {
57
- "c8": "^8.0.0",
59
+ "c8": "^9.1.0",
58
60
  "eslint": "^8.0.1",
59
61
  "eslint-plugin-n": "^16.0.0",
60
62
  "eslint-plugin-putout": "^22.0.0",