anubis-ui 1.3.1 → 1.4.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 (60) hide show
  1. package/README.md +96 -27
  2. package/dist/interfaces/color.interface.d.ts +8 -0
  3. package/dist/interfaces/color.interface.js +2 -0
  4. package/{src/interfaces/config.interface.ts → dist/interfaces/config.interface.d.ts} +0 -3
  5. package/dist/interfaces/config.interface.js +2 -0
  6. package/dist/interfaces/files.interface.d.ts +4 -0
  7. package/dist/interfaces/files.interface.js +2 -0
  8. package/{src/interfaces/preset.interface.ts → dist/interfaces/preset.interface.d.ts} +3 -7
  9. package/dist/interfaces/preset.interface.js +2 -0
  10. package/dist/tools/config.tool.d.ts +4 -0
  11. package/dist/tools/config.tool.js +64 -0
  12. package/dist/tools/extraction/extractClasses.d.ts +5 -0
  13. package/dist/tools/extraction/extractClasses.js +134 -0
  14. package/dist/tools/fileStuff/config.file.d.ts +5 -0
  15. package/dist/tools/fileStuff/config.file.js +41 -0
  16. package/dist/tools/fileStuff/file.tools.d.ts +19 -0
  17. package/dist/tools/fileStuff/file.tools.js +88 -0
  18. package/dist/tools/fileStuff/quasar-variables.file.d.ts +1 -0
  19. package/dist/tools/fileStuff/quasar-variables.file.js +12 -0
  20. package/dist/tools/logger.d.ts +5 -0
  21. package/dist/tools/logger.js +27 -0
  22. package/dist/tools/main.d.ts +1 -0
  23. package/dist/tools/main.js +54 -0
  24. package/dist/tools/mapping/mapClassIntoRule.d.ts +5 -0
  25. package/dist/tools/mapping/mapClassIntoRule.js +256 -0
  26. package/dist/tools/mapping/mapColors.d.ts +3 -0
  27. package/dist/tools/mapping/mapColors.js +18 -0
  28. package/dist/tools/mapping/mapUtilities.d.ts +1 -0
  29. package/dist/tools/mapping/mapUtilities.js +17 -0
  30. package/dist/tools/output/css.output.d.ts +11 -0
  31. package/dist/tools/output/css.output.js +118 -0
  32. package/dist/tools/validation/color.validation.d.ts +12 -0
  33. package/{src/tools/validation/color.validation.ts → dist/tools/validation/color.validation.js} +14 -31
  34. package/dist/version.d.ts +5 -0
  35. package/dist/version.js +7 -0
  36. package/index.js +5 -18
  37. package/package.json +10 -3
  38. package/index.html +0 -20
  39. package/scripts/generate-version.js +0 -15
  40. package/src/config/colors.config.json +0 -230
  41. package/src/config/files.config.json +0 -5
  42. package/src/config/force.config.json +0 -1
  43. package/src/config/states.config.json +0 -4
  44. package/src/config/utilities.config.json +0 -152
  45. package/src/interfaces/color.interface.ts +0 -9
  46. package/src/interfaces/files.interface.ts +0 -4
  47. package/src/manual/build.js +0 -4
  48. package/src/tools/config.tool.ts +0 -70
  49. package/src/tools/extraction/extractClasses.ts +0 -215
  50. package/src/tools/fileStuff/config.file.ts +0 -44
  51. package/src/tools/fileStuff/css.file.ts +0 -47
  52. package/src/tools/fileStuff/file.tools.ts +0 -12
  53. package/src/tools/logger.ts +0 -23
  54. package/src/tools/mapping/mapClassIntoRule.ts +0 -335
  55. package/src/tools/mapping/mapColorIntoDeclaration.ts +0 -14
  56. package/src/tools/output/css.output.ts +0 -104
  57. package/tests/README.md +0 -54
  58. package/tests/validation/color.validation.test.ts +0 -182
  59. package/tsconfig.json +0 -22
  60. package/vitest.config.ts +0 -19
