@@ -56,11 +56,22 @@ async function generateRepo({
5656 printOutput,
5757 } ) ;
5858
59- //const resolvedContext = await resolveEffectiveContext({ instance, workspace, branch }, core);
60- const { instanceConfig, workspaceConfig, branchConfig } = await resolveConfigs ( {
61- cliContext : { instance, workspace, branch } ,
62- core,
63- } ) ;
59+ let instanceConfig , workspaceConfig , branchConfig ;
60+ if ( input && ! fetch ) {
61+ // Skip context validation, provide dummy configs or minimal required fields
62+ instanceConfig = {
63+ name : instance || 'defaultInstance' ,
64+ process : { output : output || './output' } ,
65+ } ;
66+ workspaceConfig = { name : workspace || 'defaultWorkspace' , id : 'dummyId' } ;
67+ branchConfig = { label : branch || 'main' } ;
68+ } else {
69+ // Perform normal context resolution and validation
70+ ( { instanceConfig, workspaceConfig, branchConfig } = await resolveConfigs ( {
71+ cliContext : { instance, workspace, branch } ,
72+ core,
73+ } ) ) ;
74+ }
6475
6576 // Resolve output dir
6677 const outputDir = output
@@ -96,25 +107,42 @@ async function generateRepo({
96107 log . step ( `Reading and parsing YAML file -> ${ inputFile } ` ) ;
97108 const fileContents = await core . storage . readFile ( inputFile , 'utf8' ) ;
98109 const jsonData = load ( fileContents ) ;
99-
100110 const plannedWrites : { path : string ; content : string } [ ] = await core . generateRepo ( {
101111 jsonData,
102112 instance : instanceConfig . name ,
103113 workspace : workspaceConfig . name ,
104114 branch : branchConfig . label ,
105115 } ) ;
116+
106117 log . step ( `Writing Repository to the output directory -> ${ outputDir } ` ) ;
107- await Promise . all (
118+
119+ // Track results for logging
120+ const writeResults = await Promise . all (
108121 plannedWrites . map ( async ( { path, content } ) => {
109122 const outputPath = joinPath ( outputDir , path ) ;
110123 const writeDir = dirname ( outputPath ) ;
111- if ( ! ( await core . storage . exists ( writeDir ) ) ) {
112- await core . storage . mkdir ( writeDir , { recursive : true } ) ;
124+
125+ try {
126+ if ( ! ( await core . storage . exists ( writeDir ) ) ) {
127+ await core . storage . mkdir ( writeDir , { recursive : true } ) ;
128+ }
129+ await core . storage . writeFile ( outputPath , content ) ;
130+ return { path : outputPath , success : true } ;
131+ } catch ( err ) {
132+ return { path : outputPath , success : false , error : err } ;
113133 }
114- await core . storage . writeFile ( outputPath , content ) ;
115134 } )
116135 ) ;
117136
137+ // Summary log
138+ const failedWrites = writeResults . filter ( ( r ) => ! r . success ) ;
139+ if ( failedWrites . length ) {
140+ log . warn ( `Some files failed to write (${ failedWrites . length } ):` ) ;
141+ failedWrites . forEach ( ( r ) => log . warn ( ` - ${ r . path } : ${ r . error } ` ) ) ;
142+ } else {
143+ log . info ( 'All files written successfully.' ) ;
144+ }
145+
118146 printOutputDir ( printOutput , outputDir ) ;
119147 outro ( 'Directory structure rebuilt successfully!' ) ;
120148}
0 commit comments