@o3r/styling 12.1.0-prerelease.21 → 12.1.0-prerelease.3
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/builders/style-extractor/helpers/css-variable.extractor.d.ts +5 -17
- package/builders/style-extractor/helpers/css-variable.extractor.d.ts.map +1 -1
- package/builders/style-extractor/helpers/css-variable.extractor.js +57 -108
- package/builders/style-extractor/index.js +14 -16
- package/package.json +6 -10
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StringOptions } from 'sass';
|
|
2
2
|
import type { StyleExtractorBuilderSchema } from '../schema';
|
|
3
3
|
import type { CssMetadata, CssVariable } from '@o3r/styling';
|
|
4
|
-
/**
|
|
5
|
-
* This method will iterate on all characters in str and return the substring that is balanced which corresponds to a var declaration.
|
|
6
|
-
* @param str
|
|
7
|
-
*/
|
|
8
|
-
export declare const getVarDeclaration: (str: string) => string | null;
|
|
9
4
|
/**
|
|
10
5
|
* CSS Variable extractor
|
|
11
6
|
*/
|
|
12
7
|
export declare class CssVariableExtractor {
|
|
13
|
-
defaultSassOptions?: StringOptions<"
|
|
8
|
+
defaultSassOptions?: StringOptions<"sync"> | undefined;
|
|
14
9
|
private readonly builderOptions?;
|
|
15
|
-
private static readonly asyncCompiler;
|
|
16
|
-
private static readonly varRegex;
|
|
17
10
|
private readonly cache;
|
|
18
|
-
constructor(defaultSassOptions?: StringOptions<"
|
|
11
|
+
constructor(defaultSassOptions?: StringOptions<"sync"> | undefined, builderOptions?: Pick<StyleExtractorBuilderSchema, "ignoreInvalidValue"> | undefined);
|
|
19
12
|
/**
|
|
20
13
|
* Parse the CSS variable as reported
|
|
21
14
|
* @param name CSS Variable name
|
|
@@ -38,23 +31,18 @@ export declare class CssVariableExtractor {
|
|
|
38
31
|
*/
|
|
39
32
|
private static getPackageName;
|
|
40
33
|
private static extractTags;
|
|
41
|
-
static getCalcString(item: CalculationValue, isSubCalc: boolean): string;
|
|
42
34
|
/**
|
|
43
35
|
* Extract metadata from Sass Content
|
|
44
36
|
* @param sassFilePath SCSS file URL
|
|
45
37
|
* @param sassFileContent SCSS file content
|
|
46
38
|
* @param additionalSassOptions
|
|
47
39
|
*/
|
|
48
|
-
extractFileContent(sassFilePath: string, sassFileContent: string, additionalSassOptions?: StringOptions<'
|
|
49
|
-
/**
|
|
50
|
-
* Dispose the async compiler. Must be called once when extraction is done.
|
|
51
|
-
*/
|
|
52
|
-
disposeAsyncCompiler(): Promise<void>;
|
|
40
|
+
extractFileContent(sassFilePath: string, sassFileContent: string, additionalSassOptions?: StringOptions<'sync'>): CssVariable[];
|
|
53
41
|
/**
|
|
54
42
|
* Extract metadata from Sass file
|
|
55
43
|
* @param sassFilePath SCSS file to parse
|
|
56
44
|
*/
|
|
57
|
-
extractFile(sassFilePath: string):
|
|
45
|
+
extractFile(sassFilePath: string): CssVariable[];
|
|
58
46
|
/**
|
|
59
47
|
* Extract metadata
|
|
60
48
|
* @param libraries List of libraries
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css-variable.extractor.d.ts","sourceRoot":"","sources":["../../../../builders/style-extractor/helpers/css-variable.extractor.ts"],"names":[],"mappings":"AAWA,OAAO,
|
|
1
|
+
{"version":3,"file":"css-variable.extractor.d.ts","sourceRoot":"","sources":["../../../../builders/style-extractor/helpers/css-variable.extractor.ts"],"names":[],"mappings":"AAWA,OAAO,EAQL,aAAa,EAEd,MAAM,MAAM,CAAC;AACd,OAAO,KAAK,EACV,2BAA2B,EAC5B,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EAEZ,MAAM,cAAc,CAAC;AAUtB;;GAEG;AACH,qBAAa,oBAAoB;IAGZ,kBAAkB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC;IAAE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAF/F,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA2B;gBAE9B,kBAAkB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,YAAA,EAAmB,cAAc,CAAC,EAAE,IAAI,CAAC,2BAA2B,EAAE,oBAAoB,CAAC,YAAA;IAExJ;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IA6BxB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAIhC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IAI7B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IAO7B,OAAO,CAAC,MAAM,CAAC,WAAW;IAqB1B;;;;;OAKG;IACI,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,qBAAqB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC;IAgLtH;;;OAGG;IACI,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,WAAW,EAAE;IAKvD;;;;OAIG;IACI,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,WAAW,GAAG,WAAW;CAiBvE"}
|
|
@@ -1,43 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CssVariableExtractor =
|
|
3
|
+
exports.CssVariableExtractor = void 0;
|
|
4
4
|
const fs = require("node:fs");
|
|
5
5
|
const path = require("node:path");
|
|
6
6
|
const node_url_1 = require("node:url");
|
|
7
7
|
const extractors_1 = require("@o3r/extractors");
|
|
8
8
|
const schematics_1 = require("@o3r/schematics");
|
|
9
|
-
const
|
|
10
|
-
/**
|
|
11
|
-
* This method will iterate on all characters in str and return the substring that is balanced which corresponds to a var declaration.
|
|
12
|
-
* @param str
|
|
13
|
-
*/
|
|
14
|
-
const getVarDeclaration = (str) => {
|
|
15
|
-
const varIndex = str.indexOf('var(');
|
|
16
|
-
if (varIndex === -1) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
let nbToClose = 0;
|
|
20
|
-
for (let i = varIndex + 3; i < str.length; i++) {
|
|
21
|
-
const char = str[i];
|
|
22
|
-
if (char === '(') {
|
|
23
|
-
nbToClose++;
|
|
24
|
-
}
|
|
25
|
-
else if (char === ')') {
|
|
26
|
-
nbToClose--;
|
|
27
|
-
if (nbToClose === 0) {
|
|
28
|
-
return str.substring(varIndex, i + 1);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return str.substring(varIndex);
|
|
33
|
-
};
|
|
34
|
-
exports.getVarDeclaration = getVarDeclaration;
|
|
9
|
+
const sass_1 = require("sass");
|
|
35
10
|
/**
|
|
36
11
|
* CSS Variable extractor
|
|
37
12
|
*/
|
|
38
13
|
class CssVariableExtractor {
|
|
39
|
-
static { this.asyncCompiler = (0, sass_embedded_1.initAsyncCompiler)(); }
|
|
40
|
-
static { this.varRegex = /var\(\s*--(.*?)\s*,\s*(.*)\)/; }
|
|
41
14
|
constructor(defaultSassOptions, builderOptions) {
|
|
42
15
|
this.defaultSassOptions = defaultSassOptions;
|
|
43
16
|
this.builderOptions = builderOptions;
|
|
@@ -50,29 +23,30 @@ class CssVariableExtractor {
|
|
|
50
23
|
*/
|
|
51
24
|
parseCssVariable(name, value = '') {
|
|
52
25
|
const defaultValue = value.trim();
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
26
|
+
const res = defaultValue.match(/^var\(\s*([^\s),]+)\s*(?:,\s*([^(),]+(?:\([^)]*\))?))*\s*\)$/);
|
|
27
|
+
const ret = { name, defaultValue };
|
|
28
|
+
if (res) {
|
|
29
|
+
ret.references = [
|
|
30
|
+
this.parseCssVariable(res[1].replace(/^--/, ''), res[2])
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
let findRef = defaultValue;
|
|
35
|
+
let ref;
|
|
36
|
+
const references = {};
|
|
37
|
+
do {
|
|
38
|
+
ref = /var\(\s*([^\s),]+)\s*(?:,\s*([^(),]+(\([^)]*\))?))*\s*\)/.exec(findRef);
|
|
39
|
+
if (ref) {
|
|
40
|
+
const refName = ref[1].replace(/^--/, '');
|
|
41
|
+
references[refName] = this.parseCssVariable(refName, ref[2]);
|
|
42
|
+
findRef = findRef.replace(ref[0], '');
|
|
69
43
|
}
|
|
44
|
+
} while (ref);
|
|
45
|
+
if (Object.keys(references).length > 0) {
|
|
46
|
+
ret.references = Object.values(references);
|
|
70
47
|
}
|
|
71
|
-
} while (referenceMatch);
|
|
72
|
-
if (Object.keys(references).length > 0) {
|
|
73
|
-
resultingCssVariable.references = Object.values(references);
|
|
74
48
|
}
|
|
75
|
-
return
|
|
49
|
+
return ret;
|
|
76
50
|
}
|
|
77
51
|
/**
|
|
78
52
|
* Type predicate for SassCalculation
|
|
@@ -86,9 +60,7 @@ class CssVariableExtractor {
|
|
|
86
60
|
* @param color Sass Color
|
|
87
61
|
*/
|
|
88
62
|
static getColorString(color) {
|
|
89
|
-
return color.alpha
|
|
90
|
-
? `rgb(${color.channel('red')}, ${color.channel('green')}, ${color.channel('blue')})`
|
|
91
|
-
: `rgba(${color.channel('red')}, ${color.channel('green')}, ${color.channel('blue')}, ${color.alpha})`;
|
|
63
|
+
return color.alpha ? `rgba(${color.red}, ${color.green}, ${color.blue}, ${color.alpha})` : `rgb(${color.red}, ${color.green}, ${color.blue}})`;
|
|
92
64
|
}
|
|
93
65
|
/**
|
|
94
66
|
* Returns the package name from an url
|
|
@@ -102,19 +74,19 @@ class CssVariableExtractor {
|
|
|
102
74
|
}
|
|
103
75
|
static extractTags(tags) {
|
|
104
76
|
let contextTags;
|
|
105
|
-
if (tags instanceof
|
|
77
|
+
if (tags instanceof sass_1.SassString) {
|
|
106
78
|
contextTags = [tags.text];
|
|
107
79
|
}
|
|
108
|
-
else if (tags instanceof
|
|
80
|
+
else if (tags instanceof sass_1.SassList) {
|
|
109
81
|
contextTags = [];
|
|
110
82
|
for (let i = 0; i < tags.asList.size; i++) {
|
|
111
83
|
const item = tags.get(i);
|
|
112
|
-
if (item instanceof
|
|
84
|
+
if (item instanceof sass_1.SassString) {
|
|
113
85
|
contextTags.push(item.text);
|
|
114
86
|
}
|
|
115
87
|
}
|
|
116
88
|
}
|
|
117
|
-
else if (tags instanceof
|
|
89
|
+
else if (tags instanceof sass_1.SassMap) {
|
|
118
90
|
const value = tags.contents.toArray().find(([key]) => key.toString() === 'value');
|
|
119
91
|
if (value) {
|
|
120
92
|
contextTags = CssVariableExtractor.extractTags(value[1]);
|
|
@@ -122,30 +94,13 @@ class CssVariableExtractor {
|
|
|
122
94
|
}
|
|
123
95
|
return contextTags;
|
|
124
96
|
}
|
|
125
|
-
static getCalcString(item, isSubCalc) {
|
|
126
|
-
if (item instanceof sass_embedded_1.SassNumber) {
|
|
127
|
-
const value = item.value;
|
|
128
|
-
const unit = item.numeratorUnits.get(0) ?? '';
|
|
129
|
-
return value + unit;
|
|
130
|
-
}
|
|
131
|
-
else if (item instanceof sass_embedded_1.SassString) {
|
|
132
|
-
return item.text;
|
|
133
|
-
}
|
|
134
|
-
else if (item instanceof sass_embedded_1.CalculationOperation) {
|
|
135
|
-
return `${isSubCalc ? '(' : ''}${CssVariableExtractor.getCalcString(item.left, true)} ${item.operator} ${CssVariableExtractor.getCalcString(item.right, true)}${isSubCalc ? ')' : ''}`;
|
|
136
|
-
}
|
|
137
|
-
else if (item instanceof sass_embedded_1.CalculationInterpolation) {
|
|
138
|
-
return item.value;
|
|
139
|
-
}
|
|
140
|
-
return `calc(${item.arguments.toArray().map((arg) => CssVariableExtractor.getCalcString(arg, false)).join(' ')})`;
|
|
141
|
-
}
|
|
142
97
|
/**
|
|
143
98
|
* Extract metadata from Sass Content
|
|
144
99
|
* @param sassFilePath SCSS file URL
|
|
145
100
|
* @param sassFileContent SCSS file content
|
|
146
101
|
* @param additionalSassOptions
|
|
147
102
|
*/
|
|
148
|
-
|
|
103
|
+
extractFileContent(sassFilePath, sassFileContent, additionalSassOptions) {
|
|
149
104
|
const cssVariables = [];
|
|
150
105
|
const options = {
|
|
151
106
|
...this.defaultSassOptions,
|
|
@@ -187,30 +142,30 @@ class CssVariableExtractor {
|
|
|
187
142
|
let category;
|
|
188
143
|
let type;
|
|
189
144
|
if (details) {
|
|
190
|
-
if (details instanceof
|
|
145
|
+
if (details instanceof sass_1.SassMap) {
|
|
191
146
|
for (const [key, value] of details.contents.toArray()) {
|
|
192
|
-
if (key instanceof
|
|
147
|
+
if (key instanceof sass_1.SassString) {
|
|
193
148
|
switch (key.text) {
|
|
194
149
|
case 'description': {
|
|
195
|
-
if (value instanceof
|
|
150
|
+
if (value instanceof sass_1.SassString) {
|
|
196
151
|
description = value.text;
|
|
197
152
|
}
|
|
198
153
|
break;
|
|
199
154
|
}
|
|
200
155
|
case 'label': {
|
|
201
|
-
if (value instanceof
|
|
156
|
+
if (value instanceof sass_1.SassString) {
|
|
202
157
|
label = value.text;
|
|
203
158
|
}
|
|
204
159
|
break;
|
|
205
160
|
}
|
|
206
161
|
case 'type': {
|
|
207
|
-
if (value instanceof
|
|
162
|
+
if (value instanceof sass_1.SassString) {
|
|
208
163
|
type = value.text;
|
|
209
164
|
}
|
|
210
165
|
break;
|
|
211
166
|
}
|
|
212
167
|
case 'category': {
|
|
213
|
-
if (value instanceof
|
|
168
|
+
if (value instanceof sass_1.SassString) {
|
|
214
169
|
category = value.text;
|
|
215
170
|
}
|
|
216
171
|
break;
|
|
@@ -232,32 +187,29 @@ class CssVariableExtractor {
|
|
|
232
187
|
contextTags = CssVariableExtractor.extractTags(details);
|
|
233
188
|
}
|
|
234
189
|
}
|
|
190
|
+
if (!(varName instanceof sass_1.SassString)) {
|
|
191
|
+
throw new schematics_1.O3rCliError('Invalid variable name');
|
|
192
|
+
}
|
|
235
193
|
let parsedValue;
|
|
236
|
-
if (varValue instanceof
|
|
194
|
+
if (varValue instanceof sass_1.SassString || varValue instanceof sass_1.SassNumber || varValue instanceof sass_1.SassBoolean) {
|
|
237
195
|
parsedValue = varValue.toString();
|
|
238
196
|
}
|
|
239
|
-
else if (varValue
|
|
240
|
-
parsedValue = `${varValue.isTruthy}`;
|
|
241
|
-
}
|
|
242
|
-
else if (varValue instanceof sass_embedded_1.SassColor) {
|
|
197
|
+
else if (varValue instanceof sass_1.SassColor) {
|
|
243
198
|
parsedValue = CssVariableExtractor.getColorString(varValue);
|
|
244
199
|
}
|
|
245
|
-
else if (varValue instanceof
|
|
200
|
+
else if (varValue instanceof sass_1.SassList) {
|
|
246
201
|
const invalidIndexes = [];
|
|
247
202
|
const parsedValueItems = [];
|
|
248
203
|
for (let i = 0; i < varValue.asList.size; i++) {
|
|
249
204
|
const item = varValue.get(i);
|
|
250
|
-
if (item instanceof
|
|
205
|
+
if (item instanceof sass_1.SassString || item instanceof sass_1.SassNumber || item instanceof sass_1.SassBoolean) {
|
|
251
206
|
parsedValueItems.push(item.toString());
|
|
252
207
|
}
|
|
253
|
-
else if (item
|
|
254
|
-
parsedValueItems.push(`${item.isTruthy}`);
|
|
255
|
-
}
|
|
256
|
-
else if (item instanceof sass_embedded_1.SassColor) {
|
|
208
|
+
else if (item instanceof sass_1.SassColor) {
|
|
257
209
|
parsedValueItems.push(CssVariableExtractor.getColorString(item));
|
|
258
210
|
}
|
|
259
211
|
else if (CssVariableExtractor.isSassCalculation(item)) {
|
|
260
|
-
parsedValueItems.push(`calc(${item
|
|
212
|
+
parsedValueItems.push(`calc(${item.$arguments[0]})`);
|
|
261
213
|
}
|
|
262
214
|
else {
|
|
263
215
|
invalidIndexes.push(i);
|
|
@@ -276,14 +228,14 @@ class CssVariableExtractor {
|
|
|
276
228
|
}
|
|
277
229
|
}
|
|
278
230
|
else if (CssVariableExtractor.isSassCalculation(varValue)) {
|
|
279
|
-
parsedValue = `calc(${varValue
|
|
231
|
+
parsedValue = `calc(${varValue.$arguments[0]})`;
|
|
280
232
|
}
|
|
281
233
|
else if (varValue.realNull) {
|
|
282
234
|
const message = `Invalid value for variable ${varName.text}.`;
|
|
283
235
|
if (this.builderOptions?.ignoreInvalidValue ?? true) {
|
|
284
236
|
// eslint-disable-next-line no-console -- no other logger available
|
|
285
237
|
console.warn(`${message} It will be ignored.`);
|
|
286
|
-
return new
|
|
238
|
+
return new sass_1.SassString(`[METADATA:VARIABLE] ${varName.text} : invalid value`);
|
|
287
239
|
}
|
|
288
240
|
else {
|
|
289
241
|
throw new schematics_1.O3rCliError(message);
|
|
@@ -293,7 +245,7 @@ class CssVariableExtractor {
|
|
|
293
245
|
if (!details) {
|
|
294
246
|
// eslint-disable-next-line no-console -- no other logger available
|
|
295
247
|
console.warn(`The value "null" of ${varName.text} is available only for details override`);
|
|
296
|
-
return new
|
|
248
|
+
return new sass_1.SassString(`[METADATA:VARIABLE] ${varName.text} : invalid Null value`);
|
|
297
249
|
}
|
|
298
250
|
}
|
|
299
251
|
const cssVariableObj = this.parseCssVariable(varName.text, parsedValue);
|
|
@@ -311,34 +263,28 @@ class CssVariableExtractor {
|
|
|
311
263
|
...cssVariables[cssVariableIndex],
|
|
312
264
|
...cssVariableDetails
|
|
313
265
|
};
|
|
314
|
-
return new
|
|
266
|
+
return new sass_1.SassString(`[METADATA:VARIABLE] update ${varName.text} details` + (contextTags ? ` (tags: ${contextTags.join(', ')})` : ''));
|
|
315
267
|
}
|
|
316
|
-
return new
|
|
268
|
+
return new sass_1.SassString(`[METADATA:VARIABLE] ${varName.text} : Failed to update details of undefined variable`);
|
|
317
269
|
}
|
|
318
270
|
cssVariables.push({
|
|
319
271
|
...cssVariableObj,
|
|
320
272
|
...cssVariableDetails
|
|
321
273
|
});
|
|
322
|
-
return new
|
|
274
|
+
return new sass_1.SassString(`[METADATA:VARIABLE] ${varName.text} : ${parsedValue}` + (contextTags ? ` (tags: ${contextTags.join(', ')})` : ''));
|
|
323
275
|
}
|
|
324
276
|
}
|
|
325
277
|
};
|
|
326
|
-
|
|
278
|
+
(0, sass_1.compileString)(sassFileContent, options);
|
|
327
279
|
return cssVariables;
|
|
328
280
|
}
|
|
329
|
-
/**
|
|
330
|
-
* Dispose the async compiler. Must be called once when extraction is done.
|
|
331
|
-
*/
|
|
332
|
-
async disposeAsyncCompiler() {
|
|
333
|
-
await (await CssVariableExtractor.asyncCompiler).dispose();
|
|
334
|
-
}
|
|
335
281
|
/**
|
|
336
282
|
* Extract metadata from Sass file
|
|
337
283
|
* @param sassFilePath SCSS file to parse
|
|
338
284
|
*/
|
|
339
|
-
|
|
285
|
+
extractFile(sassFilePath) {
|
|
340
286
|
const sassFileContent = fs.readFileSync(sassFilePath, { encoding: 'utf8' });
|
|
341
|
-
return
|
|
287
|
+
return this.extractFileContent(sassFilePath, sassFileContent);
|
|
342
288
|
}
|
|
343
289
|
/**
|
|
344
290
|
* Extract metadata
|
|
@@ -349,7 +295,10 @@ class CssVariableExtractor {
|
|
|
349
295
|
return libraries
|
|
350
296
|
.map((lib) => (0, extractors_1.getLibraryCmsMetadata)(lib))
|
|
351
297
|
.filter(({ styleFilePath }) => !!styleFilePath)
|
|
352
|
-
.map(({ styleFilePath }) =>
|
|
298
|
+
.map(({ styleFilePath }) => {
|
|
299
|
+
const libConfig = JSON.parse(fs.readFileSync(styleFilePath, 'utf8'));
|
|
300
|
+
return libConfig;
|
|
301
|
+
})
|
|
353
302
|
.reduce((acc, libMetadata) => {
|
|
354
303
|
return Object.keys(libMetadata.variables)
|
|
355
304
|
.filter((key) => !!acc.variables[key])
|
|
@@ -46,10 +46,10 @@ exports.default = (0, architect_1.createBuilder)((0, extractors_1.createBuilderW
|
|
|
46
46
|
/** CSS Metadata file to write */
|
|
47
47
|
let cssMetadata = (
|
|
48
48
|
// extract metadata for each file
|
|
49
|
-
await Promise.all(files.map(
|
|
49
|
+
await Promise.all(files.map((file, idx) => {
|
|
50
50
|
try {
|
|
51
51
|
context.reportProgress(idx, STEP_NUMBER, `Extracting ${file}`);
|
|
52
|
-
const variables =
|
|
52
|
+
const variables = cssVariableExtractor.extractFile(file);
|
|
53
53
|
const themeFileSuffix = '.style.theme.scss';
|
|
54
54
|
if (file.endsWith(themeFileSuffix)) {
|
|
55
55
|
const componentPath = path.join(path.dirname(file), `${path.basename(file, themeFileSuffix)}.component.ts`);
|
|
@@ -57,10 +57,7 @@ exports.default = (0, architect_1.createBuilder)((0, extractors_1.createBuilderW
|
|
|
57
57
|
const componentDeclaration = componentSourceFile.statements.find((s) => ts.isClassDeclaration(s) && (0, schematics_1.isO3rClassComponent)(s));
|
|
58
58
|
const componentName = componentDeclaration?.name?.escapedText.toString();
|
|
59
59
|
if (componentName) {
|
|
60
|
-
|
|
61
|
-
variable.component = { library: libraryName, name: componentName };
|
|
62
|
-
}
|
|
63
|
-
return variables;
|
|
60
|
+
return variables.map((variable) => ({ ...variable, component: { library: libraryName, name: componentName } }));
|
|
64
61
|
}
|
|
65
62
|
}
|
|
66
63
|
return variables;
|
|
@@ -70,12 +67,16 @@ exports.default = (0, architect_1.createBuilder)((0, extractors_1.createBuilderW
|
|
|
70
67
|
return [];
|
|
71
68
|
}
|
|
72
69
|
}))).reduce((acc, cssVarList) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
acc.variables[cssVar.name]
|
|
78
|
-
|
|
70
|
+
// Check duplicate CSS variable
|
|
71
|
+
cssVarList
|
|
72
|
+
.filter((cssVar) => !!acc.variables[cssVar.name])
|
|
73
|
+
.filter((cssVar) => !initialPreviousMetadata.variables[cssVar.name] && acc.variables[cssVar.name].defaultValue !== cssVar.defaultValue)
|
|
74
|
+
.forEach((cssVar) => context.logger[options.ignoreDuplicateWarning ? 'debug' : 'warn'](`Duplicate "${cssVar.name}" (${acc.variables[cssVar.name].defaultValue} will be replaced by ${cssVar.defaultValue})`));
|
|
75
|
+
// merge all variables form all the files
|
|
76
|
+
cssVarList
|
|
77
|
+
.forEach((item) => {
|
|
78
|
+
acc.variables[item.name] = item;
|
|
79
|
+
});
|
|
79
80
|
return acc;
|
|
80
81
|
}, initialPreviousMetadata);
|
|
81
82
|
// exit on failure
|
|
@@ -181,7 +182,6 @@ exports.default = (0, architect_1.createBuilder)((0, extractors_1.createBuilderW
|
|
|
181
182
|
}
|
|
182
183
|
});
|
|
183
184
|
context.addTeardown(async () => {
|
|
184
|
-
await cssVariableExtractor.disposeAsyncCompiler();
|
|
185
185
|
await watcher.close();
|
|
186
186
|
await metadataWatcher.close();
|
|
187
187
|
});
|
|
@@ -191,9 +191,7 @@ exports.default = (0, architect_1.createBuilder)((0, extractors_1.createBuilderW
|
|
|
191
191
|
.on('error', (err) => reject(err)));
|
|
192
192
|
}
|
|
193
193
|
else {
|
|
194
|
-
|
|
195
|
-
void cssVariableExtractor.disposeAsyncCompiler();
|
|
196
|
-
return result;
|
|
194
|
+
return execute(getAllFiles());
|
|
197
195
|
}
|
|
198
196
|
}));
|
|
199
197
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@o3r/styling",
|
|
3
|
-
"version": "12.1.0-prerelease.
|
|
3
|
+
"version": "12.1.0-prerelease.3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"@angular/common": "^19.0.0",
|
|
39
39
|
"@angular/core": "^19.0.0",
|
|
40
40
|
"@angular/material": "^19.0.0",
|
|
41
|
-
"@o3r/core": "^12.1.0-prerelease.
|
|
42
|
-
"@o3r/dynamic-content": "^12.1.0-prerelease.
|
|
43
|
-
"@o3r/extractors": "^12.1.0-prerelease.
|
|
44
|
-
"@o3r/logger": "^12.1.0-prerelease.
|
|
45
|
-
"@o3r/schematics": "^12.1.0-prerelease.
|
|
41
|
+
"@o3r/core": "^12.1.0-prerelease.3",
|
|
42
|
+
"@o3r/dynamic-content": "^12.1.0-prerelease.3",
|
|
43
|
+
"@o3r/extractors": "^12.1.0-prerelease.3",
|
|
44
|
+
"@o3r/logger": "^12.1.0-prerelease.3",
|
|
45
|
+
"@o3r/schematics": "^12.1.0-prerelease.3",
|
|
46
46
|
"@schematics/angular": "^19.0.0",
|
|
47
47
|
"@yarnpkg/cli": "^4.3.1",
|
|
48
48
|
"@yarnpkg/core": "^4.1.1",
|
|
@@ -53,7 +53,6 @@
|
|
|
53
53
|
"globby": "^11.1.0",
|
|
54
54
|
"rxjs": "^7.8.1",
|
|
55
55
|
"sass": "^1.81.0",
|
|
56
|
-
"sass-embedded": "^1.81.0",
|
|
57
56
|
"semver": "^7.5.2",
|
|
58
57
|
"ts-node": "~10.9.2",
|
|
59
58
|
"typescript": "^5.5.4"
|
|
@@ -116,9 +115,6 @@
|
|
|
116
115
|
"sass": {
|
|
117
116
|
"optional": true
|
|
118
117
|
},
|
|
119
|
-
"sass-embedded": {
|
|
120
|
-
"optional": true
|
|
121
|
-
},
|
|
122
118
|
"semver": {
|
|
123
119
|
"optional": true
|
|
124
120
|
},
|