@@ -66,10 +66,12 @@ export async function checkForChanges(directory: string) {
6666/**
6767 * Retrieves the information for all packages in the repository
6868 */
69- export async function getAllPackages ( gitRoot : string ) {
69+ export async function getAllPackages ( gitRoot : string , maxDepth ?: number ) {
7070 const output : Record < string , RawPackageRecord > = { } ;
7171
72- async function recurser ( currentDir : string ) {
72+ async function recurser ( currentDir : string , currentDepth : number ) {
73+ if ( maxDepth !== undefined && currentDepth >= maxDepth ) return ;
74+
7375 const items = await fs . readdir ( currentDir , { withFileTypes : true } ) ;
7476 await Promise . all ( items . map ( async item => {
7577 if ( item . isFile ( ) ) {
@@ -103,7 +105,7 @@ export async function getAllPackages(gitRoot: string) {
103105
104106 if ( item . isDirectory ( ) && item . name !== 'node_modules' && ! item . name . startsWith ( '__' ) ) {
105107 const fullPath = pathlib . join ( currentDir , item . name ) ;
106- await recurser ( fullPath ) ;
108+ await recurser ( fullPath , currentDepth + 1 ) ;
107109 }
108110 } ) ) ;
109111 }
@@ -145,7 +147,7 @@ export async function getAllPackages(gitRoot: string) {
145147 return false ;
146148 }
147149
148- await recurser ( gitRoot ) ;
150+ await recurser ( gitRoot , 0 ) ;
149151 Object . keys ( output ) . forEach ( populateChanges ) ;
150152
151153 return Object . entries ( output )
@@ -203,40 +205,29 @@ function rawRecordToFullRecord(
203205 } ;
204206}
205207
206- /**
207- * Iterate through all packages and convert the raw package records to the
208- * version that the action actually outputs
209- */
210- async function processPackages ( gitRoot : string ) {
211- const packages = await getAllPackages ( gitRoot ) ;
212- const bundles : PackageRecord [ ] = [ ] ;
213- const tabs : PackageRecord [ ] = [ ] ;
214- const libs : PackageRecord [ ] = [ ] ;
215-
216- for ( const [ packageName , fullRecord ] of Object . entries ( packages ) ) {
217- if (
218- packageName === '@sourceacademy/modules' ||
219- packageName === '@sourceacademy/bundles' ||
220- packageName === '@sourceacademy/tabs'
221- ) continue ;
222-
223- if ( 'bundleName' in fullRecord ) {
224- bundles . push ( fullRecord ) ;
225- } else if ( 'tabName' in fullRecord ) {
226- tabs . push ( fullRecord ) ;
227- } else {
228- libs . push ( fullRecord ) ;
229- }
230- }
231-
232- return { packages, bundles, tabs, libs } ;
233- }
234-
235208async function main ( ) {
236209 const gitRoot = await getGitRoot ( ) ;
237210
238- const { packages, bundles, tabs, libs } = await processPackages ( gitRoot ) ;
239- const summaryItems = Object . values ( packages ) . map ( packageInfo => {
211+ const [
212+ bundles ,
213+ tabs ,
214+ libs ,
215+ rootPackages
216+ ] = await Promise . all ( [
217+ getAllPackages ( pathlib . join ( gitRoot , 'src' , 'bundles' ) ) ,
218+ getAllPackages ( pathlib . join ( gitRoot , 'src' , 'tabs' ) ) ,
219+ getAllPackages ( pathlib . join ( gitRoot , 'libs' ) ) ,
220+ getAllPackages ( pathlib . join ( gitRoot ) , 1 )
221+ ] ) ;
222+
223+ const packages = {
224+ ...Object . values ( rootPackages ) ,
225+ ...bundles ,
226+ ...tabs ,
227+ ...libs
228+ } ;
229+
230+ const summaryItems = packages . map ( packageInfo => {
240231 return `<div>
241232 <h2>${ packageInfo . name } </h2>
242233 <ul>
@@ -253,8 +244,8 @@ async function main() {
253244 core . setOutput ( 'bundles' , bundles ) ;
254245 core . setOutput ( 'tabs' , tabs ) ;
255246 core . setOutput ( 'libs' , libs ) ;
256- core . setOutput ( 'devserver' , packages [ '@sourceacademy/devserver' ] ) ;
257- core . setOutput ( 'docserver' , packages [ '@sourceacademy/docserver' ] ) ;
247+ core . setOutput ( 'devserver' , rootPackages [ '@sourceacademy/devserver' ] ) ;
248+ core . setOutput ( 'docserver' , rootPackages [ '@sourceacademy/docserver' ] ) ;
258249
259250 const workflows = await checkForChanges ( pathlib . join ( gitRoot , '.github/workflows' ) ) ;
260251 core . setOutput ( 'workflows' , workflows ) ;
0 commit comments