@ethlete/cdk 5.0.0-next.5 → 5.0.0-next.50
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/CHANGELOG.md +373 -30
- package/fesm2022/ethlete-cdk.mjs +29295 -18544
- package/fesm2022/ethlete-cdk.mjs.map +1 -1
- package/generators/generators.json +5 -0
- package/generators/migrate-from-cdk/components-classes.js +1170 -0
- package/generators/migrate-from-cdk/imports.js +250 -0
- package/generators/migrate-from-cdk/installed-version.js +86 -0
- package/generators/migrate-from-cdk/migration-map.js +21 -0
- package/generators/migrate-from-cdk/migration-scope.js +30 -0
- package/generators/migrate-from-cdk/migration.js +151 -0
- package/generators/migrate-from-cdk/report.js +401 -0
- package/generators/migrate-from-cdk/schema.json +30 -0
- package/generators/migrate-from-cdk/templates.js +91 -0
- package/generators/migrate-to-v5/cdk-menu.js +3 -8
- package/generators/migrate-to-v5/color-themes.js +110 -6
- package/generators/migrate-to-v5/dialog-bottom-sheet.js +0 -2
- package/generators/migrate-to-v5/et-let.js +2 -2
- package/generators/migrate-to-v5/overlay-positions.js +4 -44
- package/migration-map.json +3611 -0
- package/migrations/from-cdk-decisions.md +41 -0
- package/migrations.json +31 -0
- package/package.json +35 -19
- package/types/ethlete-cdk.d.ts +12592 -8700
|
@@ -1,8 +1,45 @@
|
|
|
1
1
|
import { logger, readJson, visitNotIgnoredFiles, writeJson } from '@nx/devkit';
|
|
2
|
+
const TEMPLATE_REPLACEMENTS = [
|
|
3
|
+
['[etProvideTheme]', '[etProvideColor]'],
|
|
4
|
+
['etProvideTheme', 'etProvideColor'],
|
|
5
|
+
['[etProvideAltTheme]', '[etProvideAltColor]'],
|
|
6
|
+
['etProvideAltTheme', 'etProvideAltColor'],
|
|
7
|
+
['[etColorThemed]', '[etColored]'],
|
|
8
|
+
['etColorThemed', 'etColored'],
|
|
9
|
+
['[etSurfaceThemed]', '[etSurfaced]'],
|
|
10
|
+
['etSurfaceThemed', 'etSurfaced'],
|
|
11
|
+
['et-theme-alt--', 'et-color-alt--'],
|
|
12
|
+
['et-theme--', 'et-color--'],
|
|
13
|
+
];
|
|
14
|
+
const SDK_COLOR_INPUT_HOST_ATTRIBUTES = new Set(['et-button', 'et-fab', 'et-icon-button', 'et-text-button']);
|
|
15
|
+
const SDK_COLOR_INPUT_RENAMES = new Map([
|
|
16
|
+
['theme', 'color'],
|
|
17
|
+
['[theme]', '[color]'],
|
|
18
|
+
['altTheme', 'altColor'],
|
|
19
|
+
['[altTheme]', '[altColor]'],
|
|
20
|
+
]);
|
|
21
|
+
const START_TAG_PATTERN = /<([a-zA-Z][\w.:-]*)((?:\s+[^\s"'>/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)*)(\s*\/?>)/g;
|
|
22
|
+
const ATTRIBUTE_PATTERN = /(\s+)([^\s"'>/=]+)((?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)/g;
|
|
23
|
+
const renameSdkColorInputs = (text) => text.replace(START_TAG_PATTERN, (tag, name, attributes, end) => {
|
|
24
|
+
const names = [...attributes.matchAll(ATTRIBUTE_PATTERN)].map((match) => match[2] ?? '');
|
|
25
|
+
if (!names.some((attribute) => SDK_COLOR_INPUT_HOST_ATTRIBUTES.has(attribute))) {
|
|
26
|
+
return tag;
|
|
27
|
+
}
|
|
28
|
+
const renamed = attributes.replace(ATTRIBUTE_PATTERN, (_match, space, attribute, value) => `${space}${SDK_COLOR_INPUT_RENAMES.get(attribute) ?? attribute}${value}`);
|
|
29
|
+
return `<${name}${renamed}${end}`;
|
|
30
|
+
});
|
|
31
|
+
const CSS_REPLACEMENTS = [
|
|
32
|
+
['.et-color-themed', '.et-colored'],
|
|
33
|
+
['.et-surface-themed', '.et-surfaced'],
|
|
34
|
+
['.et-theme--', '.et-color--'],
|
|
35
|
+
['.et-theme-alt--', '.et-color-alt--'],
|
|
36
|
+
];
|
|
2
37
|
// Theming-related exports that moved from @ethlete/theming and @ethlete/cdk to @ethlete/core
|
|
3
38
|
const THEMING_EXPORTS = new Set([
|
|
4
39
|
'ProvideThemeDirective',
|
|
40
|
+
'ProvideColorDirective',
|
|
5
41
|
'THEME_PROVIDER',
|
|
42
|
+
'COLOR_PROVIDER',
|
|
6
43
|
'Theme',
|
|
7
44
|
'ThemeSwatch',
|
|
8
45
|
'OnThemeColorMap',
|
|
@@ -20,6 +57,45 @@ export default async function migrateColorThemes(tree) {
|
|
|
20
57
|
let importsMoved = 0;
|
|
21
58
|
let importsMerged = 0;
|
|
22
59
|
let packagesRemoved = 0;
|
|
60
|
+
// Migrate HTML template files
|
|
61
|
+
visitNotIgnoredFiles(tree, '', (filePath) => {
|
|
62
|
+
if (!filePath.endsWith('.html')) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const content = tree.read(filePath, 'utf-8');
|
|
66
|
+
if (!content) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
let modified = content;
|
|
70
|
+
for (const [oldStr, newStr] of TEMPLATE_REPLACEMENTS) {
|
|
71
|
+
modified = modified.replaceAll(oldStr, newStr);
|
|
72
|
+
}
|
|
73
|
+
modified = renameSdkColorInputs(modified);
|
|
74
|
+
if (modified !== content) {
|
|
75
|
+
tree.write(filePath, modified);
|
|
76
|
+
filesModified++;
|
|
77
|
+
console.log(` ✓ ${filePath}`);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
// Migrate CSS/SCSS files
|
|
81
|
+
visitNotIgnoredFiles(tree, '', (filePath) => {
|
|
82
|
+
if (!filePath.endsWith('.css') && !filePath.endsWith('.scss')) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const content = tree.read(filePath, 'utf-8');
|
|
86
|
+
if (!content) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
let modified = content;
|
|
90
|
+
for (const [oldStr, newStr] of CSS_REPLACEMENTS) {
|
|
91
|
+
modified = modified.replaceAll(oldStr, newStr);
|
|
92
|
+
}
|
|
93
|
+
if (modified !== content) {
|
|
94
|
+
tree.write(filePath, modified);
|
|
95
|
+
filesModified++;
|
|
96
|
+
console.log(` ✓ ${filePath}`);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
23
99
|
// Migrate TypeScript files
|
|
24
100
|
visitNotIgnoredFiles(tree, '', (filePath) => {
|
|
25
101
|
if (!filePath.endsWith('.ts')) {
|
|
@@ -29,14 +105,44 @@ export default async function migrateColorThemes(tree) {
|
|
|
29
105
|
if (!content) {
|
|
30
106
|
return;
|
|
31
107
|
}
|
|
32
|
-
// Check if file contains provideThemes or imports from @ethlete/theming or @ethlete/cdk
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
108
|
+
// Check if file contains provideThemes or imports from @ethlete/theming or @ethlete/cdk,
|
|
109
|
+
// or any template/CSS strings that need replacing
|
|
110
|
+
const needsImportMigration = content.includes('provideThemes') || content.includes('@ethlete/theming') || content.includes('@ethlete/cdk');
|
|
111
|
+
const needsTemplateMigration = TEMPLATE_REPLACEMENTS.some(([oldStr]) => content.includes(oldStr));
|
|
112
|
+
const needsCssMigration = CSS_REPLACEMENTS.some(([oldStr]) => content.includes(oldStr));
|
|
113
|
+
const needsSdkColorInputMigration = renameSdkColorInputs(content) !== content;
|
|
114
|
+
if (!needsImportMigration && !needsTemplateMigration && !needsCssMigration && !needsSdkColorInputMigration) {
|
|
36
115
|
return;
|
|
37
116
|
}
|
|
38
117
|
let modified = content;
|
|
39
118
|
let fileChanges = 0;
|
|
119
|
+
// Apply template replacements (covers inline templates and class usages)
|
|
120
|
+
if (needsTemplateMigration) {
|
|
121
|
+
for (const [oldStr, newStr] of TEMPLATE_REPLACEMENTS) {
|
|
122
|
+
modified = modified.replaceAll(oldStr, newStr);
|
|
123
|
+
}
|
|
124
|
+
fileChanges++;
|
|
125
|
+
}
|
|
126
|
+
const withSdkColorInputs = renameSdkColorInputs(modified);
|
|
127
|
+
if (withSdkColorInputs !== modified) {
|
|
128
|
+
modified = withSdkColorInputs;
|
|
129
|
+
fileChanges++;
|
|
130
|
+
}
|
|
131
|
+
// Apply CSS replacements (covers inline styles)
|
|
132
|
+
if (needsCssMigration) {
|
|
133
|
+
for (const [oldStr, newStr] of CSS_REPLACEMENTS) {
|
|
134
|
+
modified = modified.replaceAll(oldStr, newStr);
|
|
135
|
+
}
|
|
136
|
+
fileChanges++;
|
|
137
|
+
}
|
|
138
|
+
if (!needsImportMigration) {
|
|
139
|
+
if (modified !== content) {
|
|
140
|
+
tree.write(filePath, modified);
|
|
141
|
+
filesModified++;
|
|
142
|
+
console.log(` ✓ ${filePath} (${fileChanges} change${fileChanges !== 1 ? 's' : ''})`);
|
|
143
|
+
}
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
40
146
|
// Replace provideThemes with provideColorThemes
|
|
41
147
|
const beforeProvideThemesCount = (modified.match(/\bprovideThemes\b/g) || []).length;
|
|
42
148
|
modified = modified.replace(/\bprovideThemes\b/g, 'provideColorThemes');
|
|
@@ -69,8 +175,6 @@ export default async function migrateColorThemes(tree) {
|
|
|
69
175
|
imports.forEach((imp) => {
|
|
70
176
|
// Extract the actual import name (without 'type' keyword and alias)
|
|
71
177
|
// Handle patterns like: "type Theme as EthleteTheme", "Theme", "type Theme"
|
|
72
|
-
const typeKeywordMatch = imp.match(/^type\s+/);
|
|
73
|
-
const hasTypeKeyword = !!typeKeywordMatch;
|
|
74
178
|
const withoutType = imp.replace(/^type\s+/, '').trim();
|
|
75
179
|
const importName = withoutType.split(/\s+as\s+/)[0]?.trim() || withoutType;
|
|
76
180
|
if (THEMING_EXPORTS.has(importName)) {
|
|
@@ -327,14 +327,14 @@ export function migrateEtLet(tree) {
|
|
|
327
327
|
if (variable !== originalVariable) {
|
|
328
328
|
// Pattern 1: Attribute values - match the full pattern [attr]="value"
|
|
329
329
|
// and only replace the variable in the value part, never in attribute names
|
|
330
|
-
innerContent = innerContent.replace(/\[([^\]]+)\]="([^"]*)"/g, (
|
|
330
|
+
innerContent = innerContent.replace(/\[([^\]]+)\]="([^"]*)"/g, (_match, attrName, attrValue) => {
|
|
331
331
|
// Don't rename the attribute name, only references in the value
|
|
332
332
|
const pattern = new RegExp(`\\b${originalVariable}\\b`, 'g');
|
|
333
333
|
const newValue = attrValue.replace(pattern, variable);
|
|
334
334
|
return `[${attrName}]="${newValue}"`;
|
|
335
335
|
});
|
|
336
336
|
// Pattern 2: Event bindings like (click)="method(variable)"
|
|
337
|
-
innerContent = innerContent.replace(/\(([^)]+)\)="([^"]*)"/g, (
|
|
337
|
+
innerContent = innerContent.replace(/\(([^)]+)\)="([^"]*)"/g, (_match, eventName, eventHandler) => {
|
|
338
338
|
const pattern = new RegExp(`\\b${originalVariable}\\b`, 'g');
|
|
339
339
|
const newHandler = eventHandler.replace(pattern, variable);
|
|
340
340
|
return `(${eventName})="${newHandler}"`;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
1
|
import { formatFiles, getProjects, logger, visitNotIgnoredFiles } from '@nx/devkit';
|
|
3
2
|
import * as ts from 'typescript';
|
|
4
3
|
const STRATEGY_MAP = {
|
|
@@ -201,7 +200,7 @@ function processFile(filePath, content) {
|
|
|
201
200
|
bodyCode = func.body.getText(sourceFile);
|
|
202
201
|
}
|
|
203
202
|
// Transform the body - replace builder.DEFAULTS.X with strategy calls
|
|
204
|
-
const { code: transformedBody, usesMergeConfigs, strategiesUsed, } = transformBuilderBodyForDefaults(bodyCode, builderParamName
|
|
203
|
+
const { code: transformedBody, usesMergeConfigs, strategiesUsed, } = transformBuilderBodyForDefaults(bodyCode, builderParamName);
|
|
205
204
|
if (usesMergeConfigs) {
|
|
206
205
|
importsToAdd.add('mergeOverlayBreakpointConfigs');
|
|
207
206
|
}
|
|
@@ -482,7 +481,7 @@ function transformNodeTextForDefaults(node, sourceFile) {
|
|
|
482
481
|
text = text.replace(defaultsPattern, `${varName}.build()`);
|
|
483
482
|
});
|
|
484
483
|
// Now handle mergeConfigs - do this AFTER replacing DEFAULTS
|
|
485
|
-
Object.entries(STRATEGY_INJECT_MAP).forEach(([
|
|
484
|
+
Object.entries(STRATEGY_INJECT_MAP).forEach(([_strategyName, injectFn]) => {
|
|
486
485
|
const varName = getStrategyVariableName(injectFn);
|
|
487
486
|
// Pattern: overlayService.positions.mergeConfigs(dialogStrategy.build(), ...args)
|
|
488
487
|
// We want to extract just the args after the first argument and comma
|
|
@@ -608,14 +607,6 @@ function updateImportsInContent(content, importsToAdd, importsToRemove) {
|
|
|
608
607
|
return content.replace(importRegex, newImportStatement);
|
|
609
608
|
}
|
|
610
609
|
// Type guards
|
|
611
|
-
function isInjectOverlayServiceCall(node) {
|
|
612
|
-
return (ts.isCallExpression(node) &&
|
|
613
|
-
ts.isIdentifier(node.expression) &&
|
|
614
|
-
node.expression.text === 'inject' &&
|
|
615
|
-
node.arguments.length === 1 &&
|
|
616
|
-
ts.isIdentifier(node.arguments[0]) &&
|
|
617
|
-
node.arguments[0].text === 'OverlayService');
|
|
618
|
-
}
|
|
619
610
|
function isPositionMethodCall(node) {
|
|
620
611
|
return (ts.isCallExpression(node) &&
|
|
621
612
|
ts.isPropertyAccessExpression(node.expression) &&
|
|
@@ -627,37 +618,6 @@ function isOverlayBreakpointConfigEntryType(node) {
|
|
|
627
618
|
ts.isIdentifier(node.typeName) &&
|
|
628
619
|
node.typeName.text === 'OverlayBreakpointConfigEntry');
|
|
629
620
|
}
|
|
630
|
-
// Helper functions
|
|
631
|
-
function checkIfOverlayRelated(node) {
|
|
632
|
-
// First check: Are we inside createOverlayHandler call?
|
|
633
|
-
if (isInsideOverlayHandlerCall(node)) {
|
|
634
|
-
return true;
|
|
635
|
-
}
|
|
636
|
-
// Check for overlay-related patterns that need migration using AST
|
|
637
|
-
let isOverlayRelated = false;
|
|
638
|
-
function visit(n) {
|
|
639
|
-
if (isOverlayRelated)
|
|
640
|
-
return;
|
|
641
|
-
if (isPositionMethodCall(n)) {
|
|
642
|
-
isOverlayRelated = true;
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
if (isDefaultsUsage(n)) {
|
|
646
|
-
isOverlayRelated = true;
|
|
647
|
-
return;
|
|
648
|
-
}
|
|
649
|
-
if (ts.isCallExpression(n)) {
|
|
650
|
-
const callText = n.getText();
|
|
651
|
-
if (callText.includes('getConfig') || callText.includes('getPositions') || callText.includes('getStrategies')) {
|
|
652
|
-
isOverlayRelated = true;
|
|
653
|
-
return;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
ts.forEachChild(n, visit);
|
|
657
|
-
}
|
|
658
|
-
visit(node);
|
|
659
|
-
return isOverlayRelated;
|
|
660
|
-
}
|
|
661
621
|
function isDefaultsUsage(node) {
|
|
662
622
|
return (ts.isPropertyAccessExpression(node) &&
|
|
663
623
|
ts.isPropertyAccessExpression(node.expression) &&
|
|
@@ -760,7 +720,7 @@ function isInsideOverlayHandlerCall(node) {
|
|
|
760
720
|
}
|
|
761
721
|
return false;
|
|
762
722
|
}
|
|
763
|
-
function transformBuilderBodyForDefaults(bodyCode, builderParamName
|
|
723
|
+
function transformBuilderBodyForDefaults(bodyCode, builderParamName) {
|
|
764
724
|
let code = bodyCode;
|
|
765
725
|
let usesMergeConfigs = false;
|
|
766
726
|
const strategiesUsed = new Set();
|
|
@@ -780,7 +740,7 @@ function transformBuilderBodyForDefaults(bodyCode, builderParamName, sourceFile)
|
|
|
780
740
|
}
|
|
781
741
|
});
|
|
782
742
|
// Replace builder.mergeConfigs(Xstrategy.build(), ...args) with Xstrategy.build(mergeOverlayBreakpointConfigs(...args))
|
|
783
|
-
Object.entries(STRATEGY_INJECT_MAP).forEach(([
|
|
743
|
+
Object.entries(STRATEGY_INJECT_MAP).forEach(([_strategyName, injectFn]) => {
|
|
784
744
|
const varName = getStrategyVariableName(injectFn);
|
|
785
745
|
// Pattern: builder.mergeConfigs(dialogStrategy.build(), {...})
|
|
786
746
|
const pattern = new RegExp(`${builderParamName}\\.mergeConfigs\\(\\s*${varName}\\.build\\(\\)\\s*,\\s*`, 'g');
|