Skip to content

Commit

Permalink
refactor: clean up cli output (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric authored Mar 27, 2024
1 parent fcab1ba commit 6d9395f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"dependencies": {
"@expo/server": "^0.3.1",
"arg": "^5.0.2",
"chalk": "^4.1.2",
"compression": "^1.7.4",
"connect": "^3.7.0",
"express": "^4.18.2",
Expand Down
32 changes: 19 additions & 13 deletions src/cli/bin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
import arg from 'arg';
import chalk from 'chalk';
import open from 'open';
import path from 'path';

Expand All @@ -26,16 +27,16 @@ if (args['--version']) {
}

if (args['--help']) {
console.log(`
Usage
$ expo-atlas [statsFile]
Options
--port, -p Port to listen on
--no-open Do not open the browser automatically
--help, -h Displays this message
--version, -v Displays the current version
`);
printLines([
chalk.bold('Usage'),
` ${chalk.dim('$')} expo-atlas ${chalk.dim('[statsFile]')}`,
'',
chalk.bold('Options'),
` --port${chalk.dim(', -p')} Port to listen on`,
` --no-open Do not open the browser automatically`,
` --help${chalk.dim(', -h')} Displays this message`,
` --version${chalk.dim(', -v')} Displays the current version`,
]);
process.exit(0);
}

Expand All @@ -49,9 +50,10 @@ async function run() {
server.listen(options.port, () => {
const href = `http://localhost:${options.port}`;

console.log(`Metro bundle inspector is ready on ${href}`);
console.log('Loaded stats file:');
console.log(` ${options.statsFile}`);
printLines([
`Expo Atlas is ready on: ${chalk.underline(href)}`,
` ${chalk.dim(`Using: ${options.statsFile}`)}`,
]);

if (options.browserOpen) {
open(href).catch((error) => {
Expand All @@ -61,6 +63,10 @@ async function run() {
});
}

function printLines(lines: string[]) {
console.log(` ${lines.join('\n ')}`);
}

run().catch((error) => {
if (error.type !== 'AtlasError') {
throw error;
Expand Down

0 comments on commit 6d9395f

Please sign in to comment.