Skip to content
Draft
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
10 changes: 10 additions & 0 deletions packages/boxel-cli/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@ export {
BoxelCLIClient,
type CreateRealmOptions,
type CreateRealmResult,
type PullOptions,
type PullResult,
type ReadResult,
type WriteResult,
type DeleteResult,
type SearchResult,
type ListFilesResult,
type RunCommandResult,
type LintMessage,
type LintResult,
} from './src/lib/boxel-cli-client';
50 changes: 47 additions & 3 deletions packages/boxel-cli/src/commands/realm/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface PullOptions extends SyncOptions {

class RealmPuller extends RealmSyncBase {
hasError = false;
downloadedFiles: string[] = [];

constructor(
private pullOptions: PullOptions,
Expand Down Expand Up @@ -106,7 +107,7 @@ class RealmPuller extends RealmSyncBase {
}),
),
);
const downloadedFiles = downloadResults.filter(
this.downloadedFiles = downloadResults.filter(
(f): f is string => f !== null,
);

Expand Down Expand Up @@ -138,10 +139,10 @@ class RealmPuller extends RealmSyncBase {

if (
!this.options.dryRun &&
downloadedFiles.length + deletedFiles.length > 0
this.downloadedFiles.length + deletedFiles.length > 0
) {
const pullChanges: CheckpointChange[] = [
...downloadedFiles.map((f) => ({
...this.downloadedFiles.map((f) => ({
file: f,
status: 'modified' as const,
})),
Expand Down Expand Up @@ -232,3 +233,46 @@ export async function pullCommand(
process.exit(1);
}
}

export async function pull(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop the pullCommand function and use this function in registerPullCommand and move the console.log and process.exit that previously handled in pullCommand to registerPullCommand.

realmUrl: string,
localDir: string,
options: PullCommandOptions,
): Promise<{ files: string[]; error?: string }> {
let pm = options.profileManager ?? getProfileManager();
let active = pm.getActiveProfile();
if (!active) {
return {
files: [],
error: 'No active profile. Run `boxel profile add` to create one.',
};
}

try {
const puller = new RealmPuller(
{
realmUrl,
localDir,
deleteLocal: options.delete,
},
pm,
);

await puller.sync();

if (puller.hasError) {
return {
files: puller.downloadedFiles.sort(),
error:
'Pull completed with errors. Some files may not have been downloaded.',
};
}

return { files: puller.downloadedFiles.sort() };
} catch (error) {
return {
files: [],
error: `Pull failed: ${error instanceof Error ? error.message : String(error)}`,
};
}
}
Loading