@@ -3,6 +3,7 @@ import { join, resolveResource } from '@tauri-apps/api/path';
33import { open } from '@tauri-apps/api/dialog' ;
44import { Skit , CommandDefinition , SkitCommand } from '../types' ;
55import { validateSkitData , validateCommandsYaml } from './validation' ;
6+ import { loadConfigFile } from './configLoader' ;
67// 未使用のimportを削除
78
89/**
@@ -29,7 +30,7 @@ export async function selectProjectFolder(): Promise<string | null> {
2930}
3031
3132/**
32- * Loads commands.yaml file from either project path or resources
33+ * Loads commands.yaml file based on configuration
3334 * @param projectPath Optional project path
3435 * @returns Promise with the commands.yaml content
3536 */
@@ -40,16 +41,20 @@ export async function loadCommandsYaml(projectPath: string | null = null): Promi
4041 throw new Error ( 'Running in web environment, Tauri API not available' ) ;
4142 }
4243
43- let commandsYamlPath ;
44+ if ( ! projectPath ) {
45+ throw new Error ( 'Project path is required to load commands.yaml' ) ;
46+ }
4447
45- if ( projectPath ) {
46- commandsYamlPath = await join ( projectPath , 'commands.yaml' ) ;
47- if ( await exists ( commandsYamlPath ) ) {
48- return await readTextFile ( commandsYamlPath ) ;
49- }
48+ // Load configuration file first
49+ const config = await loadConfigFile ( projectPath ) ;
50+
51+ // Get commands.yaml path from config
52+ const commandsYamlPath = await join ( projectPath , config . commandsSchema ) ;
53+
54+ if ( ! ( await exists ( commandsYamlPath ) ) ) {
55+ throw new Error ( `Commands schema file not found at ${ commandsYamlPath } ` ) ;
5056 }
5157
52- commandsYamlPath = await resolveResource ( 'commands.yaml' ) ;
5358 return await readTextFile ( commandsYamlPath ) ;
5459 } catch ( error ) {
5560 console . error ( 'Failed to load commands.yaml:' , error ) ;
@@ -81,12 +86,12 @@ export async function loadSkits(projectPath: string | null = null): Promise<Reco
8186 return { } ; // Return empty object since directory was just created
8287 }
8388
84- return await loadSkitsFromPath ( skitsPath ) ;
89+ return await loadSkitsFromPath ( skitsPath , projectPath ) ;
8590 }
8691
8792 skitsPath = await resolveResource ( 'skits' ) ;
8893 // as it should be part of the bundled resources
89- return await loadSkitsFromPath ( skitsPath ) ;
94+ return await loadSkitsFromPath ( skitsPath , null ) ;
9095 } catch ( error ) {
9196 console . error ( 'Failed to load skits:' , error ) ;
9297 return { } ; // Return empty object on error instead of throwing
@@ -96,22 +101,36 @@ export async function loadSkits(projectPath: string | null = null): Promise<Reco
96101/**
97102 * Helper function to load skits from a specific path
98103 * @param skitsPath Path to the skits directory
104+ * @param projectPath Optional project path for loading config
99105 * @returns Promise with a record of skits
100106 */
101- async function loadSkitsFromPath ( skitsPath : string ) : Promise < Record < string , Skit > > {
107+ async function loadSkitsFromPath ( skitsPath : string , projectPath : string | null ) : Promise < Record < string , Skit > > {
102108 try {
103109 const skitFiles = await readDir ( skitsPath ) ;
104110 const skits : Record < string , Skit > = { } ;
105111
106112 // Load commands.yaml to get defaultBackgroundColor for each command type
107113 let commandsConfig ;
108114 try {
109- const commandsYamlPath = await join ( skitsPath , '../commands.yaml' ) ;
110- if ( await exists ( commandsYamlPath ) ) {
111- const commandsYaml = await readTextFile ( commandsYamlPath ) ;
112- const { validateCommandsYaml } = await import ( './validation' ) ;
113- const { config } = validateCommandsYaml ( commandsYaml ) ;
114- commandsConfig = config ;
115+ if ( projectPath ) {
116+ // Load config to get commands.yaml path
117+ const config = await loadConfigFile ( projectPath ) ;
118+ const commandsYamlPath = await join ( projectPath , config . commandsSchema ) ;
119+ if ( await exists ( commandsYamlPath ) ) {
120+ const commandsYaml = await readTextFile ( commandsYamlPath ) ;
121+ const { validateCommandsYaml } = await import ( './validation' ) ;
122+ const { config : yamlConfig } = validateCommandsYaml ( commandsYaml ) ;
123+ commandsConfig = yamlConfig ;
124+ }
125+ } else {
126+ // Fallback for bundled resources
127+ const commandsYamlPath = await join ( skitsPath , '../commands.yaml' ) ;
128+ if ( await exists ( commandsYamlPath ) ) {
129+ const commandsYaml = await readTextFile ( commandsYamlPath ) ;
130+ const { validateCommandsYaml } = await import ( './validation' ) ;
131+ const { config : yamlConfig } = validateCommandsYaml ( commandsYaml ) ;
132+ commandsConfig = yamlConfig ;
133+ }
115134 }
116135 } catch ( error ) {
117136 console . error ( 'Failed to load commands.yaml for background colors:' , error ) ;
0 commit comments