@cherepanov.pavel/shareable-config 1.0.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.
Files changed (54) hide show
  1. package/.editorconfig +11 -0
  2. package/.editorconfig-get.js +19 -0
  3. package/.get-all.js +29 -0
  4. package/.gitattributes +1 -0
  5. package/.gitattributes-get.js +19 -0
  6. package/.gitignore +15 -0
  7. package/.gitignore-get.js +47 -0
  8. package/.vscode/.code-snippets-get.js +49 -0
  9. package/.vscode/all-files.code-snippets +18 -0
  10. package/.vscode/extensions.json +25 -0
  11. package/.vscode/extensions.json-get.js +43 -0
  12. package/.vscode/settings.json +42 -0
  13. package/.vscode/settings.json-get.js +43 -0
  14. package/.vscode/vue.code-snippets +28 -0
  15. package/README.md +10 -0
  16. package/env.json5.set.js +14 -0
  17. package/jsconfig.json +9 -0
  18. package/package.json +54 -0
  19. package/tools/eslint-config/configs/global.js +26 -0
  20. package/tools/eslint-config/configs/javascript.js +21 -0
  21. package/tools/eslint-config/configs/typescript.js +28 -0
  22. package/tools/eslint-config/configs/vue.js +43 -0
  23. package/tools/eslint-config/index.js +4 -0
  24. package/tools/eslint-config/rules/constants.js +15 -0
  25. package/tools/eslint-config/rules/javascript/index.js +7 -0
  26. package/tools/eslint-config/rules/javascript/possible-problems.js +62 -0
  27. package/tools/eslint-config/rules/javascript/suggestions.js +254 -0
  28. package/tools/eslint-config/rules/severity.js +3 -0
  29. package/tools/eslint-config/rules/stylistic/index.js +2 -0
  30. package/tools/eslint-config/rules/stylistic/jsFormatting.js +172 -0
  31. package/tools/eslint-config/rules/stylistic/tsFormatting.js +9 -0
  32. package/tools/eslint-config/rules/typescript/common.js +130 -0
  33. package/tools/eslint-config/rules/typescript/compatibility.js +24 -0
  34. package/tools/eslint-config/rules/typescript/extension.js +52 -0
  35. package/tools/eslint-config/rules/typescript/index.js +9 -0
  36. package/tools/eslint-config/rules/vue/base.js +6 -0
  37. package/tools/eslint-config/rules/vue/extension.js +58 -0
  38. package/tools/eslint-config/rules/vue/formatting.js +41 -0
  39. package/tools/eslint-config/rules/vue/index.js +13 -0
  40. package/tools/eslint-config/rules/vue/possibleProblems.js +113 -0
  41. package/tools/eslint-config/rules/vue/suggestions.js +83 -0
  42. package/tools/stylelint-config/config.js +29 -0
  43. package/tools/stylelint-config/rules/base.js +26 -0
  44. package/tools/stylelint-config/rules/conflicts.js +7 -0
  45. package/tools/stylelint-config/rules/order.js +42 -0
  46. package/tools/stylelint-config/rules/property-groups.js +404 -0
  47. package/tools/stylelint-config/rules/scss.js +8 -0
  48. package/tools/stylelint-config/rules/stylistic.js +124 -0
  49. package/utils/communication.js +33 -0
  50. package/utils/copy-with-override.js +43 -0
  51. package/utils/env.js +16 -0
  52. package/utils/file-header.js +16 -0
  53. package/utils/file.js +64 -0
  54. package/utils/merge.js +180 -0
