|
1 | | -import { intro, log, outro } from "@clack/prompts"; |
2 | | -import { getBranch, prepareDeploymentError } from "@trigger.dev/core/v3"; |
3 | | -import { InitializeDeploymentResponseBody } from "@trigger.dev/core/v3/schemas"; |
4 | | -import { Command, Option as CommandOption } from "commander"; |
| 1 | +import { intro } from "@clack/prompts"; |
| 2 | +import { getBranch } from "@trigger.dev/core/v3"; |
| 3 | +import { Command } from "commander"; |
5 | 4 | import { resolve } from "node:path"; |
6 | | -import { x } from "tinyexec"; |
7 | 5 | import { z } from "zod"; |
8 | | -import { isCI } from "std-env"; |
9 | | -import { CliApiClient } from "../apiClient.js"; |
10 | | -import { buildWorker } from "../build/buildWorker.js"; |
11 | | -import { resolveAlwaysExternal } from "../build/externals.js"; |
12 | 6 | import { |
13 | 7 | CommonCommandOptions, |
14 | 8 | commonOptions, |
15 | 9 | handleTelemetry, |
16 | | - SkipLoggingError, |
17 | 10 | wrapCommandAction, |
18 | 11 | } from "../cli/common.js"; |
19 | 12 | import { loadConfig } from "../config.js"; |
20 | | -import { buildImage } from "../deploy/buildImage.js"; |
21 | | -import { |
22 | | - checkLogsForErrors, |
23 | | - checkLogsForWarnings, |
24 | | - printErrors, |
25 | | - printWarnings, |
26 | | - saveLogs, |
27 | | -} from "../deploy/logs.js"; |
28 | | -import { chalkError, cliLink, isLinksSupported, prettyError } from "../utilities/cliOutput.js"; |
29 | | -import { loadDotEnvVars } from "../utilities/dotEnv.js"; |
| 13 | +import { createGitMeta } from "../utilities/gitMeta.js"; |
30 | 14 | import { printStandloneInitialBanner } from "../utilities/initialBanner.js"; |
31 | 15 | import { logger } from "../utilities/logger.js"; |
32 | | -import { getProjectClient, upsertBranch } from "../utilities/session.js"; |
33 | | -import { getTmpDir } from "../utilities/tempDirectories.js"; |
| 16 | +import { getProjectClient } from "../utilities/session.js"; |
34 | 17 | import { spinner } from "../utilities/windows.js"; |
| 18 | +import { verifyDirectory } from "./deploy.js"; |
35 | 19 | import { login } from "./login.js"; |
36 | 20 | import { updateTriggerPackages } from "./update.js"; |
37 | | -import { setGithubActionsOutputAndEnvVars } from "../utilities/githubActions.js"; |
38 | | -import { isDirectory } from "../utilities/fileSystem.js"; |
39 | | -import { createGitMeta } from "../utilities/gitMeta.js"; |
40 | | -import { verifyDirectory } from "./deploy.js"; |
| 21 | +import { CliApiClient } from "../apiClient.js"; |
41 | 22 |
|
42 | 23 | const PreviewCommandOptions = CommonCommandOptions.extend({ |
43 | 24 | branch: z.string().optional(), |
44 | 25 | config: z.string().optional(), |
45 | 26 | projectRef: z.string().optional(), |
46 | 27 | skipUpdateCheck: z.boolean().default(false), |
47 | | - envFile: z.string().optional(), |
48 | 28 | }); |
49 | 29 |
|
50 | 30 | type PreviewCommandOptions = z.infer<typeof PreviewCommandOptions>; |
51 | 31 |
|
52 | | -export function configureDeployCommand(program: Command) { |
53 | | - return commonOptions( |
54 | | - program |
55 | | - .command("preview archive") |
| 32 | +export function configurePreviewCommand(program: Command) { |
| 33 | + const preview = program.command("preview").description("Modify preview branches"); |
| 34 | + |
| 35 | + commonOptions( |
| 36 | + preview |
| 37 | + .command("archive") |
56 | 38 | .description("Archive a preview branch") |
57 | 39 | .argument("[path]", "The path to the project", ".") |
58 | 40 | .option( |
59 | 41 | "-b, --branch <branch>", |
60 | | - "The preview branch to deploy to when passing --env preview. If not provided, we'll detect your local git branch." |
| 42 | + "The preview branch to archive. If not provided, we'll detect your local git branch." |
61 | 43 | ) |
62 | 44 | .option("--skip-update-check", "Skip checking for @trigger.dev package updates") |
63 | 45 | .option("-c, --config <config file>", "The name of the config file, found at [path]") |
@@ -137,23 +119,17 @@ async function _previewArchiveCommand(dir: string, options: PreviewCommandOption |
137 | 119 | ); |
138 | 120 | } |
139 | 121 |
|
140 | | - const projectClient = await getProjectClient({ |
141 | | - accessToken: authorization.auth.accessToken, |
142 | | - apiUrl: authorization.auth.apiUrl, |
143 | | - projectRef: resolvedConfig.project, |
144 | | - env: "preview", |
145 | | - branch, |
146 | | - profile: options.profile, |
147 | | - }); |
148 | | - |
149 | | - if (!projectClient) { |
150 | | - throw new Error("Failed to get project client"); |
151 | | - } |
| 122 | + const apiClient = new CliApiClient(authorization.auth.apiUrl, authorization.auth.accessToken); |
152 | 123 |
|
153 | 124 | const $buildSpinner = spinner(); |
154 | 125 | $buildSpinner.start(`Archiving "${branch}"`); |
155 | 126 |
|
156 | | - const result = await projectClient.client.archiveBranch(branch); |
| 127 | + const result = await apiClient.archiveBranch(resolvedConfig.project, branch); |
157 | 128 |
|
158 | | - $buildSpinner.stop(`Successfully archived ${branch}`); |
| 129 | + if (result.success) { |
| 130 | + $buildSpinner.stop(`Successfully archived "${branch}"`); |
| 131 | + } else { |
| 132 | + $buildSpinner.stop(`Failed to archive "${branch}".`); |
| 133 | + logger.error(result.error); |
| 134 | + } |
159 | 135 | } |
0 commit comments