1+ import { readFileSync , writeFileSync } from "node:fs" ;
2+ import yaml from "js-yaml" ;
3+ import { bundledThemesInfo } from "shiki/bundle/full" ;
4+
5+ /* thanks to https://github.com/halo-sigs/plugin-shiki/blob/main/scripts/generate-themes-for-settings-file.mjs */
6+
7+ const THEME_FIELD_NAMES = [ "lightTheme" , "darkTheme" , "theme" ] ;
8+ const settingsFilePath = new URL (
9+ "../../../src/main/resources/extensions/settings.yaml" ,
10+ import . meta. url ,
11+ ) ;
12+
13+ try {
14+ const settingsFileContent = readFileSync ( settingsFilePath , "utf8" ) ;
15+ const settings = yaml . load ( settingsFileContent ) ;
16+
17+ if ( ! settings ?. spec ?. forms ) {
18+ console . warn ( "No forms found in settings.yaml" ) ;
19+ process . exit ( 0 ) ;
20+ }
21+
22+ const themeOptions = bundledThemesInfo . map ( ( theme ) => ( {
23+ label : `${ theme . displayName } (${ theme . type } )` ,
24+ value : theme . id ,
25+ } ) ) ;
26+
27+ let updatedCount = 0 ;
28+ settings . spec . forms . forEach ( ( form ) => {
29+ if ( form . group !== "shiki" ) {
30+ return ;
31+ }
32+ form . formSchema ?. forEach ( ( field ) => {
33+ if ( THEME_FIELD_NAMES . includes ( field . name ) ) {
34+ field . options = themeOptions ;
35+ updatedCount ++ ;
36+ }
37+ } ) ;
38+ } ) ;
39+
40+ const updatedYaml = yaml . dump ( settings , {
41+ indent : 2 ,
42+ lineWidth : - 1 ,
43+ noRefs : true ,
44+ quotingType : '"' ,
45+ forceQuotes : false ,
46+ flowLevel : - 1 ,
47+ sortKeys : false ,
48+ } ) ;
49+
50+ writeFileSync ( settingsFilePath , updatedYaml , "utf8" ) ;
51+ console . log ( `✓ Updated ${ updatedCount } theme fields in settings.yaml` ) ;
52+ } catch ( error ) {
53+ console . error ( "Error updating settings.yaml:" , error . message ) ;
54+ process . exit ( 1 ) ;
55+ }
0 commit comments