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.
- package/README.md +96 -27
- package/dist/interfaces/color.interface.d.ts +8 -0
- package/dist/interfaces/color.interface.js +2 -0
- package/{src/interfaces/config.interface.ts → dist/interfaces/config.interface.d.ts} +0 -3
- package/dist/interfaces/config.interface.js +2 -0
- package/dist/interfaces/files.interface.d.ts +4 -0
- package/dist/interfaces/files.interface.js +2 -0
- package/{src/interfaces/preset.interface.ts → dist/interfaces/preset.interface.d.ts} +3 -7
- package/dist/interfaces/preset.interface.js +2 -0
- package/dist/tools/config.tool.d.ts +4 -0
- package/dist/tools/config.tool.js +64 -0
- package/dist/tools/extraction/extractClasses.d.ts +5 -0
- package/dist/tools/extraction/extractClasses.js +134 -0
- package/dist/tools/fileStuff/config.file.d.ts +5 -0
- package/dist/tools/fileStuff/config.file.js +41 -0
- package/dist/tools/fileStuff/file.tools.d.ts +19 -0
- package/dist/tools/fileStuff/file.tools.js +88 -0
- package/dist/tools/fileStuff/quasar-variables.file.d.ts +1 -0
- package/dist/tools/fileStuff/quasar-variables.file.js +12 -0
- package/dist/tools/logger.d.ts +5 -0
- package/dist/tools/logger.js +27 -0
- package/dist/tools/main.d.ts +1 -0
- package/dist/tools/main.js +54 -0
- package/dist/tools/mapping/mapClassIntoRule.d.ts +5 -0
- package/dist/tools/mapping/mapClassIntoRule.js +256 -0
- package/dist/tools/mapping/mapColors.d.ts +3 -0
- package/dist/tools/mapping/mapColors.js +18 -0
- package/dist/tools/mapping/mapUtilities.d.ts +1 -0
- package/dist/tools/mapping/mapUtilities.js +17 -0
- package/dist/tools/output/css.output.d.ts +11 -0
- package/dist/tools/output/css.output.js +118 -0
- package/dist/tools/validation/color.validation.d.ts +12 -0
- package/{src/tools/validation/color.validation.ts → dist/tools/validation/color.validation.js} +14 -31
- package/dist/version.d.ts +5 -0
- package/dist/version.js +7 -0
- package/index.js +5 -18
- package/package.json +10 -3
- package/index.html +0 -20
- package/scripts/generate-version.js +0 -15
- package/src/config/colors.config.json +0 -230
- package/src/config/files.config.json +0 -5
- package/src/config/force.config.json +0 -1
- package/src/config/states.config.json +0 -4
- package/src/config/utilities.config.json +0 -152
- package/src/interfaces/color.interface.ts +0 -9
- package/src/interfaces/files.interface.ts +0 -4
- package/src/manual/build.js +0 -4
- package/src/tools/config.tool.ts +0 -70
- package/src/tools/extraction/extractClasses.ts +0 -215
- package/src/tools/fileStuff/config.file.ts +0 -44
- package/src/tools/fileStuff/css.file.ts +0 -47
- package/src/tools/fileStuff/file.tools.ts +0 -12
- package/src/tools/logger.ts +0 -23
- package/src/tools/mapping/mapClassIntoRule.ts +0 -335
- package/src/tools/mapping/mapColorIntoDeclaration.ts +0 -14
- package/src/tools/output/css.output.ts +0 -104
- package/tests/README.md +0 -54
- package/tests/validation/color.validation.test.ts +0 -182
- package/tsconfig.json +0 -22
- package/vitest.config.ts +0 -19
package/README.md
CHANGED
|
@@ -92,6 +92,8 @@ AnubisUI automatically generates the CSS classes you need, simply by using them
|
|
|
92
92
|
- 🔍 Smart class detection and parsing
|
|
93
93
|
- 📦 CSS variable generation for reusable values
|
|
94
94
|
- ⚙️ Export variations as CSS variables for custom styling
|
|
95
|
+
- 🎛️ SCSS tokens generation for global color access
|
|
96
|
+
- 🔧 Quasar/global variable overrides from utility defaults
|
|
95
97
|
|
|
96
98
|
# Installation
|
|
97
99
|
|
|
@@ -119,20 +121,27 @@ css: [
|
|
|
119
121
|
```
|
|
120
122
|
<sup>quasar.config.js</sup>
|
|
121
123
|
|
|
122
|
-
4.
|
|
124
|
+
4. AnubisUI generates the following files automatically in `src/css/`:
|
|
125
|
+
- `_anubis.scss` - Main stylesheet with all generated rules
|
|
126
|
+
- `anubis/_mixins.scss` - SCSS mixins for color handling
|
|
127
|
+
- `anubis/_tokens.scss` - Color token variables (`$primary`, `$primary-dark`, etc.)
|
|
128
|
+
- `anubis/_overrides.scss` - Quasar variable overrides from utilities
|
|
129
|
+
- `quasar.variables.scss` - Auto-injected imports for tokens and overrides
|
|
130
|
+
|
|
131
|
+
5. Colors are automatically defined from the configuration
|
|
123
132
|
- AnubisUI generates CSS variables for all colors defined in `colors.config.json`
|
|
124
133
|
- Colors support light/dark themes automatically
|
|
125
134
|
- Each color is exposed as a CSS variable: `--primary`, `--secondary`, etc.
|
|
126
135
|
- Pre-defined color levels: `lowest`, `lower`, `low`, `medium`, `high`, `higher`, `highest`
|
|
127
136
|
|
|
128
|
-
|
|
137
|
+
6. Start adding classes to your .vue files
|
|
129
138
|
```html
|
|
130
139
|
<div class="bg-primary-low border-neutral-medium hover:shadow-wide rounded-lg" />
|
|
131
140
|
<button class="bg-accent text-primary size-lg weight-bold smooth">Click me</button>
|
|
132
141
|
```
|
|
133
142
|
<sup>any .vue file</sup>
|
|
134
143
|
|
|
135
|
-
|
|
144
|
+
7. Enjoy
|
|
136
145
|
|
|
137
146
|
> **Note**: Generated CSS variables (from colors and export) are available for custom styling:
|
|
138
147
|
> ```css
|
|
@@ -143,6 +152,16 @@ css: [
|
|
|
143
152
|
> }
|
|
144
153
|
> ```
|
|
145
154
|
|
|
155
|
+
> **SCSS Tokens**: Color tokens are also available as SCSS variables for compile-time usage:
|
|
156
|
+
> ```scss
|
|
157
|
+
> @use "anubis/_tokens.scss" as tokens;
|
|
158
|
+
>
|
|
159
|
+
> .custom-class {
|
|
160
|
+
> border-color: tokens.$primary;
|
|
161
|
+
> background: tokens.$accent-dark;
|
|
162
|
+
> }
|
|
163
|
+
> ```
|
|
164
|
+
|
|
146
165
|
## Configuration
|
|
147
166
|
AnubisUI uses several configuration files located in the `src/config` directory:
|
|
148
167
|
<br />
|
|
@@ -180,7 +199,7 @@ For every config you want to change, add the corresponding section in your confi
|
|
|
180
199
|
"default": "4px",
|
|
181
200
|
"thin": "2px"
|
|
182
201
|
},
|
|
183
|
-
"export": "
|
|
202
|
+
"export": "variations"
|
|
184
203
|
},
|
|
185
204
|
{
|
|
186
205
|
"prefix": "rounded",
|
|
@@ -297,13 +316,7 @@ Configure all utility classes. This includes both color-based utilities and stan
|
|
|
297
316
|
- `shadow` - Box shadow with spread variations and color
|
|
298
317
|
|
|
299
318
|
|
|
300
|
-
|
|
301
|
-
### Quality of Life (`qol.config.json`)
|
|
302
|
-
Define simple style rules that can have variations but don't require color values. These are CSS declarations that work independently.
|
|
303
|
-
|
|
304
|
-
**[View default QoL config →](./src/config/qol.config.json)**
|
|
305
|
-
|
|
306
|
-
QoL utilities include:
|
|
319
|
+
**Standalone utilities** (no color required):
|
|
307
320
|
- `blur` - Backdrop filter blur effect
|
|
308
321
|
- `smooth` - Transition duration
|
|
309
322
|
- `rounded` - Border radius
|
|
@@ -314,15 +327,38 @@ QoL utilities include:
|
|
|
314
327
|
|
|
315
328
|
**Configuration options**:
|
|
316
329
|
1. `prefix` - The class name prefix
|
|
317
|
-
2. `declaration` - CSS rule using `${value}`
|
|
330
|
+
2. `declaration` - CSS rule using `${value}` and/or `${color}` placeholders
|
|
318
331
|
3. `variations` - Key-value pairs of variation names and their CSS values
|
|
319
332
|
4. `export` (optional) - Controls how variations are exported as CSS variables
|
|
333
|
+
5. `overrides` (optional) - List of Quasar/global SCSS variables to override with the default variation
|
|
320
334
|
|
|
321
335
|
**The `export` flag**:
|
|
322
|
-
- `export: "
|
|
336
|
+
- `export: "variations"` → Generates CSS variables for every variation
|
|
323
337
|
- `export: "all"` → Generates classes for every possible color
|
|
324
338
|
- These can be used in custom CSS: `font-size: var(--size-xl)`
|
|
325
339
|
|
|
340
|
+
**The `overrides` option**:
|
|
341
|
+
Override Quasar or global SCSS variables with the `default` variation value:
|
|
342
|
+
```json
|
|
343
|
+
{
|
|
344
|
+
"prefix": "border",
|
|
345
|
+
"declaration": "border-width: ${value}; border-color: ${color}; border-style: solid;",
|
|
346
|
+
"overrides": [
|
|
347
|
+
"generic-border-radius",
|
|
348
|
+
"button-border-radius"
|
|
349
|
+
],
|
|
350
|
+
"variations": {
|
|
351
|
+
"default": "4px",
|
|
352
|
+
"thin": "2px"
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
This generates in `anubis/_overrides.scss`:
|
|
357
|
+
```scss
|
|
358
|
+
$generic-border-radius: 4px;
|
|
359
|
+
$button-border-radius: 4px;
|
|
360
|
+
```
|
|
361
|
+
|
|
326
362
|
**Color support**:
|
|
327
363
|
- Use `${color}` in declaration to indicate the utility requires a color
|
|
328
364
|
- Colors are automatically injected as CSS variables: `var(--{color})`
|
|
@@ -456,37 +492,54 @@ Examples:
|
|
|
456
492
|
| size | `font-size: {value} !important;` |
|
|
457
493
|
| weight | `font-weight: {value} !important;` |
|
|
458
494
|
|
|
459
|
-
**Note**: When `export: "
|
|
495
|
+
**Note**: When `export: "variations"` is set, `{value}` becomes `var(--{prefix}-{variation})` instead of the direct value.
|
|
460
496
|
|
|
461
497
|
## Architecture
|
|
462
498
|
|
|
463
499
|
### Build Process Flow
|
|
464
500
|
|
|
501
|
+
The build process is orchestrated by `src/tools/main.ts` which runs the following steps in sequence:
|
|
502
|
+
|
|
465
503
|
1. **Configuration Initialization** (`src/tools/config.tool.ts`)
|
|
466
504
|
- Loads default configs from `src/config/*.config.json`
|
|
467
505
|
- Merges with user's `anubis.config.json` if present
|
|
468
506
|
- User config completely replaces default sections (no deep merge)
|
|
469
507
|
|
|
470
|
-
2. **
|
|
471
|
-
-
|
|
472
|
-
-
|
|
508
|
+
2. **Mixins Generation** (`src/tools/output/css.output.ts`)
|
|
509
|
+
- Generates SCSS mixins for color handling (light/dark theme support)
|
|
510
|
+
- Outputs to `src/css/anubis/_mixins.scss`
|
|
511
|
+
|
|
512
|
+
3. **Tokens Generation** (`src/tools/mapping/mapColors.ts`)
|
|
513
|
+
- Maps all colors from config into SCSS token variables
|
|
514
|
+
- Generates `$colorname`, `$colorname-light`, `$colorname-dark` variables
|
|
515
|
+
- Outputs to `src/css/anubis/_tokens.scss`
|
|
516
|
+
|
|
517
|
+
4. **Overrides Generation** (`src/tools/mapping/mapUtilities.ts`)
|
|
518
|
+
- Maps utilities with `overrides` property to SCSS variable declarations
|
|
519
|
+
- Allows overriding Quasar/global variables with utility defaults
|
|
520
|
+
- Outputs to `src/css/anubis/_overrides.scss`
|
|
473
521
|
|
|
474
|
-
|
|
522
|
+
5. **Quasar Variables Injection** (`src/tools/fileStuff/quasar-variables.file.ts`)
|
|
523
|
+
- Automatically adds `@use` imports for tokens and overrides
|
|
524
|
+
- Updates `src/css/quasar.variables.scss`
|
|
525
|
+
|
|
526
|
+
6. **Class Extraction** (`src/tools/extraction/extractClasses.ts`)
|
|
527
|
+
- Scans files matching glob patterns from `files.config.json`
|
|
475
528
|
- Builds dynamic regex from config (states, utilities prefixes)
|
|
476
529
|
- Extracts classes matching pattern: `(state:)?(prefix-)(-?(color|variation))?`
|
|
477
|
-
- Merges with forced classes from config
|
|
530
|
+
- Merges with forced classes and exported classes from config
|
|
478
531
|
- Deduplicates and returns unique classes
|
|
479
532
|
|
|
480
|
-
|
|
533
|
+
7. **Rule Generation** (`src/tools/mapping/mapClassIntoRule.ts`)
|
|
481
534
|
- Parses each class to identify state, prefix, color, and variation
|
|
482
535
|
- Validates color existence in config
|
|
483
536
|
- Handles utility variations (direct values or CSS variables)
|
|
484
537
|
- Generates CSS rules with proper selectors and declarations
|
|
485
538
|
- Collects variants for CSS variable export
|
|
486
539
|
|
|
487
|
-
|
|
540
|
+
8. **CSS Output** (`src/tools/extraction/extractClasses.ts`)
|
|
488
541
|
- Generates color CSS variables with light/dark theme support
|
|
489
|
-
- Generates variation CSS variables (from `export: "
|
|
542
|
+
- Generates variation CSS variables (from `export: "variations"` or `export: "all"`)
|
|
490
543
|
- Writes final CSS rules
|
|
491
544
|
- Outputs to `src/css/_anubis.scss`
|
|
492
545
|
|
|
@@ -499,10 +552,14 @@ The plugin (`index.js`) provides:
|
|
|
499
552
|
|
|
500
553
|
### Core Components
|
|
501
554
|
|
|
502
|
-
- **
|
|
503
|
-
- **
|
|
504
|
-
- **
|
|
505
|
-
- **
|
|
555
|
+
- **Main Orchestrator** (`main.ts`): Coordinates all initialization steps with timing
|
|
556
|
+
- **Config System** (`config.tool.ts`): Manages configuration loading and merging
|
|
557
|
+
- **Class Extractor** (`extractClasses.ts`): Regex-based pattern matching for class detection
|
|
558
|
+
- **Color Mapper** (`mapColors.ts`): Generates tokens and mixin declarations from colors
|
|
559
|
+
- **Utilities Mapper** (`mapUtilities.ts`): Generates SCSS overrides from utilities config
|
|
560
|
+
- **Rule Mapper** (`mapClassIntoRule.ts`): Complex parsing logic for class-to-CSS conversion
|
|
561
|
+
- **CSS Generator** (`css.output.ts`): Generates variables, mixins and rules with proper formatting
|
|
562
|
+
- **File Tools** (`file.tools.ts`): Centralized file I/O with concurrency control
|
|
506
563
|
|
|
507
564
|
### File Structure
|
|
508
565
|
```
|
|
@@ -511,15 +568,27 @@ The plugin (`index.js`) provides:
|
|
|
511
568
|
│ ├── config/ # Default configuration files
|
|
512
569
|
│ │ ├── colors.config.json # Color palette (light/dark themes)
|
|
513
570
|
│ │ ├── utilities.config.json # All utility classes (bg, text, border, etc.)
|
|
514
|
-
│ │ ├── states.config.json
|
|
571
|
+
│ │ ├── states.config.json # State modifiers
|
|
515
572
|
│ │ ├── files.config.json # File scan patterns
|
|
516
573
|
│ │ └── force.config.json # Force specific classes
|
|
574
|
+
│ ├── css/ # Generated CSS output (in user project)
|
|
575
|
+
│ │ ├── _anubis.scss # Main generated stylesheet
|
|
576
|
+
│ │ ├── quasar.variables.scss # Quasar variables with injected imports
|
|
577
|
+
│ │ └── anubis/
|
|
578
|
+
│ │ ├── _mixins.scss # SCSS mixins for color handling
|
|
579
|
+
│ │ ├── _tokens.scss # Color token variables
|
|
580
|
+
│ │ └── _overrides.scss # Quasar/global variable overrides
|
|
517
581
|
│ ├── interfaces/ # TypeScript type definitions
|
|
518
582
|
│ └── tools/
|
|
519
583
|
│ ├── extraction/ # Class extraction logic
|
|
520
584
|
│ ├── fileStuff/ # File I/O operations
|
|
521
585
|
│ ├── mapping/ # Class-to-CSS mapping
|
|
586
|
+
│ │ ├── mapClassIntoRule.ts # Class to CSS rule conversion
|
|
587
|
+
│ │ ├── mapColors.ts # Color to tokens/mixins mapping
|
|
588
|
+
│ │ └── mapUtilities.ts # Utilities to overrides mapping
|
|
589
|
+
│ ├── output/ # CSS output generation
|
|
522
590
|
│ ├── config.tool.ts # Configuration loader
|
|
591
|
+
│ ├── main.ts # Main orchestration entry point
|
|
523
592
|
│ └── logger.ts # Logging utilities
|
|
524
593
|
└── index.js # Vite plugin entry point
|
|
525
594
|
```
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { IColor } from './color.interface';
|
|
2
2
|
import { IUtility } from './preset.interface';
|
|
3
3
|
import { IFileConfig } from './files.interface';
|
|
4
|
-
|
|
5
4
|
export interface IEnvConfig {
|
|
6
5
|
utilities: IUtility[];
|
|
7
6
|
files: IFileConfig;
|
|
8
|
-
|
|
9
7
|
/** User-given classes to force the css rule creation */
|
|
10
8
|
force: string[];
|
|
11
|
-
|
|
12
9
|
colors: IColor;
|
|
13
10
|
states: string[];
|
|
14
11
|
[key: string]: any;
|
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
export interface IVariation {
|
|
2
2
|
[key: string]: string;
|
|
3
3
|
}
|
|
4
|
-
|
|
5
4
|
export interface IUtility {
|
|
6
|
-
// [key: string]: string
|
|
7
5
|
prefix: string;
|
|
8
6
|
declaration: string;
|
|
9
|
-
|
|
10
7
|
/** When true, class can be called without variation, creating a rule with default variation */
|
|
11
8
|
standalone?: boolean;
|
|
12
|
-
|
|
13
9
|
/**
|
|
14
10
|
* Controls how variations are exported as SCSS variables:
|
|
15
11
|
* - "variation": export every variations
|
|
16
12
|
* - "all": export every possible color class (utility prefix + every colors)
|
|
17
13
|
* - undefined: do not export variations
|
|
18
14
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
export?: 'variations' | 'all';
|
|
16
|
+
/** Override default global variables with the "default" variation if existing */
|
|
17
|
+
overrides?: string[];
|
|
21
18
|
/** List of every possible variations */
|
|
22
19
|
variations: IVariation;
|
|
23
20
|
}
|
|
24
|
-
|
|
25
21
|
export interface IRuleInfo {
|
|
26
22
|
selector: string;
|
|
27
23
|
declaration: string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.config = exports.init = void 0;
|
|
7
|
+
const config_file_1 = require("./fileStuff/config.file");
|
|
8
|
+
const logger_1 = require("./logger");
|
|
9
|
+
const color_validation_1 = require("./validation/color.validation");
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const anubisConfigFolder = path_1.default.join(__dirname, '..', '..', 'src', 'config');
|
|
13
|
+
const anubisConfigFiles = [
|
|
14
|
+
'utilities',
|
|
15
|
+
'files',
|
|
16
|
+
'colors',
|
|
17
|
+
'states',
|
|
18
|
+
'force',
|
|
19
|
+
];
|
|
20
|
+
const config = {
|
|
21
|
+
utilities: [],
|
|
22
|
+
force: [],
|
|
23
|
+
files: { targets: [], ignore: [] },
|
|
24
|
+
colors: {},
|
|
25
|
+
states: [],
|
|
26
|
+
};
|
|
27
|
+
exports.config = config;
|
|
28
|
+
const init = () => {
|
|
29
|
+
(0, config_file_1.readUserConfigFile)();
|
|
30
|
+
(0, config_file_1.checkUserConfigFile)(anubisConfigFiles);
|
|
31
|
+
for (const file of anubisConfigFiles) {
|
|
32
|
+
let configToUse = null;
|
|
33
|
+
if (config_file_1.userConfig && config_file_1.userConfig[file]) {
|
|
34
|
+
(0, logger_1.log)(`${file} config found, overriding default.`);
|
|
35
|
+
configToUse = config_file_1.userConfig[file];
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const filePath = path_1.default.join(anubisConfigFolder, `${file}.config.json`);
|
|
39
|
+
const fileExists = fs_1.default.existsSync(filePath);
|
|
40
|
+
if (!fileExists) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const configContent = fs_1.default.readFileSync(filePath, { encoding: 'utf-8' });
|
|
44
|
+
if (!configContent) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
configToUse = JSON.parse(configContent);
|
|
48
|
+
}
|
|
49
|
+
config[file] = configToUse;
|
|
50
|
+
switch (file) {
|
|
51
|
+
case 'colors':
|
|
52
|
+
(0, color_validation_1.validateColors)(config.colors);
|
|
53
|
+
break;
|
|
54
|
+
case 'force':
|
|
55
|
+
const forceClasses = config_file_1.userConfig === null || config_file_1.userConfig === void 0 ? void 0 : config_file_1.userConfig['force'];
|
|
56
|
+
if (forceClasses === null || forceClasses === void 0 ? void 0 : forceClasses.length) {
|
|
57
|
+
(0, logger_1.log)(`Forcing the creation of ${forceClasses === null || forceClasses === void 0 ? void 0 : forceClasses.length} classes`);
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return config;
|
|
63
|
+
};
|
|
64
|
+
exports.init = init;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Fetch vue file based on config target patterns */
|
|
2
|
+
export declare const init: () => Promise<string>;
|
|
3
|
+
/** Get all variations from utilities with export: "variations" */
|
|
4
|
+
export declare const getExportedVariations: () => Record<string, string>;
|
|
5
|
+
export declare const handleVariations: (extractedVariations: Record<string, string>) => string;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.handleVariations = exports.getExportedVariations = exports.init = void 0;
|
|
7
|
+
const file_tools_1 = require("../fileStuff/file.tools");
|
|
8
|
+
const mapClassIntoRule_1 = require("../mapping/mapClassIntoRule");
|
|
9
|
+
const config_tool_1 = require("../config.tool");
|
|
10
|
+
const mapColors_1 = require("../mapping/mapColors");
|
|
11
|
+
const fs_1 = __importDefault(require("fs"));
|
|
12
|
+
const css_output_1 = require("../output/css.output");
|
|
13
|
+
const logger_1 = require("../logger");
|
|
14
|
+
// Cache for regex compilation
|
|
15
|
+
let cachedRegex = null;
|
|
16
|
+
let cachedConfigHash = null;
|
|
17
|
+
/** Fetch vue file based on config target patterns */
|
|
18
|
+
const init = async () => {
|
|
19
|
+
const files = await (0, file_tools_1.getFiles)(config_tool_1.config.files);
|
|
20
|
+
const uniqueClasses = await getUniqueClasses(files);
|
|
21
|
+
const { rules, variationsFromRules } = (0, mapClassIntoRule_1.mapClassesIntoRules)(uniqueClasses);
|
|
22
|
+
const colors = `${css_output_1.comments.colors}\n${(0, mapColors_1.mapColorsIntoMixinDeclaration)(config_tool_1.config.colors)}`;
|
|
23
|
+
const skipVariations = false;
|
|
24
|
+
const variations = skipVariations ? '' : (0, exports.handleVariations)(variationsFromRules);
|
|
25
|
+
const wrappedRules = rules ? `${css_output_1.comments.rules}\n${rules}` : '';
|
|
26
|
+
const fileContent = `${(0, css_output_1.getHeader)()}\n${colors}\n\n${variations}\n\n${wrappedRules}`;
|
|
27
|
+
const file = (0, file_tools_1.writeFile)(file_tools_1.outputFile, fileContent);
|
|
28
|
+
return file;
|
|
29
|
+
};
|
|
30
|
+
exports.init = init;
|
|
31
|
+
/** Extract detected class and map into a flat set */
|
|
32
|
+
const getUniqueClasses = async (files) => {
|
|
33
|
+
/** Find matching classes from a given file based on config states and prefixes */
|
|
34
|
+
const extractClasses = async (filePath) => {
|
|
35
|
+
const file = await fs_1.default.promises.readFile(filePath, 'utf-8');
|
|
36
|
+
if (!file) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
const classDetectionRegex = getClassDetectionRegex();
|
|
40
|
+
const matches = file.match(classDetectionRegex) || [];
|
|
41
|
+
return matches;
|
|
42
|
+
};
|
|
43
|
+
const extractedClasses = (await (0, file_tools_1.pLimit)(files, extractClasses)).flat();
|
|
44
|
+
const exportedClasses = getExportedClasses();
|
|
45
|
+
const classes = [
|
|
46
|
+
...extractedClasses,
|
|
47
|
+
...exportedClasses,
|
|
48
|
+
...config_tool_1.config.force,
|
|
49
|
+
].sort();
|
|
50
|
+
const uniqueClasses = Array.from(new Set(classes));
|
|
51
|
+
return uniqueClasses;
|
|
52
|
+
};
|
|
53
|
+
/** Build regex pattern from config */
|
|
54
|
+
const buildClassDetectionRegex = () => {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
const { states, utilities } = config_tool_1.config;
|
|
57
|
+
const partialUtilities = utilities === null || utilities === void 0 ? void 0 : utilities.map(u => {
|
|
58
|
+
const { prefix, variations: variationEntries, declaration } = u;
|
|
59
|
+
if (!prefix && !variationEntries) {
|
|
60
|
+
(0, logger_1.log)(`Something doesn't look good -> ${u}`);
|
|
61
|
+
}
|
|
62
|
+
const variations = Array.isArray(variationEntries) ? variationEntries : Object.keys(variationEntries || {});
|
|
63
|
+
const hasVariations = !!(variations === null || variations === void 0 ? void 0 : variations.length);
|
|
64
|
+
const hasDefaultVariation = hasVariations && variations.includes('default');
|
|
65
|
+
const needColor = declaration.includes('${color}');
|
|
66
|
+
/** If variation has default key and doesn't need color, can be used solo */
|
|
67
|
+
if (hasVariations && hasDefaultVariation && !needColor) {
|
|
68
|
+
return `${prefix}`;
|
|
69
|
+
}
|
|
70
|
+
return `${prefix}-`;
|
|
71
|
+
});
|
|
72
|
+
const mappedUtilities = (_a = [...partialUtilities]) === null || _a === void 0 ? void 0 : _a.join('|');
|
|
73
|
+
const mappedStates = `(${(_b = states === null || states === void 0 ? void 0 : states.map(s => `${s}:`)) === null || _b === void 0 ? void 0 : _b.join('|')})`;
|
|
74
|
+
const regexp = new RegExp(`${mappedStates}?(${mappedUtilities})(-?(\\w+(-+)?)+)?`, 'g');
|
|
75
|
+
return regexp;
|
|
76
|
+
};
|
|
77
|
+
/** Get cached regex or build a new one if config changed */
|
|
78
|
+
const getClassDetectionRegex = () => {
|
|
79
|
+
const { states, utilities } = config_tool_1.config;
|
|
80
|
+
const configHash = JSON.stringify({ states, utilities });
|
|
81
|
+
if (cachedRegex && cachedConfigHash === configHash) {
|
|
82
|
+
return cachedRegex;
|
|
83
|
+
}
|
|
84
|
+
cachedRegex = buildClassDetectionRegex();
|
|
85
|
+
cachedConfigHash = configHash;
|
|
86
|
+
return cachedRegex;
|
|
87
|
+
};
|
|
88
|
+
/** Get all variations from utilities with export: "all" */
|
|
89
|
+
const getExportedClasses = () => {
|
|
90
|
+
const possiblesClasses = [];
|
|
91
|
+
const utilities = [...config_tool_1.config.utilities];
|
|
92
|
+
const colors = Object.keys(config_tool_1.config.colors);
|
|
93
|
+
for (const utility of utilities) {
|
|
94
|
+
const exportValue = utility['export'];
|
|
95
|
+
/** export every possible colors variations */
|
|
96
|
+
if (exportValue === 'all') {
|
|
97
|
+
possiblesClasses.push(...colors.map(color => `${utility.prefix}-${color}`));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return possiblesClasses;
|
|
101
|
+
};
|
|
102
|
+
/** Get all variations from utilities with export: "variations" */
|
|
103
|
+
const getExportedVariations = () => {
|
|
104
|
+
const exportAllVariations = {};
|
|
105
|
+
const utilities = [...config_tool_1.config.utilities];
|
|
106
|
+
for (const utility of utilities) {
|
|
107
|
+
const exportValue = utility['export'];
|
|
108
|
+
// Pour "variations", exporter toutes les variations
|
|
109
|
+
if (exportValue === 'variations' && utility.variations) {
|
|
110
|
+
for (const [variantName, variantValue] of Object.entries(utility.variations)) {
|
|
111
|
+
const variableName = `${utility.prefix}-${variantName}`;
|
|
112
|
+
exportAllVariations[variableName] = variantValue;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return exportAllVariations;
|
|
117
|
+
};
|
|
118
|
+
exports.getExportedVariations = getExportedVariations;
|
|
119
|
+
const handleVariations = (extractedVariations) => {
|
|
120
|
+
const exportedVariations = (0, exports.getExportedVariations)();
|
|
121
|
+
const variations = {
|
|
122
|
+
...extractedVariations,
|
|
123
|
+
...exportedVariations
|
|
124
|
+
};
|
|
125
|
+
// Generate CSS variables for variations
|
|
126
|
+
const variationsCss = Object.entries(variations)
|
|
127
|
+
.map(([varName, varValue]) => ` --${varName}: ${varValue};`)
|
|
128
|
+
.join('\n');
|
|
129
|
+
const wrappedVariations = variationsCss
|
|
130
|
+
? `${css_output_1.comments.variations}\n:root {\n${variationsCss}\n}`
|
|
131
|
+
: '';
|
|
132
|
+
return wrappedVariations;
|
|
133
|
+
};
|
|
134
|
+
exports.handleVariations = handleVariations;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.checkUserConfigFile = exports.readUserConfigFile = exports.userConfig = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const logger_1 = require("../logger");
|
|
10
|
+
const userConfigPath = path_1.default.join(process.cwd(), 'anubis.config.json');
|
|
11
|
+
let userConfig = null;
|
|
12
|
+
exports.userConfig = userConfig;
|
|
13
|
+
const readUserConfigFile = () => {
|
|
14
|
+
const userConfigExists = fs_1.default.existsSync(userConfigPath);
|
|
15
|
+
if (!userConfigExists) {
|
|
16
|
+
(0, logger_1.log)('No user config file found, using default configuration.');
|
|
17
|
+
(0, logger_1.log)('---');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const config = fs_1.default.readFileSync(userConfigPath, { encoding: 'utf-8' });
|
|
21
|
+
exports.userConfig = userConfig = JSON.parse(config);
|
|
22
|
+
return userConfig;
|
|
23
|
+
};
|
|
24
|
+
exports.readUserConfigFile = readUserConfigFile;
|
|
25
|
+
/** Print a warning if the config file has unknow keys */
|
|
26
|
+
const checkUserConfigFile = (configFile) => {
|
|
27
|
+
if (!userConfig) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// todo - also check values
|
|
31
|
+
const userConfigKeys = Object.keys(userConfig);
|
|
32
|
+
const unknownKeys = userConfigKeys === null || userConfigKeys === void 0 ? void 0 : userConfigKeys.filter(key => !configFile.includes(key) && key !== 'force');
|
|
33
|
+
if (!(unknownKeys === null || unknownKeys === void 0 ? void 0 : unknownKeys.length)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
(0, logger_1.log)(`${unknownKeys === null || unknownKeys === void 0 ? void 0 : unknownKeys.length} unknown config keys found in user config file`);
|
|
37
|
+
for (const key of unknownKeys) {
|
|
38
|
+
(0, logger_1.log)(`- ${key}`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.checkUserConfigFile = checkUserConfigFile;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IFileConfig } from '../../interfaces/files.interface';
|
|
2
|
+
export declare const srcDir: string;
|
|
3
|
+
export declare const outputDir: string;
|
|
4
|
+
export declare const quasarFile = "quasar.variables.scss";
|
|
5
|
+
export declare const outputFile = "_anubis.scss";
|
|
6
|
+
export declare const tokensFile = "anubis/_tokens.scss";
|
|
7
|
+
export declare const mixinsFile = "anubis/_mixins.scss";
|
|
8
|
+
export declare const overridesFile = "anubis/_overrides.scss";
|
|
9
|
+
export declare const checkOrCreateFile: (filePath: string) => boolean;
|
|
10
|
+
export declare const getFiles: (routeConfig: IFileConfig) => Promise<string[]>;
|
|
11
|
+
export declare const readFile: (fileName: string) => string;
|
|
12
|
+
export declare const writeFile: (fileName: string, content: string) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Execute promises with concurrency limit
|
|
15
|
+
* @param items - Items to process
|
|
16
|
+
* @param fn - Async function to execute for each item
|
|
17
|
+
* @param limit - Maximum number of concurrent operations
|
|
18
|
+
*/
|
|
19
|
+
export declare const pLimit: <T, R>(items: T[], fn: (item: T) => Promise<R>, limit?: number) => Promise<R[]>;
|