Skip to content

The open alternative to Salesforce, designed for AI.

1.7 KB
Raw Blame
import { fetchAppPlan } from '@/app/deployment/fetch-app-plan';
import { formatAppPlan } from '@/app/deployment/format-app-plan';
import { getAppPlanSummary } from '@/app/deployment/get-app-plan-summary';
import { readInferDeletionOption } from '@/app/deployment/read-infer-deletion-option';
import { runAppBuild } from '@/app/run-app-operation';
import { type CommandRun } from '@/catalog/types/command-run.type';
import { type TargetCommandContext } from '@/catalog/types/target-command-context.type';

export const runAppPlanCommand: CommandRun<TargetCommandContext> = async (
  context,
) => {
  const startedAt = performance.now();
  const inferDeletionFromMissingEntities = readInferDeletionOption(context);
  const {
    project,
    sdk,
    data: build,
    diagnostics,
  } = await runAppBuild({ context });

  context.output.progress({
    message: 'Computing metadata plan (read-only, nothing will be applied)…',
  });

  const actions = await fetchAppPlan({
    build,
    inferDeletionFromMissingEntities,
    target: context.target,
    signal: context.signal,
  });
  const summary = getAppPlanSummary(actions);

  return {
    data: {
      app: { path: project.path, name: project.name },
      sdk: { version: sdk.version },
      application: build.application,
      contentHash: build.contentHash,
      plan: true,
      inferDeletionFromMissingEntities:
        inferDeletionFromMissingEntities ?? null,
      actions,
      summary,
      diagnostics,
      durationMilliseconds: Math.round(performance.now() - startedAt),
    },
    human: formatAppPlan({
      applicationName: build.application.displayName,
      apiUrl: context.target.apiUrl,
      actions,
      summary,
      inferDeletionFromMissingEntities,
    }),
  };
};