@cherepanov.pavel/shareable-config 1.0.3 → 1.0.4

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.
Files changed (48) hide show
  1. package/.editorconfig +2 -3
  2. package/.editorconfig-get.js +3 -3
  3. package/.get-all.js +16 -12
  4. package/.gitattributes-get.js +3 -3
  5. package/.gitignore-get.js +33 -30
  6. package/.vscode/.code-snippets-get.js +34 -31
  7. package/.vscode/extensions.json +17 -17
  8. package/.vscode/extensions.json-get.js +25 -25
  9. package/.vscode/settings.json +36 -27
  10. package/.vscode/settings.json-get.js +25 -25
  11. package/env.json5.set.js +1 -1
  12. package/jsconfig.json +4 -7
  13. package/package.json +10 -1
  14. package/tools/eslint-config/configs/global.js +21 -18
  15. package/tools/eslint-config/configs/javascript.js +14 -14
  16. package/tools/eslint-config/configs/json.js +93 -0
  17. package/tools/eslint-config/configs/typescript.js +17 -17
  18. package/tools/eslint-config/configs/vue.js +22 -22
  19. package/tools/eslint-config/index.js +1 -0
  20. package/tools/eslint-config/rules/constants.js +10 -9
  21. package/tools/eslint-config/rules/javascript/index.js +2 -2
  22. package/tools/eslint-config/rules/javascript/possible-problems.js +76 -58
  23. package/tools/eslint-config/rules/javascript/suggestions.js +405 -249
  24. package/tools/eslint-config/rules/stylistic/jsFormatting.js +321 -167
  25. package/tools/eslint-config/rules/stylistic/tsFormatting.js +4 -4
  26. package/tools/eslint-config/rules/typescript/common.js +135 -126
  27. package/tools/eslint-config/rules/typescript/compatibility.js +20 -20
  28. package/tools/eslint-config/rules/typescript/extension.js +44 -44
  29. package/tools/eslint-config/rules/typescript/index.js +3 -3
  30. package/tools/eslint-config/rules/vue/base.js +2 -2
  31. package/tools/eslint-config/rules/vue/extension.js +47 -44
  32. package/tools/eslint-config/rules/vue/formatting.js +66 -36
  33. package/tools/eslint-config/rules/vue/index.js +5 -5
  34. package/tools/eslint-config/rules/vue/possibleProblems.js +182 -109
  35. package/tools/eslint-config/rules/vue/suggestions.js +82 -79
  36. package/tools/stylelint-config/config.js +18 -20
  37. package/tools/stylelint-config/rules/base.js +30 -24
  38. package/tools/stylelint-config/rules/conflicts.js +5 -5
  39. package/tools/stylelint-config/rules/order.js +38 -38
  40. package/tools/stylelint-config/rules/property-groups.js +392 -389
  41. package/tools/stylelint-config/rules/scss.js +9 -6
  42. package/tools/stylelint-config/rules/stylistic.js +110 -109
  43. package/utils/communication.js +26 -26
  44. package/utils/copy-with-override.js +35 -33
  45. package/utils/env.js +4 -4
  46. package/utils/file-header.js +9 -9
  47. package/utils/file.js +46 -46
  48. package/utils/merge.js +161 -155
@@ -1,8 +1,11 @@
1
1
  export default {
2
- rules: {
3
- /* $-variables */
4
- 'scss/dollar-variable-empty-line-before': ['never', { ignore: 'after-dollar-variable' }],
5
- // https://gitlab.kadnk.ru/frontend/configs/-/issues/1
6
- 'scss/load-partial-extension': 'always',
7
- },
2
+ rules: {
3
+ /* $-variables */
4
+ 'scss/dollar-variable-empty-line-before': [
5
+ 'never',
6
+ { ignore: 'after-dollar-variable' },
7
+ ],
8
+ // https://gitlab.kadnk.ru/frontend/configs/-/issues/1
9
+ 'scss/load-partial-extension': 'always',
10
+ },
8
11
  };
@@ -1,4 +1,5 @@
1
- const INDENT_SIZE = 2;
1
+ import { INDENT_SIZE } from '@/tools/eslint-config/rules/constants';
2
+
2
3
  const MAX_EMPTY_LINES = 1;
3
4
  // const MAX_LINE_LENGTH = 80;
