Skip to content

Commit 68f166b

Browse files
authored
Improve cli output (#100)
* fix: update documentation and configuration for getting started guide - Changed label in astro.config.mjs from 'Getting Started' to 'START HERE' - Added new 'Getting Started' page content with introductory guide and navigation cards - Improved onboarding flow for new users by providing clearer entry point and resources * fix(docs): update getting-started guide link and rename trigger-and-monitor to run-flow * fix: improve CLI output formatting and add outro messaging for better UX - Corrected string formatting in createTaskLog for consistent output - Enhanced flow name extraction with regex and fallback logic - Added outro calls after successful and failed compilations for clearer guidance - Included additional messaging in install commands to inform users about next steps - Updated import statements to include missing modules and ensure proper functionality - Refined user prompts and success/error messages for consistency and clarity * docs: add changelog entry for minor 'pgflow' update and improve outro messaging * chore: update install command to remove unused import and improve messaging
1 parent 28cecf4 commit 68f166b

File tree

6 files changed

+113
-48
lines changed

6 files changed

+113
-48
lines changed

.changeset/ninety-kings-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pgflow': minor
3+
---
4+
5+
Improve outro messaging

pkgs/cli/src/commands/compile/index.ts

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type Command } from 'commander';
22
import chalk from 'chalk';
3-
import { intro, log, note } from '@clack/prompts';
3+
import { intro, log, note, outro } from '@clack/prompts';
44
import path from 'path';
55
import fs from 'fs';
66
import { spawn } from 'child_process';
@@ -35,14 +35,18 @@ function formatCommand(command: string, args: string[]): string {
3535
/**
3636
* Creates a task log entry with a command and its output
3737
*/
38-
function createTaskLog(command: string, args: string[], output: string): string {
38+
function createTaskLog(
39+
command: string,
40+
args: string[],
41+
output: string
42+
): string {
3943
return [
40-
chalk.bold("Command:"),
44+
chalk.bold('Command:'),
4145
formatCommand(command, args),
42-
"",
43-
chalk.bold("Output:"),
44-
output.trim() ? output.trim() : "(no output)",
45-
].join("\n");
46+
'',
47+
chalk.bold('Output:'),
48+
output.trim() ? output.trim() : '(no output)',
49+
].join('\n');
4650
}
4751

4852
export default (program: Command) => {
@@ -129,20 +133,27 @@ export default (program: Command) => {
129133
resolvedFlowPath,
130134
resolvedDenoJsonPath
131135
);
132-
136+
133137
// Extract flow name from the first line of the SQL output using regex
134138
// Looking for pattern: SELECT pgflow.create_flow('flow_name', ...);
135-
const flowNameMatch = compiledSql.match(/SELECT\s+pgflow\.create_flow\s*\(\s*'([^']+)'/i);
136-
139+
const flowNameMatch = compiledSql.match(
140+
/SELECT\s+pgflow\.create_flow\s*\(\s*'([^']+)'/i
141+
);
142+
137143
// Use extracted flow name or fallback to the file basename if extraction fails
138144
let flowName;
139145
if (flowNameMatch && flowNameMatch[1]) {
140146
flowName = flowNameMatch[1];
141147
log.info(`Extracted flow name: ${flowName}`);
142148
} else {
143149
// Fallback to file basename if regex doesn't match
144-
flowName = path.basename(resolvedFlowPath, path.extname(resolvedFlowPath));
145-
log.warn(`Could not extract flow name from SQL, using file basename: ${flowName}`);
150+
flowName = path.basename(
151+
resolvedFlowPath,
152+
path.extname(resolvedFlowPath)
153+
);
154+
log.warn(
155+
`Could not extract flow name from SQL, using file basename: ${flowName}`
156+
);
146157
}
147158

148159
// Create migration filename in the format: <timestamp>_create_<flow_name>_flow.sql
@@ -157,16 +168,34 @@ export default (program: Command) => {
157168
migrationFilePath
158169
);
159170
log.success(`Migration file created: ${relativeFilePath}`);
160-
171+
172+
// Display next steps with outro
173+
outro(
174+
[
175+
chalk.bold('Flow compilation completed successfully!'),
176+
'',
177+
`- Run ${chalk.cyan('supabase migration up')} to apply the migration`,
178+
'',
179+
chalk.bold('Continue the setup:'),
180+
chalk.blue.underline('https://pgflow.dev/getting-started/run-flow/')
181+
].join('\n')
182+
);
161183
} catch (error) {
162184
log.error(
163185
`Compilation failed: ${
164186
error instanceof Error ? error.message : String(error)
165187
}`
166188
);
167-
168-
note('For troubleshooting help, visit: https://pgflow.dev/getting-started/compile-to-sql/');
169-
189+
190+
outro(
191+
[
192+
chalk.bold('Compilation failed!'),
193+
'',
194+
chalk.bold('For troubleshooting help:'),
195+
chalk.blue.underline('https://pgflow.dev/getting-started/compile-to-sql/')
196+
].join('\n')
197+
);
198+
170199
process.exit(1);
171200
}
172201
});
@@ -220,7 +249,7 @@ async function runDenoCompilation(
220249
deno.on('close', (code) => {
221250
// Always display the task log with command and output
222251
note(createTaskLog('deno', args, stdout));
223-
252+
224253
if (code === 0) {
225254
if (stdout.trim().length === 0) {
226255
reject(new Error('Compilation produced no output'));
@@ -246,4 +275,4 @@ async function runDenoCompilation(
246275
);
247276
});
248277
});
249-
}
278+
}

