|
15 | 15 |
|
16 | 16 | const { spawn } = require( 'child_process' ); |
17 | 17 | const fs = require( 'fs' ); |
| 18 | +const { pipeline } = require( 'stream/promises' ); |
18 | 19 | const path = require( 'path' ); |
19 | 20 |
|
20 | 21 | // Paths |
21 | 22 | const rootDir = path.resolve( __dirname, '../..' ); |
22 | 23 | const gutenbergDir = path.join( rootDir, 'gutenberg' ); |
23 | | -const packageJsonPath = path.join( rootDir, 'package.json' ); |
24 | 24 |
|
25 | 25 | /** |
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. |
27 | 29 | * |
28 | 30 | * @param {string} command - Command to execute. |
29 | 31 | * @param {string[]} args - Command arguments. |
@@ -74,9 +76,7 @@ async function main( force ) { |
74 | 76 | // Read Gutenberg configuration from package.json. |
75 | 77 | let sha, ghcrRepo; |
76 | 78 | try { |
77 | | - const packageJson = JSON.parse( |
78 | | - fs.readFileSync( packageJsonPath, 'utf8' ) |
79 | | - ); |
| 79 | + const packageJson = require( path.join( rootDir, 'package.json' ) ); |
80 | 80 | sha = packageJson.gutenberg?.sha; |
81 | 81 | ghcrRepo = packageJson.gutenberg?.ghcrRepo; |
82 | 82 |
|
@@ -158,8 +158,7 @@ async function main( force ) { |
158 | 158 | if ( ! response.ok ) { |
159 | 159 | throw new Error( `Failed to download blob: ${ response.status } ${ response.statusText }` ); |
160 | 160 | } |
161 | | - const buffer = await response.arrayBuffer(); |
162 | | - fs.writeFileSync( zipPath, Buffer.from( buffer ) ); |
| 161 | + await pipeline( response.body, fs.createWriteStream( zipPath ) ); |
163 | 162 | console.log( '✅ Download complete' ); |
164 | 163 | } catch ( error ) { |
165 | 164 | console.error( '❌ Download failed:', error.message ); |
|
0 commit comments