@@ -27,6 +27,8 @@ export type ConfigFormat = 'js' | 'json';
2727export interface WriteConfigOptions {
2828 /** Output format (default: 'js') */
2929 format ?: ConfigFormat ;
30+ /** Write raw content without formatting (for pre-rendered templates) */
31+ raw ?: boolean ;
3032}
3133
3234/**
@@ -71,22 +73,34 @@ export async function findExistingConfig(
7173 * Write configuration file to project root
7274 *
7375 * @param projectRoot - Project root directory
74- * @param config - Configuration to write
76+ * @param config - Configuration object or pre-rendered string (when raw: true)
7577 * @param options - Write options
7678 * @returns Path to written file
7779 */
7880export async function writeConfig (
7981 projectRoot : string ,
80- config : CodingBuddyConfig ,
82+ config : CodingBuddyConfig | string ,
8183 options : WriteConfigOptions = { } ,
8284) : Promise < string > {
8385 const format = options . format ?? 'js' ;
8486
8587 const fileName =
8688 format === 'json' ? 'codingbuddy.config.json' : 'codingbuddy.config.js' ;
8789
88- const content =
89- format === 'json' ? formatConfigAsJson ( config ) : formatConfigAsJs ( config ) ;
90+ let content : string ;
91+
92+ if ( options . raw && typeof config === 'string' ) {
93+ // Use pre-rendered content as-is
94+ content = config ;
95+ } else if ( typeof config === 'object' ) {
96+ // Format the config object
97+ content =
98+ format === 'json' ? formatConfigAsJson ( config ) : formatConfigAsJs ( config ) ;
99+ } else {
100+ throw new Error (
101+ 'Invalid config: expected object or string with raw option' ,
102+ ) ;
103+ }
90104
91105 const filePath = path . join ( projectRoot , fileName ) ;
92106
0 commit comments