pkgs/cli/src/commands/install/index.ts

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { type Command } from 'commander';
2-
import { intro, log, note, group, cancel } from '@clack/prompts';
2+
import { intro, group, cancel, outro } from '@clack/prompts';
3+
import chalk from 'chalk';
34
import { copyMigrations } from './copy-migrations.js';
45
import { updateConfigToml } from './update-config-toml.js';
56
import { updateEnvFile } from './update-env-file.js';
@@ -18,7 +19,8 @@ export default (program: Command) => {
1819
const results = await group(
1920
{
2021
// Step 1: Determine Supabase path
21-
supabasePath: () => supabasePathPrompt({ supabasePath: options.supabasePath }),
22+
supabasePath: () =>
23+
supabasePathPrompt({ supabasePath: options.supabasePath }),
2224

2325
// Step 2: Update config.toml
2426
configUpdate: async ({ results: { supabasePath } }) => {
@@ -72,40 +74,49 @@ export default (program: Command) => {
7274
}
7375

7476
// Show completion message
75-
if (migrations || configUpdate || envFile) {
76-
log.success('pgflow setup completed successfully');
77-
78-
// Show next steps if changes were made
79-
const nextSteps = [];
77+
const outroMessages = [];
8078

81-
if (configUpdate || envFile) {
82-
nextSteps.push(
83-
'• Restart your Supabase instance for configuration changes to take effect'
84-
);
85-
}
79+
// Always start with a bolded acknowledgement
80+
if (migrations || configUpdate || envFile) {
81+
outroMessages.push(chalk.bold('pgflow setup completed successfully!'));
82+
} else {
83+
outroMessages.push(
84+
chalk.bold(
85+
'pgflow is already properly configured - no changes needed!'
86+
)
87+
);
88+
}
8689

87-
if (migrations) {
88-
nextSteps.push('• Apply the migrations with: supabase migrations up');
89-
}
90+
// Add a newline after the acknowledgement
91+
outroMessages.push('');
9092

91-
// Add documentation link
92-
nextSteps.push(
93-
'• For more information, visit: https://pgflow.dev/getting-started/install-pgflow/'
93+
// Add specific next steps if changes were made
94+
if (configUpdate || envFile) {
95+
outroMessages.push(
96+
`- Restart your Supabase instance for configuration changes to take effect`
9497
);
98+
}
9599

96-
if (nextSteps.length > 0) {
97-
note(nextSteps.join('\n'), 'Next steps');
98-
}
99-
} else {
100-
log.success(
101-
'pgflow is already properly configured - no changes needed'
100+
if (migrations) {
101+
outroMessages.push(
102+
`- Apply the migrations with: ${chalk.cyan('supabase migrations up')}`
102103
);
104+
}
103105

104-
// Still show documentation link even if no changes were made
105-
note(
106-
'For more information about pgflow, visit: https://pgflow.dev/getting-started/install-pgflow/',
107-
'Documentation'
108-
);
106+
// Always add documentation link with consistent formatting
107+
if (outroMessages.length > 2) {
108+
// If we have specific steps, add another newline
109+
outroMessages.push('');
109110
}
111+
112+
outroMessages.push(
113+
chalk.bold('Continue the setup:'),
114+
chalk.blue.underline(
115+
'https://pgflow.dev/getting-started/compile-to-sql/'
116+
)
117+
);
118+
119+
// Single outro for all paths
120+
outro(outroMessages.join('\n'));
110121
});
111122
};

pkgs/website/astro.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default defineConfig({
7878
id: 'pgflow',
7979
items: [
8080
{
81-
label: 'Getting Started',
81+
label: 'START HERE',
8282
autogenerate: { directory: 'getting-started/' },
8383
},
8484
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Getting Started
3+
description: Getting started with pgflow
4+
sidebar:
5+
order: 0
6+
---
7+
8+
Welcome to pgflow! This guide will walk you through the essential steps to start using pgflow for your workflow automation needs.
9+
10+
import { CardGrid, LinkCard } from '@astrojs/starlight/components';
11+
12+
<CardGrid>
13+
<LinkCard title="Install pgflow" href="/getting-started/install-pgflow/" description="Learn how to install and set up pgflow in your project"/>
14+
<LinkCard title="Create Your First Flow" href="/getting-started/create-first-flow/" description="Define your first workflow using the pgflow DSL"/>
15+
<LinkCard title="Compile to SQL" href="/getting-started/compile-to-sql/" description="Convert your TypeScript workflows to PostgreSQL"/>
16+
<LinkCard title="Run your flow" href="/getting-started/run-flow/" description="Run your flows and track their execution"/>
17+
</CardGrid>
18+
19+
Follow these guides in order to get a complete understanding of the pgflow workflow.
20+

0 commit comments

Comments
 (0)