@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.
- package/.editorconfig +2 -3
- package/.editorconfig-get.js +3 -3
- package/.get-all.js +16 -12
- package/.gitattributes-get.js +3 -3
- package/.gitignore-get.js +33 -30
- package/.vscode/.code-snippets-get.js +34 -31
- package/.vscode/extensions.json +17 -17
- package/.vscode/extensions.json-get.js +25 -25
- package/.vscode/settings.json +36 -27
- package/.vscode/settings.json-get.js +25 -25
- package/env.json5.set.js +1 -1
- package/jsconfig.json +4 -7
- package/package.json +10 -1
- package/tools/eslint-config/configs/global.js +21 -18
- package/tools/eslint-config/configs/javascript.js +14 -14
- package/tools/eslint-config/configs/json.js +93 -0
- package/tools/eslint-config/configs/typescript.js +17 -17
- package/tools/eslint-config/configs/vue.js +22 -22
- package/tools/eslint-config/index.js +1 -0
- package/tools/eslint-config/rules/constants.js +10 -9
- package/tools/eslint-config/rules/javascript/index.js +2 -2
- package/tools/eslint-config/rules/javascript/possible-problems.js +76 -58
- package/tools/eslint-config/rules/javascript/suggestions.js +405 -249
- package/tools/eslint-config/rules/stylistic/jsFormatting.js +321 -167
- package/tools/eslint-config/rules/stylistic/tsFormatting.js +4 -4
- package/tools/eslint-config/rules/typescript/common.js +135 -126
- package/tools/eslint-config/rules/typescript/compatibility.js +20 -20
- package/tools/eslint-config/rules/typescript/extension.js +44 -44
- package/tools/eslint-config/rules/typescript/index.js +3 -3
- package/tools/eslint-config/rules/vue/base.js +2 -2
- package/tools/eslint-config/rules/vue/extension.js +47 -44
- package/tools/eslint-config/rules/vue/formatting.js +66 -36
- package/tools/eslint-config/rules/vue/index.js +5 -5
- package/tools/eslint-config/rules/vue/possibleProblems.js +182 -109
- package/tools/eslint-config/rules/vue/suggestions.js +82 -79
- package/tools/stylelint-config/config.js +18 -20
- package/tools/stylelint-config/rules/base.js +30 -24
- package/tools/stylelint-config/rules/conflicts.js +5 -5
- package/tools/stylelint-config/rules/order.js +38 -38
- package/tools/stylelint-config/rules/property-groups.js +392 -389
- package/tools/stylelint-config/rules/scss.js +9 -6
- package/tools/stylelint-config/rules/stylistic.js +110 -109
- package/utils/communication.js +26 -26
- package/utils/copy-with-override.js +35 -33
- package/utils/env.js +4 -4
- package/utils/file-header.js +9 -9
- package/utils/file.js +46 -46
- package/utils/merge.js +161 -155
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
};
|
package/utils/communication.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import readline from 'readline';
|
|
2
2
|
|
|
3
3
|
export async function askTypescript() {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
26
|
+
return { destFileData, match };
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export async function copyWithOverride({ destFile, srcFileData, fileLabel = '' }) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
try {
|
|
31
|
+
const { destFileData, match } = await copyFile({ destFile, srcFileData, fileLabel });
|
|
32
|
+
if (!destFileData) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
15
|
+
await outputFile(envFileSrc, JSON5.stringify(envObj, null, 2));
|
|
16
16
|
}
|
package/utils/file-header.js
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
11
|
+
return srcFileData;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export async function getSrcJSONFileData({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
fileName,
|
|
16
|
+
isTs = false,
|
|
17
|
+
removeDuplicateKeys = false,
|
|
18
18
|
}) {
|
|
19
|
-
|
|
19
|
+
const srcFileData = await getSrcFileData({ fileName });
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
// Если есть нет typescript, нет лишних проблем, возвращаем
|
|
22
|
+
if (!srcFileData.includes('// typescript')) {
|
|
23
|
+
return srcFileData;
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const lines = srcFileData.split('\n');
|
|
27
|
+
const result = [];
|
|
28
|
+
let nextLineIsTypescript = false;
|
|
29
|
+
let nextLineIsTypescriptMultiline = false;
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
const stringResult = result.join('\n');
|
|
59
|
+
if (removeDuplicateKeys) {
|
|
60
|
+
return JSON.stringify(JSON5.parse(stringResult), null, 2);
|
|
61
|
+
}
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
return stringResult;
|
|
64
64
|
}
|