@@ -2,7 +2,7 @@ import * as fs from 'fs';
22import * as path from 'path' ;
33import * as yaml from 'yaml' ;
44import type { ConstructConfig , StackConfig } from './plugins/types.js' ;
5- import type { DotGithubContext } from './context.js' ;
5+ import { DotGithubContext } from './context.js' ;
66
77export interface DotGithubAction {
88 /** GitHub repository in org/repo format */
@@ -11,6 +11,8 @@ export interface DotGithubAction {
1111 ref : string ;
1212 /** Original version reference that was requested (e.g., v4, main) */
1313 versionRef : string ;
14+ /** Legacy function name (backward-compat) */
15+ functionName ?: string ;
1416 /** Action name for type names and function names (overrides default from YAML) */
1517 actionName ?: string ;
1618 /** Output file path where the TypeScript was generated - required when generateCode is true */
@@ -138,9 +140,12 @@ module.exports = ${JSON.stringify(config, null, 2)};
138140/**
139141 * Sets a custom config file path to override the default discovery
140142 */
143+ let customConfigPathOverride : string | undefined ;
144+
141145export function setConfigPath ( configPath : string ) : void {
142- // This function is kept for compatibility but doesn't need to do anything
143- // since we're using DotGithubContext now
146+ customConfigPathOverride = configPath
147+ ? path . resolve ( configPath )
148+ : undefined ;
144149}
145150
146151/**
@@ -189,6 +194,25 @@ export function getConfigPath(): string {
189194 'dotgithub.yml' ,
190195 ] ;
191196
197+ if ( customConfigPathOverride ) {
198+ const stat = fs . existsSync ( customConfigPathOverride )
199+ ? fs . statSync ( customConfigPathOverride )
200+ : undefined ;
201+
202+ if ( stat ?. isDirectory ( ) ) {
203+ const githubDir = path . join ( customConfigPathOverride , '.github' ) ;
204+ for ( const fileName of CONFIG_FILE_NAMES ) {
205+ const configPath = path . join ( githubDir , fileName ) ;
206+ if ( fs . existsSync ( configPath ) ) {
207+ return configPath ;
208+ }
209+ }
210+ return path . join ( githubDir , CONFIG_FILE_NAMES [ 0 ] ! ) ;
211+ }
212+
213+ return customConfigPathOverride ;
214+ }
215+
192216 let currentDir = process . cwd ( ) ;
193217
194218 while ( currentDir !== path . dirname ( currentDir ) ) {
@@ -310,8 +334,23 @@ export function writeConfig(
310334 */
311335export function addActionToConfig (
312336 actionInfo : DotGithubAction ,
313- context : DotGithubContext
337+ contextOrRootDir : DotGithubContext | string
314338) : void {
339+ const context : DotGithubContext =
340+ typeof contextOrRootDir === 'string'
341+ ? new DotGithubContext ( {
342+ config : { ...readConfig ( ) , rootDir : contextOrRootDir } ,
343+ configPath : getConfigPath ( ) ,
344+ } )
345+ : contextOrRootDir ;
346+
347+ if ( ! context . config ) {
348+ context . config = createDefaultConfig ( ) ;
349+ }
350+ if ( ! context . config . actions ) {
351+ context . config . actions = [ ] ;
352+ }
353+
315354 // Check if action already exists (check orgRepo AND actionPath for uniqueness)
316355 const existingIndex = context . config . actions . findIndex (
317356 ( action ) =>
@@ -323,6 +362,10 @@ export function addActionToConfig(
323362 ...actionInfo ,
324363 } ;
325364
365+ if ( actionWithRelativePath . outputPath && path . isAbsolute ( actionWithRelativePath . outputPath ) ) {
366+ actionWithRelativePath . outputPath = context . relativePath ( actionWithRelativePath . outputPath ) ;
367+ }
368+
326369 if ( existingIndex >= 0 ) {
327370 // Update existing action
328371 context . config . actions [ existingIndex ] = actionWithRelativePath ;
0 commit comments