4
5
 
@@ -13,112 +14,112 @@ const NEVER_SINGLE_LINE = 'never-single-line';
13
14
  const LOWER_CASE = 'lower';
14
15
 
15
16
  export default {
16
- rules: {
17
- /* == common == */
18
- '@stylistic/indentation': INDENT_SIZE,
19
- '@stylistic/linebreaks': 'unix',
20
- '@stylistic/max-empty-lines': MAX_EMPTY_LINES,
21
- // '@stylistic/max-line-length': [MAX_LINE_LENGTH, { ignorePattern: '/^@(import|use)\\s+/' }],
22
- '@stylistic/no-empty-first-line': true,
23
- '@stylistic/no-eol-whitespace': true,
24
- '@stylistic/no-extra-semicolons': true,
25
- '@stylistic/no-missing-end-of-source-newline': true,
26
- '@stylistic/unicode-bom': NEVER,
27
-
28
- /* == color == */
29
- '@stylistic/color-hex-case': LOWER_CASE,
30
-
31
- /* == function == */
32
- '@stylistic/function-comma-newline-after': ALWAYS_MULTI_LINE,
33
- '@stylistic/function-comma-newline-before': NEVER_MULTI_LINE,
34
- '@stylistic/function-comma-space-after': ALWAYS_SINGLE_LINE,
35
- '@stylistic/function-comma-space-before': NEVER,
36
- '@stylistic/function-max-empty-lines': 0,
37
- '@stylistic/function-parentheses-space-inside': NEVER_SINGLE_LINE,
38
- '@stylistic/function-whitespace-after': ALWAYS,
39
-
40
- /* == number == */
41
- '@stylistic/number-leading-zero': ALWAYS,
42
- '@stylistic/number-no-trailing-zeros': true,
43
-
44
- /* == string == */
45
- '@stylistic/string-quotes': 'double',
46
-
47
- /* == unit == */
48
- '@stylistic/unit-case': LOWER_CASE,
49
-
50
- /* == value list == */
51
- '@stylistic/value-list-comma-newline-after': ALWAYS_MULTI_LINE,
52
- '@stylistic/value-list-comma-newline-before': NEVER_MULTI_LINE,
53
- '@stylistic/value-list-comma-space-after': ALWAYS_SINGLE_LINE,
54
- '@stylistic/value-list-comma-space-before': NEVER,
55
- '@stylistic/value-list-max-empty-lines': 0,
56
-
57
- /* == property == */
58
- '@stylistic/property-case': LOWER_CASE,
59
-
60
- /* == declaration == */
61
- '@stylistic/declaration-bang-space-after': NEVER,
62
- '@stylistic/declaration-bang-space-before': ALWAYS,
63
- '@stylistic/declaration-colon-newline-after': ALWAYS_MULTI_LINE,
64
- '@stylistic/declaration-colon-space-after': ALWAYS_SINGLE_LINE,
65
- '@stylistic/declaration-colon-space-before': NEVER,
66
-
67
- /* == declaration block == */
68
- '@stylistic/declaration-block-semicolon-newline-after': ALWAYS,
69
- '@stylistic/declaration-block-semicolon-newline-before': NEVER_MULTI_LINE,
70
- '@stylistic/declaration-block-semicolon-space-after': ALWAYS_SINGLE_LINE,
71
- '@stylistic/declaration-block-semicolon-space-before': NEVER,
72
- '@stylistic/declaration-block-trailing-semicolon': ALWAYS,
73
-
74
- /* == block == */
75
- '@stylistic/block-closing-brace-empty-line-before': NEVER,
76
- '@stylistic/block-closing-brace-newline-after': ALWAYS,
77
- '@stylistic/block-closing-brace-newline-before': ALWAYS,
78
- '@stylistic/block-closing-brace-space-after': ALWAYS_SINGLE_LINE,
79
- '@stylistic/block-closing-brace-space-before': ALWAYS_SINGLE_LINE,
80
- '@stylistic/block-opening-brace-newline-after': ALWAYS,
81
- '@stylistic/block-opening-brace-newline-before': null,
82
- '@stylistic/block-opening-brace-space-after': ALWAYS_SINGLE_LINE,
83
- '@stylistic/block-opening-brace-space-before': ALWAYS,
84
-
85
- /* == selector == */
86
- '@stylistic/selector-attribute-brackets-space-inside': NEVER,
87
- '@stylistic/selector-attribute-operator-space-after': NEVER,
88
- '@stylistic/selector-attribute-operator-space-before': NEVER,
89
- '@stylistic/selector-combinator-space-after': ALWAYS,
90
- '@stylistic/selector-combinator-space-before': ALWAYS,
91
- '@stylistic/selector-descendant-combinator-no-non-space': true,
92
- '@stylistic/selector-max-empty-lines': 0,
93
- '@stylistic/selector-pseudo-class-case': LOWER_CASE,
94
- '@stylistic/selector-pseudo-class-parentheses-space-inside': NEVER,
95
- '@stylistic/selector-pseudo-element-case': LOWER_CASE,
96
-
97
- /* == selector list == */
98
- '@stylistic/selector-list-comma-newline-after': ALWAYS,
99
- '@stylistic/selector-list-comma-newline-before': NEVER_MULTI_LINE,
100
- '@stylistic/selector-list-comma-space-after': ALWAYS_SINGLE_LINE,
101
- '@stylistic/selector-list-comma-space-before': NEVER,
102
-
103
- /* == media features == */
104
- '@stylistic/media-feature-colon-space-after': ALWAYS,
105
- '@stylistic/media-feature-colon-space-before': NEVER,
106
- '@stylistic/media-feature-name-case': LOWER_CASE,
107
- '@stylistic/media-feature-parentheses-space-inside': NEVER,
108
- '@stylistic/media-feature-range-operator-space-after': ALWAYS,
109
- '@stylistic/media-feature-range-operator-space-before': ALWAYS,
110
-
111
- /* == media query list == */
112
- '@stylistic/media-query-list-comma-newline-after': ALWAYS_MULTI_LINE,
113
- '@stylistic/media-query-list-comma-newline-before': NEVER_MULTI_LINE,
114
- '@stylistic/media-query-list-comma-space-after': ALWAYS_SINGLE_LINE,
115
- '@stylistic/media-query-list-comma-space-before': NEVER_SINGLE_LINE,
116
-
117
- /* == at rule == */
118
- '@stylistic/at-rule-name-case': LOWER_CASE,
119
- '@stylistic/at-rule-name-newline-after': ALWAYS_MULTI_LINE,
120
- '@stylistic/at-rule-name-space-after': ALWAYS,
121
- '@stylistic/at-rule-semicolon-newline-after': ALWAYS,
122
- '@stylistic/at-rule-semicolon-space-before': NEVER,
123
- },
17
+ rules: {
18
+ /* == common == */
19
+ '@stylistic/indentation': INDENT_SIZE,
20
+ '@stylistic/linebreaks': 'unix',
21
+ '@stylistic/max-empty-lines': MAX_EMPTY_LINES,
22
+ // '@stylistic/max-line-length': [MAX_LINE_LENGTH, { ignorePattern: '/^@(import|use)\\s+/' }],
23
+ '@stylistic/no-empty-first-line': true,
24
+ '@stylistic/no-eol-whitespace': true,
25
+ '@stylistic/no-extra-semicolons': true,
26
+ '@stylistic/no-missing-end-of-source-newline': true,
27
+ '@stylistic/unicode-bom': NEVER,
28
+
29
+ /* == color == */
30
+ '@stylistic/color-hex-case': LOWER_CASE,
31
+
32
+ /* == function == */
33
+ '@stylistic/function-comma-newline-after': ALWAYS_MULTI_LINE,
34
+ '@stylistic/function-comma-newline-before': NEVER_MULTI_LINE,
35
+ '@stylistic/function-comma-space-after': ALWAYS_SINGLE_LINE,
36
+ '@stylistic/function-comma-space-before': NEVER,
37
+ '@stylistic/function-max-empty-lines': 0,
38
+ '@stylistic/function-parentheses-space-inside': NEVER_SINGLE_LINE,
39
+ '@stylistic/function-whitespace-after': ALWAYS,
40
+
41
+ /* == number == */
42
+ '@stylistic/number-leading-zero': ALWAYS,
43
+ '@stylistic/number-no-trailing-zeros': true,
44
+
45
+ /* == string == */
46
+ '@stylistic/string-quotes': 'double',
47
+
48
+ /* == unit == */
49
+ '@stylistic/unit-case': LOWER_CASE,
50
+
51
+ /* == value list == */
52
+ '@stylistic/value-list-comma-newline-after': ALWAYS_MULTI_LINE,
53
+ '@stylistic/value-list-comma-newline-before': NEVER_MULTI_LINE,
54
+ '@stylistic/value-list-comma-space-after': ALWAYS_SINGLE_LINE,
55
+ '@stylistic/value-list-comma-space-before': NEVER,
56
+ '@stylistic/value-list-max-empty-lines': 0,
57
+
58
+ /* == property == */
59
+ '@stylistic/property-case': LOWER_CASE,
60
+
61
+ /* == declaration == */
62
+ '@stylistic/declaration-bang-space-after': NEVER,
63
+ '@stylistic/declaration-bang-space-before': ALWAYS,
64
+ '@stylistic/declaration-colon-newline-after': ALWAYS_MULTI_LINE,
65
+ '@stylistic/declaration-colon-space-after': ALWAYS_SINGLE_LINE,
66
+ '@stylistic/declaration-colon-space-before': NEVER,
67
+
68
+ /* == declaration block == */
69
+ '@stylistic/declaration-block-semicolon-newline-after': ALWAYS,
70
+ '@stylistic/declaration-block-semicolon-newline-before': NEVER_MULTI_LINE,
71
+ '@stylistic/declaration-block-semicolon-space-after': ALWAYS_SINGLE_LINE,
72
+ '@stylistic/declaration-block-semicolon-space-before': NEVER,
73
+ '@stylistic/declaration-block-trailing-semicolon': ALWAYS,
74
+
75
+ /* == block == */
76
+ '@stylistic/block-closing-brace-empty-line-before': NEVER,
77
+ '@stylistic/block-closing-brace-newline-after': ALWAYS,
78
+ '@stylistic/block-closing-brace-newline-before': ALWAYS,
79
+ '@stylistic/block-closing-brace-space-after': ALWAYS_SINGLE_LINE,
80
+ '@stylistic/block-closing-brace-space-before': ALWAYS_SINGLE_LINE,
81
+ '@stylistic/block-opening-brace-newline-after': ALWAYS,
82
+ '@stylistic/block-opening-brace-newline-before': null,
83
+ '@stylistic/block-opening-brace-space-after': ALWAYS_SINGLE_LINE,
84
+ '@stylistic/block-opening-brace-space-before': ALWAYS,
85
+
86
+ /* == selector == */
87
+ '@stylistic/selector-attribute-brackets-space-inside': NEVER,
88
+ '@stylistic/selector-attribute-operator-space-after': NEVER,
89
+ '@stylistic/selector-attribute-operator-space-before': NEVER,
90
+ '@stylistic/selector-combinator-space-after': ALWAYS,
91
+ '@stylistic/selector-combinator-space-before': ALWAYS,
92
+ '@stylistic/selector-descendant-combinator-no-non-space': true,
93
+ '@stylistic/selector-max-empty-lines': 0,
94
+ '@stylistic/selector-pseudo-class-case': LOWER_CASE,
95
+ '@stylistic/selector-pseudo-class-parentheses-space-inside': NEVER,
96
+ '@stylistic/selector-pseudo-element-case': LOWER_CASE,
97
+
98
+ /* == selector list == */
99
+ '@stylistic/selector-list-comma-newline-after': ALWAYS,
100
+ '@stylistic/selector-list-comma-newline-before': NEVER_MULTI_LINE,
101
+ '@stylistic/selector-list-comma-space-after': ALWAYS_SINGLE_LINE,
102
+ '@stylistic/selector-list-comma-space-before': NEVER,
103
+
104
+ /* == media features == */
105
+ '@stylistic/media-feature-colon-space-after': ALWAYS,
106
+ '@stylistic/media-feature-colon-space-before': NEVER,
107
+ '@stylistic/media-feature-name-case': LOWER_CASE,
108
+ '@stylistic/media-feature-parentheses-space-inside': NEVER,
109
+ '@stylistic/media-feature-range-operator-space-after': ALWAYS,
110
+ '@stylistic/media-feature-range-operator-space-before': ALWAYS,
111
+
112
+ /* == media query list == */
113
+ '@stylistic/media-query-list-comma-newline-after': ALWAYS_MULTI_LINE,
114
+ '@stylistic/media-query-list-comma-newline-before': NEVER_MULTI_LINE,
115
+ '@stylistic/media-query-list-comma-space-after': ALWAYS_SINGLE_LINE,
116
+ '@stylistic/media-query-list-comma-space-before': NEVER_SINGLE_LINE,
117
+
118
+ /* == at rule == */
119
+ '@stylistic/at-rule-name-case': LOWER_CASE,
120
+ '@stylistic/at-rule-name-newline-after': ALWAYS_MULTI_LINE,
121
+ '@stylistic/at-rule-name-space-after': ALWAYS,
122
+ '@stylistic/at-rule-semicolon-newline-after': ALWAYS,
123
+ '@stylistic/at-rule-semicolon-space-before': NEVER,
124
+ },
124
125
  };
