@@ -93,27 +93,7 @@ module.exports = class ArtifactGenerator extends BaseGenerator {
9393 } ) ;
9494
9595 if ( generationStatus ) {
96- /**
97- * Update the index.ts in this.artifactInfo.outDir. Creates it if it
98- * doesn't exist.
99- * this.artifactInfo.outFile is what is exported from the file.
100- *
101- * Both those properties must be present for this to happen. Optionally,
102- * this can be disabled even if the properties are present by setting:
103- * this.artifactInfo.disableIndexUpdate = true;
104- */
105- if (
106- this . artifactInfo . outDir &&
107- this . artifactInfo . outFile &&
108- ! this . artifactInfo . disableIndexUpdate
109- ) {
110- await updateIndex ( this . artifactInfo . outDir , this . artifactInfo . outFile ) ;
111- // Output for users
112- this . log (
113- chalk . green ( ' update' ) ,
114- `${ this . artifactInfo . relPath } /index.ts` ,
115- ) ;
116- }
96+ await this . _updateIndexFiles ( ) ;
11797
11898 // User Output
11999 this . log ( ) ;
@@ -128,4 +108,55 @@ module.exports = class ArtifactGenerator extends BaseGenerator {
128108
129109 await super . end ( ) ;
130110 }
111+
112+ /**
113+ * Update the index.ts in this.artifactInfo.outDir. Creates it if it
114+ * doesn't exist.
115+ * this.artifactInfo.outFile is what is exported from the file.
116+ *
117+ * Both those properties must be present for this to happen. Optionally,
118+ * this can be disabled even if the properties are present by setting:
119+ * this.artifactInfo.disableIndexUpdate = true;
120+ *
121+ * Multiple indexes / files can be updated by providing an array of
122+ * index update objects as follows:
123+ * this.artifactInfo.indexesToBeUpdated = [{
124+ * dir: 'directory in which to update index.ts',
125+ * file: 'file to add to index.ts',
126+ * }, {dir: '...', file: '...'}]
127+ */
128+ async _updateIndexFiles ( ) {
129+ // Index Update Disabled
130+ if ( this . artifactInfo . disableIndexUpdate ) return ;
131+
132+ // No Array given for Index Update, Create default array
133+ if (
134+ ! this . artifactInfo . indexesToBeUpdated &&
135+ this . artifactInfo . outDir &&
136+ this . artifactInfo . outFile
137+ ) {
138+ this . artifactInfo . indexesToBeUpdated = [
139+ { dir : this . artifactInfo . outDir , file : this . artifactInfo . outFile } ,
140+ ] ;
141+ } else {
142+ this . artifactInfo . indexesToBeUpdated = [ ] ;
143+ }
144+
145+ for ( const idx of this . artifactInfo . indexesToBeUpdated ) {
146+ await updateIndex ( idx . dir , idx . file ) ;
147+ // Output for users
148+ const updateDirRelPath = path . relative (
149+ this . artifactInfo . relPath ,
150+ idx . dir ,
151+ ) ;
152+
153+ const outPath = path . join (
154+ this . artifactInfo . relPath ,
155+ updateDirRelPath ,
156+ 'index.ts' ,
157+ ) ;
158+
159+ this . log ( chalk . green ( ' update' ) , `${ outPath } ` ) ;
160+ }
161+ }
131162} ;
0 commit comments