devextreme-schematics 1.11.2 → 1.12.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.
@@ -0,0 +1,80 @@
1
+ import { Rule, Tree, SchematicContext } from '@angular-devkit/schematics';
2
+ import type { HostRule } from './template-migrator';
3
+ import { applyHostAwareTemplateMigrations, applyInlineComponentTemplateMigrations } from './template-migrator';
4
+ import mapping from './mappings/deprecated-config-map.json';
5
+
6
+ export interface Options {
7
+ include?: string[];
8
+ dry?: boolean;
9
+ scriptInclude?: string[];
10
+ }
11
+
12
+ export function migrateConfigComponents(options: Options = {}): Rule {
13
+ // Accept --include as array or comma-separated string
14
+ let include: string[] = ['**/*.html'];
15
+ const rawInclude = options.include;
16
+ if (Array.isArray(rawInclude) && rawInclude.length) {
17
+ include = rawInclude;
18
+ } else if (typeof rawInclude === 'string' && rawInclude) {
19
+ let str = (rawInclude as string).trim();
20
+ if (str.startsWith('[') && str.endsWith(']')) {
21
+ str = str.slice(1, -1);
22
+ }
23
+ include = str.split(',').map((s: string) => s.trim()).filter((s: string) => !!s);
24
+ }
25
+
26
+ // Coerce string 'true'/'false' to boolean for dry option
27
+ let dryFlag: boolean = false;
28
+ if (typeof options.dry === 'string') {
29
+ dryFlag = options.dry === 'true';
30
+ } else {
31
+ dryFlag = !!options.dry;
32
+ }
33
+
34
+ // Accept --script-include as array or comma-separated string
35
+ let scriptGlobs: string[] = ['**/*.ts', '**/*.js'];
36
+ const rawScriptInclude = options.scriptInclude;
37
+ if (Array.isArray(rawScriptInclude) && rawScriptInclude.length) {
38
+ scriptGlobs = rawScriptInclude;
39
+ } else if (typeof rawScriptInclude === 'string' && rawScriptInclude) {
40
+ let str = (rawScriptInclude as string).trim();
41
+ if (str.startsWith('[') && str.endsWith(']')) {
42
+ str = str.slice(1, -1);
43
+ }
44
+ scriptGlobs = str.split(',').map((s: string) => s.trim()).filter((s: string) => !!s);
45
+ }
46
+
47
+ return async (tree: Tree, ctx: SchematicContext): Promise<void> => {
48
+ ctx.logger.info(`[config-migrator] Starting…`);
49
+
50
+ type HostMap = Record<string, { _hostSelector?: string } & Record<string, string>>;
51
+ const hostMap = mapping as unknown as HostMap;
52
+
53
+ const processedMapping = Object.entries(hostMap).map(([hostComponentName, map]) => {
54
+ const hostSelector = map._hostSelector ?? componentToSelectorGuess(hostComponentName);
55
+ const configMap: Record<string, string> = Object.fromEntries(
56
+ Object.entries(map).filter(([k]) => k !== '_hostSelector')
57
+ );
58
+ return { hostSelector, configMap };
59
+ }) as HostRule[];
60
+
61
+ // External HTML templates
62
+ await applyHostAwareTemplateMigrations(tree, {
63
+ includeGlobs: include,
64
+ rules: processedMapping
65
+ }, { dryRun: dryFlag, logger: ctx.logger });
66
+
67
+ // Inline templates inside component decorators (ts/js)
68
+ await applyInlineComponentTemplateMigrations(tree, {
69
+ includeGlobs: [], rules: processedMapping
70
+ }, { dryRun: dryFlag, logger: ctx.logger }, scriptGlobs);
71
+
72
+ ctx.logger.info(`[config-migrator] Done.`);
73
+ };
74
+ }
75
+
76
+ // Fallback if _hostSelector is missing: "DxFooBarComponent" -> "dx-foo-bar"
77
+ function componentToSelectorGuess(componentName: string): string {
78
+ const core = componentName.replace(/Component$/, '').replace(/^Dx/, 'dx-');
79
+ return core.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
80
+ }