-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iterate some themes and generate theme catalog.json for maui
- Loading branch information
panayot-cankov
committed
Jan 26, 2024
1 parent
ba663a4
commit d4d237e
Showing
3 changed files
with
242 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |