@deepdynamic/cli 0.1.0 → 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/dist/agents/content.js +1 -1
- package/dist/agents/install.js +22 -12
- package/dist/agents/refresh.js +20 -0
- package/dist/agents/setup.js +7 -7
- package/dist/cli.js +8 -8
- package/dist/commands/account.js +19 -19
- package/dist/commands/activity.js +13 -13
- package/dist/commands/blocked.js +16 -16
- package/dist/commands/deploy/index.js +16 -16
- package/dist/commands/deploy/ship.js +8 -8
- package/dist/commands/deployments.js +8 -7
- package/dist/commands/dns.js +228 -242
- package/dist/commands/domains.js +188 -260
- package/dist/commands/emails.js +17 -17
- package/dist/commands/env.js +38 -38
- package/dist/commands/help.js +18 -19
- package/dist/commands/keys.js +83 -89
- package/dist/commands/login/flow.js +11 -11
- package/dist/commands/login/index.js +3 -3
- package/dist/commands/logout.js +11 -11
- package/dist/commands/mail.js +62 -62
- package/dist/commands/notifications.js +30 -29
- package/dist/commands/plan.js +109 -125
- package/dist/commands/projects.js +159 -157
- package/dist/commands/reference.js +109 -102
- package/dist/commands/search.js +29 -18
- package/dist/commands/server.js +99 -112
- package/dist/commands/sessions.js +38 -44
- package/dist/commands/sites.js +16 -16
- package/dist/commands/sms.js +14 -14
- package/dist/commands/status.js +9 -9
- package/dist/commands/support.js +19 -19
- package/dist/commands/update.js +18 -16
- package/dist/commands/usage.js +12 -12
- package/dist/commands/verify.js +16 -16
- package/dist/guide.js +9 -48
- package/dist/http/request.js +3 -3
- package/dist/pretty.js +4 -4
- package/dist/refresh-skills.js +5 -0
- package/dist/registry.js +72 -144
- package/dist/runtime/card-request.js +6 -6
- package/dist/runtime/confirm.js +1 -1
- package/dist/runtime/development.js +1 -1
- package/dist/runtime/dry-run.js +2 -2
- package/dist/runtime/env-file.js +6 -9
- package/dist/runtime/flags.js +11 -13
- package/dist/runtime/login-screen.js +5 -5
- package/dist/runtime/page.js +4 -4
- package/dist/runtime/server-options.js +4 -8
- package/dist/runtime/spinner.js +3 -1
- package/dist/runtime/support.js +2 -3
- package/dist/runtime/text-file.js +5 -5
- package/dist/runtime/timeout.js +2 -2
- package/dist/runtime/update-check.js +48 -14
- package/dist/runtime/update-install.js +34 -4
- package/dist/runtime/usage-error.js +2 -2
- package/dist/setup-agents.js +9 -2
- package/package.json +1 -1
|
@@ -24,7 +24,9 @@ const COMMIT_PREFIX = /^[a-f0-9]{7,40}$/;
|
|
|
24
24
|
const DEPLOY_STATUSES = ['published', 'deploying', 'failed', 'none'];
|
|
25
25
|
const DEPLOY_STAGES = ['preparing', 'packing', 'uploading', 'verifying', 'awaiting_publish', 'publishing', 'published', 'failed'];
|
|
26
26
|
const BUILD = /^pnpm (build|run [A-Za-z0-9][A-Za-z0-9:._-]{0,63})$/;
|
|
27
|
-
const STATUS_LABELS = { published: '●
|
|
27
|
+
const STATUS_LABELS = { published: '● Published', deploying: '◐ Deploying', failed: '✕ Deploy failed', none: '○ Not deployed' };
|
|
28
|
+
const plainFailure = (code, message) => ({ code, message, display: message });
|
|
29
|
+
const counted = (count, noun) => `${count.toLocaleString('en-US')} ${noun}${count === 1 ? '' : 's'}`;
|
|
28
30
|
function projectStatus(body, project) {
|
|
29
31
|
const value = body;
|
|
30
32
|
const server = value?.server;
|
|
@@ -58,30 +60,30 @@ function exchangeFailure(result) {
|
|
|
58
60
|
if (result.status === 401)
|
|
59
61
|
return LOGIN_EXPIRED;
|
|
60
62
|
if (result.status === 404)
|
|
61
|
-
return
|
|
63
|
+
return plainFailure('project_not_found', 'You have no project with that name. Create it with deepdynamic projects create <name>.');
|
|
62
64
|
if (result.status === 409)
|
|
63
|
-
return
|
|
65
|
+
return plainFailure('project_taken', 'Another account already uses that project name. Choose a different name.');
|
|
64
66
|
if (result.status === 400)
|
|
65
|
-
return
|
|
67
|
+
return plainFailure('invalid_arguments', 'The server rejected the project name. Follow the naming steps in deepdynamic projects create --help.');
|
|
66
68
|
if (result.status !== 200 && result.status !== 201)
|
|
67
69
|
return httpFailure(result.status);
|
|
68
70
|
return null;
|
|
69
71
|
}
|
|
70
|
-
function parseName(args
|
|
71
|
-
const parsed = parseCommand(args, []
|
|
72
|
+
function parseName(args) {
|
|
73
|
+
const parsed = parseCommand(args, []);
|
|
72
74
|
if ('error' in parsed)
|
|
73
75
|
return parsed;
|
|
74
76
|
const { names } = parsed;
|
|
75
77
|
if (names.length !== 1)
|
|
76
|
-
return { error:
|
|
78
|
+
return { error: 'Specify exactly one project name.' };
|
|
77
79
|
if (!PROJECT.test(names[0]))
|
|
78
|
-
return { error:
|
|
80
|
+
return { error: 'Project names are 1-63 lowercase letters, digits or hyphens and start and end with a letter or digit.' };
|
|
79
81
|
return names[0];
|
|
80
82
|
}
|
|
81
83
|
function finish(command, code, depth, pretty, siteUrl, project, server, site, failure, message) {
|
|
82
84
|
if (pretty) {
|
|
83
85
|
return prettyResult(code, depth, command, message, [
|
|
84
|
-
['
|
|
86
|
+
['Server', siteUrl], ['Project', project], ...(site ? [['Site URL', site]] : []), ['Status', failure?.display ?? server.message]
|
|
85
87
|
]);
|
|
86
88
|
}
|
|
87
89
|
return agentResult(code, {
|
|
@@ -90,15 +92,15 @@ function finish(command, code, depth, pretty, siteUrl, project, server, site, fa
|
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
94
|
async function runProjects(command, args, pretty, depth, deps, waitMs) {
|
|
93
|
-
const { usage
|
|
94
|
-
const project = parseName(args
|
|
95
|
+
const { usage } = spec(command);
|
|
96
|
+
const project = parseName(args);
|
|
95
97
|
if (typeof project !== 'string') {
|
|
96
98
|
return pretty
|
|
97
|
-
? prettyResult(2, depth, command, project.error, [['
|
|
99
|
+
? prettyResult(2, depth, command, project.error, [['Usage', usage]])
|
|
98
100
|
: agentResult(2, { command, error: { code: 'invalid_arguments', message: project.error }, usage });
|
|
99
101
|
}
|
|
100
102
|
const sent = await authorized(deps, (session) => command === 'projects create'
|
|
101
|
-
? postJson(new URL(PROJECTS_PATH, session.siteUrl).href, session.token, { project }, deps, pretty ? '
|
|
103
|
+
? postJson(new URL(PROJECTS_PATH, session.siteUrl).href, session.token, { project }, deps, pretty ? 'Creating the project.' : null)
|
|
102
104
|
: readStatus(session, project, deps));
|
|
103
105
|
if ('login' in sent)
|
|
104
106
|
return sent.login;
|
|
@@ -113,24 +115,24 @@ async function runProjects(command, args, pretty, depth, deps, waitMs) {
|
|
|
113
115
|
if (!status) {
|
|
114
116
|
const shown = failure ?? UNEXPECTED;
|
|
115
117
|
return pretty
|
|
116
|
-
? prettyResult(1, depth, command, '
|
|
118
|
+
? prettyResult(1, depth, command, 'Could not check the project.', [['Server', session.siteUrl], ['Project', project], ['Reason', shown.display]])
|
|
117
119
|
: agentResult(1, { command, siteUrl: session.siteUrl, project, error: failureError(shown) });
|
|
118
120
|
}
|
|
119
121
|
const { server, site, poll } = status;
|
|
120
122
|
if (server.stage === 'failed') {
|
|
121
123
|
const failed = supportFailure('server_failed');
|
|
122
|
-
return finish(command, 1, depth, pretty, session.siteUrl, project, server, site, failed, '
|
|
124
|
+
return finish(command, 1, depth, pretty, session.siteUrl, project, server, site, failed, 'Could not prepare the project server.');
|
|
123
125
|
}
|
|
124
126
|
if (server.ready || command === 'projects status') {
|
|
125
|
-
return finish(command, 0, depth, pretty, session.siteUrl, project, server, site, null, server.ready ? '
|
|
127
|
+
return finish(command, 0, depth, pretty, session.siteUrl, project, server, site, null, server.ready ? 'The project server is ready.' : 'The project server is being prepared.');
|
|
126
128
|
}
|
|
127
129
|
const output = pretty ? `${plain(server.message)}\n` : jsonLine({ event: 'project_progress', project, server });
|
|
128
130
|
if (output !== lastOutput)
|
|
129
131
|
deps.stream.write(output);
|
|
130
132
|
lastOutput = output;
|
|
131
133
|
if (Date.now() >= deadline) {
|
|
132
|
-
const pending = { code: 'server_pending', message: `The project server is still being prepared. Keep running deepdynamic projects status ${project} until server.ready is true or server.stage is failed.`, display:
|
|
133
|
-
return finish(command, 1, depth, pretty, session.siteUrl, project, server, site, pending, '
|
|
134
|
+
const pending = { code: 'server_pending', message: `The project server is still being prepared. Keep running deepdynamic projects status ${project} until server.ready is true or server.stage is failed.`, display: `Still being prepared. Keep checking with deepdynamic projects status ${project} until it is ready.` };
|
|
135
|
+
return finish(command, 1, depth, pretty, session.siteUrl, project, server, site, pending, 'The project server is still being prepared.');
|
|
134
136
|
}
|
|
135
137
|
await (deps.pause ?? pauseFor)(poll ?? 5000);
|
|
136
138
|
result = await readStatus(session, project, deps);
|
|
@@ -138,10 +140,10 @@ async function runProjects(command, args, pretty, depth, deps, waitMs) {
|
|
|
138
140
|
}
|
|
139
141
|
async function checkProjectName(args, pretty, depth, deps) {
|
|
140
142
|
const command = 'projects create';
|
|
141
|
-
const project = parseName(args
|
|
143
|
+
const project = parseName(args);
|
|
142
144
|
if (typeof project !== 'string')
|
|
143
145
|
return usageError(command, project.error, pretty, depth);
|
|
144
|
-
const sent = await authorized(deps, (session) => postJson(new URL(PROJECTS_PATH, session.siteUrl).href, session.token, { project, dryRun: true }, deps, pretty ? '
|
|
146
|
+
const sent = await authorized(deps, (session) => postJson(new URL(PROJECTS_PATH, session.siteUrl).href, session.token, { project, dryRun: true }, deps, pretty ? 'Checking the name.' : null));
|
|
145
147
|
if ('login' in sent)
|
|
146
148
|
return sent.login;
|
|
147
149
|
const { session, result } = sent;
|
|
@@ -150,20 +152,20 @@ async function checkProjectName(args, pretty, depth, deps) {
|
|
|
150
152
|
if (failure || value?.ok !== true || value.dryRun !== true || value.project !== project || typeof value.available !== 'boolean' || typeof value.owned !== 'boolean') {
|
|
151
153
|
const shown = failure ?? UNEXPECTED;
|
|
152
154
|
return pretty
|
|
153
|
-
? prettyResult(1, depth, command, '
|
|
155
|
+
? prettyResult(1, depth, command, 'Could not check the name.', [['Server', session.siteUrl], ['Project', project], ['Reason', shown.display]])
|
|
154
156
|
: agentResult(1, { command, siteUrl: session.siteUrl, dryRun: true, project, error: failureError(shown) });
|
|
155
157
|
}
|
|
156
158
|
const { available, owned } = value;
|
|
157
159
|
if (!pretty)
|
|
158
160
|
return agentResult(0, { command, siteUrl: session.siteUrl, dryRun: true, project, available, owned });
|
|
159
161
|
return prettyResult(0, depth, command, available
|
|
160
|
-
? '
|
|
161
|
-
: owned ? '
|
|
162
|
-
['
|
|
162
|
+
? 'The name is available. No project was created.'
|
|
163
|
+
: owned ? 'You already own this project. Deploy to it instead of creating it again.' : 'Another account uses this name. Choose a different name.', [
|
|
164
|
+
['Server', session.siteUrl], ['Project', project]
|
|
163
165
|
]);
|
|
164
166
|
}
|
|
165
167
|
export async function runProjectsCreate(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
166
|
-
const timeout = parseTimeout(args, SERVER_WAIT_SECONDS
|
|
168
|
+
const timeout = parseTimeout(args, SERVER_WAIT_SECONDS);
|
|
167
169
|
if ('error' in timeout)
|
|
168
170
|
return usageError('projects create', timeout.error, pretty, depth);
|
|
169
171
|
return timeout.rest.includes('--dry-run')
|
|
@@ -175,7 +177,7 @@ export async function runProjectsStatus(args, pretty, depth, deps = defaultAuthD
|
|
|
175
177
|
const { args: rest, dryRun } = splitDryRun(args);
|
|
176
178
|
if (!dryRun)
|
|
177
179
|
return runProjects(command, rest, pretty, depth, deps, 0);
|
|
178
|
-
const project = parseName(rest
|
|
180
|
+
const project = parseName(rest);
|
|
179
181
|
if (typeof project !== 'string')
|
|
180
182
|
return usageError(command, project.error, pretty, depth);
|
|
181
183
|
return preview(command, pretty, depth, deps, (siteUrl) => new URL(`${PROJECTS_PATH}/${project}`, siteUrl).href);
|
|
@@ -204,38 +206,38 @@ function isProjectSummary(item) {
|
|
|
204
206
|
function ago(iso, now) {
|
|
205
207
|
const minutes = Math.floor((now - Date.parse(iso)) / 60_000);
|
|
206
208
|
if (minutes < 1)
|
|
207
|
-
return '
|
|
209
|
+
return 'just now';
|
|
208
210
|
if (minutes < 60)
|
|
209
|
-
return `${minutes}
|
|
211
|
+
return `${counted(minutes, 'minute')} ago`;
|
|
210
212
|
if (minutes < 24 * 60)
|
|
211
|
-
return `${Math.floor(minutes / 60)}
|
|
213
|
+
return `${counted(Math.floor(minutes / 60), 'hour')} ago`;
|
|
212
214
|
const days = Math.floor(minutes / (24 * 60));
|
|
213
215
|
if (days === 1)
|
|
214
|
-
return '
|
|
215
|
-
return days < 30 ? `${days}
|
|
216
|
+
return 'yesterday';
|
|
217
|
+
return days < 30 ? `${days} days ago` : iso.slice(0, 10);
|
|
216
218
|
}
|
|
217
219
|
const offline = ({ server, status, live }) => server?.stage === 'stopped' && live !== null && status !== 'deploying';
|
|
218
220
|
function projectRow(item, now) {
|
|
219
221
|
const { project, status, latest, live, deployments } = item;
|
|
220
|
-
const label = offline(item) ? '■
|
|
221
|
-
const build = !latest ? '-' : typeof latest.manifest.build === 'string' ? latest.manifest.build : '
|
|
222
|
+
const label = offline(item) ? '■ Server off' : status === 'failed' && latest?.errorCode === 'publish_failed' ? '✕ Build failed' : STATUS_LABELS[status];
|
|
223
|
+
const build = !latest ? '-' : typeof latest.manifest.build === 'string' ? latest.manifest.build : 'static';
|
|
222
224
|
return [project, label, build, String(deployments), live ? ago(live.publishedAt, now) : '-'];
|
|
223
225
|
}
|
|
224
226
|
export async function runProjectsList(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
225
227
|
const command = 'projects';
|
|
226
228
|
const invalid = (message) => usageError(command, message, pretty, depth);
|
|
227
229
|
const { args: rest, dryRun } = splitDryRun(args);
|
|
228
|
-
const flags = parseFlags(rest, ['--page']
|
|
230
|
+
const flags = parseFlags(rest, ['--page']);
|
|
229
231
|
if ('error' in flags)
|
|
230
232
|
return invalid(flags.error);
|
|
231
233
|
const page = flags.entries[0]?.[1] ?? '1';
|
|
232
234
|
if (flags.entries.length > 1 || !/^[1-9]\d{0,5}$/.test(page))
|
|
233
|
-
return invalid(
|
|
235
|
+
return invalid('Give --page once, as a positive integer.');
|
|
234
236
|
if (dryRun)
|
|
235
237
|
return preview(command, pretty, depth, deps, (siteUrl) => `${new URL(PROJECTS_PATH, siteUrl).href}?page=${page}`);
|
|
236
238
|
const sent = await authorized(deps, (session) => request(`${new URL(PROJECTS_PATH, session.siteUrl).href}?page=${page}`, {
|
|
237
239
|
method: 'GET', headers: { authorization: `Bearer ${session.token}` }
|
|
238
|
-
}, deps, pretty ? '
|
|
240
|
+
}, deps, pretty ? 'Loading projects.' : null));
|
|
239
241
|
if ('login' in sent)
|
|
240
242
|
return sent.login;
|
|
241
243
|
const { session, result } = sent;
|
|
@@ -245,7 +247,7 @@ export async function runProjectsList(args, pretty, depth, deps = defaultAuthDep
|
|
|
245
247
|
|| !Array.isArray(value.projects) || !value.projects.every(isProjectSummary)) {
|
|
246
248
|
const shown = failure ?? UNEXPECTED;
|
|
247
249
|
return pretty
|
|
248
|
-
? prettyResult(1, depth, command, '
|
|
250
|
+
? prettyResult(1, depth, command, 'Could not load the project list.', [['Server', session.siteUrl], ['Reason', shown.display]])
|
|
249
251
|
: agentResult(1, { command, siteUrl: session.siteUrl, error: failureError(shown) });
|
|
250
252
|
}
|
|
251
253
|
const { total, pageSize, totalPages } = value;
|
|
@@ -254,17 +256,17 @@ export async function runProjectsList(args, pretty, depth, deps = defaultAuthDep
|
|
|
254
256
|
if (!pretty)
|
|
255
257
|
return agentResult(0, { command, siteUrl: session.siteUrl, total, page: value.page, pageSize, totalPages, next, projects });
|
|
256
258
|
const footer = [
|
|
257
|
-
['
|
|
258
|
-
...(next ? [['
|
|
259
|
-
...(projects.length ? [['
|
|
259
|
+
['Page', `${value.page} / ${totalPages} (${total} total)`],
|
|
260
|
+
...(next ? [['Next', next]] : []),
|
|
261
|
+
...(projects.length ? [['URL', 'deepdynamic projects status <name>']] : [])
|
|
260
262
|
];
|
|
261
263
|
if (!projects.length) {
|
|
262
|
-
return prettyResult(0, depth, command, total ?
|
|
264
|
+
return prettyResult(0, depth, command, total ? `Page ${value.page} has no projects.` : 'You have no projects yet. Create one with deepdynamic projects create <name>.', total ? footer : []);
|
|
263
265
|
}
|
|
264
266
|
const { accent, dim } = paint(depth);
|
|
265
267
|
const tones = { published: accent, none: dim };
|
|
266
268
|
const now = Date.now();
|
|
267
|
-
const table = [['
|
|
269
|
+
const table = [['Name', 'Status', 'Build', 'Deploys', 'Last published'], ...projects.map((item) => projectRow(item, now).map(plain))];
|
|
268
270
|
const widths = table[0].map((_, column) => Math.max(...table.map((row) => displayWidth(row[column]))));
|
|
269
271
|
const lines = table.map((row, index) => row.map((cell, column) => {
|
|
270
272
|
const text = column === 3 ? ' '.repeat(widths[column] - displayWidth(cell)) + cell : pad(cell, widths[column]);
|
|
@@ -273,7 +275,7 @@ export async function runProjectsList(args, pretty, depth, deps = defaultAuthDep
|
|
|
273
275
|
const item = projects[index - 1];
|
|
274
276
|
return column === 1 ? (offline(item) ? dim : tones[item.status] ?? String)(text) : text;
|
|
275
277
|
}).join(' ').trimEnd());
|
|
276
|
-
return prettyResult(0, depth, command,
|
|
278
|
+
return prettyResult(0, depth, command, `Listed ${counted(projects.length, 'project')}, most recently active first.`, [
|
|
277
279
|
...lines.map((line) => [null, new Styled(line)]),
|
|
278
280
|
[null, ''],
|
|
279
281
|
...footer
|
|
@@ -305,14 +307,14 @@ async function loadHistory(command, project, pretty, depth, deps) {
|
|
|
305
307
|
const shown = failure ?? UNEXPECTED;
|
|
306
308
|
return {
|
|
307
309
|
result: pretty
|
|
308
|
-
? prettyResult(1, depth, command, '
|
|
310
|
+
? prettyResult(1, depth, command, 'Could not load the deploy history.', [['Server', sent.session.siteUrl], ['Project', project], ['Reason', shown.display]])
|
|
309
311
|
: agentResult(1, { command, siteUrl: sent.session.siteUrl, project, error: failureError(shown) })
|
|
310
312
|
};
|
|
311
313
|
}
|
|
312
314
|
export async function runProjectsHistory(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
313
315
|
const command = 'projects history';
|
|
314
316
|
const { args: rest, dryRun } = splitDryRun(args);
|
|
315
|
-
const project = parseName(rest
|
|
317
|
+
const project = parseName(rest);
|
|
316
318
|
if (typeof project !== 'string')
|
|
317
319
|
return usageError(command, project.error, pretty, depth);
|
|
318
320
|
if (dryRun)
|
|
@@ -323,16 +325,16 @@ export async function runProjectsHistory(args, pretty, depth, deps = defaultAuth
|
|
|
323
325
|
const { session, deployments } = history;
|
|
324
326
|
if (!pretty)
|
|
325
327
|
return agentResult(0, { command, siteUrl: session.siteUrl, project, deployments });
|
|
326
|
-
return prettyResult(0, depth, command, deployments.length ?
|
|
327
|
-
['
|
|
328
|
+
return prettyResult(0, depth, command, deployments.length ? `Found ${counted(deployments.length, 'published deployment')}.` : 'No deployment has been published yet.', [
|
|
329
|
+
['Server', session.siteUrl], ['Project', project],
|
|
328
330
|
...deployments.map(({ commit, publishedAt, current }, index) => [
|
|
329
|
-
index === 0 ? '
|
|
330
|
-
`${commit.slice(0, 12)} ${new Date(publishedAt).toISOString().slice(0, 16).replace('T', ' ')} UTC${current ? ' (
|
|
331
|
+
index === 0 ? 'Deployments' : '',
|
|
332
|
+
`${commit.slice(0, 12)} ${new Date(publishedAt).toISOString().slice(0, 16).replace('T', ' ')} UTC${current ? ' (current)' : ''}`
|
|
331
333
|
])
|
|
332
334
|
]);
|
|
333
335
|
}
|
|
334
336
|
const METRIC_PERIODS = ['24h', '7d', '30d'];
|
|
335
|
-
const PERIOD_LABELS = { '24h': '24
|
|
337
|
+
const PERIOD_LABELS = { '24h': '24 hours', '7d': '7 days', '30d': '30 days' };
|
|
336
338
|
const PERIOD_LENGTHS = { '24h': 24, '7d': 7, '30d': 30 };
|
|
337
339
|
const isMetricPeriod = (value) => METRIC_PERIODS.includes(value);
|
|
338
340
|
const isPercent = (value) => typeof value === 'number' && value >= 0 && value <= 100;
|
|
@@ -390,84 +392,84 @@ function metricReport(body, project, period) {
|
|
|
390
392
|
traffic: value.traffic
|
|
391
393
|
};
|
|
392
394
|
}
|
|
393
|
-
function parseMetric(args
|
|
394
|
-
const parsed = parseCommand(args, ['--period']
|
|
395
|
+
function parseMetric(args) {
|
|
396
|
+
const parsed = parseCommand(args, ['--period']);
|
|
395
397
|
if ('error' in parsed)
|
|
396
398
|
return parsed;
|
|
397
|
-
const project = parseName(parsed.names
|
|
399
|
+
const project = parseName(parsed.names);
|
|
398
400
|
if (typeof project !== 'string')
|
|
399
401
|
return project;
|
|
400
402
|
if (parsed.entries.length > 1)
|
|
401
|
-
return { error:
|
|
403
|
+
return { error: 'Give --period only once.' };
|
|
402
404
|
const period = parsed.entries[0]?.[1] ?? '7d';
|
|
403
405
|
if (!isMetricPeriod(period)) {
|
|
404
|
-
return { error:
|
|
406
|
+
return { error: `--period must be one of ${METRIC_PERIODS.join(', ')}: ${period}` };
|
|
405
407
|
}
|
|
406
408
|
return { project, period };
|
|
407
409
|
}
|
|
408
|
-
const metricNumber = (value) => value.toLocaleString('
|
|
409
|
-
const metricChange = (value, previous) => previous === 0 ? '
|
|
410
|
+
const metricNumber = (value) => value.toLocaleString('en-US');
|
|
411
|
+
const metricChange = (value, previous) => previous === 0 ? 'no previous data' : `${value < previous ? '-' : '+'}${(Math.abs(value - previous) / previous * 100).toFixed(1)}% vs previous period`;
|
|
410
412
|
const compared = (shown, value, previous) => `${shown} · ${metricChange(value, previous)}`;
|
|
411
|
-
const stay = (seconds) => `${Math.floor(seconds / 60)}
|
|
413
|
+
const stay = (seconds) => `${counted(Math.floor(seconds / 60), 'minute')} ${counted(seconds % 60, 'second')}`;
|
|
412
414
|
const shares = (items) => items.map(({ label, share }) => `${label} ${share.toFixed(1)}%`).join(' · ');
|
|
413
415
|
const BAR_WIDTH = 20;
|
|
414
|
-
const severityLabels = { critical: '
|
|
416
|
+
const severityLabels = { critical: 'Critical', high: 'High' };
|
|
415
417
|
function trendRows(title, labels, current, previous) {
|
|
416
418
|
const peak = Math.max(1, ...current, ...previous);
|
|
417
419
|
return labels.map((label, index) => {
|
|
418
420
|
const width = current[index] > 0 ? Math.max(1, Math.round(current[index] / peak * BAR_WIDTH)) : 0;
|
|
419
|
-
return [index === 0 ? title : '', `${label.padEnd(8)}${'█'.repeat(width).padEnd(BAR_WIDTH)} ${metricNumber(current[index])}
|
|
421
|
+
return [index === 0 ? title : '', `${label.padEnd(8)}${'█'.repeat(width).padEnd(BAR_WIDTH)} ${metricNumber(current[index])} (previous ${metricNumber(previous[index])})`];
|
|
420
422
|
});
|
|
421
423
|
}
|
|
422
424
|
function softwareRows({ server, poweredBy, advisories }) {
|
|
423
425
|
const observed = [server, poweredBy].filter(Boolean).join(' · ');
|
|
424
426
|
if (!observed)
|
|
425
|
-
return [['
|
|
427
|
+
return [['Server software', 'No server responses observed yet.']];
|
|
426
428
|
const notes = advisories.length
|
|
427
|
-
? advisories.map(({ severity, product, version, summary, reference }, index) => [index === 0 ? '
|
|
428
|
-
: [['
|
|
429
|
-
return [['
|
|
429
|
+
? advisories.map(({ severity, product, version, summary, reference }, index) => [index === 0 ? 'Vulnerable versions' : '', `[${severityLabels[severity]}] ${product}/${version} · ${summary} (${reference})`])
|
|
430
|
+
: [['Vulnerable versions', 'No known vulnerable versions.']];
|
|
431
|
+
return [['Server software', observed], ...notes];
|
|
430
432
|
}
|
|
431
433
|
function trafficRows(traffic) {
|
|
432
434
|
if (traffic.requests === 0)
|
|
433
|
-
return [['
|
|
434
|
-
const ratio = (count) => `${metricNumber(count)}
|
|
435
|
+
return [['Edge traffic', 'No requests counted yet.']];
|
|
436
|
+
const ratio = (count) => `${metricNumber(count)} (${(count / traffic.requests * 100).toFixed(1)}%)`;
|
|
435
437
|
return [
|
|
436
|
-
['
|
|
437
|
-
['
|
|
438
|
-
['
|
|
439
|
-
['
|
|
440
|
-
['
|
|
441
|
-
['
|
|
442
|
-
['
|
|
443
|
-
['
|
|
444
|
-
...traffic.paths.map(({ path, count, share }, index) => [index === 0 ? '
|
|
438
|
+
['Edge traffic', counted(traffic.requests, 'request')],
|
|
439
|
+
['Server pageviews', metricNumber(traffic.pageviews)],
|
|
440
|
+
['Visitors (hourly sum)', metricNumber(traffic.visitors)],
|
|
441
|
+
['Bot requests', metricNumber(traffic.bots)],
|
|
442
|
+
['Success (2xx)', ratio(traffic.statuses.ok)],
|
|
443
|
+
['Redirects (3xx)', ratio(traffic.statuses.redirect)],
|
|
444
|
+
['Client errors (4xx)', ratio(traffic.statuses.client)],
|
|
445
|
+
['Server errors (5xx)', ratio(traffic.statuses.server)],
|
|
446
|
+
...traffic.paths.map(({ path, count, share }, index) => [index === 0 ? 'Top paths (server pageviews)' : '', `${path} ${metricNumber(count)} (${share.toFixed(1)}%)`])
|
|
445
447
|
];
|
|
446
448
|
}
|
|
447
449
|
function metricRows(siteUrl, project, period, { report, software, traffic }) {
|
|
448
450
|
const { labels, visits, previousVisits, views, previousViews, range, totalVisits, totalViews, previousTotalVisits, previousTotalViews, duration, previousDuration, bounce, previousBounce, sources, devices, pages } = report;
|
|
449
451
|
return [
|
|
450
|
-
['
|
|
451
|
-
['
|
|
452
|
-
['
|
|
453
|
-
['
|
|
454
|
-
['
|
|
455
|
-
['
|
|
456
|
-
...trendRows('
|
|
457
|
-
...trendRows('
|
|
458
|
-
['
|
|
459
|
-
['
|
|
452
|
+
['Server', siteUrl], ['Project', project],
|
|
453
|
+
['Period', `${PERIOD_LABELS[period]} · ${range} · KST`],
|
|
454
|
+
['Visits', compared(metricNumber(totalVisits), totalVisits, previousTotalVisits)],
|
|
455
|
+
['Pageviews', compared(metricNumber(totalViews), totalViews, previousTotalViews)],
|
|
456
|
+
['Avg. visit duration', compared(stay(duration), duration, previousDuration)],
|
|
457
|
+
['Bounce rate', compared(`${bounce.toFixed(1)}%`, bounce, previousBounce)],
|
|
458
|
+
...trendRows('Visit trend', labels, visits, previousVisits),
|
|
459
|
+
...trendRows('Pageview trend', labels, views, previousViews),
|
|
460
|
+
['Traffic sources', shares(sources)],
|
|
461
|
+
['Devices', shares(devices)],
|
|
460
462
|
...(software ? softwareRows(software) : []),
|
|
461
463
|
...(traffic ? trafficRows(traffic) : []),
|
|
462
464
|
...(pages.length
|
|
463
|
-
? pages.map(({ path, count, share }, index) => [index === 0 ? '
|
|
464
|
-
: [['
|
|
465
|
+
? pages.map(({ path, count, share }, index) => [index === 0 ? 'Top pages' : '', `${path} ${metricNumber(count)} (${share.toFixed(1)}%)`])
|
|
466
|
+
: [['Top pages', 'None']])
|
|
465
467
|
];
|
|
466
468
|
}
|
|
467
469
|
export async function runProjectsMetric(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
468
470
|
const command = 'projects metric';
|
|
469
471
|
const { args: rest, dryRun } = splitDryRun(args);
|
|
470
|
-
const parsed = parseMetric(rest
|
|
472
|
+
const parsed = parseMetric(rest);
|
|
471
473
|
if ('error' in parsed)
|
|
472
474
|
return usageError(command, parsed.error, pretty, depth);
|
|
473
475
|
const { project, period } = parsed;
|
|
@@ -476,7 +478,7 @@ export async function runProjectsMetric(args, pretty, depth, deps = defaultAuthD
|
|
|
476
478
|
return preview(command, pretty, depth, deps, url);
|
|
477
479
|
const sent = await authorized(deps, (session) => request(url(session.siteUrl), {
|
|
478
480
|
method: 'GET', headers: { authorization: `Bearer ${session.token}` }
|
|
479
|
-
}, deps, pretty ? '
|
|
481
|
+
}, deps, pretty ? 'Loading visit statistics.' : null));
|
|
480
482
|
if ('login' in sent)
|
|
481
483
|
return sent.login;
|
|
482
484
|
const { session, result } = sent;
|
|
@@ -485,12 +487,12 @@ export async function runProjectsMetric(args, pretty, depth, deps = defaultAuthD
|
|
|
485
487
|
if (!metric) {
|
|
486
488
|
const shown = failure ?? UNEXPECTED;
|
|
487
489
|
return pretty
|
|
488
|
-
? prettyResult(1, depth, command, '
|
|
490
|
+
? prettyResult(1, depth, command, 'Could not load the visit statistics.', [['Server', session.siteUrl], ['Project', project], ['Reason', shown.display]])
|
|
489
491
|
: agentResult(1, { command, siteUrl: session.siteUrl, project, error: failureError(shown) });
|
|
490
492
|
}
|
|
491
493
|
if (!pretty)
|
|
492
494
|
return agentResult(0, { command, siteUrl: session.siteUrl, project, period, ...metric });
|
|
493
|
-
const message = metric.report.totalVisits ?
|
|
495
|
+
const message = metric.report.totalVisits ? `Loaded visit statistics for the last ${PERIOD_LABELS[period]}.` : `No visits in the last ${PERIOD_LABELS[period]}.`;
|
|
494
496
|
return prettyResult(0, depth, command, message, metricRows(session.siteUrl, project, period, metric));
|
|
495
497
|
}
|
|
496
498
|
export async function runProjectsRollback(args, pretty, depth, deps = { ...defaultAuthDeps(pretty, depth), restore: restoreDeployment }) {
|
|
@@ -498,48 +500,48 @@ export async function runProjectsRollback(args, pretty, depth, deps = { ...defau
|
|
|
498
500
|
const invalid = (message) => usageError(command, message, pretty, depth);
|
|
499
501
|
const { args: plain, dryRun } = splitDryRun(args);
|
|
500
502
|
const { args: rest, yes } = splitYes(plain);
|
|
501
|
-
const timeout = parseTimeout(rest, PUBLISH_WAIT_SECONDS
|
|
503
|
+
const timeout = parseTimeout(rest, PUBLISH_WAIT_SECONDS);
|
|
502
504
|
if ('error' in timeout)
|
|
503
505
|
return invalid(timeout.error);
|
|
504
|
-
const parsed = parseCommand(timeout.rest, ['--to']
|
|
506
|
+
const parsed = parseCommand(timeout.rest, ['--to']);
|
|
505
507
|
if ('error' in parsed)
|
|
506
508
|
return invalid(parsed.error);
|
|
507
|
-
const project = parseName(parsed.names
|
|
509
|
+
const project = parseName(parsed.names);
|
|
508
510
|
if (typeof project !== 'string')
|
|
509
511
|
return invalid(project.error);
|
|
510
512
|
const to = parsed.entries[0]?.[1];
|
|
511
513
|
if (parsed.entries.length > 1 || (to !== undefined && !COMMIT_PREFIX.test(to))) {
|
|
512
|
-
return invalid(
|
|
514
|
+
return invalid('Give --to once, as 7-40 lowercase hex characters of a commit from deepdynamic projects history.');
|
|
513
515
|
}
|
|
514
516
|
if (dryRun)
|
|
515
517
|
return plannedRollback(project, to ?? null, pretty, depth, deps);
|
|
516
518
|
if (!yes) {
|
|
517
519
|
return confirmationRequired(command, plain, pretty, depth, {
|
|
518
520
|
message: 'Rolling back replaces the live site with an earlier deployment.',
|
|
519
|
-
display: '
|
|
521
|
+
display: 'Rolling back replaces the live site with an earlier deployment. Confirm with the user, then run the command with --yes.'
|
|
520
522
|
}, { project });
|
|
521
523
|
}
|
|
522
524
|
const history = await loadHistory(command, project, pretty, depth, deps);
|
|
523
525
|
if ('result' in history)
|
|
524
526
|
return history.result;
|
|
525
527
|
const { session, deployments } = history;
|
|
526
|
-
const refuse = (code, message
|
|
527
|
-
? prettyResult(1, depth, command,
|
|
528
|
+
const refuse = (code, message) => pretty
|
|
529
|
+
? prettyResult(1, depth, command, message, [['Server', session.siteUrl], ['Project', project]])
|
|
528
530
|
: agentResult(1, { command, siteUrl: session.siteUrl, project, deployments, error: { code, message } });
|
|
529
531
|
const matches = to === undefined ? deployments.slice(1, 2) : deployments.filter(({ commit }) => commit.startsWith(to));
|
|
530
532
|
if (matches.length !== 1) {
|
|
531
533
|
return to === undefined
|
|
532
|
-
? refuse('no_previous_deployment', 'There is no earlier published deployment to roll back to. Nothing was changed.'
|
|
533
|
-
: refuse('deployment_not_found', `No single published deployment matches ${to}. Pick a commit from deepdynamic projects history ${project}. Nothing was changed
|
|
534
|
+
? refuse('no_previous_deployment', 'There is no earlier published deployment to roll back to. Nothing was changed.')
|
|
535
|
+
: refuse('deployment_not_found', `No single published deployment matches ${to}. Pick a commit from deepdynamic projects history ${project}. Nothing was changed.`);
|
|
534
536
|
}
|
|
535
537
|
const [target] = matches;
|
|
536
538
|
if (target.current)
|
|
537
|
-
return refuse('already_current', 'That deployment is already published. Nothing was changed.'
|
|
539
|
+
return refuse('already_current', 'That deployment is already published. Nothing was changed.');
|
|
538
540
|
return shipDeployment({
|
|
539
541
|
command, project, manifest: target.manifest,
|
|
540
542
|
context: { project, target: { commit: target.commit, publishedAt: target.publishedAt } },
|
|
541
543
|
success: {},
|
|
542
|
-
rows: [['
|
|
544
|
+
rows: [['Project', project], ['Target', target.commit]],
|
|
543
545
|
waitMs: timeout.waitMs,
|
|
544
546
|
send: (remote, branch, token, onUploading) => deps.restore(remote, branch, token, target.commit, { onUploading })
|
|
545
547
|
}, pretty, depth, deps);
|
|
@@ -557,34 +559,34 @@ async function plannedRollback(project, to, pretty, depth, deps) {
|
|
|
557
559
|
];
|
|
558
560
|
if (!pretty)
|
|
559
561
|
return agentResult(0, { command, siteUrl, dryRun: true, applied: false, plan: { project, to }, requests });
|
|
560
|
-
return prettyResult(0, depth, command, '
|
|
561
|
-
['
|
|
562
|
-
...requests.map(({ method, url }, index) => [index === 0 ? '
|
|
562
|
+
return prettyResult(0, depth, command, 'Checked the rollback. Nothing was rolled back.', [
|
|
563
|
+
['Server', siteUrl], ['Project', project], ['Target', to ?? 'The deployment before the live one'],
|
|
564
|
+
...requests.map(({ method, url }, index) => [index === 0 ? 'Request' : '', `${method} ${url}`])
|
|
563
565
|
]);
|
|
564
566
|
}
|
|
565
567
|
export async function runProjectsRename(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
566
568
|
const command = 'projects rename';
|
|
567
569
|
const invalid = (message) => usageError(command, message, pretty, depth);
|
|
568
570
|
const dryRun = args.includes('--dry-run');
|
|
569
|
-
const parsed = parseCommand(args.filter((arg) => arg !== '--dry-run'), []
|
|
571
|
+
const parsed = parseCommand(args.filter((arg) => arg !== '--dry-run'), []);
|
|
570
572
|
if ('error' in parsed)
|
|
571
573
|
return invalid(parsed.error);
|
|
572
574
|
const { names } = parsed;
|
|
573
575
|
if (names.length !== 2)
|
|
574
|
-
return invalid(
|
|
575
|
-
const [project, name] = names.map((value) => parseName([value]
|
|
576
|
+
return invalid('Specify the current name and then the new name.');
|
|
577
|
+
const [project, name] = names.map((value) => parseName([value]));
|
|
576
578
|
if (typeof project !== 'string')
|
|
577
579
|
return invalid(project.error);
|
|
578
580
|
if (typeof name !== 'string')
|
|
579
581
|
return invalid(name.error);
|
|
580
582
|
if (project === name)
|
|
581
|
-
return invalid(
|
|
582
|
-
const sent = await authorized(deps, (session) => postJson(new URL(`${PROJECTS_PATH}/${project}/rename`, session.siteUrl).href, session.token, dryRun ? { name, dryRun: true } : { name }, deps, pretty ? (dryRun ? '
|
|
583
|
+
return invalid('The new name is the same as the current name.');
|
|
584
|
+
const sent = await authorized(deps, (session) => postJson(new URL(`${PROJECTS_PATH}/${project}/rename`, session.siteUrl).href, session.token, dryRun ? { name, dryRun: true } : { name }, deps, pretty ? (dryRun ? 'Checking the name.' : 'Renaming the project.') : null));
|
|
583
585
|
if ('login' in sent)
|
|
584
586
|
return sent.login;
|
|
585
587
|
const { session, result } = sent;
|
|
586
588
|
const failure = !('failure' in result) && result.status === 409
|
|
587
|
-
?
|
|
589
|
+
? plainFailure('project_taken', 'Another project already uses that name. Pick another name with the naming steps in deepdynamic projects create --help.')
|
|
588
590
|
: exchangeFailure(result);
|
|
589
591
|
const value = failure ? null : result.body;
|
|
590
592
|
const valid = dryRun
|
|
@@ -593,31 +595,31 @@ export async function runProjectsRename(args, pretty, depth, deps = defaultAuthD
|
|
|
593
595
|
if (failure || !valid) {
|
|
594
596
|
const shown = failure ?? UNEXPECTED;
|
|
595
597
|
return pretty
|
|
596
|
-
? prettyResult(1, depth, command, '
|
|
598
|
+
? prettyResult(1, depth, command, 'Could not rename the project.', [['Server', session.siteUrl], ['Project', project], ['New name', name], ['Reason', shown.display]])
|
|
597
599
|
: agentResult(1, { command, siteUrl: session.siteUrl, project, name, renamed: false, error: failureError(shown) });
|
|
598
600
|
}
|
|
599
601
|
if (dryRun) {
|
|
600
602
|
const available = value?.available === true;
|
|
601
603
|
if (!pretty)
|
|
602
604
|
return agentResult(0, { command, siteUrl: session.siteUrl, dryRun: true, project, name, available });
|
|
603
|
-
return prettyResult(0, depth, command, available ? '
|
|
604
|
-
['
|
|
605
|
+
return prettyResult(0, depth, command, available ? 'The name is available. The project was not renamed.' : 'The name is already taken. Choose a different name.', [
|
|
606
|
+
['Server', session.siteUrl], ['Project', project], ['New name', name]
|
|
605
607
|
]);
|
|
606
608
|
}
|
|
607
609
|
if (!pretty)
|
|
608
610
|
return agentResult(0, { command, siteUrl: session.siteUrl, project: name, previous: project, renamed: true });
|
|
609
|
-
return prettyResult(0, depth, command, '
|
|
610
|
-
['
|
|
611
|
+
return prettyResult(0, depth, command, 'Renamed the project. The site URL changes to the new name on the next deploy. The server, repository and deploy history stay the same.', [
|
|
612
|
+
['Server', session.siteUrl], ['Previous', project], ['New name', name], ['Next', `deepdynamic projects deploy ${name} <directory> --agent <code>`]
|
|
611
613
|
]);
|
|
612
614
|
}
|
|
613
|
-
const pwaLabel = (enabled) => enabled ? '
|
|
615
|
+
const pwaLabel = (enabled) => enabled ? 'on' : 'off';
|
|
614
616
|
function pwaFailure(result) {
|
|
615
617
|
if ('failure' in result)
|
|
616
618
|
return result.failure;
|
|
617
619
|
if (result.status === 403)
|
|
618
|
-
return
|
|
620
|
+
return plainFailure('login_required', 'The access token lacks the project scope for this command. Run deepdynamic login again.');
|
|
619
621
|
if (result.status === 503)
|
|
620
|
-
return supportFailure('unavailable', { note:
|
|
622
|
+
return supportFailure('unavailable', { note: 'The setting was not applied.', retryable: true });
|
|
621
623
|
return exchangeFailure(result);
|
|
622
624
|
}
|
|
623
625
|
function pwaState(body, project) {
|
|
@@ -628,19 +630,19 @@ export async function runProjectsPwa(args, pretty, depth, deps = defaultAuthDeps
|
|
|
628
630
|
const command = 'projects pwa';
|
|
629
631
|
const invalid = (message) => usageError(command, message, pretty, depth);
|
|
630
632
|
const { args: rest, dryRun } = splitDryRun(args);
|
|
631
|
-
const parsed = parseCommand(rest, []
|
|
633
|
+
const parsed = parseCommand(rest, []);
|
|
632
634
|
if ('error' in parsed)
|
|
633
635
|
return invalid(parsed.error);
|
|
634
636
|
const [input, state, ...extra] = parsed.names;
|
|
635
637
|
if (input === undefined)
|
|
636
|
-
return invalid(
|
|
637
|
-
const project = parseName([input]
|
|
638
|
+
return invalid('Specify the project name.');
|
|
639
|
+
const project = parseName([input]);
|
|
638
640
|
if (typeof project !== 'string')
|
|
639
641
|
return invalid(project.error);
|
|
640
642
|
if (state !== undefined && state !== 'on' && state !== 'off')
|
|
641
|
-
return invalid(
|
|
643
|
+
return invalid('After the project name give on or off, or nothing to show the current state.');
|
|
642
644
|
if (extra.length)
|
|
643
|
-
return invalid(unknownArgument(extra[0]
|
|
645
|
+
return invalid(unknownArgument(extra[0]));
|
|
644
646
|
const enabled = state === undefined ? null : state === 'on';
|
|
645
647
|
const url = (siteUrl) => new URL(`${PROJECTS_PATH}/${project}/pwa`, siteUrl).href;
|
|
646
648
|
if (dryRun) {
|
|
@@ -649,11 +651,11 @@ export async function runProjectsPwa(args, pretty, depth, deps = defaultAuthDeps
|
|
|
649
651
|
const session = await signedIn(deps);
|
|
650
652
|
if ('login' in session)
|
|
651
653
|
return session.login;
|
|
652
|
-
return plannedChange(command, pretty, depth, session.siteUrl, { url: url(session.siteUrl), body: { enabled } }, '
|
|
654
|
+
return plannedChange(command, pretty, depth, session.siteUrl, { url: url(session.siteUrl), body: { enabled } }, 'Checked the PWA change. Nothing was changed.', [['Project', project], ['PWA', pwaLabel(enabled)]], { project, pwa: enabled });
|
|
653
655
|
}
|
|
654
656
|
const sent = await authorized(deps, (session) => enabled === null
|
|
655
|
-
? request(url(session.siteUrl), { method: 'GET', headers: { authorization: `Bearer ${session.token}` } }, deps, pretty ? '
|
|
656
|
-
: postJson(url(session.siteUrl), session.token, { enabled }, deps, pretty ? '
|
|
657
|
+
? request(url(session.siteUrl), { method: 'GET', headers: { authorization: `Bearer ${session.token}` } }, deps, pretty ? 'Loading the PWA setting.' : null)
|
|
658
|
+
: postJson(url(session.siteUrl), session.token, { enabled }, deps, pretty ? 'Changing the PWA setting.' : null));
|
|
657
659
|
if ('login' in sent)
|
|
658
660
|
return sent.login;
|
|
659
661
|
const { session, result } = sent;
|
|
@@ -662,15 +664,15 @@ export async function runProjectsPwa(args, pretty, depth, deps = defaultAuthDeps
|
|
|
662
664
|
if (pwa === null) {
|
|
663
665
|
const shown = failure ?? UNEXPECTED;
|
|
664
666
|
return pretty
|
|
665
|
-
? prettyResult(1, depth, command, enabled === null ? '
|
|
667
|
+
? prettyResult(1, depth, command, enabled === null ? 'Could not load the PWA setting.' : 'Could not change the PWA setting.', [['Server', session.siteUrl], ['Project', project], ['Reason', shown.display]])
|
|
666
668
|
: agentResult(1, { command, siteUrl: session.siteUrl, project, error: failureError(shown) });
|
|
667
669
|
}
|
|
668
670
|
if (!pretty)
|
|
669
671
|
return agentResult(0, { command, siteUrl: session.siteUrl, project, pwa });
|
|
670
672
|
const message = enabled === null
|
|
671
|
-
? (pwa ? '
|
|
672
|
-
: (pwa ? '
|
|
673
|
-
return prettyResult(0, depth, command, message, [['
|
|
673
|
+
? (pwa ? 'PWA is on. Visitors can install this site as an app.' : 'PWA is off. Visitors cannot install this site as an app.')
|
|
674
|
+
: (pwa ? 'Turned PWA on. Visitors can install the site as an app.' : 'Turned PWA off. Visitors no longer see the install prompt.');
|
|
675
|
+
return prettyResult(0, depth, command, message, [['Server', session.siteUrl], ['Project', project], ['PWA', pwaLabel(pwa)]]);
|
|
674
676
|
}
|
|
675
677
|
function postProject(session, project, action, deps, spinner) {
|
|
676
678
|
return request(new URL(`${PROJECTS_PATH}/${project}/${action}`, session.siteUrl).href, {
|
|
@@ -681,79 +683,79 @@ async function plannedProjectChange(command, project, action, message, pretty, d
|
|
|
681
683
|
const session = await signedIn(deps);
|
|
682
684
|
if ('login' in session)
|
|
683
685
|
return session.login;
|
|
684
|
-
return plannedChange(command, pretty, depth, session.siteUrl, { url: new URL(`${PROJECTS_PATH}/${project}/${action}`, session.siteUrl).href }, message, [['
|
|
686
|
+
return plannedChange(command, pretty, depth, session.siteUrl, { url: new URL(`${PROJECTS_PATH}/${project}/${action}`, session.siteUrl).href }, message, [['Project', project]], { project });
|
|
685
687
|
}
|
|
686
688
|
export async function runProjectsStop(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
687
689
|
const command = 'projects stop';
|
|
688
690
|
const { args: plain, dryRun } = splitDryRun(args);
|
|
689
691
|
const { args: rest, yes } = splitYes(plain);
|
|
690
|
-
const project = parseName(rest
|
|
692
|
+
const project = parseName(rest);
|
|
691
693
|
if (typeof project !== 'string')
|
|
692
694
|
return usageError(command, project.error, pretty, depth);
|
|
693
695
|
if (dryRun)
|
|
694
|
-
return plannedProjectChange(command, project, 'stop', '
|
|
696
|
+
return plannedProjectChange(command, project, 'stop', 'Checked stopping the project server. Nothing was stopped.', pretty, depth, deps);
|
|
695
697
|
if (!yes) {
|
|
696
698
|
return confirmationRequired(command, plain, pretty, depth, {
|
|
697
699
|
message: 'Stopping cancels the running deploys of the project and turns its server off, so the site is offline until the next deploy.',
|
|
698
|
-
display: '
|
|
700
|
+
display: 'Stopping cancels running deploys and takes the site offline until the next deploy. Confirm with the user, then run the command with --yes.'
|
|
699
701
|
}, { project });
|
|
700
702
|
}
|
|
701
|
-
const sent = await authorized(deps, (session) => postProject(session, project, 'stop', deps, pretty ? '
|
|
703
|
+
const sent = await authorized(deps, (session) => postProject(session, project, 'stop', deps, pretty ? 'Stopping the project server.' : null));
|
|
702
704
|
if ('login' in sent)
|
|
703
705
|
return sent.login;
|
|
704
706
|
const { session, result } = sent;
|
|
705
707
|
const failure = !('failure' in result) && result.status === 409
|
|
706
|
-
? { code: 'server_updating', message: 'The project server is installing updates. Keep running deepdynamic projects stop until it no longer fails with server_updating.', display: '
|
|
708
|
+
? { code: 'server_updating', message: 'The project server is installing updates. Keep running deepdynamic projects stop until it no longer fails with server_updating.', display: 'The project server is installing updates. Try again after they finish.' }
|
|
707
709
|
: exchangeFailure(result);
|
|
708
710
|
const status = failure ? null : projectStatus(result.body, project);
|
|
709
711
|
if (!status) {
|
|
710
712
|
const shown = failure ?? UNEXPECTED;
|
|
711
713
|
return pretty
|
|
712
|
-
? prettyResult(1, depth, command, '
|
|
714
|
+
? prettyResult(1, depth, command, 'Could not stop the project server.', [['Server', session.siteUrl], ['Project', project], ['Reason', shown.display]])
|
|
713
715
|
: agentResult(1, { command, siteUrl: session.siteUrl, project, error: failureError(shown) });
|
|
714
716
|
}
|
|
715
717
|
const { server, site } = status;
|
|
716
|
-
return finish(command, 0, depth, pretty, session.siteUrl, project, server, site, null, server.stage === 'stopped' ? '
|
|
718
|
+
return finish(command, 0, depth, pretty, session.siteUrl, project, server, site, null, server.stage === 'stopped' ? 'Stopped the project server. The next deploy turns it back on.' : 'No project server is running.');
|
|
717
719
|
}
|
|
718
720
|
export async function runProjectsDelete(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
719
721
|
const command = 'projects delete';
|
|
720
722
|
const { args: plain, dryRun } = splitDryRun(args);
|
|
721
723
|
const { args: rest, yes } = splitYes(plain);
|
|
722
|
-
const project = parseName(rest
|
|
724
|
+
const project = parseName(rest);
|
|
723
725
|
if (typeof project !== 'string')
|
|
724
726
|
return usageError(command, project.error, pretty, depth);
|
|
725
727
|
if (dryRun)
|
|
726
|
-
return plannedProjectChange(command, project, 'delete', '
|
|
728
|
+
return plannedProjectChange(command, project, 'delete', 'Checked deleting the project. Nothing was deleted.', pretty, depth, deps);
|
|
727
729
|
if (!yes) {
|
|
728
730
|
return confirmationRequired(command, plain, pretty, depth, {
|
|
729
731
|
message: 'Deleting removes the project, its server and its deploy history permanently.',
|
|
730
|
-
display: '
|
|
732
|
+
display: 'Deleting removes the project, its server and its deploy history. This cannot be undone. Confirm with the user, then run the command with --yes.'
|
|
731
733
|
}, { project });
|
|
732
734
|
}
|
|
733
|
-
const sent = await authorized(deps, (session) => postProject(session, project, 'delete', deps, pretty ? '
|
|
735
|
+
const sent = await authorized(deps, (session) => postProject(session, project, 'delete', deps, pretty ? 'Deleting the project.' : null));
|
|
734
736
|
if ('login' in sent)
|
|
735
737
|
return sent.login;
|
|
736
738
|
const { session, result } = sent;
|
|
737
739
|
const failure = !('failure' in result) && result.status === 409
|
|
738
|
-
? { code: 'server_busy', message: 'The project server is busy with another job. Try again after it finishes.', display: '
|
|
740
|
+
? { code: 'server_busy', message: 'The project server is busy with another job. Try again after it finishes.', display: 'The project server is still being created or is busy with another job. Try again after it finishes.' }
|
|
739
741
|
: exchangeFailure(result);
|
|
740
742
|
const value = failure ? null : result.body;
|
|
741
743
|
if (failure || value?.ok !== true || value.project !== project || value.deleted !== true) {
|
|
742
744
|
const shown = failure ?? UNEXPECTED;
|
|
743
745
|
return pretty
|
|
744
|
-
? prettyResult(1, depth, command, '
|
|
746
|
+
? prettyResult(1, depth, command, 'Could not delete the project.', [['Server', session.siteUrl], ['Project', project], ['Reason', shown.display]])
|
|
745
747
|
: agentResult(1, { command, siteUrl: session.siteUrl, project, deleted: false, error: failureError(shown) });
|
|
746
748
|
}
|
|
747
749
|
if (!pretty)
|
|
748
750
|
return agentResult(0, { command, siteUrl: session.siteUrl, project, deleted: true });
|
|
749
|
-
return prettyResult(0, depth, command, '
|
|
751
|
+
return prettyResult(0, depth, command, 'Deleted the project. Its server is stopped and removed in the background.', [['Server', session.siteUrl], ['Project', project]]);
|
|
750
752
|
}
|
|
751
753
|
const PHOTOCARD_SIDES = [1, 2];
|
|
752
|
-
const PHOTOCARD_LABELS = { 1: '
|
|
754
|
+
const PHOTOCARD_LABELS = { 1: 'Front', 2: 'Back' };
|
|
753
755
|
const FLIGHT_REQUIRED = {
|
|
754
756
|
code: 'flight_required',
|
|
755
757
|
message: 'The project has no flight yet. Deploy it once with deepdynamic projects deploy <name> <directory> --agent <code>, then run this again.',
|
|
756
|
-
display: '
|
|
758
|
+
display: 'The photocard needs a deploy made with --agent. Deploy the project once with --agent, then run this again.'
|
|
757
759
|
};
|
|
758
760
|
function attachmentName(header) {
|
|
759
761
|
const encoded = /filename\*=UTF-8''([^;]+)/i.exec(header ?? '')?.[1];
|
|
@@ -783,14 +785,14 @@ export async function runProjectsPhotocard(args, pretty, depth, deps = { ...defa
|
|
|
783
785
|
const command = 'projects photocard';
|
|
784
786
|
const invalid = (message) => usageError(command, message, pretty, depth);
|
|
785
787
|
const { args: rest, dryRun } = splitDryRun(args);
|
|
786
|
-
const parsed = parseCommand(rest, ['--out']
|
|
788
|
+
const parsed = parseCommand(rest, ['--out']);
|
|
787
789
|
if ('error' in parsed)
|
|
788
790
|
return invalid(parsed.error);
|
|
789
|
-
const project = parseName(parsed.names
|
|
791
|
+
const project = parseName(parsed.names);
|
|
790
792
|
if (typeof project !== 'string')
|
|
791
793
|
return invalid(project.error);
|
|
792
794
|
if (parsed.entries.length > 1)
|
|
793
|
-
return invalid(
|
|
795
|
+
return invalid('Give --out at most once.');
|
|
794
796
|
const out = parsed.entries[0]?.[1] ?? '.';
|
|
795
797
|
const url = (siteUrl, side) => `${new URL(`${PROJECTS_PATH}/${project}/photocard`, siteUrl).href}?side=${side}`;
|
|
796
798
|
if (dryRun) {
|
|
@@ -799,18 +801,18 @@ export async function runProjectsPhotocard(args, pretty, depth, deps = { ...defa
|
|
|
799
801
|
return session.login;
|
|
800
802
|
const requests = PHOTOCARD_SIDES.map((side) => ({ method: 'GET', url: url(session.siteUrl, side) }));
|
|
801
803
|
return pretty
|
|
802
|
-
? prettyResult(0, depth, command, '
|
|
804
|
+
? prettyResult(0, depth, command, 'Checked without sending the requests.', [['Server', session.siteUrl], ['Project', project], ['Directory', out], ...requests.map(({ url }) => ['Request', `GET ${url}`])])
|
|
803
805
|
: agentResult(0, { command, siteUrl: session.siteUrl, dryRun: true, project, out, requests });
|
|
804
806
|
}
|
|
805
807
|
const images = [];
|
|
806
808
|
const failed = (siteUrl, shown) => pretty
|
|
807
|
-
? prettyResult(1, depth, command, '
|
|
809
|
+
? prettyResult(1, depth, command, 'Could not save the photocard.', [['Server', siteUrl], ['Project', project], ['Reason', shown.display]])
|
|
808
810
|
: agentResult(1, { command, siteUrl, project, images, error: failureError(shown) });
|
|
809
811
|
let siteUrl = '';
|
|
810
812
|
for (const side of PHOTOCARD_SIDES) {
|
|
811
813
|
const sent = await authorized(deps, (session) => request(url(session.siteUrl, side), {
|
|
812
814
|
method: 'GET', headers: { authorization: `Bearer ${session.token}` }
|
|
813
|
-
}, deps, pretty ?
|
|
815
|
+
}, deps, pretty ? `Rendering the photocard ${PHOTOCARD_LABELS[side].toLowerCase()}.` : null, readPhotocard));
|
|
814
816
|
if ('login' in sent)
|
|
815
817
|
return sent.login;
|
|
816
818
|
siteUrl = sent.session.siteUrl;
|
|
@@ -824,13 +826,13 @@ export async function runProjectsPhotocard(args, pretty, depth, deps = { ...defa
|
|
|
824
826
|
await deps.writeFile(path, image.bytes);
|
|
825
827
|
}
|
|
826
828
|
catch {
|
|
827
|
-
return failed(siteUrl,
|
|
829
|
+
return failed(siteUrl, plainFailure('save_failed', `Could not write ${path}. Check that the directory exists and is writable.`));
|
|
828
830
|
}
|
|
829
831
|
images.push({ side, path, bytes: image.bytes.length });
|
|
830
832
|
}
|
|
831
833
|
if (!pretty)
|
|
832
834
|
return agentResult(0, { command, siteUrl, project, images });
|
|
833
|
-
return prettyResult(0, depth, command, '
|
|
834
|
-
['
|
|
835
|
+
return prettyResult(0, depth, command, 'Saved the photocard front and back as PNG files.', [
|
|
836
|
+
['Server', siteUrl], ['Project', project], ...images.map(({ side, path }) => [PHOTOCARD_LABELS[side], path])
|
|
835
837
|
]);
|
|
836
838
|
}
|