Skip to content

Commit 2b47586

Browse files
chore: Fix components-themable output (#85)
- Include required files to create a themeable package Co-authored-by: Andrei Zhaleznichenka <[email protected]>
1 parent 07a245e commit 2b47586

File tree

6 files changed

+77
-1
lines changed

6 files changed

+77
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"build:src:copy": "cp README.md NOTICE LICENSE lib/components/",
3535
"build:src:docs": "node scripts/docs.js",
3636
"build:src:environment": "node scripts/environment",
37-
"build:themeable": "node scripts/themeable-source",
37+
"build:themeable": "tsc -p tsconfig.src-themeable.json && node scripts/themeable-source.js",
3838
"build:pages:vite": "vite build",
3939
"build:pages:tsc": "tsc -p pages/tsconfig.json"
4040
},

scripts/package-json.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,11 @@ function themablePackage() {
2323
version: pkg.version,
2424
repository: pkg.repository,
2525
homepage: pkg.homepage,
26+
exports: {
27+
".": {
28+
types: "./theming.d.ts",
29+
import: "./theming.js",
30+
},
31+
},
2632
});
2733
}

scripts/themeable-source.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ function copyStyles() {
3232
function copyTemplate() {
3333
fs.mkdirSync(componentsTargetDir, { recursive: true });
3434
fs.cpSync(componentsSourceDir, componentsTargetDir, { recursive: true });
35+
fs.writeFileSync(
36+
path.join(componentsTargetDir, "package.json"),
37+
JSON.stringify(
38+
{
39+
name: "@cloudscape-design/chat-components-themed",
40+
version: "1.0.0",
41+
},
42+
null,
43+
2,
44+
),
45+
"utf-8",
46+
);
3547
}
3648

3749
copyTemplate();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import { GlobalValue, ThemePreset, TypedModeValueOverride } from "@cloudscape-design/theming-build";
4+
5+
export interface TypedOverride {
6+
tokens: Partial<Record<string, GlobalValue | TypedModeValueOverride>>;
7+
}
8+
export const preset: ThemePreset;

src-themeable/theming.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import { join } from "node:path";
4+
5+
import { buildThemedComponents as themingCoreBuild } from "@cloudscape-design/theming-build";
6+
7+
// eslint-disable-next-line import/no-useless-path-segments
8+
import { preset, TypedOverride } from "./internal/template/internal/generated/theming/index.cjs";
9+
10+
const internalDir = join(__dirname, "./internal");
11+
const scssDir = join(internalDir, "./scss");
12+
const templateDir = join(internalDir, "./template");
13+
const designTokensTemplateDir = join(internalDir, "./template-tokens");
14+
15+
export type Theme = TypedOverride;
16+
export interface BuildThemedComponentsParams {
17+
theme: Theme;
18+
outputDir: string;
19+
baseThemeId?: string;
20+
}
21+
22+
export function buildThemedComponents({ theme, outputDir, baseThemeId }: BuildThemedComponentsParams): Promise<void> {
23+
return themingCoreBuild({
24+
override: theme,
25+
preset,
26+
baseThemeId,
27+
componentsOutputDir: join(outputDir, "components"),
28+
designTokensOutputDir: join(outputDir, "design-tokens"),
29+
templateDir,
30+
designTokensTemplateDir,
31+
scssDir,
32+
});
33+
}

tsconfig.src-themeable.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["es2019", "dom", "dom.iterable"],
4+
"target": "ES2019",
5+
"module": "ESNext",
6+
"moduleResolution": "nodenext",
7+
"rootDir": "src-themeable",
8+
"declaration": true,
9+
"incremental": true,
10+
"outDir": "lib/components-themeable",
11+
"skipLibCheck": true,
12+
"strict": true,
13+
"tsBuildInfoFile": "./.cache/themeable-source.tsbuildinfo"
14+
},
15+
"include": ["src-themeable"],
16+
"exclude": ["**/__tests__/**", "src/test-utils/**"]
17+
}

0 commit comments

Comments
 (0)