@@ -1,33 +1,33 @@
1
1
  import readline from 'readline';
2
2
 
3
3
  export async function askTypescript() {
4
- return new Promise((resolve) => {
5
- const rl = readline.createInterface({
6
- input: process.stdin,
7
- output: process.stdout,
8
- });
9
- rl.question(
10
- 'Вы используете typescript? (Enter - нет, любые символы + Enter - да):',
11
- (answer) => {
12
- rl.close();
13
- resolve(Boolean(answer.trim().toLowerCase()));
14
- },
15
- );
16
- });
4
+ return new Promise((resolve) => {
5
+ const rl = readline.createInterface({
6
+ input: process.stdin,
7
+ output: process.stdout,
8
+ });
9
+ rl.question(
10
+ 'Вы используете typescript? (Enter - нет, любые символы + Enter - да):',
11
+ (answer) => {
12
+ rl.close();
13
+ resolve(Boolean(answer.trim().toLowerCase()));
14
+ },
15
+ );
16
+ });
17
17
  }
18
18
 
19
19
  export async function askFramework() {
20
- return new Promise((resolve) => {
21
- const rl = readline.createInterface({
22
- input: process.stdin,
23
- output: process.stdout,
24
- });
25
- rl.question(
26
- 'Какой фреймворк вы используете? (vue/nuxt/quasar, нажмите Enter, чтобы скопировать только framework-less): ',
27
- (answer) => {
28
- rl.close();
29
- resolve(answer.trim().toLowerCase());
30
- },
31
- );
32
- });
20
+ return new Promise((resolve) => {
21
+ const rl = readline.createInterface({
22
+ input: process.stdin,
23
+ output: process.stdout,
24
+ });
25
+ rl.question(
26
+ 'Какой фреймворк вы используете? (vue/nuxt/quasar, нажмите Enter, чтобы скопировать только framework-less): ',
27
+ (answer) => {
28
+ rl.close();
29
+ resolve(answer.trim().toLowerCase());
30
+ },
31
+ );
32
+ });
33
33
  }
