bernova 0.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 (125) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1778 -0
  3. package/dist/bin/bernova.js +2 -0
  4. package/dist/bin/buildstyle.js +2 -0
  5. package/dist/bin/createConfigFile.js +2 -0
  6. package/dist/bin/declareCssType.js +1 -0
  7. package/dist/index.js +1 -0
  8. package/dist/src/app.js +1 -0
  9. package/dist/src/constants/compilerType.js +1 -0
  10. package/dist/src/constants/cssAdvancedSelectors.js +1 -0
  11. package/dist/src/constants/cssProps.js +1 -0
  12. package/dist/src/constants/cssPseudoClasses.js +1 -0
  13. package/dist/src/constants/cssPseudoElements.js +1 -0
  14. package/dist/src/constants/index.js +1 -0
  15. package/dist/src/constants/resetCss.js +1 -0
  16. package/dist/src/index.d.ts +31 -0
  17. package/dist/src/index.js +1 -0
  18. package/dist/src/lib/compileConfig.js +1 -0
  19. package/dist/src/lib/compileThemes.js +1 -0
  20. package/dist/src/lib/copyLocalFonts/copyLocalFonts.utils.js +1 -0
  21. package/dist/src/lib/copyLocalFonts/generateCssFonts.utils.js +1 -0
  22. package/dist/src/lib/extractDocFragment/extractDocFragment.utils.js +1 -0
  23. package/dist/src/lib/fileExists/fileExists.utils.js +1 -0
  24. package/dist/src/lib/generateBaseCss/generateBaseCss.utils.js +1 -0
  25. package/dist/src/lib/generateCss/generateCSS.utils.js +1 -0
  26. package/dist/src/lib/generateCss/helpers/advanceselector/advancedSelectorHandler.utils.js +1 -0
  27. package/dist/src/lib/generateCss/helpers/attribute/attributeHandler.utils.js +1 -0
  28. package/dist/src/lib/generateCss/helpers/classnames/formatClassName.utils.js +1 -0
  29. package/dist/src/lib/generateCss/helpers/classnames/handlerRegister.utils.js +1 -0
  30. package/dist/src/lib/generateCss/helpers/cssVars/generateVars.utils.js +1 -0
  31. package/dist/src/lib/generateCss/helpers/dynamicValues/dynamicValues.utils.js +1 -0
  32. package/dist/src/lib/generateCss/helpers/dynamicValues/processDynamic.utils.js +1 -0
  33. package/dist/src/lib/generateCss/helpers/filterGenerateCss.utils.js +1 -0
  34. package/dist/src/lib/generateCss/helpers/foreign/foreignHandler.utils.js +1 -0
  35. package/dist/src/lib/generateCss/helpers/generateCssStyles.utils.js +1 -0
  36. package/dist/src/lib/generateCss/helpers/index.js +1 -0
  37. package/dist/src/lib/generateCss/helpers/mediaqueries/generateMediaQueries.utils.js +1 -0
  38. package/dist/src/lib/generateCss/helpers/mediaqueries/mediaQueriesHandler.utils.js +1 -0
  39. package/dist/src/lib/generateCss/helpers/other/declareCssType.utils.js +1 -0
  40. package/dist/src/lib/generateCss/helpers/other/generateGlobalStyles.utils.js +1 -0
  41. package/dist/src/lib/generateCss/helpers/pseudo/pseudoHandler.utils.js +1 -0
  42. package/dist/src/lib/generateCss/helpers/rulename/formatRuleName.utils.js +1 -0
  43. package/dist/src/lib/generateCss/helpers/utils/extractValues.utils.js +1 -0
  44. package/dist/src/lib/generateCss/helpers/utils/formattedStatKey.utils.js +1 -0
  45. package/dist/src/lib/generateCss/helpers/utils/index.js +1 -0
  46. package/dist/src/lib/generateCss/helpers/utils/processCss.utils.js +1 -0
  47. package/dist/src/lib/generateCss/helpers/utils/separateStyles.utils.js +1 -0
  48. package/dist/src/lib/generateCss/helpers/utils/validatePreviouslyExists.utils.js +1 -0
  49. package/dist/src/lib/generateCssDoc/generateCssDoc.util.js +1 -0
  50. package/dist/src/lib/generateProvider/generateProvider.utils.js +1 -0
  51. package/dist/src/lib/generateProvider/template/providerTemplate.d.ts +60 -0
  52. package/dist/src/lib/generateProvider/template/providerTemplate.js +1 -0
  53. package/dist/src/lib/generateThemeRegister/generateThemeRegister.utils.js +1 -0
  54. package/dist/src/lib/generateTools/generateTools.utils.js +1 -0
  55. package/dist/src/lib/generateTypesTools/generateTypesTools.utils.js +1 -0
  56. package/dist/src/lib/handlerForeignThemes/handlerForeignThemes.utils.js +1 -0
  57. package/dist/src/lib/index.js +1 -0
  58. package/dist/src/lib/processMediaConfig/processMediaConfig.util.js +1 -0
  59. package/dist/src/lib/readFile/readFile.utils.js +1 -0
  60. package/dist/src/lib/simplifyName/simplifyName.utils.js +1 -0
  61. package/dist/src/lib/typingStyles/index.js +1 -0
  62. package/dist/src/lib/typingStyles/typingStyles.utils.js +1 -0
  63. package/dist/src/lib/writeDoc/writeDoc.utils.js +1 -0
  64. package/package.json +80 -0
  65. package/src/app.js +176 -0
  66. package/src/constants/__tests__/compilerType.test.js +20 -0
  67. package/src/constants/__tests__/cssAdvancedSelectors.test.js +38 -0
  68. package/src/constants/__tests__/cssProps.test.js +331 -0
  69. package/src/constants/__tests__/cssPseudoClasses.test.js +48 -0
  70. package/src/constants/compilerType.js +14 -0
  71. package/src/constants/cssAdvancedSelectors.js +32 -0
  72. package/src/constants/cssProps.js +325 -0
  73. package/src/constants/cssPseudoClasses.js +138 -0
  74. package/src/constants/cssPseudoElements.js +83 -0
  75. package/src/constants/index.js +15 -0
  76. package/src/constants/resetCss.js +171 -0
  77. package/src/index.d.ts +31 -0
  78. package/src/index.js +20 -0
  79. package/src/lib/compileConfig.js +59 -0
  80. package/src/lib/compileThemes.js +118 -0
  81. package/src/lib/copyLocalFonts/copyLocalFonts.utils.js +42 -0
  82. package/src/lib/copyLocalFonts/generateCssFonts.utils.js +56 -0
  83. package/src/lib/extractDocFragment/extractDocFragment.utils.js +25 -0
  84. package/src/lib/fileExists/fileExists.utils.js +31 -0
  85. package/src/lib/generateBaseCss/generateBaseCss.utils.js +51 -0
  86. package/src/lib/generateCss/generateCSS.utils.js +42 -0
  87. package/src/lib/generateCss/helpers/advanceselector/advancedSelectorHandler.utils.js +22 -0
  88. package/src/lib/generateCss/helpers/attribute/attributeHandler.utils.js +47 -0
  89. package/src/lib/generateCss/helpers/classnames/formatClassName.utils.js +28 -0
  90. package/src/lib/generateCss/helpers/classnames/handlerRegister.utils.js +124 -0
  91. package/src/lib/generateCss/helpers/cssVars/generateVars.utils.js +73 -0
  92. package/src/lib/generateCss/helpers/dynamicValues/dynamicValues.utils.js +72 -0
  93. package/src/lib/generateCss/helpers/dynamicValues/processDynamic.utils.js +10 -0
  94. package/src/lib/generateCss/helpers/filterGenerateCss.utils.js +73 -0
  95. package/src/lib/generateCss/helpers/foreign/foreignHandler.utils.js +85 -0
  96. package/src/lib/generateCss/helpers/generateCssStyles.utils.js +249 -0
  97. package/src/lib/generateCss/helpers/index.js +53 -0
  98. package/src/lib/generateCss/helpers/mediaqueries/generateMediaQueries.utils.js +9 -0
  99. package/src/lib/generateCss/helpers/mediaqueries/mediaQueriesHandler.utils.js +181 -0
  100. package/src/lib/generateCss/helpers/other/declareCssType.utils.js +120 -0
  101. package/src/lib/generateCss/helpers/other/generateGlobalStyles.utils.js +30 -0
  102. package/src/lib/generateCss/helpers/pseudo/pseudoHandler.utils.js +56 -0
  103. package/src/lib/generateCss/helpers/rulename/formatRuleName.utils.js +163 -0
  104. package/src/lib/generateCss/helpers/utils/extractValues.utils.js +44 -0
  105. package/src/lib/generateCss/helpers/utils/formattedStatKey.utils.js +43 -0
  106. package/src/lib/generateCss/helpers/utils/index.js +15 -0
  107. package/src/lib/generateCss/helpers/utils/processCss.utils.js +93 -0
  108. package/src/lib/generateCss/helpers/utils/separateStyles.utils.js +43 -0
  109. package/src/lib/generateCss/helpers/utils/validatePreviouslyExists.utils.js +61 -0
  110. package/src/lib/generateCssDoc/generateCssDoc.util.js +47 -0
  111. package/src/lib/generateProvider/generateProvider.utils.js +283 -0
  112. package/src/lib/generateProvider/template/providerTemplate.d.ts +60 -0
  113. package/src/lib/generateProvider/template/providerTemplate.js +160 -0
  114. package/src/lib/generateThemeRegister/generateThemeRegister.utils.js +136 -0
  115. package/src/lib/generateTools/generateTools.utils.js +181 -0
  116. package/src/lib/generateTypesTools/generateTypesTools.utils.js +59 -0
  117. package/src/lib/handlerForeignThemes/handlerForeignThemes.utils.js +96 -0
  118. package/src/lib/index.js +61 -0
  119. package/src/lib/processMediaConfig/processMediaConfig.util.js +32 -0
  120. package/src/lib/readFile/readFile.utils.js +110 -0
  121. package/src/lib/simplifyName/__tests__/simplifyName.utils.test.js +87 -0
  122. package/src/lib/simplifyName/simplifyName.utils.js +28 -0
  123. package/src/lib/typingStyles/index.js +3 -0
  124. package/src/lib/typingStyles/typingStyles.utils.js +144 -0
  125. package/src/lib/writeDoc/writeDoc.utils.js +30 -0
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Tools Generator for Bernova CSS Framework
3
+ *
4
+ * Generates JavaScript utility files for CSS class names, variables, and components.
5
+ * Creates developer tools for accessing generated CSS classes and custom properties.
6
+ */
7
+
8
+ const path = require('path');
9
+ const { compilerTypeValid } = require('../../constants');
10
+ const { writeDoc } = require('../writeDoc/writeDoc.utils');
11
+
12
+ /**
13
+ * Generates developer tools and utility files for the compiled CSS theme
14
+ * Creates JavaScript exports for class names, variables, and component mappings
15
+ *
16
+ * @param {Object} params - Generation parameters
17
+ * @param {string} params.dir - Output directory for tools
18
+ * @param {Object} params.bvTools - Tools configuration and paths
19
+ * @param {string} params.compilerType - Compilation type (full, foundation-only, component-only)
20
+ * @param {string} params.name - Theme name
21
+ * @param {Object} params.stylesDocs - Styles documentation data
22
+ * @param {Object} params.rootDocs - Root/variables documentation
23
+ * @param {Object} params.globalDocs - Global styles documentation
24
+ * @param {Object} params.mediaDocs - Media queries documentation
25
+ */
26
+ const generateTools = async ({
27
+ dir,
28
+ bvTools,
29
+ compilerType,
30
+ name,
31
+ stylesDocs,
32
+ rootDocs,
33
+ globalDocs,
34
+ mediaDocs,
35
+ }) => {
36
+ const {
37
+ path: bvToolsPath,
38
+ cssClassNames,
39
+ cssVariables,
40
+ availableComponents,
41
+ cssMediaQueries,
42
+ cssGlobalStyles,
43
+ declarationHelp,
44
+ } = bvTools;
45
+
46
+ const hasClassNames = compilerType !== compilerTypeValid.foundationOnly;
47
+ const hasFoundations = compilerType !== compilerTypeValid.componentOnly;
48
+
49
+ //* Generate tools for classNames
50
+ if (!!cssClassNames && hasClassNames) {
51
+ // Generate CSS class names utility file
52
+ const {
53
+ tools: { doc, declare },
54
+ } = stylesDocs;
55
+ const classNamePath = path.resolve(dir, bvToolsPath, 'cssClasses.js');
56
+ const docClassNames = `export const cssClasses = {\n${doc}}`;
57
+ await writeDoc(classNamePath, docClassNames, 'cssClasses.js');
58
+ if (declarationHelp) {
59
+ const classNameDeclarePath = path.resolve(
60
+ dir,
61
+ bvToolsPath,
62
+ 'cssClasses.d.ts'
63
+ );
64
+ const docClassNamesDeclare = `export declare const cssClasses: {\n${declare}}`;
65
+ await writeDoc(
66
+ classNameDeclarePath,
67
+ docClassNamesDeclare,
68
+ 'cssClasses.d.ts'
69
+ );
70
+ }
71
+ // CSS class names tools generated successfully
72
+ }
73
+ //* Generate tools for cssVariables
74
+ if (!!cssVariables && hasFoundations) {
75
+ // Generate CSS variables utility file
76
+ const { doc, declare } = rootDocs;
77
+ const cssVariablesPath = path.resolve(dir, bvToolsPath, 'cssVars.js');
78
+ const docCssVariables = `export const cssVars = {\n${doc}}`;
79
+ await writeDoc(cssVariablesPath, docCssVariables, 'cssVars.js');
80
+ if (declarationHelp) {
81
+ const cssVariablesDeclarePath = path.resolve(
82
+ dir,
83
+ bvToolsPath,
84
+ 'cssVars.d.ts'
85
+ );
86
+ const docCssVariablesDeclare = `export declare const cssVars: {\n${declare}}`;
87
+ await writeDoc(
88
+ cssVariablesDeclarePath,
89
+ docCssVariablesDeclare,
90
+ 'cssVars.d.ts'
91
+ );
92
+ }
93
+ // CSS variables tools generated successfully
94
+ }
95
+ //* Generate tools for cssMediaQueries
96
+ if (!!availableComponents && hasClassNames) {
97
+ // spinner.start(
98
+ // `Generating Available Components Tools for theme: ${name}...`
99
+ // );
100
+ const { comp } = stylesDocs;
101
+ const availableComponentsPath = path.resolve(
102
+ dir,
103
+ bvToolsPath,
104
+ 'cssAvailableComponents.js'
105
+ );
106
+ const docAvailableComponents = `export const cssAvailableComponents = {\n${comp.object}}`;
107
+ await writeDoc(
108
+ availableComponentsPath,
109
+ docAvailableComponents,
110
+ 'cssAvailableComponents.js'
111
+ );
112
+ if (declarationHelp) {
113
+ const availableComponentsDeclarePath = path.resolve(
114
+ dir,
115
+ bvToolsPath,
116
+ 'cssAvailableComponents.d.ts'
117
+ );
118
+ const declareAvailableComponents = `export declare const cssAvailableComponents: {\n${comp.object}}`;
119
+ await writeDoc(
120
+ availableComponentsDeclarePath,
121
+ declareAvailableComponents,
122
+ 'cssAvailableComponents.d.ts'
123
+ );
124
+ }
125
+ // spinner.succeed(
126
+ // `Available Components Tools generated for theme: ${name}.`
127
+ // );
128
+ }
129
+ //* Generate tools for cssMediaQueries
130
+ if (hasFoundations && !!cssMediaQueries) {
131
+ const mediaQueriesPath = path.resolve(
132
+ dir,
133
+ bvToolsPath,
134
+ 'cssMediaQueries.js'
135
+ );
136
+ const docMediaQueries = `export const cssMediaQueries = {\n${mediaDocs}}`;
137
+ await writeDoc(mediaQueriesPath, docMediaQueries, 'cssMediaQueries.js');
138
+ if (declarationHelp) {
139
+ const mediaQueriesDeclarePath = path.resolve(
140
+ dir,
141
+ bvToolsPath,
142
+ 'cssMediaQueries.d.ts'
143
+ );
144
+ const docMediaQueriesDeclare = `export declare const cssMediaQueries: {\n${mediaDocs}}`;
145
+ await writeDoc(
146
+ mediaQueriesDeclarePath,
147
+ docMediaQueriesDeclare,
148
+ 'cssMediaQueries.d.ts'
149
+ );
150
+ }
151
+ }
152
+
153
+ //* Generate tools for cssGlobalStyles
154
+ if (hasFoundations && !!cssGlobalStyles) {
155
+ const { doc, declare } = globalDocs;
156
+ const globalStylesPath = path.resolve(
157
+ dir,
158
+ bvToolsPath,
159
+ 'cssGlobalStyles.js'
160
+ );
161
+ const docGlobalStyles = `export const cssGlobalStyles = {\n${doc}}`;
162
+ await writeDoc(globalStylesPath, docGlobalStyles, 'cssGlobalStyles.js');
163
+ if (declarationHelp) {
164
+ const globalStylesDeclarePath = path.resolve(
165
+ dir,
166
+ bvToolsPath,
167
+ 'cssGlobalStyles.d.ts'
168
+ );
169
+ const docGlobalStylesDeclare = `export declare const cssGlobalStyles: {\n${declare}}`;
170
+ await writeDoc(
171
+ globalStylesDeclarePath,
172
+ docGlobalStylesDeclare,
173
+ 'cssGlobalStyles.d.ts'
174
+ );
175
+ }
176
+ }
177
+
178
+ return true;
179
+ };
180
+
181
+ module.exports = { generateTools };
@@ -0,0 +1,59 @@
1
+ /**
2
+ * TypeScript Types Generator for Bernova CSS Framework
3
+ *
4
+ * Generates TypeScript definition files for CSS classes, components, and media queries.
5
+ * Provides type safety and autocomplete support for generated CSS utilities.
6
+ */
7
+
8
+ const path = require('path');
9
+ const { typingStyles } = require('../typingStyles');
10
+ const { writeDoc } = require('../writeDoc/writeDoc.utils');
11
+
12
+ /**
13
+ * Generates TypeScript definition files for the compiled CSS theme
14
+ * Creates type-safe interfaces for CSS classes, components, and media queries
15
+ *
16
+ * @param {Object} params - Generation parameters
17
+ * @param {string} params.dir - Output directory for type files
18
+ * @param {Object} params.typesTools - TypeScript generation configuration
19
+ * @param {Object} params.mediaConfig - Media queries configuration for type generation
20
+ * @param {Object} params.stylesDocs - Component styles documentation for type extraction
21
+ */
22
+ const generateTypesTools = async ({
23
+ dir,
24
+ typesTools,
25
+ mediaConfig,
26
+ stylesDocs,
27
+ }) => {
28
+ const { stylesTypes, componentsTypes } = typesTools;
29
+
30
+ if (!!stylesTypes) {
31
+ const { name: styleName, path: stylesPath } = stylesTypes;
32
+ const stylesTypesPath = path.resolve(dir, stylesPath, `${styleName}.ts`);
33
+ const stylesTyping = typingStyles({ mediaConfig });
34
+ await writeDoc(stylesTypesPath, stylesTyping, `${styleName}.ts`);
35
+ }
36
+ if (!!componentsTypes && Object.keys(stylesDocs).length > 0) {
37
+ const { name: componentsName, path: componentPath } = componentsTypes;
38
+ const componentsTypesPath = path.resolve(
39
+ dir,
40
+ componentPath,
41
+ `${componentsName}.ts`
42
+ );
43
+ const { comp, prov } = stylesDocs;
44
+ const typeName =
45
+ componentsName.charAt(0).toUpperCase() + componentsName.slice(1);
46
+ const libAvailableComponents = `export type ${typeName}AvailableComponents = ${comp.simple}\n`;
47
+ const libComponents = `export type ${typeName}Components = {\n${prov.declare}}`;
48
+ const filteredKeys = `
49
+ type NonVariablesKeys<T> = {
50
+ [K in keyof T]: K extends \`$\${string}\` ? never : K;
51
+ }[keyof T];
52
+ export type ComponentSelected<T> = Pick<T, NonVariablesKeys<T>>;
53
+ `;
54
+ const docComponents = `${libAvailableComponents}${filteredKeys}\n${libComponents}`;
55
+ await writeDoc(componentsTypesPath, docComponents, `${componentsName}.ts`);
56
+ }
57
+ };
58
+
59
+ module.exports = { generateTypesTools };
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Foreign Themes Handler for Bernova CSS Framework
3
+ *
4
+ * Processes external CSS theme files and extracts variables and class names.
5
+ * Integrates foreign themes into the main compilation process by analyzing
6
+ * their CSS content and generating appropriate documentation.
7
+ */
8
+
9
+ const fs = require('fs').promises;
10
+ const path = require('path');
11
+ const { fileExists } = require('../fileExists/fileExists.utils');
12
+ const { simplifyName } = require('../simplifyName/simplifyName.utils');
13
+
14
+ /**
15
+ * Processes and integrates foreign CSS theme files into Bernova compilation
16
+ * Extracts CSS variables and class names from external stylesheets
17
+ *
18
+ * @param {string} dir - Base directory for resolving theme file paths
19
+ * @param {Array} foreignThemes - Array of foreign theme configurations
20
+ * @param {string} foreignThemes[].path - Relative path to the theme CSS file
21
+ * @param {string} foreignThemes[].position - Where to include ('before' or 'after')
22
+ * @param {string} foreignThemes[].name - Theme identifier name
23
+ * @returns {Object} Processed theme data with variables, classes, and file paths
24
+ */
25
+ const handlerForeignThemes = async ({ dir, foreignThemes }) => {
26
+ // Initialize data structures for organizing theme content
27
+ const themeByPosition = { after: '', before: '' }; // File paths by position
28
+ const classesExtracted = { doc: '', declare: '' }; // CSS class documentation
29
+ const variablesExtracted = { doc: '', declare: '' }; // CSS variables documentation
30
+ const variablesRegistered = new Set(); // Track processed variables
31
+
32
+ if (!!foreignThemes && foreignThemes.length > 0) {
33
+ // Process each foreign theme configuration
34
+ for (const { path: themePath, position, name } of foreignThemes) {
35
+ if (!fileExists(dir, themePath)) continue;
36
+
37
+ // Generate normalized theme name
38
+ const themeName = simplifyName(name).toLocaleUpperCase();
39
+
40
+ // Resolve absolute path to theme file
41
+ const themeRoute = path.resolve(dir, themePath);
42
+
43
+ // Read and parse theme CSS content
44
+ const data = await fs.readFile(themeRoute, 'utf-8');
45
+ //* save the route of the file read;
46
+ // themeByPosition[position] +=
47
+ // idx === 0 ? `'${themeRoute}'` : `, '${themeRoute}'`;
48
+ themeByPosition[position] +=
49
+ themeByPosition[position].length === 0
50
+ ? `'${themeRoute}'`
51
+ : `, '${themeRoute}'`;
52
+ //* get the css variables
53
+ const variableMatches = data.match(/--[a-zA-Z0-9-_]+:\s*[^;]+;/g);
54
+ if (variableMatches) {
55
+ [...new Set(variableMatches)].forEach((variable) => {
56
+ const [varName] = variable.split(':').map((s) => s.trim()); //? <-- recorver only the name
57
+ const keyVarName = simplifyName(varName);
58
+ //* avoid duplicate variables
59
+ if (variablesRegistered.has(keyVarName)) return;
60
+ variablesRegistered.add(keyVarName);
61
+ //* set register by theme name
62
+ variablesExtracted.doc += ` ${keyVarName}: 'var(${varName})',\n`;
63
+ variablesExtracted.declare += ` ${keyVarName}: string; \n`;
64
+ });
65
+ }
66
+ //* get the css classes
67
+ const classMatches = data.match(/\.[a-zA-Z0-9_-]+/g);
68
+ if (classMatches) {
69
+ const { doc, declare } = [...new Set(classMatches)].reduce(
70
+ (acc, cls) => {
71
+ const className = cls.slice(1); //? <-- Remove the dot
72
+ const keyClassName = simplifyName(className);
73
+ acc.doc += ` ${keyClassName}: '${className}',\n`;
74
+ acc.declare += ` ${keyClassName}: string; \n`;
75
+ return acc;
76
+ },
77
+ { doc: '', declare: '' }
78
+ );
79
+ //* set register by theme name
80
+ classesExtracted.doc += ` ${themeName}: {\n${doc} },\n`;
81
+ classesExtracted.declare += ` ${themeName}: {\n${declare} },\n`;
82
+ }
83
+ }
84
+ }
85
+
86
+ return {
87
+ themeByPosition: {
88
+ after: `[${themeByPosition.after}]`,
89
+ before: `[${themeByPosition.before}]`,
90
+ },
91
+ variablesExtracted,
92
+ classesExtracted,
93
+ };
94
+ };
95
+
96
+ module.exports = { handlerForeignThemes };
@@ -0,0 +1,61 @@
1
+ const { generateCSS } = require('./generateCss/generateCSS.utils.js');
2
+ const {
3
+ readConfigData,
4
+ readThemeData,
5
+ } = require('./readFile/readFile.utils.js');
6
+ const { writeDoc } = require('./writeDoc/writeDoc.utils.js');
7
+ const {
8
+ generateBaseCss,
9
+ } = require('./generateBaseCss/generateBaseCss.utils.js');
10
+ const { copyLocalFonts } = require('./copyLocalFonts/copyLocalFonts.utils.js');
11
+ const {
12
+ generateCssFonts,
13
+ } = require('./copyLocalFonts/generateCssFonts.utils.js');
14
+ const {
15
+ generateProvider,
16
+ } = require('./generateProvider/generateProvider.utils.js');
17
+ //* compilers
18
+ const { compileThemes } = require('./compileThemes.js');
19
+ const { compileConfig } = require('./compileConfig.js');
20
+ //* typing
21
+ const { typingStyles } = require('./typingStyles');
22
+ //* doc handlers
23
+ const {
24
+ extractDocFragment,
25
+ } = require('./extractDocFragment/extractDocFragment.utils.js');
26
+ const { fileExists } = require('./fileExists/fileExists.utils.js');
27
+ const {
28
+ handlerForeignThemes,
29
+ } = require('./handlerForeignThemes/handlerForeignThemes.utils.js');
30
+ //* helpers
31
+ const { simplifyName } = require('./simplifyName/simplifyName.utils.js');
32
+ const {
33
+ processMediaConfig,
34
+ } = require('./processMediaConfig/processMediaConfig.util.js');
35
+ //* register
36
+ const {
37
+ generateThemeRegister,
38
+ } = require('./generateThemeRegister/generateThemeRegister.utils.js');
39
+ //* generate css string doc
40
+ const { generateCssDoc } = require('./generateCssDoc/generateCssDoc.util.js');
41
+
42
+ module.exports = {
43
+ generateCSS,
44
+ readConfigData,
45
+ readThemeData,
46
+ writeDoc,
47
+ generateBaseCss,
48
+ copyLocalFonts,
49
+ generateCssFonts,
50
+ generateProvider,
51
+ compileThemes,
52
+ compileConfig,
53
+ typingStyles,
54
+ extractDocFragment,
55
+ handlerForeignThemes,
56
+ fileExists,
57
+ simplifyName,
58
+ processMediaConfig,
59
+ generateThemeRegister,
60
+ generateCssDoc,
61
+ };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Media Configuration Processor for Bernova CSS Framework
3
+ *
4
+ * Processes media query configurations and generates documentation strings
5
+ * for provider and tool generation systems.
6
+ */
7
+
8
+ const { simplifyName } = require('../simplifyName/simplifyName.utils.js');
9
+
10
+ /**
11
+ * Processes media configuration array and generates object property strings
12
+ * Creates key-value pairs for media query name mappings
13
+ *
14
+ * @param {Object} params - Processing parameters
15
+ * @param {Array} params.mediaConfig - Array of media query configurations
16
+ * @param {string} params.mediaConfig[].name - Media query breakpoint name
17
+ * @returns {string} Formatted object properties for media queries
18
+ * @example
19
+ * processMediaConfig({
20
+ * mediaConfig: [{ name: 'mobile' }, { name: 'tablet' }]
21
+ * })
22
+ * // Returns: ' mobile: \'mobile\',\n tablet: \'tablet\',\n'
23
+ */
24
+ const processMediaConfig = ({ mediaConfig }) => {
25
+ return mediaConfig.reduce((acc, { name }) => {
26
+ // Generate simplified property name and original value mapping
27
+ acc += ` ${simplifyName(name)}: '${name}',\n`;
28
+ return acc;
29
+ }, '');
30
+ };
31
+
32
+ module.exports = { processMediaConfig };
@@ -0,0 +1,110 @@
1
+ /**
2
+ * File Reading Utilities for Bernova
3
+ *
4
+ * Provides utilities for reading and parsing configuration files and theme data.
5
+ * Includes TypeScript support via ts-node for importing .ts configuration files.
6
+ */
7
+
8
+ const fs = require('fs').promises;
9
+ const path = require('path');
10
+ const { register } = require('ts-node');
11
+
12
+ // Configure ts-node for TypeScript file imports
13
+ register({
14
+ compilerOptions: {
15
+ module: 'commonjs',
16
+ target: 'es6',
17
+ moduleResolution: 'node',
18
+ esModuleInterop: true,
19
+ allowJs: true,
20
+ skipLibCheck: true, // Skip type checking for faster compilation
21
+ },
22
+ });
23
+
24
+ /**
25
+ * Reads and parses JSON configuration data from a file
26
+ * Supports both .json and .js configuration files
27
+ *
28
+ * @param {string} filePath - The absolute path to the configuration file
29
+ * @returns {Promise<Object>} The parsed configuration data
30
+ * @throws {Error} When file cannot be read or parsed
31
+ */
32
+ const readConfigData = async (filePath) => {
33
+ try {
34
+ const data = await fs.readFile(filePath, 'utf8');
35
+ const parsedData = JSON.parse(data);
36
+
37
+ // Validate basic structure
38
+ if (!parsedData || typeof parsedData !== 'object') {
39
+ throw new Error('Configuration file must contain a valid JSON object');
40
+ }
41
+
42
+ return parsedData;
43
+ } catch (error) {
44
+ if (error.code === 'ENOENT') {
45
+ throw new Error(`Configuration file not found: ${filePath}`);
46
+ } else if (error instanceof SyntaxError) {
47
+ throw new Error(`Invalid JSON in configuration file: ${error.message}`);
48
+ }
49
+
50
+ console.error(`Error reading config file at ${filePath}:`, error.message);
51
+ throw error;
52
+ }
53
+ };
54
+
55
+ /**
56
+ * Reads and loads theme data from TypeScript/JavaScript modules
57
+ * Dynamically requires modules and extracts named exports
58
+ *
59
+ * @param {Object} paths - Object containing path and export name configurations
60
+ * @param {string} paths[].path - Relative or absolute path to the module file
61
+ * @param {string} paths[].name - Named export to extract from the module
62
+ * @returns {Object} Object with loaded theme data keyed by the original path keys
63
+ * @throws {Error} When module cannot be loaded or export is not found
64
+ *
65
+ * @example
66
+ * const paths = {
67
+ * foundations: { path: './design/foundations.ts', name: 'FOUNDATIONS' },
68
+ * theme: { path: './design/theme.ts', name: 'THEME' }
69
+ * };
70
+ * const data = readThemeData(paths);
71
+ * // Returns: { foundations: {...}, theme: {...} }
72
+ */
73
+ const readThemeData = (paths) => {
74
+ const data = {};
75
+
76
+ Object.entries(paths).forEach(([key, config]) => {
77
+ try {
78
+ const { path: modulePath, name } = config;
79
+
80
+ if (!modulePath || !name) {
81
+ throw new Error(
82
+ `Invalid configuration for ${key}: missing path or name`
83
+ );
84
+ }
85
+
86
+ // Resolve the module path
87
+ const resolvedPath = path.resolve(modulePath);
88
+
89
+ // Clear require cache to ensure fresh imports
90
+ delete require.cache[resolvedPath];
91
+
92
+ // Load the module
93
+ const module = require(resolvedPath);
94
+
95
+ // Extract the named export
96
+ if (!(name in module)) {
97
+ throw new Error(`Export "${name}" not found in module ${modulePath}`);
98
+ }
99
+
100
+ data[key] = module[name];
101
+ } catch (error) {
102
+ console.error(`Failed to load theme data for ${key}:`, error.message);
103
+ throw new Error(`Cannot load theme data for "${key}": ${error.message}`);
104
+ }
105
+ });
106
+
107
+ return data;
108
+ };
109
+
110
+ module.exports = { readConfigData, readThemeData };
@@ -0,0 +1,87 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { simplifyName } from '../simplifyName.utils.js';
3
+
4
+ describe('simplifyName', () => {
5
+ it('should simplify basic hyphenated names', () => {
6
+ expect(simplifyName('my-button-large')).toBe('my_button_large');
7
+ });
8
+
9
+ it('should simplify dot-separated names', () => {
10
+ expect(simplifyName('header.nav.item')).toBe('header_nav_item');
11
+ });
12
+
13
+ it('should remove duplicate parts', () => {
14
+ expect(simplifyName('duplicate-duplicate-word')).toBe('duplicate_word');
15
+ });
16
+
17
+ it('should handle mixed separators', () => {
18
+ expect(simplifyName('mixed-name.with_different-separators')).toBe(
19
+ 'mixed_name_with_different_separators'
20
+ );
21
+ });
22
+
23
+ it('should handle names with numbers', () => {
24
+ expect(simplifyName('button-v2-large')).toBe('button_v2_large');
25
+ });
26
+
27
+ it('should handle camelCase names', () => {
28
+ expect(simplifyName('myButtonComponent')).toBe('myButtonComponent');
29
+ });
30
+
31
+ it('should handle names with special characters', () => {
32
+ expect(simplifyName('button--modifier__variant')).toBe(
33
+ 'button_modifier_variant'
34
+ );
35
+ });
36
+
37
+ it('should handle empty string', () => {
38
+ expect(simplifyName('')).toBe('');
39
+ });
40
+
41
+ it('should handle null input', () => {
42
+ expect(simplifyName(null)).toBe('');
43
+ });
44
+
45
+ it('should handle undefined input', () => {
46
+ expect(simplifyName(undefined)).toBe('');
47
+ });
48
+
49
+ it('should handle non-string input', () => {
50
+ expect(simplifyName(123)).toBe('');
51
+ expect(simplifyName({})).toBe('');
52
+ expect(simplifyName([])).toBe('');
53
+ });
54
+
55
+ it('should handle names with only special characters', () => {
56
+ expect(simplifyName('---___...')).toBe('');
57
+ });
58
+
59
+ it('should handle single word names', () => {
60
+ expect(simplifyName('button')).toBe('button');
61
+ });
62
+
63
+ it('should preserve alphanumeric order when no duplicates', () => {
64
+ expect(simplifyName('a1-b2-c3')).toBe('a1_b2_c3');
65
+ });
66
+
67
+ it('should handle names with spaces', () => {
68
+ expect(simplifyName('my button component')).toBe('my_button_component');
69
+ });
70
+
71
+ it('should handle BEM-style class names', () => {
72
+ expect(simplifyName('block__element--modifier')).toBe(
73
+ 'block_element_modifier'
74
+ );
75
+ });
76
+
77
+ it('should handle file-like names', () => {
78
+ expect(simplifyName('my-component.styles.css')).toBe(
79
+ 'my_component_styles_css'
80
+ );
81
+ });
82
+
83
+ it('should remove duplicates regardless of case', () => {
84
+ // Note: Since we're using Set, case sensitivity is preserved
85
+ expect(simplifyName('Button-button-BUTTON')).toBe('Button_button_BUTTON');
86
+ });
87
+ });
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Simplifies a name by extracting alphanumeric parts, removing duplicates, and joining with underscores
3
+ * Useful for creating clean CSS class names or identifiers from complex strings
4
+ *
5
+ * @param {string} name - The original name to simplify
6
+ * @returns {string} Simplified name with alphanumeric parts joined by underscores
7
+ *
8
+ * @example
9
+ * simplifyName('my-button--large') // returns 'my_button_large'
10
+ * simplifyName('header.nav.item') // returns 'header_nav_item'
11
+ * simplifyName('duplicate-duplicate-word') // returns 'duplicate_word'
12
+ */
13
+ const simplifyName = (name) => {
14
+ if (!name || typeof name !== 'string') {
15
+ return '';
16
+ }
17
+
18
+ // Extract alphanumeric sequences from the string
19
+ const alphanumericParts = name.match(/[a-zA-Z0-9]+/g) || [];
20
+
21
+ // Remove duplicate parts while preserving order
22
+ const uniqueParts = new Set(alphanumericParts);
23
+
24
+ // Join unique parts with underscores
25
+ return [...uniqueParts].join('_');
26
+ };
27
+
28
+ module.exports = { simplifyName };
@@ -0,0 +1,3 @@
1
+ const { typingStyles } = require('./typingStyles.utils');
2
+
3
+ module.exports = { typingStyles };