Skip to content

Commit e07ac40

Browse files
authored
Merge pull request #28 from easyops-cn/steve/contracts
Steve/contracts
2 parents 5e0d4d0 + 59a0ecc commit e07ac40

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

apps/test/src/app.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
22
"id": "test",
33
"name": "Test App",
4-
"homepage": "/test"
4+
"homepage": "/test",
5+
"defaultConfig": {
6+
"settings": {
7+
"misc": {
8+
"globalThemeVariant": "elevo"
9+
}
10+
}
11+
}
512
}

packages/builder/bin/builder.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,13 @@ async function buildApp(watchMode, withContracts) {
277277
}
278278
}
279279

280+
console.log(
281+
`Using global theme variant: ${appJson?.defaultConfig?.settings?.misc?.globalThemeVariant}`
282+
);
283+
280284
const { routes, functions, templates, errors } = await convertApp(app, {
281285
rootId: "",
286+
themeVariant: appJson?.defaultConfig?.settings?.misc?.globalThemeVariant,
282287
});
283288

284289
if (errors.length > 0) {

packages/converter/src/convertComponent.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ import { convertLifeCycle } from "./convertLifeCycle.js";
3838
import { convertProperties } from "./convertProperties.js";
3939
import { hasOwnProperty } from "@next-core/utils/general";
4040

41-
const PORTAL_COMPONENTS = [
41+
const PORTAL_COMPONENTS = new Set([
4242
"eo-modal",
4343
"eo-drawer",
4444
"eo-event-agent",
4545
"eo-batch-agent",
46-
];
46+
]);
47+
48+
const NO_THEME_VARIANT_BRICKS = new Set(["eo-event-agent", "eo-batch-agent"]);
4749

4850
export async function convertComponent(
4951
component: ComponentChild,
@@ -234,6 +236,18 @@ export async function convertComponent(
234236
brick.slot = component.slot;
235237
}
236238

239+
if (
240+
options.themeVariant &&
241+
brick.brick?.includes("-") &&
242+
!brick.brick.startsWith("tpl-") &&
243+
!brick.brick.startsWith("isolated-tpl-") &&
244+
!brick.properties?.themeVariant &&
245+
!NO_THEME_VARIANT_BRICKS.has(brick.brick)
246+
) {
247+
brick.properties ??= {};
248+
brick.properties.themeVariant = options.themeVariant;
249+
}
250+
237251
brick.events = convertEvents(component, options);
238252

239253
brick.lifeCycle = convertLifeCycle(component, options);
@@ -270,7 +284,7 @@ export async function convertComponent(
270284
}
271285
}
272286

273-
if (component.portal || PORTAL_COMPONENTS.includes(brick.brick)) {
287+
if (component.portal || PORTAL_COMPONENTS.has(brick.brick)) {
274288
brick.portal = true;
275289
}
276290

packages/converter/src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface ConvertOptions {
1515
withContexts?: Record<string, unknown>;
1616
allowAnyBricks?: boolean;
1717
withoutWrapper?: boolean;
18+
themeVariant?: string;
1819
}
1920

2021
export interface ConvertResult {

packages/converter/src/modules/getTplName.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export function getAppTplName(name: string) {
1111

1212
function getViewTplNamePrefixByRootId(rootId: string) {
1313
if (!tplNameMap.has(rootId)) {
14-
tplNameMap.set(rootId, `isolated-tpl-${counter++}`);
14+
const tplName = `isolated-tpl-${counter++}`;
15+
tplNameMap.set(rootId, tplName);
16+
return tplName;
1517
}
1618
return tplNameMap.get(rootId)!;
1719
}

0 commit comments

Comments
 (0)