@@ -1,70 +0,0 @@
1
- import { IEnvConfig } from '@interfaces/config.interface';
2
- import { readUserConfigFile, checkUserConfigFile, userConfig } from '@tools/fileStuff/config.file';
3
- import { log } from '@tools/logger';
4
- import { validateColors } from '@validation/color.validation';
5
- import fs from 'fs';
6
- import path from 'path';
7
-
8
- const anubisConfigFolder = path.join(__dirname, '..', '..', 'src', 'config');
9
- const anubisConfigFiles = [
10
- 'utilities',
11
- 'files',
12
- 'colors',
13
- 'states',
14
- 'force',
15
- ]
16
-
17
- const config = {
18
- utilities: [],
19
-
20
- force: [],
21
-
22
- files: { targets: [], ignore: [] },
23
- colors: {},
24
- states: [],
25
- } as IEnvConfig
26
-
27
- const init = () => {
28
- readUserConfigFile()
29
- checkUserConfigFile(anubisConfigFiles)
30
-
31
- for (const file of anubisConfigFiles) {
32
- let configToUse = null
33
-
34
- if (userConfig && userConfig[file]) {
35
- log(`${file} config found, overriding default.`)
36
- configToUse = userConfig[file]
37
- } else {
38
- const filePath = path.join(anubisConfigFolder, `${file}.config.json`)
39
- const fileExists = fs.existsSync(filePath)
40
- if (!fileExists) { continue }
41
-
42
- const configContent = fs.readFileSync(filePath, { encoding: 'utf-8' })
43
- if (!configContent) { continue }
44
-
45
- configToUse = JSON.parse(configContent)
46
- }
47
-
48
- config[file as keyof typeof config] = configToUse
49
-
50
- switch (file) {
51
- case 'colors':
52
- validateColors(config.colors)
53
- break
54
-
55
- case 'force':
56
- const forceClasses = userConfig?.['force']
57
- if (forceClasses?.length) {
58
- log(`Forcing the creation of ${forceClasses?.length} classes`)
59
- }
60
- break
61
- }
62
- }
63
-
64
- return config
65
- }
66
-
67
- export {
68
- init,
69
- config
70
- }
@@ -1,215 +0,0 @@
1
- import { getFiles } from '@tools/fileStuff/file.tools';
2
- import { mapClassesIntoRules } from '@tools/mapping/mapClassIntoRule';
3
- import { writeCssRuleFile } from '@tools/fileStuff/css.file';
4
- import { config } from '@tools/config.tool';
5
- import { mapColorsIntoMixinDeclaration } from '@tools/mapping/mapColorIntoDeclaration';
6
-
7
- import fs from 'fs';
8
- import {
9
- CLASS_COMMENT,
10
- COLOR_COMMENT,
11
- VARIANT_COMMENT,
12
- } from '../output/css.output';
13
- import { log } from '../logger';
14
-
15
- // Cache for regex compilation
16
- let cachedRegex: RegExp | null = null;
17
- let cachedConfigHash: string | null = null;
18
-
19
- // Performance optimization: limit concurrent file reads to avoid overwhelming the system
20
- const MAX_CONCURRENT_FILE_READS = 10;
21
-
22
- /**
23
- * Execute promises with concurrency limit
24
- * @param items - Items to process
25
- * @param fn - Async function to execute for each item
26
- * @param limit - Maximum number of concurrent operations
27
- */
28
- const pLimit = async <T, R>(
29
- items: T[],
30
- fn: (item: T) => Promise<R>,
31
- limit: number
32
- ): Promise<R[]> => {
33
- const results: R[] = [];
34
- let index = 0;
35
-
36
- const executeNext = async (): Promise<void> => {
37
- if (index >= items.length) return;
38
-
39
- const currentIndex = index++;
40
- const item = items[currentIndex];
41
- const result = await fn(item);
42
- results[currentIndex] = result;
43
- };
44
-
45
- const workers = Array(Math.min(limit, items.length))
46
- .fill(null)
47
- .map(async () => {
48
- while (index < items.length) {
49
- await executeNext();
50
- }
51
- });
52
-
53
- await Promise.all(workers);
54
- return results;
55
- };
56
-
57
- /** Fetch vue file based on config target patterns */
58
- const init = async () => {
59
- // console.log({ config })
60
- const files = await getFiles(config.files);
61
-
62
- const uniqueClasses = await getUniqueClasses(files);
63
- const { rules, variationsFromRules } = mapClassesIntoRules(uniqueClasses);
64
-
65
- // Generate all colors from config (no filtering)
66
- const mappedColors = `${COLOR_COMMENT}\n${mapColorsIntoMixinDeclaration(
67
- config.colors
68
- )}`;
69
-
70
- // Get all variations that should be exported (export: "variations")
71
- const exportVariations = getExportVariations();
72
-
73
- // Merge used variations with all export variations (all export variations take priority)
74
- const finalVariations = {
75
- ...variationsFromRules,
76
- ...exportVariations
77
- };
78
-
79
- // Generate CSS variables for variations
80
- const variationsCss = Object.entries(finalVariations)
81
- .map(([varName, varValue]) => ` --${varName}: ${varValue};`)
82
- .join('\n');
83
-
84
- const wrappedVariations = variationsCss
85
- ? `${VARIANT_COMMENT}\n:root {\n${variationsCss}\n}`
86
- : '';
87
-
88
- const wrappedRules = rules ? `${CLASS_COMMENT}\n${rules}` : '';
89
-
90
- const file = writeCssRuleFile(mappedColors, wrappedVariations, wrappedRules);
91
- return file;
92
- };
93
-
94
- /** Extract detected class and map into a flat set */
95
- const getUniqueClasses = async (files: string[]): Promise<string[]> => {
96
- // Use concurrency limit to avoid overwhelming the system on large codebases
97
- const extractedClasses = (
98
- await pLimit(files, extractClasses, MAX_CONCURRENT_FILE_READS)
99
- ).flat();
100
-
101
- const exportClasses = getExportAllClasses()
102
-
103
- const classes = [
104
- ...extractedClasses,
105
- ...exportClasses,
106
- ...config.force,
107
- ].sort();
108
-
109
- const uniqueClasses = Array.from(new Set(classes));
110
- return uniqueClasses;
111
- };
112
-
113
- /** Build regex pattern from config */
114
- const buildClassDetectionRegex = (): RegExp => {
115
- const { states, utilities } = config;
116
-
117
- const partialUtilities = utilities?.map(u => {
118
- const { prefix, variations: variationEntries, declaration } = u
119
-
120
- if (!prefix && !variationEntries) {
121
- log(`Something doesn't look good -> ${u}`)
122
- }
123
- const variations = Array.isArray(variationEntries) ? variationEntries : Object.keys(variationEntries || {})
124
- const hasVariations = !!variations?.length
125
- const hasDefaultVariation = hasVariations && variations.includes('default')
126
- const needColor = declaration.includes('${color}')
127
-
128
- /** If variation has default key and doesn't need color, can be used solo */
129
- if (hasVariations && hasDefaultVariation && !needColor) {
130
- return `${prefix}`
131
- }
132
-
133
- return `${prefix}-`
134
- })
135
-
136
- const mappedUtilities = [...partialUtilities]?.join('|')
137
- const mappedStates = `(${states?.map(s => `${s}:`)?.join('|')})`;
138
-
139
- const regexp = new RegExp(
140
- `${mappedStates}?(${mappedUtilities})(-?(\\w+(-+)?)+)?`,
141
- 'g'
142
- );
143
-
144
- return regexp
145
- };
146
-
147
- /** Get cached regex or build a new one if config changed */
148
- const getClassDetectionRegex = (): RegExp => {
149
- const { states, utilities } = config;
150
- const configHash = JSON.stringify({ states, utilities });
151
-
152
- if (cachedRegex && cachedConfigHash === configHash) {
153
- return cachedRegex;
154
- }
155
-
156
- cachedRegex = buildClassDetectionRegex();
157
- cachedConfigHash = configHash;
158
- return cachedRegex;
159
- };
160
-
161
- /** Find matching classes from a given file based on config states and prefixes */
162
- const extractClasses = async (filePath: string): Promise<string[]> => {
163
- const file = await fs.promises.readFile(filePath, 'utf-8');
164
- if (!file) {
165
- return [];
166
- }
167
-
168
- const classDetectionRegex = getClassDetectionRegex();
169
- const matches = file.match(classDetectionRegex) || [];
170
-
171
- return matches;
172
- };
173
-
174
- /** Get all variations from utilities with export: "all" */
175
- const getExportAllClasses = (): string[] => {
176
- const possiblesClasses: string[] = [];
177
-
178
- const utilities = [...config.utilities];
179
- const colors = Object.keys(config.colors);
180
-
181
- for (const utility of utilities) {
182
- const exportValue = utility['export'];
183
- // Pour "all", exporter toutes les possibilités de couleurs
184
- if (exportValue === 'all') {
185
- possiblesClasses.push(
186
- ...colors.map(c => `${utility.prefix}-${c}`)
187
- )
188
- }
189
- }
190
-
191
- return possiblesClasses;
192
- };
193
-
194
- /** Get all variations from utilities with export: "variations" */
195
- const getExportVariations = (): Record<string, string> => {
196
- const exportAllVariations: Record<string, string> = {};
197
- const utilities = [...config.utilities];
198
-
199
- for (const utility of utilities) {
200
- const exportValue = utility['export'];
201
- // Pour "variations", exporter toutes les variations
202
- if (exportValue === 'variations' && utility.variations) {
203
- for (const [variantName, variantValue] of Object.entries(
204
- utility.variations
205
- )) {
206
- const variableName = `${utility.prefix}-${variantName}`;
207
- exportAllVariations[variableName] = variantValue as string;
208
- }
209
- }
210
- }
211
-
212
- return exportAllVariations;
213
- };
214
-
215
- export { init };
@@ -1,44 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { log } from '@tools/logger';
4
-
5
- const userConfigPath = path.join(process.cwd(), 'anubis.config.json');
6
- let userConfig = null;
7
-
8
- const readUserConfigFile = () => {
9
- const userConfigExists = fs.existsSync(userConfigPath);
10
-
11
- if (!userConfigExists) {
12
- log('No user config file found, using default configuration.');
13
- return;
14
- }
15
-
16
- const config = fs.readFileSync(userConfigPath, { encoding: 'utf-8' });
17
- userConfig = JSON.parse(config);
18
-
19
- return userConfig;
20
- };
21
-
22
- /** Print a warning if the config file has unknow keys */
23
- const checkUserConfigFile = (configFile: string[]): void => {
24
- if (!userConfig) {
25
- return;
26
- }
27
-
28
- // todo - also check values
29
- const userConfigKeys = Object.keys(userConfig);
30
-
31
- const unknownKeys = userConfigKeys?.filter(
32
- key => !configFile.includes(key) && key !== 'force'
33
- );
34
- if (!unknownKeys?.length) {
35
- return;
36
- }
37
-
38
- log(`${unknownKeys?.length} unknown config keys found in user config file`);
39
- for (const key of unknownKeys) {
40
- log(`- ${key}`);
41
- }
42
- };
43
-
44
- export { userConfig, readUserConfigFile, checkUserConfigFile };
@@ -1,47 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
-
4
- import { log } from '@tools/logger';
5
- import { getHeader } from '@tools/output/css.output';
6
-
7
- const srcDir = path.join(process.cwd(), 'src', 'css');
8
- const outputPath = path.join(srcDir, '_anubis.scss');
9
-
10
- const checkCssRuleFilePresence = () => {
11
- try {
12
- fs.mkdirSync(srcDir, { recursive: true });
13
-
14
- if (fs.existsSync(outputPath)) {
15
- return;
16
- }
17
-
18
- log('Output file missing, generating..');
19
- fs.writeFileSync(outputPath, '');
20
- } catch (err: any) {
21
- throw new Error(
22
- `Erreur lors de la vérification du fichier CSS: ${err.message}`
23
- );
24
- }
25
- };
26
-
27
- const writeCssRuleFile = (
28
- colors: string = '',
29
- variants: string = '',
30
- classes: string = ''
31
- ) => {
32
- try {
33
- checkCssRuleFilePresence();
34
-
35
- const content = `${getHeader()}\n${colors}\n\n${variants}\n\n${classes}`;
36
-
37
- fs.writeFileSync(outputPath, content);
38
-
39
- return outputPath;
40
- } catch (err: any) {
41
- throw new Error(
42
- `Erreur lors de l'écriture du fichier CSS: ${err.message}`
43
- );
44
- }
45
- };
46
-
47
- export { writeCssRuleFile };
@@ -1,12 +0,0 @@
1
- import fg from 'fast-glob';
2
- import { IFileConfig } from '@interfaces/files.interface';
3
-
4
- const getFiles = async (routeConfig: IFileConfig) => {
5
- return await fg(routeConfig.targets || '*.vue', {
6
- absolute: true,
7
- onlyFiles: true,
8
- ignore: routeConfig.ignore || [],
9
- });
10
- };
11
-
12
- export { getFiles };
@@ -1,23 +0,0 @@
1
- import { version } from '../version';
2
-
3
- const logPrefix = '☯︎ [ANUBIS]'
4
- const log = (str: string) => console.log(`${logPrefix} ${str}`)
5
-
6
- const logo = () => {
7
- log(' ___ _ ____ ______ _________')
8
- log(' / | / | / / / / / __ )/ _/ ___/')
9
- log(' / /| | / |/ / / / / __ |/ / \\__ \\')
10
- log(' / ___ |/ /| / /_/ / /_/ // / ___/ /')
11
- log('/_/ |_/_/ |_/\\____/_____/___//____/')
12
- log('')
13
- log(`Welcome to Anubis v${version}`)
14
- log('Autonomous Nominative Utility Based Intuitive Styler')
15
- log('---')
16
- }
17
-
18
- export {
19
- logo,
20
-
21
- log,
22
- logPrefix
23
- }