Skip to content

Commit 3e7478d

Browse files
author
Rúben Carvalho
authored
feat: Add theming script (#10)
* feat: Add theming script
1 parent f5b64b8 commit 3e7478d

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ jobs:
1616
release:
1717
uses: cloudscape-design/actions/.github/workflows/release.yml@main
1818
secrets: inherit
19+
with:
20+
publish-packages: lib/components,lib/components-themeable

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## React components for Cloudscape Design System
1+
## Code view component for Cloudscape Design System
22

33
This package contains the source code of the Code View component in the [Cloudscape Design System](https://cloudscape.design/).
44
For more information about the code view component, see [the documentation](https://cloudscape.design/components/code-view/).

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"homepage": "https://cloudscape.design",
99
"scripts": {
1010
"prebuild": "rm -rf lib dist .cache",
11-
"build": "npm-run-all build:pkg --parallel build:src:* --parallel build:pages:*",
11+
"build": "npm-run-all build:pkg --parallel build:src:* --parallel build:pages:* build:themeable",
1212
"lint": "eslint --ignore-path .gitignore --ext ts,tsx,js . && stylelint --ignore-path .gitignore '{src,pages}/**/*.{css,scss}'",
1313
"prepare": "husky install",
1414
"test:unit": "vitest run --config vite.unit.config.mjs",
@@ -29,6 +29,7 @@
2929
"build:src:copy": "cp README.md lib/components/",
3030
"build:src:docs": "node scripts/docs.js",
3131
"build:src:environment": "node scripts/environment",
32+
"build:themeable": "node scripts/themeable-source",
3233
"build:pages:vite": "vite build",
3334
"build:pages:tsc": "tsc -p pages/tsconfig.json"
3435
},

scripts/package-json.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { writeJSON } from "./utils.js";
66
const pkg = JSON.parse(fs.readFileSync("package.json", "utf-8"));
77

88
mainPackage();
9+
themablePackage();
910

1011
function mainPackage() {
1112
writeJSON("lib/components/package.json", {
@@ -14,3 +15,12 @@ function mainPackage() {
1415
scripts: undefined,
1516
});
1617
}
18+
19+
function themablePackage() {
20+
writeJSON("lib/components-themeable/package.json", {
21+
name: "@cloudscape-design/code-view-themeable",
22+
version: pkg.version,
23+
repository: pkg.repository,
24+
homepage: pkg.homepage,
25+
});
26+
}

scripts/themeable-source.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import fs from "node:fs";
4+
import path from "node:path";
5+
import process from "node:process";
6+
import { globbySync } from "globby";
7+
const cwd = process.cwd();
8+
9+
const targetDir = path.join(cwd, "./lib/components-themeable/internal");
10+
const stylesSourceDir = path.join(cwd, "./src/");
11+
const stylesTargetDir = path.join(targetDir, "/scss");
12+
13+
const componentsSourceDir = path.join(cwd, "./lib/components");
14+
const componentsTargetDir = path.join(targetDir, "/template");
15+
16+
function copyStyles() {
17+
for (const file of globbySync("**/*.scss", { cwd: stylesSourceDir })) {
18+
const content = fs.readFileSync(path.join(stylesSourceDir, file), "utf-8");
19+
fs.mkdirSync(path.join(stylesTargetDir, path.dirname(file)), { recursive: true });
20+
fs.writeFileSync(
21+
path.join(stylesTargetDir, file),
22+
content.replace(
23+
/@use "(\.\.\/)+node_modules\/@cloudscape-design\/design-tokens\/index.scss"/,
24+
'@use "awsui:tokens"'
25+
),
26+
"utf-8"
27+
);
28+
}
29+
}
30+
31+
function copyTemplate() {
32+
fs.mkdirSync(componentsTargetDir, { recursive: true });
33+
fs.cpSync(componentsSourceDir, componentsTargetDir, { recursive: true });
34+
}
35+
36+
copyTemplate();
37+
copyStyles();

0 commit comments

Comments
 (0)