@@ -21,6 +21,7 @@ import path from 'node:path'
2121import { fileURLToPath } from 'node:url'
2222
2323import { spawn } from '@socketsecurity/lib/spawn'
24+ import { logger } from '@socketsecurity/lib/logger'
2425
2526const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
2627const rootPath = path . join ( __dirname , '..' )
@@ -38,9 +39,9 @@ function checkNodeVersion() {
3839 const major = Number . parseInt ( nodeVersion . split ( '.' ) [ 0 ] , 10 )
3940
4041 if ( major < 18 ) {
41- console . error ( '❌ Node.js version 18 or higher is required' )
42- console . error ( ` Current version: ${ nodeVersion } ` )
43- console . error ( ' Please upgrade: https://nodejs.org/' )
42+ logger . error ( ' Node.js version 18 or higher is required' )
43+ logger . error ( `Current version: ${ nodeVersion } ` )
44+ logger . error ( 'Please upgrade: https://nodejs.org/' )
4445 process . exit ( 1 )
4546 }
4647}
@@ -49,7 +50,7 @@ function checkNodeVersion() {
4950 * Show help message.
5051 */
5152function showHelp ( ) {
52- console . log ( `
53+ logger . info ( `
5354╔═══════════════════════════════════════════════════╗
5455║ Socket CLI WASM Bundle Manager ║
5556╚═══════════════════════════════════════════════════╝
@@ -112,53 +113,53 @@ async function exec(command, args, options = {}) {
112113 * Build WASM bundle from source.
113114 */
114115async function buildWasm ( ) {
115- console . log ( '╔═══════════════════════════════════════════════════╗' )
116- console . log ( '║ Building WASM Bundle from Source ║' )
117- console . log ( '╚═══════════════════════════════════════════════════╝\n' )
116+ logger . info ( '╔═══════════════════════════════════════════════════╗' )
117+ logger . info ( '║ Building WASM Bundle from Source ║' )
118+ logger . info ( '╚═══════════════════════════════════════════════════╝\n' )
118119
119120 const convertScript = path . join ( __dirname , 'wasm' , 'convert-codet5.mjs' )
120121 const buildScript = path . join ( __dirname , 'wasm' , 'build-unified-wasm.mjs' )
121122
122123 // Step 1: Convert CodeT5 models to INT4.
123- console . log ( 'Step 1: Converting CodeT5 models to ONNX INT4...\n' )
124+ logger . info ( 'Step 1: Converting CodeT5 models to ONNX INT4...\n' )
124125 try {
125126 await exec ( 'node' , [ convertScript ] , { stdio : 'inherit' } )
126127 } catch ( e ) {
127- console . error ( '\n❌ CodeT5 conversion failed' )
128- console . error ( ` Error: ${ e . message } ` )
128+ logger . error ( '\n❌ CodeT5 conversion failed' )
129+ logger . error ( `Error: ${ e . message } ` )
129130 process . exit ( 1 )
130131 }
131132
132133 // Step 2: Build unified WASM bundle.
133- console . log ( '\nStep 2: Building unified WASM bundle...\n' )
134+ logger . info ( '\nStep 2: Building unified WASM bundle...\n' )
134135 try {
135136 await exec ( 'node' , [ buildScript ] , { stdio : 'inherit' } )
136137 } catch ( e ) {
137- console . error ( '\n❌ WASM bundle build failed' )
138- console . error ( ` Error: ${ e . message } ` )
138+ logger . error ( '\n❌ WASM bundle build failed' )
139+ logger . error ( `Error: ${ e . message } ` )
139140 process . exit ( 1 )
140141 }
141142
142143 // Verify output file exists.
143144 if ( ! existsSync ( outputFile ) ) {
144- console . error ( `\n❌ Output file not found: ${ outputFile } ` )
145+ logger . error ( `\n❌ Output file not found: ${ outputFile } ` )
145146 process . exit ( 1 )
146147 }
147148
148149 const stats = await fs . stat ( outputFile )
149- console . log ( '\n╔═══════════════════════════════════════════════════╗' )
150- console . log ( '║ Build Complete ║' )
151- console . log ( '╚═══════════════════════════════════════════════════╝\n' )
152- console . log ( '✓ WASM bundle built successfully')
153- console . log ( `✓ Output: ${ outputFile } ` )
154- console . log ( `✓ Size: ${ ( stats . size / 1024 / 1024 ) . toFixed ( 2 ) } MB\n` )
150+ logger . info ( '\n╔═══════════════════════════════════════════════════╗' )
151+ logger . info ( '║ Build Complete ║' )
152+ logger . info ( '╚═══════════════════════════════════════════════════╝\n' )
153+ logger . done ( ' WASM bundle built successfully')
154+ logger . info ( `✓ Output: ${ outputFile } ` )
155+ logger . info ( `✓ Size: ${ ( stats . size / 1024 / 1024 ) . toFixed ( 2 ) } MB\n` )
155156}
156157
157158/**
158159 * Get latest WASM build release from GitHub.
159160 */
160161async function getLatestWasmRelease ( ) {
161- console . log ( '📡 Fetching latest WASM build from GitHub...\n' )
162+ logger . info ( '📡 Fetching latest WASM build from GitHub...\n' )
162163
163164 try {
164165 const apiUrl = `https://api.github.com/repos/${ GITHUB_REPO } /releases`
@@ -198,10 +199,10 @@ async function getLatestWasmRelease() {
198199 url : asset . browser_download_url ,
199200 }
200201 } catch ( e ) {
201- console . error ( '❌ Failed to fetch release information' )
202- console . error ( ` Error: ${ e . message } ` )
203- console . error ( '\nTry building from source instead:' )
204- console . error ( ' node scripts/wasm.mjs --build\n' )
202+ logger . error ( ' Failed to fetch release information' )
203+ logger . error ( `Error: ${ e . message } ` )
204+ logger . error ( '\nTry building from source instead:' )
205+ logger . error ( 'node scripts/wasm.mjs --build\n' )
205206 process . exit ( 1 )
206207 }
207208}
@@ -210,9 +211,9 @@ async function getLatestWasmRelease() {
210211 * Download file with progress.
211212 */
212213async function downloadFile ( url , outputPath , expectedSize ) {
213- console . log ( '📥 Downloading from GitHub...')
214- console . log ( ` URL: ${ url } `)
215- console . log ( ` Size: ${ ( expectedSize / 1024 / 1024 ) . toFixed ( 2 ) } MB\n`)
214+ logger . progress ( ' Downloading from GitHub...')
215+ logger . substep ( ` URL: ${ url } `)
216+ logger . substep ( ` Size: ${ ( expectedSize / 1024 / 1024 ) . toFixed ( 2 ) } MB\n`)
216217
217218 try {
218219 const response = await fetch ( url , {
@@ -230,13 +231,13 @@ async function downloadFile(url, outputPath, expectedSize) {
230231 await fs . writeFile ( outputPath , Buffer . from ( buffer ) )
231232
232233 const stats = await fs . stat ( outputPath )
233- console . log ( `✓ Downloaded ${ ( stats . size / 1024 / 1024 ) . toFixed ( 2 ) } MB` )
234- console . log ( `✓ Saved to ${ outputPath } \n` )
234+ logger . info ( `✓ Downloaded ${ ( stats . size / 1024 / 1024 ) . toFixed ( 2 ) } MB` )
235+ logger . info ( `✓ Saved to ${ outputPath } \n` )
235236 } catch ( e ) {
236- console . error ( '❌ Download failed' )
237- console . error ( ` Error: ${ e . message } ` )
238- console . error ( '\nTry building from source instead:' )
239- console . error ( ' node scripts/wasm.mjs --build\n' )
237+ logger . error ( ' Download failed' )
238+ logger . error ( `Error: ${ e . message } ` )
239+ logger . error ( '\nTry building from source instead:' )
240+ logger . error ( 'node scripts/wasm.mjs --build\n' )
240241 process . exit ( 1 )
241242 }
242243}
@@ -245,49 +246,49 @@ async function downloadFile(url, outputPath, expectedSize) {
245246 * Download pre-built WASM bundle from GitHub releases.
246247 */
247248async function downloadWasm ( ) {
248- console . log ( '╔═══════════════════════════════════════════════════╗' )
249- console . log ( '║ Downloading Pre-built WASM Bundle ║' )
250- console . log ( '╚═══════════════════════════════════════════════════╝\n' )
249+ logger . info ( '╔═══════════════════════════════════════════════════╗' )
250+ logger . info ( '║ Downloading Pre-built WASM Bundle ║' )
251+ logger . info ( '╚═══════════════════════════════════════════════════╝\n' )
251252
252253 // Check if output file already exists.
253254 if ( existsSync ( outputFile ) ) {
254255 const stats = await fs . stat ( outputFile )
255- console . log ( '⚠ WASM bundle already exists:')
256- console . log ( ` ${ outputFile } `)
257- console . log ( ` Size: ${ ( stats . size / 1024 / 1024 ) . toFixed ( 2 ) } MB\n`)
256+ logger . warn ( ' WASM bundle already exists:')
257+ logger . substep ( ` ${ outputFile } `)
258+ logger . substep ( ` Size: ${ ( stats . size / 1024 / 1024 ) . toFixed ( 2 ) } MB\n`)
258259
259260 // Ask user if they want to overwrite (simple y/n).
260- console . log ( 'Overwrite? (y/N): ' )
261+ logger . info ( 'Overwrite? (y/N): ' )
261262 const answer = await new Promise ( resolve => {
262263 process . stdin . once ( 'data' , data => {
263264 resolve ( data . toString ( ) . trim ( ) . toLowerCase ( ) )
264265 } )
265266 } )
266267
267268 if ( answer !== 'y' && answer !== 'yes' ) {
268- console . log ( '\n✓ Keeping existing file\n' )
269+ logger . info ( '\n✓ Keeping existing file\n' )
269270 return
270271 }
271272
272- console . log ( )
273+ logger . info ( )
273274 }
274275
275276 // Get latest release info.
276277 const release = await getLatestWasmRelease ( )
277- console . log ( `✓ Found release: ${ release . name } ` )
278- console . log ( ` Tag: ${ release . tagName } \n`)
278+ logger . info ( `✓ Found release: ${ release . name } ` )
279+ logger . substep ( ` Tag: ${ release . tagName } \n`)
279280
280281 // Ensure output directory exists.
281282 await fs . mkdir ( externalDir , { recursive : true } )
282283
283284 // Download the file.
284285 await downloadFile ( release . url , outputFile , release . asset . size )
285286
286- console . log ( '╔═══════════════════════════════════════════════════╗' )
287- console . log ( '║ Download Complete ║' )
288- console . log ( '╚═══════════════════════════════════════════════════╝\n' )
289- console . log ( '✓ WASM bundle downloaded successfully')
290- console . log ( `✓ Output: ${ outputFile } \n` )
287+ logger . info ( '╔═══════════════════════════════════════════════════╗' )
288+ logger . info ( '║ Download Complete ║' )
289+ logger . info ( '╚═══════════════════════════════════════════════════╝\n' )
290+ logger . done ( ' WASM bundle downloaded successfully')
291+ logger . info ( `✓ Output: ${ outputFile } \n` )
291292}
292293
293294/**
@@ -314,12 +315,12 @@ async function main() {
314315 return
315316 }
316317
317- console . error ( '❌ Unknown command\n' )
318+ logger . error ( ' Unknown command\n' )
318319 showHelp ( )
319320 process . exit ( 1 )
320321}
321322
322323main ( ) . catch ( e => {
323- console . error ( '❌ Unexpected error:' , e )
324+ logger . error ( ' Unexpected error:' , e )
324325 process . exit ( 1 )
325326} )
0 commit comments