@deepdynamic/cli 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +32 -2
- package/THIRD_PARTY_NOTICES.txt +102 -0
- package/dist/agents/content.js +12 -0
- package/dist/agents/edit.js +140 -0
- package/dist/agents/install.js +190 -0
- package/dist/agents/refresh.js +20 -0
- package/dist/agents/setup.js +29 -0
- package/dist/agents/targets.js +91 -0
- package/dist/auth/credentials.js +63 -0
- package/dist/auth/session.js +49 -0
- package/dist/cli.js +198 -0
- package/dist/commands/account.js +96 -0
- package/dist/commands/activity.js +80 -0
- package/dist/commands/blocked.js +89 -0
- package/dist/commands/deploy/agents.js +11 -0
- package/dist/commands/deploy/files.js +62 -0
- package/dist/commands/deploy/index.js +95 -0
- package/dist/commands/deploy/manifest.js +24 -0
- package/dist/commands/deploy/minify.js +27 -0
- package/dist/commands/deploy/progress.js +85 -0
- package/dist/commands/deploy/ship.js +117 -0
- package/dist/commands/deploy/upload.js +125 -0
- package/dist/commands/deployments.js +60 -0
- package/dist/commands/dns.js +777 -0
- package/dist/commands/domains.js +639 -0
- package/dist/commands/emails.js +74 -0
- package/dist/commands/env.js +194 -0
- package/dist/commands/help.js +148 -0
- package/dist/commands/keys.js +263 -0
- package/dist/commands/login/flow.js +155 -0
- package/dist/commands/login/index.js +26 -0
- package/dist/commands/logout.js +71 -0
- package/dist/commands/mail.js +241 -0
- package/dist/commands/notifications.js +133 -0
- package/dist/commands/plan.js +355 -0
- package/dist/commands/projects.js +838 -0
- package/dist/commands/reference.js +2187 -0
- package/dist/commands/search.js +86 -0
- package/dist/commands/server.js +301 -0
- package/dist/commands/sessions.js +114 -0
- package/dist/commands/sites.js +102 -0
- package/dist/commands/sms.js +65 -0
- package/dist/commands/status.js +87 -0
- package/dist/commands/support.js +115 -0
- package/dist/commands/update.js +100 -0
- package/dist/commands/usage.js +51 -0
- package/dist/commands/verify.js +149 -0
- package/dist/commands/version.js +6 -0
- package/dist/guide.js +37 -0
- package/dist/http/call.js +6 -0
- package/dist/http/request.js +54 -0
- package/dist/index.js +11 -0
- package/dist/metadata.js +4 -0
- package/dist/output.js +9 -0
- package/dist/pretty.js +70 -0
- package/dist/refresh-skills.js +5 -0
- package/dist/registry.js +688 -0
- package/dist/runtime/browser.js +15 -0
- package/dist/runtime/card-request.js +55 -0
- package/dist/runtime/confirm.js +21 -0
- package/dist/runtime/development.js +13 -0
- package/dist/runtime/domain-name.js +5 -0
- package/dist/runtime/dry-run.js +28 -0
- package/dist/runtime/env-file.js +55 -0
- package/dist/runtime/error-hints.js +26 -0
- package/dist/runtime/flags.js +48 -0
- package/dist/runtime/login-screen.js +78 -0
- package/dist/runtime/page.js +18 -0
- package/dist/runtime/project-name.js +1 -0
- package/dist/runtime/run-mode.js +7 -0
- package/dist/runtime/server-options.js +28 -0
- package/dist/runtime/spinner.js +17 -0
- package/dist/runtime/suggest.js +22 -0
- package/dist/runtime/support.js +13 -0
- package/dist/runtime/text-file.js +20 -0
- package/dist/runtime/timeout.js +22 -0
- package/dist/runtime/update-check.js +158 -0
- package/dist/runtime/update-install.js +80 -0
- package/dist/runtime/usage-error.js +9 -0
- package/dist/setup-agents.js +15 -0
- package/dist/site.js +1 -0
- package/dist/update-refresh.js +5 -0
- package/package.json +46 -3
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { agentResult } from "../../output.js";
|
|
2
|
+
import { prettyResult } from "../../pretty.js";
|
|
3
|
+
import { signedIn } from "../../auth/session.js";
|
|
4
|
+
import { LoginExpiredError, postJson } from "../../http/request.js";
|
|
5
|
+
import { TransferRejected, validGitRemote } from "./upload.js";
|
|
6
|
+
import { ProgressRejected, progressTracker } from "./progress.js";
|
|
7
|
+
import { MANIFEST_FILE } from "./manifest.js";
|
|
8
|
+
import { supportMessage } from "../../runtime/support.js";
|
|
9
|
+
export const PUBLISH_WAIT_SECONDS = 15 * 60;
|
|
10
|
+
const PROJECT_BRANCH = /^projects\/[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
11
|
+
const READ_RETRIES = 3;
|
|
12
|
+
const PUBLISH_FAILURES = {
|
|
13
|
+
publish_failed: 'The project server could not build or publish this commit. Read progress.forAgent.publishLog, fix the project and deploy again.',
|
|
14
|
+
project_not_found: 'The project no longer exists. Create it with deepdynamic projects create <name>.',
|
|
15
|
+
deploy_stopped: 'The deploy was stopped with deepdynamic projects stop and the project server was turned off. Deploy again to turn it back on.'
|
|
16
|
+
};
|
|
17
|
+
export function publishFailure(code) {
|
|
18
|
+
const message = PUBLISH_FAILURES[code];
|
|
19
|
+
return message ? { message, display: message } : { message: supportMessage(code), display: supportMessage(code) };
|
|
20
|
+
}
|
|
21
|
+
export async function shipDeployment(shipment, pretty, depth, deps) {
|
|
22
|
+
const { command, project, agent, manifest, context, rows } = shipment;
|
|
23
|
+
let uploaded = false;
|
|
24
|
+
let tracker;
|
|
25
|
+
const failure = (code, message, display = message) => pretty
|
|
26
|
+
? prettyResult(1, depth, command, display, [...rows, ...(tracker?.url ? [['Status URL', tracker.url]] : [])])
|
|
27
|
+
: agentResult(1, { command, ...context, uploaded, deployed: false, statusUrl: tracker?.url ?? null, progress: tracker?.latest ?? null, error: { code, message } });
|
|
28
|
+
let session = await signedIn(deps);
|
|
29
|
+
for (let renewed = false;; renewed = true) {
|
|
30
|
+
if ('login' in session)
|
|
31
|
+
return session.login;
|
|
32
|
+
tracker = progressTracker(session.siteUrl, session.token, project, deps, pretty);
|
|
33
|
+
try {
|
|
34
|
+
await tracker.start(manifest, agent);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error instanceof ProgressRejected) {
|
|
39
|
+
return error.status === 404
|
|
40
|
+
? failure('project_not_found', 'You have no project with that name. Check it with deepdynamic projects. No files were uploaded.')
|
|
41
|
+
: failure('invalid_manifest', `The server rejected ${MANIFEST_FILE}. Check it against deepdynamic projects deploy --help. No files were uploaded.`);
|
|
42
|
+
}
|
|
43
|
+
if (renewed || !(error instanceof LoginExpiredError))
|
|
44
|
+
return failure('progress_unavailable', 'Could not start deployment tracking. No files were uploaded.');
|
|
45
|
+
session = await signedIn(deps, true);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const { token, siteUrl } = session;
|
|
49
|
+
const recheck = `deepdynamic deployments ${tracker.latest.id}`;
|
|
50
|
+
const abort = async (code, message, display = message) => {
|
|
51
|
+
try {
|
|
52
|
+
await tracker.update('failed');
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return failure('progress_unavailable', `${message} Could not record the failure; check it with ${recheck}.`, `${display} Could not record the failure; check it with ${recheck}.`);
|
|
56
|
+
}
|
|
57
|
+
return failure(code, message, display);
|
|
58
|
+
};
|
|
59
|
+
const supportAbort = (code) => abort(code, supportMessage(code), supportMessage(code));
|
|
60
|
+
const result = await postJson(new URL('/api/v1/git/repository', siteUrl).href, token, { project }, deps, pretty ? 'Preparing the deploy repository.' : null);
|
|
61
|
+
if ('failure' in result)
|
|
62
|
+
return abort(result.failure.code, result.failure.message, result.failure.display);
|
|
63
|
+
if (result.status !== 200)
|
|
64
|
+
return supportAbort('repository_failed');
|
|
65
|
+
const body = result.body;
|
|
66
|
+
if (!body?.ok || typeof body.remote !== 'string' || !validGitRemote(body.remote) || typeof body.branch !== 'string' || !PROJECT_BRANCH.test(body.branch)) {
|
|
67
|
+
return supportAbort('invalid_repository');
|
|
68
|
+
}
|
|
69
|
+
let upload;
|
|
70
|
+
try {
|
|
71
|
+
await tracker.update('packing');
|
|
72
|
+
upload = await shipment.send(body.remote, body.branch, token, async () => { await tracker.update('uploading'); });
|
|
73
|
+
uploaded = true;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
return error instanceof TransferRejected
|
|
77
|
+
? abort(error.code, error.message)
|
|
78
|
+
: supportAbort('upload_failed');
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
await tracker.update('verifying', upload.commit);
|
|
82
|
+
let progress = await tracker.read();
|
|
83
|
+
const pause = deps.pause ?? ((ms) => new Promise((done) => setTimeout(done, ms)));
|
|
84
|
+
for (let misses = 0, deadline = Date.now() + shipment.waitMs; progress.forAgent.status === 'running' && Date.now() < deadline;) {
|
|
85
|
+
await pause(progress.forAgent.pollAfterMs ?? 2000);
|
|
86
|
+
try {
|
|
87
|
+
progress = await tracker.read();
|
|
88
|
+
misses = 0;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (++misses >= READ_RETRIES)
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const verifying = progress.forAgent.status === 'running' && progress.forAgent.stage === 'verifying';
|
|
96
|
+
if (progress.forAgent.commit !== upload.commit || (!progress.forAgent.gitUploaded && !verifying)) {
|
|
97
|
+
return failure('upload_unverified', `Git finished, but the server has not confirmed this commit. Check it with ${recheck}; the site is not published.`);
|
|
98
|
+
}
|
|
99
|
+
if (progress.forAgent.stage === 'failed') {
|
|
100
|
+
const code = progress.forAgent.errorCode ?? 'publish_failed';
|
|
101
|
+
const { message, display } = publishFailure(code);
|
|
102
|
+
return failure(code, message, display);
|
|
103
|
+
}
|
|
104
|
+
if (progress.forAgent.stage !== 'published') {
|
|
105
|
+
return failure('publish_pending', `The site is still being published. Keep running ${recheck} until forAgent.status is succeeded or failed, and do not deploy again before that.`);
|
|
106
|
+
}
|
|
107
|
+
return pretty
|
|
108
|
+
? prettyResult(0, depth, command, `[${progress.percent}%] ${progress.forHuman.message} ${progress.forHuman.detail}`, [
|
|
109
|
+
...(progress.publicUrl ? [['URL', progress.publicUrl]] : []),
|
|
110
|
+
['Repository', body.remote], ['Branch', body.branch], ['Status URL', tracker.url]
|
|
111
|
+
])
|
|
112
|
+
: agentResult(0, { command, ...context, ...shipment.success, uploaded: true, changed: upload.changed, deployed: true, remote: body.remote, branch: body.branch, statusUrl: tracker.url, ...progress });
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return failure('progress_unavailable', `Git finished, but progress verification is unavailable. Check ${recheck} before retrying. The site is not published.`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { mkdtemp, mkdir, readdir, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { developmentRun } from "../../runtime/run-mode.js";
|
|
6
|
+
import { deployFileReader } from "./files.js";
|
|
7
|
+
import { minifyFile } from "./minify.js";
|
|
8
|
+
export class TransferRejected extends Error {
|
|
9
|
+
code;
|
|
10
|
+
constructor(code, message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.code = code;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const runGit = (args, cwd, env) => new Promise((resolve, reject) => {
|
|
16
|
+
execFile('git', args, { cwd, env, windowsHide: true, timeout: 180_000, maxBuffer: 1024 * 1024 }, (error, stdout) => {
|
|
17
|
+
if (error && 'code' in error && error.code === 'ENOENT')
|
|
18
|
+
return reject(new Error('Git is required. Install Git and retry.'));
|
|
19
|
+
resolve({ code: error ? typeof error.code === 'number' ? error.code : -1 : 0, stdout });
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
const LOCAL_GIT_ORIGIN = /^http:\/\/(localhost|127\.0\.0\.1):[0-9]{2,5}$/;
|
|
23
|
+
const COMMIT = /^[a-f0-9]{40}$/;
|
|
24
|
+
const IDENTITY = ['-c', 'user.name=DeepDynamic', '-c', 'user.email=uploads@deepdynamic.net', '-c', 'commit.gpgsign=false'];
|
|
25
|
+
export function validGitRemote(remote) {
|
|
26
|
+
try {
|
|
27
|
+
const url = new URL(remote);
|
|
28
|
+
const origin = url.origin === 'https://git.deepdynamic.net' || (developmentRun() && LOCAL_GIT_ORIGIN.test(url.origin));
|
|
29
|
+
return origin && !url.username && !url.password && !url.search && !url.hash
|
|
30
|
+
&& /^\/project-[a-f0-9]{64}\.git$/.test(url.pathname);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function inRepository(remote, branch, token, git, use) {
|
|
37
|
+
if (!validGitRemote(remote) || !/^projects\/[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/.test(branch))
|
|
38
|
+
throw new Error('Invalid repository destination.');
|
|
39
|
+
const work = await mkdtemp(join(tmpdir(), 'dd-upload-'));
|
|
40
|
+
try {
|
|
41
|
+
const repository = join(work, 'repository');
|
|
42
|
+
const gitDir = join(work, 'git');
|
|
43
|
+
const hooks = join(work, 'hooks');
|
|
44
|
+
const config = join(work, 'config');
|
|
45
|
+
const askpass = join(work, 'askpass.cjs');
|
|
46
|
+
const wrapper = join(work, 'askpass.sh');
|
|
47
|
+
const slash = (path) => path.replaceAll('\\', '/');
|
|
48
|
+
const quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
49
|
+
await mkdir(repository);
|
|
50
|
+
await mkdir(hooks);
|
|
51
|
+
await writeFile(config, '');
|
|
52
|
+
await writeFile(askpass, `const prompt = process.argv[2] ?? '';\nlet origin = '';\ntry { origin = new URL(/'(https?:\\/\\/[^']+)'/.exec(prompt)?.[1] ?? '').origin; } catch {}\nif (origin !== ${JSON.stringify(new URL(remote).origin)}) process.exit(1);\nprocess.stdout.write(prompt.toLowerCase().includes('username') ? 'dd\\n' : (process.env.DEEPDYNAMIC_GIT_TOKEN ?? '') + '\\n');\n`);
|
|
53
|
+
await writeFile(wrapper, `#!/bin/sh\nexec ${quote(slash(process.execPath))} ${quote(slash(askpass))} "$@"\n`, { mode: 0o700 });
|
|
54
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !/^(GIT_|GCM_|CURL_|DEEPDYNAMIC_GIT_TOKEN$|NODE_OPTIONS$)/i.test(key)));
|
|
55
|
+
Object.assign(env, {
|
|
56
|
+
GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: config, GIT_CONFIG_SYSTEM: config,
|
|
57
|
+
GIT_ATTR_NOSYSTEM: '1', GIT_TEMPLATE_DIR: hooks, GIT_TERMINAL_PROMPT: '0', GIT_ALLOW_PROTOCOL: new URL(remote).protocol.slice(0, -1),
|
|
58
|
+
GIT_ASKPASS: slash(wrapper),
|
|
59
|
+
DEEPDYNAMIC_GIT_TOKEN: token
|
|
60
|
+
});
|
|
61
|
+
const run = async (args, allowed = [0]) => {
|
|
62
|
+
const result = await (git ?? runGit)([`--git-dir=${gitDir}`, `--work-tree=${repository}`, '-c', 'credential.helper=', '-c', 'http.followRedirects=false', '-c', `core.hooksPath=${hooks}`, ...args], work, env);
|
|
63
|
+
if (!allowed.includes(result.code))
|
|
64
|
+
throw new Error('Git upload failed. Check your login and retry; concurrent updates are not overwritten.');
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
67
|
+
await run(['init', '--initial-branch', branch]);
|
|
68
|
+
await run(['remote', 'add', 'origin', remote]);
|
|
69
|
+
return await use(run, repository);
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
await rm(work, { recursive: true, force: true });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function uploadDeployment(directory, files, remote, branch, token, options = {}) {
|
|
76
|
+
return inRepository(remote, branch, token, options.git, async (run, repository) => {
|
|
77
|
+
if ((await run(['ls-remote', '--exit-code', '--heads', 'origin', `refs/heads/${branch}`], [0, 2])).code === 0) {
|
|
78
|
+
await run(['fetch', '--depth=1', 'origin', `refs/heads/${branch}`]);
|
|
79
|
+
await run(['reset', '--hard', 'FETCH_HEAD']);
|
|
80
|
+
}
|
|
81
|
+
for (const entry of await readdir(repository))
|
|
82
|
+
await rm(join(repository, entry), { recursive: true, force: true });
|
|
83
|
+
const read = options.read ?? await deployFileReader(directory);
|
|
84
|
+
for (const file of files) {
|
|
85
|
+
const original = await read(file);
|
|
86
|
+
const content = options.minify === false ? original : await minifyFile(file, original);
|
|
87
|
+
await mkdir(dirname(join(repository, file)), { recursive: true });
|
|
88
|
+
await writeFile(join(repository, file), content);
|
|
89
|
+
}
|
|
90
|
+
await run(['read-tree', '--empty']);
|
|
91
|
+
await run(['add', '--all', '--force']);
|
|
92
|
+
const changed = (await run(['diff', '--cached', '--quiet'], [0, 1])).code !== 0;
|
|
93
|
+
if (changed)
|
|
94
|
+
await run([...IDENTITY, 'commit', '--quiet', '-m', 'Upload site']);
|
|
95
|
+
const commit = (await run(['rev-parse', 'HEAD'])).stdout.trim();
|
|
96
|
+
if (!COMMIT.test(commit))
|
|
97
|
+
throw new Error('Could not identify the uploaded commit.');
|
|
98
|
+
if (changed) {
|
|
99
|
+
await options.onUploading?.();
|
|
100
|
+
await run(['push', 'origin', `HEAD:refs/heads/${branch}`]);
|
|
101
|
+
}
|
|
102
|
+
return { changed, commit };
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
export function restoreDeployment(remote, branch, token, target, options = {}) {
|
|
106
|
+
if (!COMMIT.test(target))
|
|
107
|
+
return Promise.reject(new Error('Invalid commit.'));
|
|
108
|
+
return inRepository(remote, branch, token, options.git, async (run) => {
|
|
109
|
+
await run(['fetch', 'origin', `refs/heads/${branch}`]);
|
|
110
|
+
if ((await run(['merge-base', '--is-ancestor', target, 'FETCH_HEAD'], [0, 1, 128])).code !== 0) {
|
|
111
|
+
throw new TransferRejected('commit_not_found', 'That commit is not in the project history, so nothing was uploaded. Pick another deployment from deepdynamic projects history <name>.');
|
|
112
|
+
}
|
|
113
|
+
const [head, headTree, tree] = (await run(['rev-parse', 'FETCH_HEAD', 'FETCH_HEAD^{tree}', `${target}^{tree}`])).stdout.trim().split(/\r?\n/);
|
|
114
|
+
if (![head, headTree, tree].every((value) => COMMIT.test(value ?? '')))
|
|
115
|
+
throw new Error('Could not identify the commits to restore.');
|
|
116
|
+
if (tree === headTree)
|
|
117
|
+
return { changed: false, commit: head };
|
|
118
|
+
const commit = (await run([...IDENTITY, 'commit-tree', tree, '-p', head, '-m', `Rollback to ${target}`])).stdout.trim();
|
|
119
|
+
if (!COMMIT.test(commit))
|
|
120
|
+
throw new Error('Could not identify the rollback commit.');
|
|
121
|
+
await options.onUploading?.();
|
|
122
|
+
await run(['push', 'origin', `${commit}:refs/heads/${branch}`]);
|
|
123
|
+
return { changed: true, commit };
|
|
124
|
+
});
|
|
125
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { authorized, defaultAuthDeps, signedIn } from "../auth/session.js";
|
|
2
|
+
import { LOGIN_EXPIRED, UNEXPECTED, failureError, httpFailure, request } from "../http/request.js";
|
|
3
|
+
import { agentResult } from "../output.js";
|
|
4
|
+
import { prettyResult } from "../pretty.js";
|
|
5
|
+
import { spec } from "../registry.js";
|
|
6
|
+
import { plannedRequest, splitDryRun } from "../runtime/dry-run.js";
|
|
7
|
+
import { parseCommand } from "../runtime/flags.js";
|
|
8
|
+
import { DEPLOYMENT_ID, parseProgress } from "./deploy/progress.js";
|
|
9
|
+
import { publishFailure } from "./deploy/ship.js";
|
|
10
|
+
const { name: COMMAND, usage } = spec('deployments');
|
|
11
|
+
const NOT_FOUND_MESSAGE = 'You have no deployment with that ID. Take the id from the deepdynamic projects deploy or deepdynamic projects rollback output.';
|
|
12
|
+
const NOT_FOUND = { code: 'deployment_not_found', message: NOT_FOUND_MESSAGE, display: NOT_FOUND_MESSAGE };
|
|
13
|
+
export async function runDeployments(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
14
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
15
|
+
const parsed = parseCommand(rest, []);
|
|
16
|
+
const [id] = 'error' in parsed ? [] : parsed.names;
|
|
17
|
+
if ('error' in parsed || parsed.names.length !== 1 || !DEPLOYMENT_ID.test(id)) {
|
|
18
|
+
const message = 'error' in parsed ? parsed.error : 'Specify exactly one deployment id from the deepdynamic projects deploy output.';
|
|
19
|
+
return pretty
|
|
20
|
+
? prettyResult(2, depth, COMMAND, message, [['Usage', usage]])
|
|
21
|
+
: agentResult(2, { command: COMMAND, error: { code: 'invalid_arguments', message }, usage });
|
|
22
|
+
}
|
|
23
|
+
const statusUrl = (siteUrl) => new URL(`/api/v1/deployments/${id}`, siteUrl).href;
|
|
24
|
+
if (dryRun) {
|
|
25
|
+
const session = await signedIn(deps);
|
|
26
|
+
if ('login' in session)
|
|
27
|
+
return session.login;
|
|
28
|
+
return plannedRequest(COMMAND, pretty, depth, session.siteUrl, statusUrl(session.siteUrl));
|
|
29
|
+
}
|
|
30
|
+
const sent = await authorized(deps, (session) => request(statusUrl(session.siteUrl), {
|
|
31
|
+
method: 'GET', headers: { authorization: `Bearer ${session.token}` }
|
|
32
|
+
}, deps, null));
|
|
33
|
+
if ('login' in sent)
|
|
34
|
+
return sent.login;
|
|
35
|
+
const { session, result } = sent;
|
|
36
|
+
const failure = 'failure' in result ? result.failure
|
|
37
|
+
: result.status === 401 ? LOGIN_EXPIRED
|
|
38
|
+
: result.status === 404 ? NOT_FOUND
|
|
39
|
+
: result.status !== 200 ? httpFailure(result.status) : null;
|
|
40
|
+
const progress = failure ? null : parseProgress(result.body, session.token, { id });
|
|
41
|
+
if (!progress) {
|
|
42
|
+
const shown = failure ?? UNEXPECTED;
|
|
43
|
+
return pretty
|
|
44
|
+
? prettyResult(1, depth, COMMAND, 'Could not load the deploy progress.', [['Server', session.siteUrl], ['Deployment ID', id], ['Reason', shown.display]])
|
|
45
|
+
: agentResult(1, { command: COMMAND, siteUrl: session.siteUrl, id, error: failureError(shown) });
|
|
46
|
+
}
|
|
47
|
+
const { ok: _, ...snapshot } = progress;
|
|
48
|
+
const failed = snapshot.forAgent.stage === 'failed';
|
|
49
|
+
const code = failed ? 1 : 0;
|
|
50
|
+
if (pretty) {
|
|
51
|
+
return prettyResult(code, depth, COMMAND, `[${snapshot.percent}%] ${snapshot.forHuman.message} ${snapshot.forHuman.detail}`, [
|
|
52
|
+
['Server', session.siteUrl], ['Project', snapshot.project], ...(snapshot.publicUrl ? [['URL', snapshot.publicUrl]] : [])
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
const errorCode = snapshot.forAgent.errorCode ?? 'publish_failed';
|
|
56
|
+
return agentResult(code, {
|
|
57
|
+
command: COMMAND, siteUrl: session.siteUrl, statusUrl: statusUrl(session.siteUrl), ...snapshot,
|
|
58
|
+
...(failed ? { error: { code: errorCode, message: publishFailure(errorCode).message } } : {})
|
|
59
|
+
});
|
|
60
|
+
}
|