react-responsive-tools 1.0.1 → 1.0.2

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 (2) hide show
  1. package/loadBreakpoints.js +44 -0
  2. package/package.json +2 -1
@@ -0,0 +1,44 @@
1
+ // loadBreakpoints.js
2
+ import {
3
+ HORIZONTAL_BREAKPOINTS as defaultHorizontalBreakpoints,
4
+ VERTICAL_BREAKPOINTS as defaultVerticalBreakpoint
5
+ } from './src/breakpoints.configs';
6
+
7
+ import fs from 'fs';
8
+ import path from 'path';
9
+
10
+ // Путь к пользовательскому конфигурационному файлу
11
+ const userConfigPath = path.resolve(__dirname, './breakpoints.config.js');
12
+
13
+ // Функция объединения значений по умолчанию с пользовательскими значениями
14
+ const mergeConfigs = (defaultConfig, userConfig) => ({
15
+ ...defaultConfig,
16
+ ...userConfig,
17
+ });
18
+
19
+ let horizontalBreakpoints = defaultHorizontalBreakpoints;
20
+ let verticalBreakpoints = defaultVerticalBreakpoint;
21
+
22
+ // Проверяем, существует ли пользовательский конфигурационный файл
23
+ if (fs.existsSync(userConfigPath)) {
24
+ const userConfig = require(userConfigPath);
25
+ horizontalBreakpoints = mergeConfigs(defaultHorizontalBreakpoints, userConfig.HORIZONTAL_BREAKPOINTS || {});
26
+ verticalBreakpoints = mergeConfigs(defaultVerticalBreakpoints, userConfig.VERTICAL_BREAKPOINTS || {});
27
+ }
28
+
29
+ const generateSCSSContent = (breakpoints, name) => {
30
+ return `$${name}-breakpoints: (\n${Object.entries(breakpoints)
31
+ .map(([key, value]) => ` ${key}: ${value}`)
32
+ .join(',\n')}\n);`;
33
+ };
34
+
35
+ const scssContent = `
36
+ // Этот файл генерируется автоматически. Не редактируйте его напрямую.
37
+ ${generateSCSSContent(horizontalBreakpoints, 'horizontal')}
38
+ ${generateSCSSContent(verticalBreakpoints, 'vertical')}
39
+ `;
40
+
41
+ fs.writeFileSync(
42
+ path.resolve(__dirname, './scss/_custom-breakpoints.scss'),
43
+ scssContent
44
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-responsive-tools",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -18,6 +18,7 @@
18
18
  "files": [
19
19
  "src",
20
20
  "*.ts",
21
+ "loadBreakpoints.js",
21
22
  "*.scss",
22
23
  "index.js",
23
24
  "index.d.ts"