-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dark dimmed overrides and update combineTheme script (#1177)
* add dark dimmed overrides and update combineTheme script * fix linting issues
- Loading branch information
1 parent
a41211d
commit 55b6538
Showing
3 changed files
with
114 additions
and
106 deletions.
There are no files selected for viewing
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,59 @@ | ||
import {readFileSync, writeFileSync} from 'fs' | ||
import {basename, extname} from 'path' | ||
import JSON5 from 'json5' | ||
|
||
interface Theme { | ||
[key: string]: unknown | ||
} | ||
|
||
function combineThemes(baseFilePath: string, overrideFilePath: string, outputFilePath: string): void { | ||
const baseFile = JSON5.parse(readFileSync(baseFilePath, 'utf8')) | ||
const overrideFile = JSON5.parse(readFileSync(overrideFilePath, 'utf8')) | ||
const overrideFileName = basename(overrideFilePath, extname(overrideFilePath)).replace(/\./g, '-') | ||
|
||
const combinedTheme = combine(baseFile, overrideFile, overrideFileName) | ||
|
||
writeFileSync(outputFilePath, JSON5.stringify(combinedTheme, null, 2)) | ||
} | ||
|
||
function combine(base: Theme, override: Theme, overrideFileName: string): Theme { | ||
const result = {...base} | ||
|
||
for (const key in override) { | ||
if (Object.prototype.hasOwnProperty.call(override, key) && Object.prototype.hasOwnProperty.call(result, key)) { | ||
const overrideValue = override[key] | ||
|
||
if (overrideValue && typeof overrideValue === 'object' && overrideValue.$value) { | ||
if (!result[key].$extensions) { | ||
result[key].$extensions = {} | ||
} | ||
if (!result[key].$extensions['org.primer.overrides']) { | ||
result[key].$extensions['org.primer.overrides'] = {} | ||
} | ||
result[key].$extensions['org.primer.overrides'][overrideFileName] = { | ||
$value: overrideValue.$value, | ||
...(overrideValue.alpha !== undefined && {alpha: overrideValue.alpha}), | ||
} | ||
} else if (typeof overrideValue === 'object' && !Array.isArray(overrideValue)) { | ||
result[key] = combine(result[key], overrideValue, overrideFileName) | ||
} | ||
} | ||
} | ||
|
||
return result | ||
} | ||
|
||
// Main function to handle CLI arguments | ||
function main() { | ||
const args = process.argv.slice(2) | ||
if (args.length !== 3) { | ||
// eslint-disable-next-line no-console | ||
console.error('Usage: npx tsx combineThemes.ts <baseFilePath> <overrideFilePath> <outputFilePath>') | ||
process.exit(1) | ||
} | ||
|
||
const [baseFilePath, overrideFilePath, outputFilePath] = args | ||
combineThemes(baseFilePath, overrideFilePath, outputFilePath) | ||
} | ||
|
||
main() |
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