Skip to content

Commit

Permalink
chore: fix autoupdate log
Browse files Browse the repository at this point in the history
  • Loading branch information
zdm committed Oct 11, 2024
1 parent 29abe7b commit 23ec0e9
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/external-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ class ExternalResources extends Events {
}

async update ( { force, remote = true, forceRemote, ignoreEtag, log, autoUpdate } = {} ) {
if ( autoUpdate ) log = false;

var error,
pad = 0,
cache = {};

if ( log ) {
if ( log || autoUpdate ) {
for ( const resource of Object.values( this.#resources ) ) {
if ( autoUpdate && !resource.autoUpdate ) continue;

Expand All @@ -74,7 +76,9 @@ class ExternalResources extends Events {
for ( const resource of Object.values( this.#resources ) ) {
if ( autoUpdate && !resource.autoUpdate ) continue;

if ( log ) process.stdout.write( `Updating resounrce "${ resource.name }" ... `.padEnd( pad + 26 ) );
const logHeader = `Updating resounrce "${ resource.name }" ... `.padEnd( pad + 26 );

if ( log ) process.stdout.write( logHeader );

const res = await resource.update( {
force,
Expand All @@ -84,16 +88,25 @@ class ExternalResources extends Events {
cache,
} );

let logResult;

if ( res.ok ) {
if ( log ) console.log( ansi.ok( " " + res.statusText + " " ) );
logResult = ansi.ok( " " + res.statusText + " " );
}
else if ( res.is3xx ) {
if ( log ) console.log( res.statusText );
logResult = res.statusText;
}
else {
error = true;

if ( log ) console.log( ansi.error( " " + res.statusText + " " ) );
logResult = ansi.error( " " + res.statusText + " " );
}

if ( log ) {
console.log( logResult );
}
else if ( autoUpdate && res.status !== 304 ) {
console.log( logHeader + logResult );
}
}

Expand Down

0 comments on commit 23ec0e9

Please sign in to comment.