Skip to content

Commit d29ce36

Browse files
committed
chore(themes): generate themes in top-level directory and pass to CI
1 parent 68d110a commit d29ce36

File tree

6 files changed

+14
-17
lines changed

6 files changed

+14
-17
lines changed

.github/workflows/actions/build-core-stencil-prerelease/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ runs:
2929
with:
3030
name: ionic-core
3131
output: core/CoreBuild.zip
32-
paths: core/dist core/components core/src/foundations core/css core/hydrate core/loader core/src/components.d.ts
32+
paths: core/dist core/components core/src/foundations core/css core/themes core/hydrate core/loader core/src/components.d.ts

.github/workflows/actions/build-core/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ runs:
3333
output: core/CoreBuild.zip
3434
# Include generated proxy files from Stencil output targets so
3535
# framework builds can detect when they need to be updated
36-
paths: core/dist core/components core/src/foundations core/css core/hydrate core/loader core/src/components.d.ts core/api.txt packages/angular/src/directives/proxies.ts packages/angular/src/directives/proxies-list.ts packages/angular/standalone/src/directives/proxies.ts packages/vue/src/proxies.ts packages/react/src/components/proxies.ts packages/react/src/components/inner-proxies.ts packages/react/src/components/routing-proxies.ts
36+
paths: core/dist core/components core/src/foundations core/css core/themes core/hydrate core/loader core/src/components.d.ts core/api.txt packages/angular/src/directives/proxies.ts packages/angular/src/directives/proxies-list.ts packages/angular/standalone/src/directives/proxies.ts packages/vue/src/proxies.ts packages/react/src/components/proxies.ts packages/react/src/components/inner-proxies.ts packages/react/src/components/routing-proxies.ts

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ temp/
2323
core/theme-builder/
2424
core/test-components/
2525
core/css/
26+
core/themes/
2627
$RECYCLE.BIN/
2728

2829
.DS_Store

core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@
7676
"stylelint-order": "^4.1.0"
7777
},
7878
"scripts": {
79-
"build": "npm run clean && npm run build.css && npm run build.newTokens && stencil build --es5 --docs-json dist/docs.json",
79+
"build": "npm run clean && npm run build.css && npm run build.themes && stencil build --es5 --docs-json dist/docs.json",
8080
"build.css": "npm run css.sass && npm run css.minify",
8181
"build.debug": "npm run clean && stencil build --debug",
8282
"build.docs.json": "stencil build --docs-json dist/docs.json",
8383
"build.tokens": "npx build.tokens --config scripts/tokens/index.mjs && npm run prettier.tokens",
84-
"build.newTokens": "esbuild src/themes/*/*.tokens.ts --bundle --format=esm --platform=browser --target=es2017 --outdir=dist/themes --outbase=src/themes && esbuild src/utils/theme.ts --bundle --format=esm --platform=browser --target=es2017 --outfile=dist/themes/utils/theme.js",
84+
"build.themes": "esbuild src/themes/*/*.tokens.ts --bundle --format=esm --platform=browser --target=es2017 --outdir=themes --outbase=src/themes && esbuild src/utils/theme.ts --bundle --format=esm --platform=browser --target=es2017 --outfile=themes/utils/theme.js",
8585
"clean": "node scripts/clean.js",
8686
"css.minify": "cleancss -O2 -o ./css/ionic.bundle.css ./css/ionic.bundle.css",
8787
"css.sass": "sass --embed-sources --style compressed src/css:./css",
@@ -95,7 +95,7 @@
9595
"prerender.e2e": "node scripts/testing/prerender.js",
9696
"prettier": "prettier \"./src/**/*.{html,ts,tsx,js,jsx,scss}\"",
9797
"prettier.tokens": "prettier \"./src/foundations/*.{scss, html}\" --write --cache",
98-
"start": "npm run build.css && npm run build.newTokens && stencil build --dev --watch --serve",
98+
"start": "npm run build.css && npm run build.themes && stencil build --dev --watch --serve",
9999
"test": "npm run test.spec && npm run test.e2e",
100100
"test.spec": "stencil test --spec --max-workers=2",
101101
"test.e2e": "npx playwright test",

core/scripts/clean.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const path = require('path');
44

55
const cleanDirs = [
66
'dist',
7-
'css'
7+
'css',
8+
'themes'
89
];
910

1011
cleanDirs.forEach(dir => {

core/scripts/testing/scripts.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@
4949
const paletteQuery = window.location.search.match(/palette=([a-z]+)/);
5050
const paletteName = paletteQuery?.[1] || 'light';
5151

52-
// Load theme tokens dynamically instead of stylesheets
52+
// Load theme tokens if the theme is valid
5353
if (themeName && ['ionic', 'ios', 'md'].includes(themeName)) {
5454
loadThemeTokens(themeName, paletteName);
5555
}
5656

5757
async function loadThemeTokens(themeName, paletteName) {
5858
try {
59-
// Dynamically import the theme tokens
60-
const defaultTokens = await import(`/dist/themes/${themeName}/default.tokens.js`);
59+
// Load the default tokens for the theme
60+
const defaultTokens = await import(`/themes/${themeName}/default.tokens.js`);
6161
const theme = defaultTokens.defaultTheme;
6262

6363
// If a specific palette is requested, modify the palette structure
@@ -73,16 +73,11 @@
7373

7474
// Re-apply the global theme
7575
if (window.Ionic.config.get && window.Ionic.config.set) {
76-
import('/dist/themes/utils/theme.js').then(themeModule => {
77-
themeModule.applyGlobalTheme(theme);
78-
}).catch(() => {
79-
console.warn('Could not reapply theme - theme module not found');
80-
});
76+
const themeModule = await import('/themes/utils/theme.js');
77+
themeModule.applyGlobalTheme(theme);
8178
}
82-
83-
console.info(`Loaded ${themeName} theme with palette ${paletteName}:`, theme);
8479
} catch (error) {
85-
console.warn(`Failed to load theme tokens for ${themeName}:`, error);
80+
console.error(`Failed to load theme tokens for ${themeName}:`, error);
8681
}
8782
}
8883

0 commit comments

Comments
 (0)