Skip to content

Commit fdd1bc3

Browse files
committed
Address some review feedback.
1 parent 346e4df commit fdd1bc3

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

tools/gutenberg/download-gutenberg.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515

1616
const { spawn } = require( 'child_process' );
1717
const fs = require( 'fs' );
18+
const { pipeline } = require( 'stream/promises' );
1819
const path = require( 'path' );
1920

2021
// Paths
2122
const rootDir = path.resolve( __dirname, '../..' );
2223
const gutenbergDir = path.join( rootDir, 'gutenberg' );
23-
const packageJsonPath = path.join( rootDir, 'package.json' );
2424

2525
/**
26-
* Execute a command, streaming stdio directly so progress is visible.
26+
* Execute a command. By default, stdio is inherited so progress is visible in
27+
* the terminal. When `options.captureOutput` is true, stdout is piped and the
28+
* promise resolves with the captured stdout once the process exits.
2729
*
2830
* @param {string} command - Command to execute.
2931
* @param {string[]} args - Command arguments.
@@ -74,9 +76,7 @@ async function main( force ) {
7476
// Read Gutenberg configuration from package.json.
7577
let sha, ghcrRepo;
7678
try {
77-
const packageJson = JSON.parse(
78-
fs.readFileSync( packageJsonPath, 'utf8' )
79-
);
79+
const packageJson = require( path.join( rootDir, 'package.json' ) );
8080
sha = packageJson.gutenberg?.sha;
8181
ghcrRepo = packageJson.gutenberg?.ghcrRepo;
8282

@@ -158,8 +158,7 @@ async function main( force ) {
158158
if ( ! response.ok ) {
159159
throw new Error( `Failed to download blob: ${ response.status } ${ response.statusText }` );
160160
}
161-
const buffer = await response.arrayBuffer();
162-
fs.writeFileSync( zipPath, Buffer.from( buffer ) );
161+
await pipeline( response.body, fs.createWriteStream( zipPath ) );
163162
console.log( '✅ Download complete' );
164163
} catch ( error ) {
165164
console.error( '❌ Download failed:', error.message );

0 commit comments

Comments
 (0)