Skip to content

Commit

Permalink
fix: pipes studio logs to CLI if passed --verbose (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
alec-chernicki authored Jan 17, 2024
1 parent 950c517 commit d719a75
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .changeset/lovely-cows-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"commonality": patch
"@commonalityco/studio": patch
---

Updates logging information for Studio failures
16 changes: 10 additions & 6 deletions apps/commonality/src/cli/commands/studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@ const spinner = ora('Starting Commonality Studio...');
export const studio = command
.name('studio')
.description('Open Commonality Studio')
.option('--debug', 'Show additional logging output')
.option('--verbose', 'Show additional logging output')
.option(
'--port <port>',
'The port that Commonality Studio will run on',
'8888',
)
.action(
async (options: { debug?: boolean; port?: string; install?: boolean }) => {
async (options: {
verbose?: boolean;
port?: string;
install?: boolean;
}) => {
spinner.start();

const preferredPort = Number(options.port);
const debug = Boolean(options.debug);
const verbose = Boolean(options.verbose);

try {
await validateProjectStructure({
Expand Down Expand Up @@ -61,7 +65,7 @@ export const studio = command
const { kill } = studio.startStudio({
port,
rootDirectory,
debug,
debug: verbose,
});

const handleExit = () => {
Expand All @@ -85,9 +89,9 @@ export const studio = command
suffixText: chalk.dim('\n (press ctrl-c to quit)'),
});
} catch (error) {
console.log(chalk.red('Failed to start Commonality Studio'));
spinner.fail('Failed to start Commonality Studio');

if (debug) {
if (verbose) {
console.log(error);
}
}
Expand Down
6 changes: 3 additions & 3 deletions apps/commonality/test/integration/studio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe.concurrent('studio', () => {

const cliProcess = execa(
binPath,
['studio', '--debug', '--port', String(preferredPort)],
['studio', '--verbose', '--port', String(preferredPort)],
{
cwd: temporaryPath,
stdout: 'pipe',
Expand Down Expand Up @@ -92,7 +92,7 @@ describe.concurrent('studio', () => {

const cliProcess = execa(
binPath,
['studio', '--debug', '--port', String(preferredPort)],
['studio', '--verbose', '--port', String(preferredPort)],
{
cwd: temporaryPath,
stdout: 'pipe',
Expand Down Expand Up @@ -155,7 +155,7 @@ describe.concurrent('studio', () => {

const cliProcess = execa(
binPath,
['studio', '--debug', '--port', String(preferredPort)],
['studio', '--verbose', '--port', String(preferredPort)],
{
cwd: temporaryPath,
stdout: 'pipe',
Expand Down
4 changes: 2 additions & 2 deletions apps/documentation/pages/docs/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ The port that Commonality Studio should run on. By default, Commonality Studio w
commonality studio --port 1234
```

##### `--debug`
##### `--verbose`

Show the server logs from the Commonality Studio application.

```bash copy
commonality studio --debug
commonality studio --verbose
```
4 changes: 2 additions & 2 deletions apps/studio/start.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
*/
export const startStudio = ({ port, rootDirectory, debug }) => {
const serverProcess = execa('node', ['server.js'], {
stdout: debug ? 'pipe' : 'ignore',
stderr: debug ? 'pipe' : 'ignore',
stdout: debug ? 'inherit' : 'ignore',
stderr: debug ? 'inherit' : 'ignore',
cwd: __dirname,
env: {
PATH: process.env.PATH,
Expand Down

0 comments on commit d719a75

Please sign in to comment.