@@ -1,43 +1,45 @@
1
1
  import { readFile } from 'fs/promises';
2
- import { getHeader } from '../utils/file-header.js'
2
+ import { getHeader } from '../utils/file-header.js';
3
3
  import { outputFile } from 'fs-extra';
4
4
 
5
- export async function copyFile({ destFile, srcFileData, fileLabel }){
6
- // Если файла нет — просто создаём его
7
- try {
8
- await readFile(destFile, 'utf8');
9
- } catch {
10
- await outputFile(destFile, `${getHeader('#')}${srcFileData}`);
11
- console.info(`${fileLabel} пересоздан`);
12
- return {};
13
- }
5
+ export async function copyFile({ destFile, srcFileData, fileLabel }) {
6
+ // Если файла нет — просто создаём его
7
+ try {
8
+ await readFile(destFile, 'utf8');
9
+ } catch {
10
+ await outputFile(destFile, `${getHeader('#')}${srcFileData}`);
11
+ console.info(`${fileLabel} пересоздан`);
12
+ return {};
13
+ }
14
14
 
15
- // Если файл есть — разбираем оба файла
16
- const destFileData = await readFile(destFile, 'utf8')
17
- // Ищем строку override (без учёта регистра)
18
- const overrideRegex = /^# override.*$/im;
19
- const match = destFileData.match(overrideRegex);
20
- if (!match) {
21
- await outputFile(destFile, `${getHeader('#')}${srcFileData}`);
22
- console.info(`${fileLabel} пересоздан`);
23
- return {};
24
- }
15
+ // Если файл есть — разбираем оба файла
16
+ const destFileData = await readFile(destFile, 'utf8');
17
+ // Ищем строку override (без учёта регистра)
18
+ const overrideRegex = /^# override.*$/imu;
19
+ const match = destFileData.match(overrideRegex);
20
+ if (!match) {
21
+ await outputFile(destFile, `${getHeader('#')}${srcFileData}`);
22
+ console.info(`${fileLabel} пересоздан`);
23
+ return {};
24
+ }
25
25
 
26
- return { destFileData, match }
26
+ return { destFileData, match };
27
27
  }
28
28
 
29
29
  export async function copyWithOverride({ destFile, srcFileData, fileLabel = '' }) {
30
- try {
31
- const { destFileData, match } = await copyFile({ destFile, srcFileData, fileLabel })
32
- if(!destFileData) return
30
+ try {
31
+ const { destFileData, match } = await copyFile({ destFile, srcFileData, fileLabel });
32
+ if (!destFileData) {
33
+ return;
34
+ }
33
35
 
34
- const overrideIndex = destFileData.indexOf(match[0]);
35
- const preserved = destFileData.slice(overrideIndex);
36
- const newContent = srcFileData.trimEnd() + '\n\n' + preserved.trimStart();
36
+ const overrideIndex = destFileData.indexOf(match[0]);
37
+ const preserved = destFileData.slice(overrideIndex);
38
+ const newContent = `${srcFileData.trimEnd()}\n\n${preserved.trimStart()}`;
37
39
 
38
- await outputFile(destFile, `${getHeader('#')}${newContent}`);
39
- console.info(`${fileLabel} обновлён с учётом override`);
40
- } catch (err) {
41
- console.error(`Ошибка копирования ${fileLabel}:`, err.message);
42
- }
43
- }
40
+ await outputFile(destFile, `${getHeader('#')}${newContent}`);
41
+ console.info(`${fileLabel} обновлён с учётом override`);
42
+ } catch (err) {
43
+ console.error(`Ошибка копирования ${fileLabel}:`, err.message);
44
+ }
45
+ }
package/utils/env.js CHANGED
@@ -6,11 +6,11 @@ import { outputFile } from 'fs-extra';
6
6
  const envFileSrc = path.join(process.cwd(), 'frontend-configs.env.json5');
