Skip to content

Commit 9955286

Browse files
committed
simplify CLI install command output formatting and show full paths
1 parent 6a52203 commit 9955286

File tree

4 files changed

+43
-119
lines changed

4 files changed

+43
-119
lines changed

pkgs/cli/src/commands/install/copy-migrations.ts

Lines changed: 14 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33
import { createRequire } from 'module';
44
import { fileURLToPath } from 'url';
5-
import { log, confirm, note } from '@clack/prompts';
5+
import { log, confirm } from '@clack/prompts';
66
import chalk from 'chalk';
77

88
// Get the directory name in ES modules
@@ -231,38 +231,9 @@ export async function copyMigrations({
231231
}
232232
}
233233

234-
// If no files to copy, show message with details and return false (no changes made)
234+
// If no files to copy, show message and return false (no changes made)
235235
if (filesToCopy.length === 0) {
236-
// Show success message
237-
log.success('All pgflow migrations are already in place');
238-
239-
// Show details of already installed migrations
240-
if (skippedFiles.length > 0) {
241-
const detailedMsg = [
242-
'Already installed migrations:',
243-
...skippedFiles.map((file) => {
244-
// Find the matching existing file to show how it was installed
245-
const matchingFile = existingFiles.find((existingFile) =>
246-
existingFile.includes(file)
247-
);
248-
249-
if (matchingFile === file) {
250-
// Installed with old direct method
251-
return ` ${chalk.dim('•')} ${chalk.bold(file)}`;
252-
} else {
253-
// Installed with new timestamped method
254-
const timestampPart =
255-
matchingFile?.substring(0, matchingFile.indexOf(file) - 1) || '';
256-
return ` ${chalk.dim('•')} ${chalk.dim(
257-
timestampPart + '_'
258-
)}${chalk.bold(file)}`;
259-
}
260-
}),
261-
].join('\n');
262-
263-
note(detailedMsg, 'Existing pgflow Migrations');
264-
}
265-
236+
log.success(`All ${skippedFiles.length} pgflow migrations are already in place`);
266237
return false;
267238
}
268239

@@ -276,40 +247,17 @@ export async function copyMigrations({
276247
file.destination = `${baseTimestamp}_${file.source}`;
277248
});
278249

279-
log.info(
280-
`Found ${filesToCopy.length} migration${
281-
filesToCopy.length !== 1 ? 's' : ''
282-
} to install`
283-
);
284-
285-
// Prepare summary message with colored output
286-
const summaryParts = [];
287-
288-
if (filesToCopy.length > 0) {
289-
summaryParts.push(
290-
`${chalk.green('New migrations to install:')}\n${filesToCopy
291-
.map((file) => {
292-
// Extract the timestamp part from the new filename
293-
const newTimestamp = file.destination.substring(0, 14);
294-
// Format: dim timestamp + bright original name
295-
return `${chalk.green('+')} ${file.source}${chalk.dim(
296-
newTimestamp + '_'
297-
)}${chalk.bold(file.source)}`;
298-
})
299-
.join('\n')}`
300-
);
301-
}
302-
303-
if (skippedFiles.length > 0) {
304-
summaryParts.push(
305-
`${chalk.yellow('Already installed:')}\n${skippedFiles
306-
.map((file) => `${chalk.yellow('•')} ${file}`)
307-
.join('\n')}`
308-
);
309-
}
250+
// Build summary message similar to success output style
251+
const summaryMsg = [
252+
`New migrations to install:`,
253+
'',
254+
...filesToCopy.map((file) => {
255+
const newTimestamp = file.destination.substring(0, 14);
256+
return ` ${chalk.dim(newTimestamp + '_')}${chalk.bold(file.source)}`;
257+
}),
258+
].join('\n');
310259

311-
// Show summary and ask for confirmation if not auto-confirming
312-
note(summaryParts.join('\n\n'), 'pgflow Migrations');
260+
log.info(summaryMsg);
313261

314262
let shouldContinue = autoConfirm;
315263

