Skip to content

Commit

Permalink
iterate some themes and generate theme catalog.json for maui
Browse files Browse the repository at this point in the history
  • Loading branch information
panayot-cankov committed Jan 26, 2024
1 parent ba663a4 commit d4d237e
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 1 deletion.
156 changes: 156 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"stylelint-config-standard": "^36.0.0",
"stylelint-config-standard-scss": "^12.0.0",
"stylelint-scss": "^6.0.0",
"ts-node": "^10.9.2",
"typescript": "^5.0.3"
},
"peerDependencies": {
Expand Down Expand Up @@ -71,7 +72,8 @@
"embed-assets": "gulp assets",
"create-component": "gulp create-component",
"test-contrast": "node ./scripts/test-contrast.mjs",
"test:integrations": "npm run build --prefix integrations"
"test:integrations": "npm run build --prefix integrations",
"build:maui": "node --no-warnings=ExperimentalWarning --loader ts-node/esm ./scripts/build-maui.ts"
},
"engines": {
"node": "^20"
Expand Down
83 changes: 83 additions & 0 deletions scripts/build-maui.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import fs from "fs/promises";
import { resolve, join, extname, parse, } from 'path';
import * as ts from "typescript";

interface Theme {
theme: string;
swatches: Swatch[];
}

interface Swatch {
theme: string;
swatch: string;
previewColors: string[];
}

(async () => {

let themesCatalog: Theme[] = [];

const root = resolve(__dirname, "../");

const mauiDist = join(root, "dist", "maui");

await fs.rm(mauiDist, { recursive: true, force: true });
await fs.mkdir(mauiDist, { recursive: true });

const themes = ["Default", "Bootstrap"].map(name => ({
name,
path: join(root, "packages", name.toLowerCase()),
swatchesDir: join(root, "packages", name, "lib", "swatches")
}));

for (const { name, swatchesDir } of themes) {
console.log(name.toUpperCase());
console.log(underline(name, "="));
console.log();

const themeCatalog: Theme = {
theme: name,
swatches: []
};
themesCatalog.push(themeCatalog);

const swatches =
(await fs.readdir(swatchesDir, { withFileTypes: true }))
.filter(f => f.isFile() && extname(f.name) == ".json")
.map(f => ({ swatch: parse(f.name).name, path: join(swatchesDir, f.name) }));
for (const { swatch, path } of swatches) {
console.log(`## ${swatch}\n`);

const content = await fs.readFile(path, "utf-8");
const json = JSON.parse(content);
console.log(json);

const fullName: string = json.name;

const separator = fullName.indexOf(" ");
const theme = fullName.substring(0, separator);
const swatchName = fullName.substring(separator + 1);
const previewColors = json.previewColors;

themeCatalog.swatches.push({ theme, swatch: swatchName, previewColors });

console.log();
}
}

// let telerikThemingCatalog: string = "";
// telerikThemingCatalog += "namespace QSF;\n";
// fs.writeFile(join(mauiDist, "TelerikThemingCatalog.cs"), telerikThemingCatalog);

fs.writeFile(
join(mauiDist, "catalog.json"),
JSON.stringify(themesCatalog, null, " "));


})().catch(console.error);

function underline(title: string, char: string = "="): string {
let underline = "";
for (let i = 0; i < title.length; i++) underline += char;
return underline;
}

0 comments on commit d4d237e

Please sign in to comment.