7
7
 
8
8
  export async function getEnvs() {
9
- const srcFileData = await readFile(envFileSrc, 'utf8');
10
- const parsedSrcFileData = JSON5.parse(srcFileData);
11
- return parsedSrcFileData;
9
+ const srcFileData = await readFile(envFileSrc, 'utf8');
10
+ const parsedSrcFileData = JSON5.parse(srcFileData);
11
+ return parsedSrcFileData;
12
12
  }
13
13
 
14
14
  export async function setEnvs(envObj) {
15
- await outputFile(envFileSrc, JSON5.stringify(envObj, null, 2));
15
+ await outputFile(envFileSrc, JSON5.stringify(envObj, null, 2));
16
16
  }
@@ -3,14 +3,14 @@ import { readFile } from 'fs/promises';
3
3
  const pkg = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
4
4
 
5
5
  export function getHeader(comment = '//') {
6
- const lines = [
7
- 'This file is generated with',
8
- `${pkg.repository?.url || ''}`,
9
- `Version: ${pkg.version || ''}`,
10
- 'File may contain override sections, see project README for more details',
11
- ];
6
+ const lines = [
7
+ 'This file is generated with',
8
+ `${pkg.repository?.url || ''}`,
9
+ `Version: ${pkg.version || ''}`,
10
+ 'File may contain override sections, see project README for more details',
11
+ ];
12
12
 
13
- return `${lines.map((line) => {
14
- return `${comment} ${line}`.trim();
15
- }).join('\n')}\n`;
13
+ return `${lines.map((line) => {
14
+ return `${comment} ${line}`.trim();
15
+ }).join('\n')}\n`;
16
16
  }