@@ -341,6 +289,7 @@ export async function copyMigrations({
341289
`Installed ${filesToCopy.length} migration${
342290
filesToCopy.length !== 1 ? 's' : ''
343291
} to your Supabase project:`,
292+
'',
344293
...filesToCopy.map((file) => {
345294
const newTimestamp = file.destination.substring(0, 14);
346295
return ` ${chalk.dim(newTimestamp + '_')}${chalk.bold(file.source)}`;

pkgs/cli/src/commands/install/create-edge-function.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import { log, confirm, note } from '@clack/prompts';
3+
import { log, confirm } from '@clack/prompts';
44
import chalk from 'chalk';
55
import { getVersion } from '../../utils/get-version.js';
66

@@ -41,40 +41,42 @@ export async function createEdgeFunction({
4141
const indexPath = path.join(pgflowFunctionDir, 'index.ts');
4242
const denoJsonPath = path.join(pgflowFunctionDir, 'deno.json');
4343

44+
// Relative paths for display
45+
const relativeFunctionDir = 'supabase/functions/pgflow';
46+
const relativeIndexPath = `${relativeFunctionDir}/index.ts`;
47+
const relativeDenoJsonPath = `${relativeFunctionDir}/deno.json`;
48+
4449
// Check what needs to be created
45-
const filesToCreate: Array<{ path: string; name: string }> = [];
50+
const filesToCreate: Array<{ path: string; relativePath: string }> = [];
4651

4752
if (!fs.existsSync(indexPath)) {
48-
filesToCreate.push({ path: indexPath, name: 'index.ts' });
53+
filesToCreate.push({ path: indexPath, relativePath: relativeIndexPath });
4954
}
5055

5156
if (!fs.existsSync(denoJsonPath)) {
52-
filesToCreate.push({ path: denoJsonPath, name: 'deno.json' });
57+
filesToCreate.push({ path: denoJsonPath, relativePath: relativeDenoJsonPath });
5358
}
5459

5560
// If all files exist, return success
5661
if (filesToCreate.length === 0) {
57-
log.success('ControlPlane edge function files are already in place');
58-
5962
const detailedMsg = [
60-
'Existing files:',
61-
` ${chalk.dim('•')} ${chalk.bold('supabase/functions/pgflow/index.ts')}`,
62-
` ${chalk.dim('•')} ${chalk.bold('supabase/functions/pgflow/deno.json')}`,
63+
'ControlPlane edge function files are already in place:',
64+
` ${chalk.bold(relativeIndexPath)}`,
65+
` ${chalk.bold(relativeDenoJsonPath)}`,
6366
].join('\n');
6467

65-
note(detailedMsg, 'ControlPlane Edge Function');
68+
log.success(detailedMsg);
6669

6770
return false;
6871
}
6972

7073
// Show what will be created
71-
log.info(`Found ${filesToCreate.length} file${filesToCreate.length !== 1 ? 's' : ''} to create`);
72-
73-
const summaryParts = [`${chalk.green('Files to create:')}\n${filesToCreate
74-
.map((file) => `${chalk.green('+')} ${file.name}`)
75-
.join('\n')}`];
74+
const summaryMsg = [
75+
`Files to create:`,
76+
...filesToCreate.map((file) => ` ${chalk.bold(file.relativePath)}`),
77+
].join('\n');
7678

77-
note(summaryParts.join('\n'), 'ControlPlane Edge Function');
79+
log.info(summaryMsg);
7880

7981
// Get confirmation
8082
let shouldContinue = autoConfirm;
@@ -109,7 +111,7 @@ export async function createEdgeFunction({
109111
// Show success message
110112
const detailedSuccessMsg = [
111113
`Created ${filesToCreate.length} file${filesToCreate.length !== 1 ? 's' : ''}:`,
112-
...filesToCreate.map((file) => ` ${chalk.bold(file.name)}`),
114+
...filesToCreate.map((file) => ` ${chalk.bold(file.relativePath)}`),
113115
].join('\n');
114116

115117
log.success(detailedSuccessMsg);

pkgs/cli/src/commands/install/supabase-path-prompt.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ export async function supabasePathPrompt(options?: { supabasePath?: string }) {
2828
}
2929
}
3030

31-
// Always prompt for detected paths - don't skip
32-
if (detectedPath) {
33-
log.info(`Found Supabase project at: ${detectedPath}`);
34-
}
35-
3631
const promptMessage = 'Where is your Supabase project located?';
3732

3833
const supabasePath = await text({

pkgs/cli/src/commands/install/update-env-file.ts

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import { log, note, confirm } from '@clack/prompts';
3+
import { log, confirm } from '@clack/prompts';
44
import chalk from 'chalk';
55

66
/**
@@ -47,16 +47,12 @@ export async function updateEnvFile({
4747
// Prepare new content
4848
let newContent = currentContent;
4949

50-
// Build diff preview
50+
// Check which variables need to be added
5151
const missingVars: Array<{ key: string; value: string }> = [];
52-
const existingVars: Array<string> = [];
5352

54-
// Check which variables need to be added
5553
for (const [key, value] of Object.entries(envVars)) {
5654
if (!newContent.includes(`${key}=`)) {
5755
missingVars.push({ key, value });
58-
} else {
59-
existingVars.push(key);
6056
}
6157
}
6258

@@ -66,33 +62,15 @@ export async function updateEnvFile({
6662
return false;
6763
}
6864

69-
log.info(`Found ${missingVars.length} variable${missingVars.length !== 1 ? 's' : ''} to add`);
70-
71-
// Build diff preview
72-
const diffPreview: Array<string> = [];
73-
74-
if (isNewFile) {
75-
diffPreview.push(`${chalk.green('Creating new .env file with:')}`);
76-
} else {
77-
diffPreview.push(`${chalk.green('Adding to existing .env file:')}`);
78-
}
79-
80-
// Show variables to be added
81-
for (const { key, value } of missingVars) {
82-
diffPreview.push(`${chalk.green('+')} ${key}="${value}"`);
83-
}
84-
85-
// Show existing variables if any
86-
if (existingVars.length > 0) {
87-
diffPreview.push('');
88-
diffPreview.push(`${chalk.yellow('Already present:')}`);
89-
for (const key of existingVars) {
90-
diffPreview.push(`${chalk.yellow('•')} ${key}`);
91-
}
92-
}
65+
// Build summary message
66+
const summaryParts = [
67+
isNewFile
68+
? `Creating .env file in supabase/functions/:`
69+
: `Adding to supabase/functions/.env:`,
70+
...missingVars.map(({ key, value }) => ` ${chalk.bold(`${key}="${value}"`)}`),
71+
];
9372

94-
// Show the diff preview
95-
note(diffPreview.join('\n'), 'Environment Variables');
73+
log.info(summaryParts.join('\n'));
9674

9775
// Ask for confirmation if not auto-confirming
9876
let shouldContinue = autoConfirm;

0 commit comments

Comments
 (0)