@@ -0,0 +1,404 @@
1
+ /**
2
+ * @typedef {Object} Group
3
+ * @property {Array<string>} properties
4
+ */
5
+
6
+ /** @type {Group[]} */
7
+ export const propertyGroups = [
8
+ {
9
+ /**
10
+ * Compose rules from other selectors in CSS Modules.
11
+ * @see https://github.com/css-modules/css-modules#composition
12
+ */
13
+ properties: ['composes'],
14
+ },
15
+ {
16
+ // Must be first (unless using the above).
17
+ properties: [
18
+ 'all',
19
+ 'content',
20
+ ],
21
+ },
22
+ {
23
+ // Position.
24
+ properties: [
25
+ 'position',
26
+ 'inset',
27
+ 'inset-block',
28
+ 'inset-block-start',
29
+ 'inset-block-end',
30
+ 'inset-inline',
31
+ 'inset-inline-start',
32
+ 'inset-inline-end',
33
+ 'top',
34
+ 'right',
35
+ 'bottom',
36
+ 'left',
37
+ 'z-index',
38
+ ],
39
+ },
40
+ {
41
+ // Display mode.
42
+ properties: ['box-sizing', 'display'],
43
+ },
44
+ {
45
+ // Flexible boxes.
46
+ properties: [
47
+ 'flex',
48
+ 'flex-basis',
49
+ 'flex-direction',
50
+ 'flex-flow',
51
+ 'flex-grow',
52
+ 'flex-shrink',
53
+ 'flex-wrap',
54
+ 'grid',
55
+ 'grid-area',
56
+ 'grid-template',
57
+ 'grid-template-areas',
58
+ 'grid-template-rows',
59
+ 'grid-template-columns',
60
+ 'grid-row',
61
+ 'grid-row-start',
62
+ 'grid-row-end',
63
+ 'grid-column',
64
+ 'grid-column-start',
65
+ 'grid-column-end',
66
+ 'grid-auto-rows',
67
+ 'grid-auto-columns',
68
+ 'grid-auto-flow',
69
+ 'grid-gap',
70
+ 'grid-row-gap',
71
+ 'grid-column-gap',
72
+ 'gap',
73
+ 'row-gap',
74
+ 'column-gap',
75
+ 'place-content',
76
+ 'place-items',
77
+ 'place-self',
78
+ 'align-content',
79
+ 'align-items',
80
+ 'align-self',
81
+ 'justify-content',
82
+ 'justify-items',
83
+ 'justify-self',
84
+ 'order',
85
+ ],
86
+ },
87
+ {
88
+ // Box model.
89
+ properties: [
90
+ 'float',
91
+ 'inline-size',
92
+ 'min-inline-size',
93
+ 'max-inline-size',
94
+ 'width',
95
+ 'min-width',
96
+ 'max-width',
97
+ 'inline-size',
98
+ 'min-inline-size',
99
+ 'max-inline-size',
100
+ 'height',
101
+ 'min-height',
102
+ 'max-height',
103
+ 'aspect-ratio',
104
+ 'padding',
105
+ 'padding-block',
106
+ 'padding-block-start',
107
+ 'padding-block-end',
108
+ 'padding-inline',
109
+ 'padding-inline-start',
110
+ 'padding-inline-end',
111
+ 'padding-top',
112
+ 'padding-right',
113
+ 'padding-bottom',
114
+ 'padding-left',
115
+ 'margin',
116
+ 'margin-block',
117
+ 'margin-block-start',
118
+ 'margin-block-end',
119
+ 'margin-inline',
120
+ 'margin-inline-start',
121
+ 'margin-inline-end',
122
+ 'margin-top',
123
+ 'margin-right',
124
+ 'margin-bottom',
125
+ 'margin-left',
126
+ 'overflow',
127
+ 'overflow-block',
128
+ 'overflow-inline',
129
+ 'overflow-x',
130
+ 'overflow-y',
131
+ '-webkit-overflow-scrolling',
132
+ '-ms-overflow-x',
133
+ '-ms-overflow-y',
134
+ '-ms-overflow-style',
135
+ 'overscroll-behavior',
136
+ 'overscroll-behavior-inline',
137
+ 'overscroll-behavior-block',
138
+ 'overscroll-behavior-x',
139
+ 'overscroll-behavior-y',
140
+ 'clip',
141
+ 'clip-path',
142
+ 'clear',
143
+ ],
144
+ },
145
+ {
146
+ // Typography.
147
+ properties: [
148
+ 'font',
149
+ 'font-family',
150
+ 'font-size',
151
+ 'font-variation-settings',
152
+ 'font-style',
153
+ 'font-weight',
154
+ 'font-feature-settings',
155
+ 'font-optical-sizing',
156
+ 'font-kerning',
157
+ 'font-variant',
158
+ 'font-variant-ligatures',
159
+ 'font-variant-caps',
160
+ 'font-variant-alternates',
161
+ 'font-variant-numeric',
162
+ 'font-variant-east-asian',
163
+ 'font-variant-position',
164
+ 'font-size-adjust',
165
+ 'font-stretch',
166
+ 'font-effect',
167
+ 'font-emphasize',
168
+ 'font-emphasize-position',
169
+ 'font-emphasize-style',
170
+ '-webkit-font-smoothing',
171
+ '-moz-osx-font-smoothing',
172
+ 'font-smooth',
173
+ 'hyphens',
174
+ 'line-height',
175
+ 'color',
176
+ 'text-align',
177
+ 'text-align-last',
178
+ 'text-emphasis',
179
+ 'text-emphasis-color',
180
+ 'text-emphasis-style',
181
+ 'text-emphasis-position',
182
+ 'text-decoration',
183
+ 'text-decoration-line',
184
+ 'text-decoration-thickness',
185
+ 'text-decoration-style',
186
+ 'text-decoration-color',
187
+ 'text-underline-position',
188
+ 'text-underline-offset',
189
+ 'text-indent',
190
+ 'text-justify',
191
+ 'text-outline',
192
+ '-ms-text-overflow',
193
+ 'text-overflow',
194
+ 'text-overflow-ellipsis',
195
+ 'text-overflow-mode',
196
+ 'text-shadow',
197
+ 'text-transform',
198
+ 'text-wrap',
199
+ '-webkit-text-size-adjust',
200
+ '-ms-text-size-adjust',
201
+ 'letter-spacing',
202
+ 'word-break',
203
+ 'word-spacing',
204
+ 'word-wrap', // Legacy name for `overflow-wrap`
205
+ 'overflow-wrap',
206
+ 'tab-size',
207
+ 'white-space',
208
+ 'vertical-align',
209
+
210
+ 'list-style',
211
+ 'list-style-position',
212
+ 'list-style-type',
213
+ 'list-style-image',
214
+
215
+ 'src',
216
+ 'font-display',
217
+ 'unicode-range',
218
+ 'size-adjust',
219
+ 'ascent-override',
220
+ 'descent-override',
221
+ 'line-gap-override',
222
+ ],
223
+ },
224
+ {
225
+ // Accessibility & Interactions.
226
+ properties: [
227
+ 'appearance',
228
+ 'accent-color',
229
+ 'color-scheme',
230
+ 'pointer-events',
231
+ '-ms-touch-action',
232
+ 'touch-action',
233
+ 'cursor',
234
+ 'caret-color',
235
+ 'visibility',
236
+ 'zoom',
237
+ 'table-layout',
238
+ 'empty-cells',
239
+ 'caption-side',
240
+ 'border-spacing',
241
+ 'border-collapse',
242
+ 'quotes',
243
+ 'counter-reset',
244
+ 'counter-set',
245
+ 'counter-increment',
246
+ 'resize',
247
+ 'user-select',
248
+ 'nav-index',
249
+ 'nav-up',
250
+ 'nav-right',
251
+ 'nav-down',
252
+ 'nav-left',
253
+ ],
254
+ },
255
+ {
256
+ // Background & Borders.
257
+ properties: [
258
+ 'background',
259
+ 'background-color',
260
+ 'background-image',
261
+ "-ms-filter:\\'progid:DXImageTransform.Microsoft.gradient",
262
+ 'filter:progid:DXImageTransform.Microsoft.gradient',
263
+ 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader',
264
+ 'filter',
265
+ 'background-repeat',
266
+ 'background-attachment',
267
+ 'background-position',
268
+ 'background-position-x',
269
+ 'background-position-y',
270
+ 'background-clip',
271
+ 'background-origin',
272
+ 'background-size',
273
+ 'background-blend-mode',
274
+ 'isolation',
275
+ 'backdrop-filter',
276
+ 'border',
277
+ 'border-color',
278
+ 'border-style',
279
+ 'border-width',
280
+ 'border-block',
281
+ 'border-block-start',
282
+ 'border-block-start-color',
283
+ 'border-block-start-style',
284
+ 'border-block-start-width',
285
+ 'border-block-end',
286
+ 'border-block-end-color',
287
+ 'border-block-end-style',
288
+ 'border-block-end-width',
289
+ 'border-inline',
290
+ 'border-inline-start',
291
+ 'border-inline-start-color',
292
+ 'border-inline-start-style',
293
+ 'border-inline-start-width',
294
+ 'border-inline-end',
295
+ 'border-inline-end-color',
296
+ 'border-inline-end-style',
297
+ 'border-inline-end-width',
298
+ 'border-top',
299
+ 'border-top-color',
300
+ 'border-top-style',
301
+ 'border-top-width',
302
+ 'border-right',
303
+ 'border-right-color',
304
+ 'border-right-style',
305
+ 'border-right-width',
306
+ 'border-bottom',
307
+ 'border-bottom-color',
308
+ 'border-bottom-style',
309
+ 'border-bottom-width',
310
+ 'border-left',
311
+ 'border-left-color',
312
+ 'border-left-style',
313
+ 'border-left-width',
314
+ 'border-radius',
315
+ 'border-start-start-radius',
316
+ 'border-start-end-radius',
317
+ 'border-end-start-radius',
318
+ 'border-end-end-radius',
319
+ 'border-top-left-radius',
320
+ 'border-top-right-radius',
321
+ 'border-bottom-right-radius',
322
+ 'border-bottom-left-radius',
323
+ 'border-image',
324
+ 'border-image-source',
325
+ 'border-image-slice',
326
+ 'border-image-width',
327
+ 'border-image-outset',
328
+ 'border-image-repeat',
329
+ 'outline',
330
+ 'outline-width',
331
+ 'outline-style',
332
+ 'outline-color',
333
+ 'outline-offset',
334
+ 'box-shadow',
335
+ 'mix-blend-mode',
336
+ 'filter:progid:DXImageTransform.Microsoft.Alpha(Opacity',
337
+ "-ms-filter:\\'progid:DXImageTransform.Microsoft.Alpha",
338
+ 'opacity',
339
+ '-ms-interpolation-mode',
340
+ ],
341
+ },
342
+ {
343
+ // SVG Presentation Attributes.
344
+ properties: [
345
+ 'alignment-baseline',
346
+ 'baseline-shift',
347
+ 'dominant-baseline',
348
+ 'text-anchor',
349
+ 'word-spacing',
350
+ 'writing-mode',
351
+
352
+ 'fill',
353
+ 'fill-opacity',
354
+ 'fill-rule',
355
+ 'stroke',
356
+ 'stroke-dasharray',
357
+ 'stroke-dashoffset',
358
+ 'stroke-linecap',
359
+ 'stroke-linejoin',
360
+ 'stroke-miterlimit',
361
+ 'stroke-opacity',
362
+ 'stroke-width',
363
+
364
+ 'color-interpolation',
365
+ 'color-interpolation-filters',
366
+ 'color-profile',
367
+ 'color-rendering',
368
+ 'flood-color',
369
+ 'flood-opacity',
370
+ 'image-rendering',
371
+ 'lighting-color',
372
+ 'marker-start',
373
+ 'marker-mid',
374
+ 'marker-end',
375
+ 'mask',
376
+ 'shape-rendering',
377
+ 'stop-color',
378
+ 'stop-opacity',
379
+ ],
380
+ },
381
+ {
382
+ // Transitions & Animation.
383
+ properties: [
384
+ 'transition',
385
+ 'transition-delay',
386
+ 'transition-timing-function',
387
+ 'transition-duration',
388
+ 'transition-property',
389
+ 'transform',
390
+ 'transform-origin',
391
+ 'rotate',
392
+ 'scale',
393
+ 'translate',
394
+ 'animation',
395
+ 'animation-name',
396
+ 'animation-duration',
397
+ 'animation-play-state',
398
+ 'animation-timing-function',
399
+ 'animation-delay',
400
+ 'animation-iteration-count',
401
+ 'animation-direction',
402
+ ],
403
+ },
404
+ ];
@@ -0,0 +1,8 @@
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
+ },
8
+ };
@@ -0,0 +1,124 @@
1
+ const INDENT_SIZE = 2;
2
+ const MAX_EMPTY_LINES = 1;
3
+ // const MAX_LINE_LENGTH = 80;
4
+
5
+ const ALWAYS = 'always';
6
+ const ALWAYS_MULTI_LINE = 'always-multi-line';
7
+ const ALWAYS_SINGLE_LINE = 'always-single-line';
8
+
9
+ const NEVER = 'never';
10
+ const NEVER_MULTI_LINE = 'never-multi-line';
11
+ const NEVER_SINGLE_LINE = 'never-single-line';
12
+
13
+ const LOWER_CASE = 'lower';
14
+
15
+ 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
+ },
124
+ };
@@ -0,0 +1,33 @@
1
+ import readline from 'readline';
2
+
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
+ });
17
+ }
18
+
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
+ });
33
+ }
@@ -0,0 +1,43 @@
1
+ import { readFile } from 'fs/promises';
2
+ import { getHeader } from '../utils/file-header.js'
3
+ import { outputFile } from 'fs-extra';
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
+ }
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
+ }
25
+
26
+ return { destFileData, match }
27
+ }
28
+
29
+ export async function copyWithOverride({ destFile, srcFileData, fileLabel = '' }) {
30
+ try {
31
+ const { destFileData, match } = await copyFile({ destFile, srcFileData, fileLabel })
32
+ if(!destFileData) return
33
+
34
+ const overrideIndex = destFileData.indexOf(match[0]);
35
+ const preserved = destFileData.slice(overrideIndex);
36
+ const newContent = srcFileData.trimEnd() + '\n\n' + preserved.trimStart();
37
+
38
+ await outputFile(destFile, `${getHeader('#')}${newContent}`);
39
+ console.info(`${fileLabel} обновлён с учётом override`);
40
+ } catch (err) {
41
+ console.error(`Ошибка копирования ${fileLabel}:`, err.message);
42
+ }
43
+ }
package/utils/env.js ADDED
@@ -0,0 +1,16 @@
1
+ import { readFile } from 'fs/promises';
2
+ import path from 'path';
3
+ import JSON5 from 'json5';
4
+ import { outputFile } from 'fs-extra';
5
+
6
+ const envFileSrc = path.join(process.cwd(), 'frontend-configs.env.json5');
7
+
8
+ export async function getEnvs() {
9
+ const srcFileData = await readFile(envFileSrc, 'utf8');
10
+ const parsedSrcFileData = JSON5.parse(srcFileData);
11
+ return parsedSrcFileData;
12
+ }
13
+
14
+ export async function setEnvs(envObj) {
15
+ await outputFile(envFileSrc, JSON5.stringify(envObj, null, 2));
16
+ }
@@ -0,0 +1,16 @@
1
+ import { readFile } from 'fs/promises';
2
+
3
+ const pkg = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
4
+
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
+ ];
12
+
13
+ return `${lines.map((line) => {
14
+ return `${comment} ${line}`.trim();
15
+ }).join('\n')}\n`;
16
+ }