Skip to content

Commit 7d45485

Browse files
author
Adam McKee
committed
rename exports and cli script
1 parent e818e6a commit 7d45485

File tree

7 files changed

+26
-25
lines changed

7 files changed

+26
-25
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
## [Unreleased]
44

5-
- ???
5+
### Fixed
6+
7+
- Cleaning up console output of errors and CLI usage
68

79
## [v0.0.3] - 2025-06-26
810

File renamed without changes.

lib/attachments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ function compareAttachmentFilenames(
3131
a1: Attachment,
3232
a2: Attachment,
3333
): 1 | 0 | -1 {
34-
if (a1.filename === a2.filename) return 0
34+
if (a1.filename < a2.filename) return -1
3535
if (a1.filename > a2.filename) return 1
36-
return -1
36+
return 0
3737
}
3838

3939
export function resolveAttachmentType(

lib/c2.bin.ts renamed to lib/bin.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ let args: ParsedArgs | undefined
99
try {
1010
args = parseArgs()
1111
} catch (e: any) {
12-
if (e.message) {
13-
console.error(e.message)
14-
}
12+
errorExit(e.message)
1513
}
1614

1715
if (!args || args.help) {
1816
const optional = (s: string) => `\u001b[90m${s}\u001b[0m`
1917
const required = (s: string) => `\u001b[1m${s}\u001b[0m`
20-
errorExit(
18+
console.error(
2119
`c2 ${optional('[[--base64] | [--http PORT]]')} ${required('USER_DATA_DIR')}`,
2220
)
21+
process.exit(1)
2322
}
2423

2524
if (!(await doesDirExist(args.userDataDir))) {
@@ -46,6 +45,10 @@ try {
4645
}
4746

4847
function errorExit(msg: string): never {
49-
console.error(msg)
48+
console.error(errorText('error:'), msg)
5049
process.exit(1)
5150
}
51+
52+
function errorText(s: string): string {
53+
return `\u001b[1;31m${s}\u001b[0m`
54+
}

lib/cli.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test('parseArgs with ts entrypoint', () => {
55
expect(
66
parseArgs([
77
'/Users/who/.bun/bin/bun',
8-
'/Users/who/user-data/lib/c2.bin.ts',
8+
'/Users/who/user-data/lib/bin.ts',
99
'user_data_dir',
1010
]),
1111
).toStrictEqual({
@@ -31,7 +31,7 @@ test('parseArgs with js entrypoint', () => {
3131
expect(
3232
parseArgs([
3333
'/Users/who/.nvm/versions/node/v23.7.0/bin/node',
34-
'/Users/who/user-data/lib_js/c2.bin.js',
34+
'/Users/who/user-data/lib_js/bin.js',
3535
'user_data_dir',
3636
]),
3737
).toStrictEqual({
@@ -50,7 +50,7 @@ test('parseArgs errors without USER_DATA_DIR', () => {
5050
expect(() =>
5151
parseArgs([
5252
'/Users/who/.bun/bin/bun',
53-
'/Users/who/user-data/lib/c2.bin.ts',
53+
'/Users/who/user-data/lib/bin.ts',
5454
]),
5555
).toThrow()
5656
})
@@ -59,7 +59,7 @@ test('parseArgs errors with extra USER_DATA_DIR', () => {
5959
expect(() =>
6060
parseArgs([
6161
'/Users/who/.bun/bin/bun',
62-
'/Users/who/user-data/lib/c2.bin.ts',
62+
'/Users/who/user-data/lib/bin.ts',
6363
'user_data_dir',
6464
'some_other_arg',
6565
]),
@@ -70,7 +70,7 @@ test('parseArgs with --base64', () => {
7070
expect(
7171
parseArgs([
7272
'/Users/who/.bun/bin/bun',
73-
'/Users/who/user-data/lib/c2.bin.ts',
73+
'/Users/who/user-data/lib/bin.ts',
7474
'--base64',
7575
'user_data_dir',
7676
]),
@@ -84,7 +84,7 @@ test('parseArgs with --http PORT', () => {
8484
expect(
8585
parseArgs([
8686
'/Users/who/.bun/bin/bun',
87-
'/Users/who/user-data/lib/c2.bin.ts',
87+
'/Users/who/user-data/lib/bin.ts',
8888
'--http',
8989
'6666',
9090
'user_data_dir',
@@ -96,7 +96,7 @@ test('parseArgs with --http bunk', () => {
9696
expect(() =>
9797
parseArgs([
9898
'/Users/who/.bun/bin/bun',
99-
'/Users/who/user-data/lib/c2.bin.ts',
99+
'/Users/who/user-data/lib/bin.ts',
100100
'--http',
101101
'bunk',
102102
'user_data_dir',
@@ -108,7 +108,7 @@ test('parseArgs with --http without PORT', () => {
108108
expect(() =>
109109
parseArgs([
110110
'/Users/who/.bun/bin/bun',
111-
'/Users/who/user-data/lib/c2.bin.ts',
111+
'/Users/who/user-data/lib/bin.ts',
112112
'user_data_dir',
113113
'--http',
114114
]),

lib/cli.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ export type ParsedArgs =
77
userDataDir: string
88
}
99

10-
const SCRIPT_SUFFIXES = Object.freeze([
11-
'/c2',
12-
'/lib_js/c2.bin.js',
13-
'/lib/c2.bin.ts',
14-
])
10+
const SCRIPT_SUFFIXES = Object.freeze(['/c2', '/lib_js/bin.js', '/lib/bin.ts'])
1511

1612
export function parseArgs(input?: Array<string>): ParsedArgs {
1713
if (!input) {

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
"node": ">=23"
2121
},
2222
"bin": {
23-
"c2": "./lib_js/c2.bin.js"
23+
"c2": "./lib_js/bin.js"
2424
},
2525
"exports": {
2626
".": {
27-
"bun": "./lib/c2.api.ts",
28-
"node": "./lib_js/c2.api.js",
29-
"types": "./lib_types/c2.api.d.ts"
27+
"bun": "./lib/api.ts",
28+
"node": "./lib_js/api.js",
29+
"types": "./lib_types/api.d.ts"
3030
}
3131
},
3232
"scripts": {

0 commit comments

Comments
 (0)