@@ -66,7 +66,11 @@ let completed = 0;
66
66
* and we want to build the static output.
67
67
*/
68
68
const finishBuild : ( ) => void = async ( ) => {
69
- console . log ( "\nDone fetching everything!" ) ;
69
+ completed ++ ;
70
+ // if this isn't the last feed, just return early
71
+ if ( completed !== feedListLength ) return ;
72
+
73
+ process . stdout . write ( "\nDone fetching everything!\n" ) ;
70
74
71
75
// generate the static HTML output from our template renderer
72
76
const output = render ( {
@@ -77,10 +81,10 @@ const finishBuild: () => void = async () => {
77
81
78
82
// write the output to public/index.html
79
83
await writeFile ( "./public/index.html" , output ) ;
80
- console . log (
84
+ process . stdout . write (
81
85
`\nFinished writing to output:\n- ${ feedListLength } feeds in ${ benchmark (
82
86
initTime
83
- ) } \n- ${ errors . length } errors`
87
+ ) } \n- ${ errors . length } errors\n `
84
88
) ;
85
89
} ;
86
90
@@ -103,8 +107,7 @@ const processFeed =
103
107
} ) =>
104
108
async ( response : Response ) : Promise < void > => {
105
109
const body = await parseFeed ( response ) ;
106
- completed ++ ;
107
- // skip to the next one if this didn't work out
110
+ //skip to the next one if this didn't work out
108
111
if ( ! body ) return ;
109
112
110
113
try {
@@ -124,20 +127,19 @@ const processFeed =
124
127
} ) ;
125
128
126
129
contentFromAllFeeds [ group ] . push ( contents as object ) ;
127
- console . log (
128
- `${ success ( "Successfully fetched:" ) } ${ feed } - ${ benchmark ( startTime ) } `
130
+ process . stdout . write (
131
+ `${ success ( "Successfully fetched:" ) } ${ feed } - ${ benchmark ( startTime ) } \n `
129
132
) ;
130
133
} catch ( err ) {
131
- console . log (
134
+ process . stdout . write (
132
135
`${ error ( "Error processing:" ) } ${ feed } - ${ benchmark (
133
136
startTime
134
- ) } \n${ err } `
137
+ ) } \n${ err } \n `
135
138
) ;
136
139
errors . push ( `Error processing: ${ feed } \n\t${ err } ` ) ;
137
140
}
138
141
139
- // if this is the last feed, go ahead and build the output
140
- completed === feedListLength && finishBuild ( ) ;
142
+ finishBuild ( ) ;
141
143
} ;
142
144
143
145
// go through each group of feeds and process
@@ -150,20 +152,21 @@ const processFeeds = () => {
150
152
for ( const feed of feeds ) {
151
153
const startTime = Date . now ( ) ;
152
154
setTimeout ( ( ) => {
153
- console . log ( `Fetching: ${ feed } ...` ) ;
155
+ process . stdout . write ( `Fetching: ${ feed } ...\n ` ) ;
154
156
155
157
fetch ( feed )
156
158
. then ( processFeed ( { group, feed, startTime } ) )
157
159
. catch ( err => {
158
- console . log (
159
- error ( `Error fetching ${ feed } ${ benchmark ( startTime ) } ` )
160
+ process . stdout . write (
161
+ error ( `Error fetching ${ feed } ${ benchmark ( startTime ) } \n ` )
160
162
) ;
161
- errors . push ( `Error fetching ${ feed } ${ err . toString ( ) } ` ) ;
163
+ errors . push ( `Error fetching ${ feed } ${ err . toString ( ) } \n` ) ;
164
+ finishBuild ( ) ;
162
165
} ) ;
163
166
} , ( idx % ( feedListLength / MAX_CONNECTIONS ) ) * DELAY_MS ) ;
164
167
idx ++ ;
165
168
}
166
169
}
167
170
} ;
168
171
169
- processFeeds ( ) ;
172
+ processFeeds ( ) ;
0 commit comments