1
1
#!/usr/bin/env node
2
2
// Copyright 2024 the JSR authors. MIT license.
3
- import * as kl from "kolorist" ;
4
3
import * as fs from "node:fs" ;
5
4
import * as path from "node:path" ;
6
5
import { parseArgs } from "node:util" ;
@@ -18,6 +17,7 @@ import {
18
17
JsrPackageNameError ,
19
18
prettyTime ,
20
19
setDebug ,
20
+ styleText ,
21
21
} from "./utils" ;
22
22
import { PkgManagerName } from "./pkg_manager" ;
23
23
@@ -31,7 +31,7 @@ function prettyPrintRow(rows: [string, string][]) {
31
31
}
32
32
33
33
return rows
34
- . map ( ( row ) => ` ${ kl . green ( row [ 0 ] . padStart ( max ) ) } ${ row [ 1 ] } ` )
34
+ . map ( ( row ) => ` ${ styleText ( "green" , row [ 0 ] . padEnd ( max ) ) } ${ row [ 1 ] } ` )
35
35
. join ( "\n" ) ;
36
36
}
37
37
@@ -121,7 +121,7 @@ function getPackages(positionals: string[], allowEmpty: boolean): JsrPackage[] {
121
121
const packages = pkgArgs . map ( ( p ) => JsrPackage . from ( p ) ) ;
122
122
123
123
if ( ! allowEmpty && pkgArgs . length === 0 ) {
124
- console . error ( kl . red ( `Missing packages argument.` ) ) ;
124
+ console . error ( styleText ( "red" , `Missing packages argument.` ) ) ;
125
125
console . log ( ) ;
126
126
printHelp ( ) ;
127
127
process . exit ( 1 ) ;
@@ -161,7 +161,7 @@ if (args.length === 0) {
161
161
} else if ( cmd === "view" || cmd === "show" || cmd === "info" ) {
162
162
const pkgName = args [ 1 ] ;
163
163
if ( pkgName === undefined ) {
164
- console . log ( kl . red ( `Missing package name.` ) ) ;
164
+ console . error ( styleText ( "red" , `Missing package name.` ) ) ;
165
165
printHelp ( ) ;
166
166
process . exit ( 1 ) ;
167
167
}
@@ -236,7 +236,7 @@ if (args.length === 0) {
236
236
} else if ( cmd === "run" ) {
237
237
const script = options . positionals [ 1 ] ;
238
238
if ( ! script ) {
239
- console . error ( kl . red ( `Missing script argument.` ) ) ;
239
+ console . error ( styleText ( "red" , `Missing script argument.` ) ) ;
240
240
console . log ( ) ;
241
241
printHelp ( ) ;
242
242
process . exit ( 1 ) ;
@@ -270,13 +270,13 @@ async function run(fn: () => Promise<void>) {
270
270
await fn ( ) ;
271
271
const time = Date . now ( ) - start ;
272
272
console . log ( ) ;
273
- console . log ( `${ kl . green ( "Completed" ) } in ${ prettyTime ( time ) } ` ) ;
273
+ console . log ( `${ styleText ( "green" , "Completed" ) } in ${ prettyTime ( time ) } ` ) ;
274
274
} catch ( err ) {
275
275
if ( err instanceof JsrPackageNameError ) {
276
- console . log ( kl . red ( err . message ) ) ;
276
+ console . log ( styleText ( "red" , err . message ) ) ;
277
277
process . exit ( 1 ) ;
278
278
} else if ( err instanceof ExecError ) {
279
- console . log ( kl . red ( err . message ) ) ;
279
+ console . log ( styleText ( "red" , err . message ) ) ;
280
280
process . exit ( err . code ) ;
281
281
}
282
282
@@ -285,7 +285,7 @@ async function run(fn: () => Promise<void>) {
285
285
}
286
286
287
287
function throwUnknownCommand ( cmd : string ) {
288
- console . error ( kl . red ( `Unknown command: ${ cmd } ` ) ) ;
288
+ console . error ( styleText ( "red" , `Unknown command: ${ cmd } ` ) ) ;
289
289
console . log ( ) ;
290
290
printHelp ( ) ;
291
291
process . exit ( 1 ) ;
0 commit comments