Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: clean up cli output #18

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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