package/utils/file.js CHANGED
@@ -4,61 +4,61 @@ import { readFile } from 'fs/promises';
4
4
  import JSON5 from 'json5';
5
5
 
6
6
  export async function getSrcFileData({ fileName }) {
7
- const dirname = path.dirname(fileURLToPath(import.meta.url));
8
- const src = path.join(dirname, '..', '.vscode', fileName);
9
- const srcFileData = await readFile(src, 'utf8');
7
+ const dirname = path.dirname(fileURLToPath(import.meta.url));
8
+ const src = path.join(dirname, '..', '.vscode', fileName);
9
+ const srcFileData = await readFile(src, 'utf8');
10
10
 
11
- return srcFileData;
11
+ return srcFileData;
12
12
  }
13
13
 
14
14
  export async function getSrcJSONFileData({
15
- fileName,
16
- isTs = false,
17
- removeDuplicateKeys = false,
15
+ fileName,
16
+ isTs = false,
17
+ removeDuplicateKeys = false,
18
18
  }) {
19
- const srcFileData = await getSrcFileData({ fileName });
19
+ const srcFileData = await getSrcFileData({ fileName });
20
20
 
21
- // Если есть нет typescript, нет лишних проблем, возвращаем
22
- if (!srcFileData.includes('// typescript')) {
23
- return srcFileData;
24
- }
21
+ // Если есть нет typescript, нет лишних проблем, возвращаем
22
+ if (!srcFileData.includes('// typescript')) {
23
+ return srcFileData;
24
+ }
25
25
 
26
- const lines = srcFileData.split('\n');
27
- const result = [];
28
- let nextLineIsTypescript = false;
29
- let nextLineIsTypescriptMultiline = false;
26
+ const lines = srcFileData.split('\n');
27
+ const result = [];
28
+ let nextLineIsTypescript = false;
29
+ let nextLineIsTypescriptMultiline = false;
30
30
 
31
- lines.forEach((line) => {
32
- // если следующая строка typescript only
33
- if (line.includes('// typescript')) {
34
- // если несколько следующих строк typescript only
35
- if (line.includes('// typescript multiline')) {
36
- // проверяем это конец multiline typescript комментария, или начало, и в соответствии
37
- // с этим ставим флаг
38
- nextLineIsTypescriptMultiline = !(line.includes('// typescript multiline end'));
39
- } else {
40
- nextLineIsTypescript = true; // Следующая строка будет typescript-only
41
- }
42
- // флаги проставлены, с этой строкой больше нечего делать, выходим
43
- return;
44
- }
31
+ lines.forEach((line) => {
32
+ // если следующая строка typescript only
33
+ if (line.includes('// typescript')) {
34
+ // если несколько следующих строк typescript only
35
+ if (line.includes('// typescript multiline')) {
36
+ // проверяем это конец multiline typescript комментария, или начало, и в соответствии
37
+ // с этим ставим флаг
38
+ nextLineIsTypescriptMultiline = !(line.includes('// typescript multiline end'));
39
+ } else {
40
+ nextLineIsTypescript = true; // Следующая строка будет typescript-only
41
+ }
42
+ // флаги проставлены, с этой строкой больше нечего делать, выходим
43
+ return;
44
+ }
45
45
 
46
- if (nextLineIsTypescript || nextLineIsTypescriptMultiline) {
47
- // Включаем строку только если нужен typescript
48
- if (isTs) {
49
- result.push(line);
50
- }
51
- nextLineIsTypescript = false; // Сбрасываем флаг
52
- } else {
53
- // Обычная строка - всегда включаем
54
- result.push(line);
55
- }
56
- });
46
+ if (nextLineIsTypescript || nextLineIsTypescriptMultiline) {
47
+ // Включаем строку только если нужен typescript
48
+ if (isTs) {
49
+ result.push(line);
50
+ }
51
+ nextLineIsTypescript = false; // Сбрасываем флаг
52
+ } else {
53
+ // Обычная строка - всегда включаем
54
+ result.push(line);
55
+ }
56
+ });
57
57
 
58
- const stringResult = result.join('\n');
59
- if (removeDuplicateKeys) {
60
- return JSON.stringify(JSON5.parse(stringResult), null, 2);
61
- }
58
+ const stringResult = result.join('\n');
59
+ if (removeDuplicateKeys) {
60
+ return JSON.stringify(JSON5.parse(stringResult), null, 2);
61
+ }
62
62
 
63
- return stringResult;
63
+ return stringResult;
64
64
  }