beathers 5.1.0 → 5.2.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.
@@ -6,14 +6,59 @@ import { BuildScssVariables } from './BuildScssVariables.js';
6
6
  import { CallNewVariables } from './CallNewVariables.js';
7
7
  import { LoadUserConfigs } from './LoadUserConfigs.js';
8
8
  import { DeepMerge } from './Merge.js';
9
+ import { ReadDefaultValues } from './ReadDefaultValues.js';
9
10
  const __filename = fileURLToPath(import.meta.url);
10
11
  const __dirname = path.dirname(__filename);
11
12
  const projectRoot = path.resolve(__dirname, '../..');
12
13
  const variablesPath = path.join(projectRoot, 'src', 'scss', '_variables.scss');
14
+ async function defaultTheme() {
15
+ let values = null;
16
+ try {
17
+ values = await ReadDefaultValues([path.join(projectRoot, 'src', 'scss', 'settings', '_index.scss')], [
18
+ 'useMediaQueries',
19
+ 'useIcons',
20
+ 'useFontFamilies',
21
+ 'useFontSizes',
22
+ 'useFontShapes',
23
+ 'useTextAligns',
24
+ 'useTextTruncate',
25
+ 'useColors',
26
+ 'useColorsOpacities',
27
+ 'useColorsLightMode',
28
+ 'useColorsDarkMode',
29
+ 'useCurrentColors',
30
+ 'useRootColors',
31
+ 'useGrid',
32
+ 'useFlex',
33
+ 'useTransitions',
34
+ 'useWrappers',
35
+ 'useShadows',
36
+ 'useDisplays',
37
+ 'useOverflows',
38
+ 'useOpacities',
39
+ 'useBlur',
40
+ 'useObjectFits',
41
+ 'usePositions',
42
+ 'useInsets',
43
+ 'useSizes',
44
+ 'useGutters',
45
+ 'useBorders',
46
+ 'useTextBorders',
47
+ 'useRadius',
48
+ ]);
49
+ }
50
+ catch (error) {
51
+ // eslint-disable-next-line no-console
52
+ console.error('❌ buildCustomTheme failed:', error instanceof Error ? error.message : error);
53
+ process.exit(1);
54
+ }
55
+ return values;
56
+ }
13
57
  export async function BuildTheme() {
14
58
  try {
59
+ const defaults = await defaultTheme();
15
60
  const userConfigs = await LoadUserConfigs();
16
- const theme = DeepMerge({}, userConfigs);
61
+ const theme = DeepMerge(defaults, userConfigs);
17
62
  const variablesString = BuildScssVariables(theme);
18
63
  await fs.writeFile(variablesPath, variablesString, { flag: 'w' });
19
64
  await CallNewVariables(projectRoot);
@@ -13,7 +13,7 @@ async function loadJsOrTsConfig(filePath) {
13
13
  try {
14
14
  const absolutePath = path.resolve(filePath);
15
15
  const module = await import(absolutePath);
16
- return module.default || module;
16
+ return module.default ?? module;
17
17
  }
18
18
  catch (error) {
19
19
  throw new Error(`Failed to load config from ${filePath}: ${error}`);
@@ -29,7 +29,7 @@ function loadJsonConfig(filePath) {
29
29
  }
30
30
  }
31
31
  export async function LoadUserConfigs(projectPath) {
32
- const basePath = projectPath || process.cwd();
32
+ const basePath = projectPath ?? process.cwd();
33
33
  const configFilePath = findConfigFile(basePath);
34
34
  if (!configFilePath)
35
35
  return null;
@@ -62,7 +62,7 @@ function buildWrappers(value) {
62
62
  const raw = value
63
63
  .replace(/\(/g, '{')
64
64
  .replace(/\)/g, '}')
65
- .replace(/([a-zA-Z0-9_]+):\s*([0-9%px]+)\s+([0-9.]+rem)/g, '"$1": {"size": "$2", "padding": "$3"}')
65
+ .replace(/([a-zA-Z0-9_]+):\s*([0-9%px]+)\s+([0-9.]+rem)/g, '"$1": {"width": "$2", "padding": "$3"}')
66
66
  .replace(/,\s*}/g, '}');
67
67
  const parsed = JSON.parse(raw);
68
68
  return parsed;
@@ -2,6 +2,7 @@
2
2
  /* eslint-disable no-console */
3
3
  import fs from 'fs-extra';
4
4
  import path from 'path';
5
+ import { fileURLToPath } from 'node:url';
5
6
  import { BuildTheme } from './BuildTheme.js';
6
7
  import { ReadDefaultValues } from './ReadDefaultValues.js';
7
8
  const commands = {
@@ -45,7 +46,9 @@ function showVersion() {
45
46
  }
46
47
  }
47
48
  async function getDefaultValues() {
48
- const projectRoot = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..', '..');
49
+ const __filename = fileURLToPath(import.meta.url);
50
+ const __dirname = path.dirname(__filename);
51
+ const projectRoot = path.resolve(__dirname, '..', '..');
49
52
  return (await ReadDefaultValues([
50
53
  path.join(projectRoot, 'src', 'scss', 'settings', '_defaults.scss'),
51
54
  path.join(projectRoot, 'src', 'scss', 'settings', '_configs.scss'),
@@ -131,7 +134,7 @@ async function initCommand() {
131
134
  const fileName = formatMap[format];
132
135
  const filePath = path.join(process.cwd(), fileName);
133
136
  if (await fs.pathExists(filePath)) {
134
- const shouldOverride = await promptUser(`⚠️ ${fileName} already exists. Do you want to override it? (y/n): `);
137
+ const shouldOverride = await promptUser(`⚠️ ${fileName} already exists. Do you want to override it? (y/n): `);
135
138
  if (!shouldOverride) {
136
139
  console.log('❌ Operation aborted.');
137
140
  return;
@@ -1,55 +1,52 @@
1
- export type ColorType = Record<string, {
1
+ type SizeUnit = `${number}px` | `${number}rem` | `${number}em` | `${number}vw` | `${number}vh` | `${number}%`;
2
+ type ColorType = Record<string, {
2
3
  light: `#${string}`;
3
4
  dark: `#${string}`;
4
5
  }>;
5
- export type FontWeight = 'thin' | 'extra-light' | 'light' | 'regular' | 'medium' | 'semibold' | 'bold' | 'extra-bold' | 'black';
6
- export type FontStyle = 'normal' | 'italic' | 'oblique';
7
- export type FontSize = `${number}px` | `${number}rem` | `${number}em`;
8
- export interface FontVariant {
6
+ type FontWeight = 'thin' | 'extra-light' | 'light' | 'regular' | 'medium' | 'semibold' | 'bold' | 'extra-bold' | 'black';
7
+ type FontStyle = 'normal' | 'italic' | 'oblique';
8
+ interface FontVariant {
9
9
  title: string;
10
10
  unicode?: string;
11
11
  format?: 'woff' | 'woff2';
12
12
  isLocal?: boolean;
13
13
  url?: `https://${string}` | `http://${string}`;
14
14
  }
15
- export type FontType = {
15
+ type FontType = {
16
16
  weights?: FontWeight[];
17
17
  styles?: FontStyle[];
18
18
  variants?: Record<string, FontVariant>;
19
19
  };
20
- export interface Typography {
20
+ interface Typography {
21
21
  defaultFontFamilies?: string[];
22
22
  fontMainPath?: string;
23
23
  fontFormat?: 'woff' | 'woff2';
24
24
  fontWeights?: FontWeight[];
25
25
  fontStyles?: FontStyle[];
26
- fontSizes?: Record<string, FontSize>;
26
+ fontSizes?: Record<string, SizeUnit>;
27
27
  textTruncate?: number;
28
28
  fonts?: Record<string, FontType>;
29
29
  }
30
- export type Breakpoints = Record<'sm' | 'md' | 'lg' | 'xl' | 'xxl', `${number}px` | `${number}rem` | `${number}em`>;
31
- export type Wrappers = Record<'sm' | 'md' | 'lg' | 'xl' | 'xxl', {
32
- width: `${number}px` | `${number}rem` | `${number}em`;
33
- padding?: `${number}px` | `${number}rem` | `${number}em`;
34
- }>;
35
- export type GutterValues = Record<'auto' | number, `${number}px` | `${number}rem` | `${number}em`>;
36
- export interface Settings {
30
+ interface Settings {
37
31
  axisDivisions?: number;
38
32
  opacities?: number[];
39
33
  blurValues?: number[];
40
34
  insetValues?: number[];
41
35
  bordersValue?: number;
42
36
  radiuses?: number[];
43
- breakpoints?: Breakpoints;
44
- wrappers?: Wrappers;
45
- guttersValues?: GutterValues;
37
+ breakpoints?: Record<'null' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl', 0 | SizeUnit>;
38
+ wrappers?: Record<'null' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl', {
39
+ width: SizeUnit;
40
+ padding?: SizeUnit;
41
+ }>;
42
+ guttersValues?: Record<'auto' | number, 'auto' | SizeUnit>;
46
43
  }
47
44
  type RoleKeys = 'useMediaQueries' | 'useIcons' | 'useFontFamilies' | 'useFontSizes' | 'useFontShapes' | 'useTextAligns' | 'useTextTruncate' | 'useColors' | 'useColorsOpacities' | 'useColorsLightMode' | 'useColorsDarkMode' | 'useCurrentColors' | 'useRootColors' | 'useGrid' | 'useFlex' | 'useTransitions' | 'useWrappers' | 'useShadows' | 'useDisplays' | 'useOverflows' | 'useOpacities' | 'useBlur' | 'useObjectFits' | 'usePositions' | 'useInsets' | 'useSizes' | 'useGutters' | 'useBorders' | 'useTextBorders' | 'useRadius';
48
- export type Roles = Partial<Record<RoleKeys, boolean>>;
49
- export interface Theme {
45
+ type Roles = Partial<Record<RoleKeys, boolean>>;
46
+ interface Theme {
50
47
  colors?: ColorType;
51
48
  typography?: Typography;
52
49
  settings?: Settings;
53
50
  roles?: Roles;
54
51
  }
55
- export {};
52
+ export type { SizeUnit, ColorType, FontWeight, FontStyle, FontVariant, FontType, Typography, Settings, RoleKeys, Roles, Theme, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beathers",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "type": "module",
5
5
  "description": "Beather is a lightweight SCSS library that serves as a comprehensive design system for your projects. It offers a structured and consistent approach to manage colors, fonts, and other design related variables, making it easier to maintain a cohesive visual identity across your application.",
6
6
  "main": "dist/index.js",
@@ -8,16 +8,6 @@
8
8
  "bin": {
9
9
  "beathers": "dist/scripts/cli.js"
10
10
  },
11
- "scripts": {
12
- "watch": "nodemon --watch src/scss/ --ext scss --exec \"npm-run-all build:expanded\"",
13
- "build:compressed": "sass --style compressed --source-map --embed-sources --no-error-css src/scss/:dist/css/",
14
- "build:expanded": "sass --style expanded --source-map --embed-sources --no-error-css src/scss/:dist/css/",
15
- "build:user-configs": "tsx src/scripts/BuildTheme.ts",
16
- "prepublish": "rimraf dist && tsc && pnpm build:compressed",
17
- "lint": "eslint . && stylelint \"**/*.scss\"",
18
- "format:check": "prettier --check --ignore-path .gitignore .",
19
- "format:fix": "prettier --write --ignore-path .gitignore . && pnpm lint"
20
- },
21
11
  "keywords": [
22
12
  "design-system",
23
13
  "scss-library",
@@ -76,5 +66,15 @@
76
66
  "src/scss/**/*.scss",
77
67
  "public/images/logo.png",
78
68
  "readme.md"
79
- ]
80
- }
69
+ ],
70
+ "scripts": {
71
+ "watch": "nodemon --watch src/scss/ --ext scss --exec \"npm-run-all build:expanded\"",
72
+ "build:compressed": "sass --style compressed --source-map --embed-sources --no-error-css src/scss/:dist/css/",
73
+ "build:expanded": "sass --style expanded --source-map --embed-sources --no-error-css src/scss/:dist/css/",
74
+ "build:user-configs": "tsx src/scripts/BuildTheme.ts",
75
+ "prepublish": "rimraf dist && tsc && pnpm build:compressed",
76
+ "lint": "eslint . && stylelint \"**/*.scss\"",
77
+ "format:check": "prettier --check --ignore-path .gitignore .",
78
+ "format:fix": "prettier --write --ignore-path .gitignore . && pnpm lint"
79
+ }
80
+ }