@deepdynamic/cli 0.0.0-stage → 0.1.0
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 +180 -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 +59 -0
- package/dist/commands/dns.js +791 -0
- package/dist/commands/domains.js +711 -0
- package/dist/commands/emails.js +74 -0
- package/dist/commands/env.js +194 -0
- package/dist/commands/help.js +149 -0
- package/dist/commands/keys.js +269 -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 +132 -0
- package/dist/commands/plan.js +371 -0
- package/dist/commands/projects.js +836 -0
- package/dist/commands/reference.js +2180 -0
- package/dist/commands/search.js +75 -0
- package/dist/commands/server.js +314 -0
- package/dist/commands/sessions.js +120 -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 +98 -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 +76 -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/registry.js +760 -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 +58 -0
- package/dist/runtime/error-hints.js +26 -0
- package/dist/runtime/flags.js +50 -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 +32 -0
- package/dist/runtime/spinner.js +15 -0
- package/dist/runtime/suggest.js +22 -0
- package/dist/runtime/support.js +14 -0
- package/dist/runtime/text-file.js +20 -0
- package/dist/runtime/timeout.js +22 -0
- package/dist/runtime/update-check.js +124 -0
- package/dist/runtime/update-install.js +50 -0
- package/dist/runtime/usage-error.js +9 -0
- package/dist/setup-agents.js +8 -0
- package/dist/site.js +1 -0
- package/dist/update-refresh.js +5 -0
- package/package.json +46 -3
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { authorized, defaultAuthDeps } from "../auth/session.js";
|
|
2
|
+
import { LOGIN_EXPIRED, accepted, httpFailure, postJson, sendFailureError } from "../http/request.js";
|
|
3
|
+
import { agentResult } from "../output.js";
|
|
4
|
+
import { prettyResult } from "../pretty.js";
|
|
5
|
+
import { spec } from "../registry.js";
|
|
6
|
+
import { splitDryRun } from "../runtime/dry-run.js";
|
|
7
|
+
import { parseFlags } from "../runtime/flags.js";
|
|
8
|
+
import { readText } from "../runtime/text-file.js";
|
|
9
|
+
export const EMAILS_PATH = '/api/v1/emails';
|
|
10
|
+
const { name: command, usage, prettyUsage } = spec('emails send');
|
|
11
|
+
const FLAGS = ['--to', '--title', '--body', '--body-file'];
|
|
12
|
+
const BODY_ESCAPE_RE = /\\(\\|r\\n|n|t)/g;
|
|
13
|
+
function unescapeBody(body) {
|
|
14
|
+
return body.replace(BODY_ESCAPE_RE, (_, escape) => (escape === '\\' ? '\\' : escape === 't' ? '\t' : '\n'));
|
|
15
|
+
}
|
|
16
|
+
async function parseSendArgs(args, pretty) {
|
|
17
|
+
const parsed = parseFlags(args, FLAGS, pretty);
|
|
18
|
+
if ('error' in parsed)
|
|
19
|
+
return parsed;
|
|
20
|
+
const values = Object.fromEntries(parsed.entries);
|
|
21
|
+
const { '--to': to, '--title': title, '--body': body, '--body-file': bodyFile } = values;
|
|
22
|
+
if (to === undefined || title === undefined) {
|
|
23
|
+
const missing = to === undefined ? '--to' : '--title';
|
|
24
|
+
return { error: pretty ? `${missing} 를 지정하세요.` : `${missing} is required.` };
|
|
25
|
+
}
|
|
26
|
+
const content = await readText('--body', body === undefined ? undefined : unescapeBody(body), bodyFile, pretty);
|
|
27
|
+
return 'error' in content ? content : { to, title, body: content.text };
|
|
28
|
+
}
|
|
29
|
+
export async function runEmailSend(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
30
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
31
|
+
const parsed = await parseSendArgs(rest, pretty);
|
|
32
|
+
if ('error' in parsed) {
|
|
33
|
+
return pretty
|
|
34
|
+
? prettyResult(2, depth, command, parsed.error, [['사용법', prettyUsage]])
|
|
35
|
+
: agentResult(2, { command, error: { code: 'invalid_arguments', message: parsed.error }, usage });
|
|
36
|
+
}
|
|
37
|
+
const sent = await authorized(deps, ({ siteUrl, token }) => postJson(new URL(EMAILS_PATH, siteUrl).href, token, dryRun ? { ...parsed, dryRun } : parsed, deps, pretty ? (dryRun ? '메일을 검증하고 있습니다.' : '메일을 보내고 있습니다.') : null));
|
|
38
|
+
if ('login' in sent)
|
|
39
|
+
return sent.login;
|
|
40
|
+
const { session: { siteUrl }, result } = sent;
|
|
41
|
+
let failure = null;
|
|
42
|
+
let rejected = false;
|
|
43
|
+
if ('failure' in result) {
|
|
44
|
+
failure = result.failure;
|
|
45
|
+
}
|
|
46
|
+
else if (result.status === 401) {
|
|
47
|
+
failure = LOGIN_EXPIRED;
|
|
48
|
+
}
|
|
49
|
+
else if (!accepted(result)) {
|
|
50
|
+
rejected = result.status === 400 && result.body?.rejected === true;
|
|
51
|
+
failure = rejected
|
|
52
|
+
? { code: 'spam_rejected', message: 'The server rejected the email as advertising or spam. The account may be blocked if this continues.', display: '광고·스팸으로 보이는 내용이라 거절되었습니다.' }
|
|
53
|
+
: result.status === 429
|
|
54
|
+
? { code: 'rate_limited', message: 'Too many emails. Try again later.', display: '요청이 너무 많습니다.' }
|
|
55
|
+
: result.status === 400
|
|
56
|
+
? { code: 'rejected', message: 'The server rejected the email. Check the recipient, title and body.', display: '받는 사람·제목·본문을 확인하세요.' }
|
|
57
|
+
: httpFailure(result.status);
|
|
58
|
+
}
|
|
59
|
+
if (failure) {
|
|
60
|
+
return pretty
|
|
61
|
+
? prettyResult(1, depth, command, rejected ? '메일이 거절되었습니다.' : dryRun ? '메일을 검증하지 못했습니다.' : '메일을 보내지 못했습니다.', [['서버', siteUrl], ['원인', failure.display]])
|
|
62
|
+
: agentResult(1, { command, siteUrl, delivered: false, ...(rejected ? { rejected } : {}), error: sendFailureError(result, failure) });
|
|
63
|
+
}
|
|
64
|
+
const { dryRun: checked, delivered, id, from, to, replyTo, bcc } = result.body;
|
|
65
|
+
if (!pretty) {
|
|
66
|
+
return agentResult(0, { command, siteUrl, ...(checked === true ? { dryRun: true } : {}), delivered, rejected, id, from, to, replyTo, bcc });
|
|
67
|
+
}
|
|
68
|
+
return prettyResult(0, depth, command, checked === true ? '메일을 검증했습니다. 보내지 않았습니다.' : '메일을 보냈습니다.', [
|
|
69
|
+
['서버', siteUrl],
|
|
70
|
+
['보낸 사람', from],
|
|
71
|
+
['받는 사람', to],
|
|
72
|
+
['답장 주소', replyTo]
|
|
73
|
+
]);
|
|
74
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { authorized, defaultAuthDeps, signedIn } from "../auth/session.js";
|
|
4
|
+
import { LOGIN_EXPIRED, UNEXPECTED, failureError, httpFailure, postJson, request } from "../http/request.js";
|
|
5
|
+
import { agentResult } from "../output.js";
|
|
6
|
+
import { prettyResult } from "../pretty.js";
|
|
7
|
+
import { confirmationRequired, splitYes } from "../runtime/confirm.js";
|
|
8
|
+
import { plannedChange, plannedRequest, splitDryRun } from "../runtime/dry-run.js";
|
|
9
|
+
import { readEnv, sealEnv, validSeal } from "../runtime/env-file.js";
|
|
10
|
+
import { parseCommand } from "../runtime/flags.js";
|
|
11
|
+
import { PROJECT } from "../runtime/project-name.js";
|
|
12
|
+
import { supportDisplay, supportFailure } from "../runtime/support.js";
|
|
13
|
+
import { usageError } from "../runtime/usage-error.js";
|
|
14
|
+
export const ENV_FILE = '.env';
|
|
15
|
+
const NEXT_DEPLOY = '다음 배포·되돌리기부터 빌드와 앱 서버에 적용됩니다.';
|
|
16
|
+
const NAME_ERROR = [
|
|
17
|
+
'The project name must be 1-63 lowercase letters, digits or hyphens that start and end with a letter or digit.',
|
|
18
|
+
'프로젝트 이름은 영문 소문자·숫자로 시작하고 끝나는 1~63자의 소문자·숫자·하이픈입니다.'
|
|
19
|
+
];
|
|
20
|
+
const PROJECT_NOT_FOUND = { code: 'project_not_found', message: 'You have no project with that name. Check the name with deepdynamic projects.', display: '그 이름의 내 프로젝트가 없습니다.' };
|
|
21
|
+
const ENV_UNAVAILABLE = supportFailure('env_unavailable', { note: { en: 'Nothing was sent.', ko: '보낸 값은 없습니다.' } });
|
|
22
|
+
const SEAL_KEY_CHANGED = { code: 'seal_key_changed', message: 'The variables could not be saved. Run the same command again.', display: '환경변수를 저장하지 못했습니다. 같은 명령을 다시 실행하세요.' };
|
|
23
|
+
const envUrl = (siteUrl, project, action = '') => new URL(`/api/v1/projects/${project}/env${action}`, siteUrl).href;
|
|
24
|
+
function envState(body, project) {
|
|
25
|
+
const value = body;
|
|
26
|
+
if (value?.ok !== true || value.project !== project || !Array.isArray(value.names) || !value.names.every((name) => typeof name === 'string')
|
|
27
|
+
|| (value.updatedAt !== null && typeof value.updatedAt !== 'string') || (value.seal !== undefined && value.seal !== null && !validSeal(value.seal)))
|
|
28
|
+
return null;
|
|
29
|
+
return { names: value.names, updatedAt: value.updatedAt, seal: (value.seal ?? null) };
|
|
30
|
+
}
|
|
31
|
+
function failureOf(result) {
|
|
32
|
+
if ('failure' in result)
|
|
33
|
+
return result.failure;
|
|
34
|
+
if (result.status === 401)
|
|
35
|
+
return LOGIN_EXPIRED;
|
|
36
|
+
if (result.status === 404)
|
|
37
|
+
return PROJECT_NOT_FOUND;
|
|
38
|
+
if (result.status === 409)
|
|
39
|
+
return SEAL_KEY_CHANGED;
|
|
40
|
+
if (result.status !== 200)
|
|
41
|
+
return httpFailure(result.status);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
function failed(command, pretty, depth, siteUrl, project, message, failure) {
|
|
45
|
+
return pretty
|
|
46
|
+
? prettyResult(1, depth, command, message, [['서버', siteUrl], ['프로젝트', project], ['원인', failure.display]])
|
|
47
|
+
: agentResult(1, { command, siteUrl, project, error: failureError(failure) });
|
|
48
|
+
}
|
|
49
|
+
function parseProject(command, names, max, pretty, depth) {
|
|
50
|
+
if (names.length < 1 || names.length > max) {
|
|
51
|
+
return usageError(command, max === 1
|
|
52
|
+
? pretty ? '프로젝트 이름을 하나만 지정하세요.' : 'Specify exactly one project name.'
|
|
53
|
+
: pretty ? '프로젝트 이름과 환경변수 파일을 차례로 지정하세요.' : 'Specify the project name and at most one env file.', pretty, depth);
|
|
54
|
+
}
|
|
55
|
+
return PROJECT.test(names[0]) ? names[0] : usageError(command, NAME_ERROR[pretty ? 1 : 0], pretty, depth);
|
|
56
|
+
}
|
|
57
|
+
const getEnv = (session, project, deps, spinner) => request(envUrl(session.siteUrl, project), { method: 'GET', headers: { authorization: `Bearer ${session.token}` } }, deps, spinner);
|
|
58
|
+
async function readVars(command, path, pretty, depth) {
|
|
59
|
+
let text;
|
|
60
|
+
try {
|
|
61
|
+
text = await readFile(path, 'utf8');
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const reason = error.code ?? String(error);
|
|
65
|
+
return {
|
|
66
|
+
result: pretty
|
|
67
|
+
? prettyResult(1, depth, command, '환경변수 파일을 읽지 못했습니다.', [['파일', path], ['원인', reason]])
|
|
68
|
+
: agentResult(1, { command, file: path, error: { code: 'env_file_unreadable', message: `Cannot read the env file (${reason}).` } })
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const read = readEnv(text);
|
|
72
|
+
if ('vars' in read)
|
|
73
|
+
return read;
|
|
74
|
+
return {
|
|
75
|
+
result: pretty
|
|
76
|
+
? prettyResult(1, depth, command, '환경변수 파일을 확인하세요.', [['파일', path], ['원인', read.error[1]]])
|
|
77
|
+
: agentResult(1, { command, file: path, error: { code: 'invalid_env', message: read.error[0] } })
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export async function runEnvPush(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
81
|
+
const command = 'projects env push';
|
|
82
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
83
|
+
const parsed = parseCommand(rest, [], pretty);
|
|
84
|
+
if ('error' in parsed)
|
|
85
|
+
return usageError(command, parsed.error, pretty, depth);
|
|
86
|
+
const project = parseProject(command, parsed.names, 2, pretty, depth);
|
|
87
|
+
if (typeof project !== 'string')
|
|
88
|
+
return project;
|
|
89
|
+
const file = resolve(parsed.names[1] ?? ENV_FILE);
|
|
90
|
+
const read = await readVars(command, file, pretty, depth);
|
|
91
|
+
if ('result' in read)
|
|
92
|
+
return read.result;
|
|
93
|
+
const names = Object.keys(read.vars).sort();
|
|
94
|
+
if (dryRun) {
|
|
95
|
+
const session = await signedIn(deps);
|
|
96
|
+
if ('login' in session)
|
|
97
|
+
return session.login;
|
|
98
|
+
return plannedChange(command, pretty, depth, session.siteUrl, { url: envUrl(session.siteUrl, project), body: { names } }, `환경변수 ${names.length}개를 확인했습니다. 봉인하거나 보내지 않았습니다.`, [['프로젝트', project], ['파일', file], ['변수', names.join(', ')]], { project, file, names });
|
|
99
|
+
}
|
|
100
|
+
const sent = await authorized(deps, (session) => getEnv(session, project, deps, pretty ? '환경변수 저장을 준비하고 있습니다.' : null));
|
|
101
|
+
if ('login' in sent)
|
|
102
|
+
return sent.login;
|
|
103
|
+
const { session } = sent;
|
|
104
|
+
const current = failureOf(sent.result) ? null : envState(sent.result.body, project);
|
|
105
|
+
const keyFailure = failureOf(sent.result) ?? (current ? current.seal ? null : ENV_UNAVAILABLE : UNEXPECTED);
|
|
106
|
+
if (keyFailure)
|
|
107
|
+
return failed(command, pretty, depth, session.siteUrl, project, '환경변수를 저장하지 못했습니다.', keyFailure);
|
|
108
|
+
let sealed;
|
|
109
|
+
try {
|
|
110
|
+
sealed = sealEnv(read.vars, current.seal);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return failed(command, pretty, depth, session.siteUrl, project, '환경변수를 저장하지 못했습니다.', UNEXPECTED);
|
|
114
|
+
}
|
|
115
|
+
const saved = await postJson(envUrl(session.siteUrl, project), session.token, { sealed, names }, deps, pretty ? '환경변수를 봉인해 보내고 있습니다.' : null);
|
|
116
|
+
const state = failureOf(saved) ? null : envState(saved.body, project);
|
|
117
|
+
const saveFailure = failureOf(saved) ?? (state ? null : UNEXPECTED);
|
|
118
|
+
if (saveFailure)
|
|
119
|
+
return failed(command, pretty, depth, session.siteUrl, project, '환경변수를 저장하지 못했습니다.', saveFailure);
|
|
120
|
+
if (!pretty)
|
|
121
|
+
return agentResult(0, { command, siteUrl: session.siteUrl, project, file, names: state.names, updatedAt: state.updatedAt, appliesFrom: 'next_deploy' });
|
|
122
|
+
return prettyResult(0, depth, command, `환경변수 ${state.names.length}개를 봉인해 저장했습니다. ${NEXT_DEPLOY}`, [
|
|
123
|
+
['서버', session.siteUrl], ['프로젝트', project], ['파일', file], ['변수', state.names.join(', ')]
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
126
|
+
export async function runEnvList(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
127
|
+
const command = 'projects env list';
|
|
128
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
129
|
+
const parsed = parseCommand(rest, [], pretty);
|
|
130
|
+
if ('error' in parsed)
|
|
131
|
+
return usageError(command, parsed.error, pretty, depth);
|
|
132
|
+
const project = parseProject(command, parsed.names, 1, pretty, depth);
|
|
133
|
+
if (typeof project !== 'string')
|
|
134
|
+
return project;
|
|
135
|
+
if (dryRun) {
|
|
136
|
+
const session = await signedIn(deps);
|
|
137
|
+
if ('login' in session)
|
|
138
|
+
return session.login;
|
|
139
|
+
return plannedRequest(command, pretty, depth, session.siteUrl, envUrl(session.siteUrl, project));
|
|
140
|
+
}
|
|
141
|
+
const sent = await authorized(deps, (session) => getEnv(session, project, deps, pretty ? '환경변수 목록을 불러오고 있습니다.' : null));
|
|
142
|
+
if ('login' in sent)
|
|
143
|
+
return sent.login;
|
|
144
|
+
const { session, result } = sent;
|
|
145
|
+
const state = failureOf(result) ? null : envState(result.body, project);
|
|
146
|
+
const failure = failureOf(result) ?? (state ? null : UNEXPECTED);
|
|
147
|
+
if (failure)
|
|
148
|
+
return failed(command, pretty, depth, session.siteUrl, project, '환경변수 목록을 확인하지 못했습니다.', failure);
|
|
149
|
+
const { names, updatedAt, seal } = state;
|
|
150
|
+
if (!pretty)
|
|
151
|
+
return agentResult(0, { command, siteUrl: session.siteUrl, project, names, updatedAt, enabled: seal !== null });
|
|
152
|
+
return prettyResult(0, depth, command, names.length ? `저장한 환경변수 ${names.length}개입니다. 값은 서버도 볼 수 없어 이름만 보여 줍니다.` : '저장한 환경변수가 없습니다.', [
|
|
153
|
+
['서버', session.siteUrl], ['프로젝트', project],
|
|
154
|
+
...(names.length ? [['변수', names.join(', ')], ['저장 시각', updatedAt ?? '']] : []),
|
|
155
|
+
...(seal ? [] : [['안내', supportDisplay('env_unavailable')]])
|
|
156
|
+
]);
|
|
157
|
+
}
|
|
158
|
+
export async function runEnvClear(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
159
|
+
const command = 'projects env clear';
|
|
160
|
+
const { args: plain, dryRun } = splitDryRun(args);
|
|
161
|
+
const { args: rest, yes } = splitYes(plain);
|
|
162
|
+
const parsed = parseCommand(rest, [], pretty);
|
|
163
|
+
if ('error' in parsed)
|
|
164
|
+
return usageError(command, parsed.error, pretty, depth);
|
|
165
|
+
const project = parseProject(command, parsed.names, 1, pretty, depth);
|
|
166
|
+
if (typeof project !== 'string')
|
|
167
|
+
return project;
|
|
168
|
+
if (dryRun) {
|
|
169
|
+
const session = await signedIn(deps);
|
|
170
|
+
if ('login' in session)
|
|
171
|
+
return session.login;
|
|
172
|
+
return plannedChange(command, pretty, depth, session.siteUrl, { url: envUrl(session.siteUrl, project, '/clear') }, '환경변수 지우기를 확인했습니다. 지우지 않았습니다.', [['프로젝트', project]], { project });
|
|
173
|
+
}
|
|
174
|
+
if (!yes) {
|
|
175
|
+
return confirmationRequired(command, plain, pretty, depth, {
|
|
176
|
+
message: 'Clearing removes every stored environment variable of the project; the next deploy builds and runs without them.',
|
|
177
|
+
display: '지우면 저장한 환경변수가 모두 사라지고 다음 배포부터 환경변수 없이 빌드·실행됩니다. 사용자에게 확인한 뒤 --yes 를 붙여 실행하세요.'
|
|
178
|
+
}, { project });
|
|
179
|
+
}
|
|
180
|
+
const sent = await authorized(deps, (session) => request(envUrl(session.siteUrl, project, '/clear'), {
|
|
181
|
+
method: 'POST', headers: { authorization: `Bearer ${session.token}` }
|
|
182
|
+
}, deps, pretty ? '환경변수를 지우고 있습니다.' : null));
|
|
183
|
+
if ('login' in sent)
|
|
184
|
+
return sent.login;
|
|
185
|
+
const { session, result } = sent;
|
|
186
|
+
const value = failureOf(result) ? null : result.body;
|
|
187
|
+
const failure = failureOf(result) ?? (value?.ok === true && value.project === project && typeof value.cleared === 'boolean' ? null : UNEXPECTED);
|
|
188
|
+
if (failure)
|
|
189
|
+
return failed(command, pretty, depth, session.siteUrl, project, '환경변수를 지우지 못했습니다.', failure);
|
|
190
|
+
const cleared = value.cleared;
|
|
191
|
+
if (!pretty)
|
|
192
|
+
return agentResult(0, { command, siteUrl: session.siteUrl, project, cleared, appliesFrom: 'next_deploy' });
|
|
193
|
+
return prettyResult(0, depth, command, cleared ? `저장한 환경변수를 모두 지웠습니다. ${NEXT_DEPLOY}` : '지울 환경변수가 없습니다.', [['서버', session.siteUrl], ['프로젝트', project]]);
|
|
194
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { SITE_URL } from "../metadata.js";
|
|
2
|
+
import { agentResult } from "../output.js";
|
|
3
|
+
import { displayWidth, pad, paint, prettyResult } from "../pretty.js";
|
|
4
|
+
import { commands, requiredUsage } from "../registry.js";
|
|
5
|
+
import { unknownArgument } from "../runtime/flags.js";
|
|
6
|
+
import { LOGIN_TIMEOUT_OPTION } from "../runtime/timeout.js";
|
|
7
|
+
import { usageError } from "../runtime/usage-error.js";
|
|
8
|
+
import { LOGIN_TIMEOUT_MS } from "./login/flow.js";
|
|
9
|
+
import { HELP_USAGE, details } from "./reference.js";
|
|
10
|
+
export const CLI_USAGE = 'deepdynamic [--pretty] [--login-timeout <seconds>] <command> [options]';
|
|
11
|
+
export const CLI_PRETTY_USAGE = 'deepdynamic [--pretty] [--login-timeout <초>] <명령> [옵션]';
|
|
12
|
+
const options = [
|
|
13
|
+
['-h, --help', '도움말 표시'],
|
|
14
|
+
['-v, --version', '버전 표시'],
|
|
15
|
+
[' --pretty', '사용자용 화면 표시'],
|
|
16
|
+
[' --login-timeout', `로그인 창 대기 최대 초, 1~${LOGIN_TIMEOUT_MS / 1000} (기본 ${LOGIN_TIMEOUT_MS / 1000})`]
|
|
17
|
+
];
|
|
18
|
+
const docs = [
|
|
19
|
+
['에이전트', `${SITE_URL}/llms.txt`],
|
|
20
|
+
['개발자', `${SITE_URL}/docs/dev`],
|
|
21
|
+
['CLI', `${SITE_URL}/cli.md`]
|
|
22
|
+
];
|
|
23
|
+
export function runHelp(args, version, depth, pretty) {
|
|
24
|
+
const rest = args.filter((arg) => arg !== '--all');
|
|
25
|
+
if (rest.length) {
|
|
26
|
+
return usageError('help', unknownArgument(rest[0], pretty), pretty, depth);
|
|
27
|
+
}
|
|
28
|
+
if (args.length)
|
|
29
|
+
return runCommands([], version, depth, pretty);
|
|
30
|
+
return pretty ? { code: 0, stdout: renderHome(depth), stderr: '' } : agentResult(0, agentHome(version));
|
|
31
|
+
}
|
|
32
|
+
function fields({ name, usage, description, effect, requiresLogin, requiresBrowser, dryRun, confirm }) {
|
|
33
|
+
return {
|
|
34
|
+
name,
|
|
35
|
+
usage,
|
|
36
|
+
description,
|
|
37
|
+
effect,
|
|
38
|
+
requiresLogin,
|
|
39
|
+
...(requiresBrowser ? { requiresBrowser } : {}),
|
|
40
|
+
...(dryRun ? { dryRun } : {}),
|
|
41
|
+
...(confirm ? { confirm } : {})
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function commandTree() {
|
|
45
|
+
const tree = [];
|
|
46
|
+
for (const entry of commands) {
|
|
47
|
+
const head = entry.name.split(' ')[0];
|
|
48
|
+
let node = tree.find(({ name }) => name === head);
|
|
49
|
+
if (!node) {
|
|
50
|
+
node = { name: head };
|
|
51
|
+
tree.push(node);
|
|
52
|
+
}
|
|
53
|
+
if (entry.name === head)
|
|
54
|
+
Object.assign(node, fields(entry));
|
|
55
|
+
else
|
|
56
|
+
(node.commands ??= []).push(fields(entry));
|
|
57
|
+
}
|
|
58
|
+
return tree;
|
|
59
|
+
}
|
|
60
|
+
export function runCommands(args, version, depth, pretty) {
|
|
61
|
+
const command = 'commands';
|
|
62
|
+
if (args.length)
|
|
63
|
+
return usageError(command, unknownArgument(args[0], pretty), pretty, depth);
|
|
64
|
+
if (!pretty)
|
|
65
|
+
return agentResult(0, { command, version, commands: commandTree() });
|
|
66
|
+
return prettyResult(0, depth, command, '전체 명령을 표시했습니다.', commands.map(({ name, summary }) => [`deepdynamic ${name}`, summary]));
|
|
67
|
+
}
|
|
68
|
+
export function runCommandHelp(args, pretty, depth) {
|
|
69
|
+
const length = args.findIndex((arg) => arg === '-h' || arg === '--help');
|
|
70
|
+
if (length < 1)
|
|
71
|
+
return null;
|
|
72
|
+
const topic = args.slice(0, length).join(' ');
|
|
73
|
+
const entries = commands.filter(({ name }) => name === topic || name.startsWith(`${topic} `));
|
|
74
|
+
if (!entries.length)
|
|
75
|
+
return null;
|
|
76
|
+
if (!pretty) {
|
|
77
|
+
return agentResult(0, {
|
|
78
|
+
command: 'help',
|
|
79
|
+
topic,
|
|
80
|
+
commands: entries.map((entry) => {
|
|
81
|
+
const { prettyOptions: _, ...detail } = details[entry.name];
|
|
82
|
+
return entry.name === topic ? { ...fields(entry), ...detail } : {
|
|
83
|
+
name: entry.name,
|
|
84
|
+
usage: entry.usage,
|
|
85
|
+
description: entry.description,
|
|
86
|
+
options: detail.options?.map(({ flag }) => flag) ?? [],
|
|
87
|
+
help: `deepdynamic ${entry.name} --help`
|
|
88
|
+
};
|
|
89
|
+
})
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const stdout = entries
|
|
93
|
+
.map((entry) => prettyResult(0, depth, entry.name, '도움말을 표시했습니다.', [['사용법', entry.prettyUsage], ...details[entry.name].prettyOptions]).stdout)
|
|
94
|
+
.join('');
|
|
95
|
+
return { code: 0, stdout, stderr: '' };
|
|
96
|
+
}
|
|
97
|
+
export function agentHome(version) {
|
|
98
|
+
return {
|
|
99
|
+
command: 'help',
|
|
100
|
+
name: 'DeepDynamic Cloud CLI',
|
|
101
|
+
version,
|
|
102
|
+
description: 'Deploy static and dynamic sites to DeepDynamic Cloud.',
|
|
103
|
+
usage: CLI_USAGE,
|
|
104
|
+
start: { command: 'deepdynamic account get', reason: 'Returns the signed-in account and the guide for talking to this user. Run it first.' },
|
|
105
|
+
commands: commands.map(({ name, usage, description, requiresBrowser, requiresLogin }) => ({
|
|
106
|
+
name,
|
|
107
|
+
usage,
|
|
108
|
+
description,
|
|
109
|
+
...(requiresBrowser ? { requiresBrowser } : {}),
|
|
110
|
+
...(requiresLogin ? { requiresLogin } : {})
|
|
111
|
+
})),
|
|
112
|
+
help: HELP_USAGE,
|
|
113
|
+
tree: 'deepdynamic commands',
|
|
114
|
+
options: [
|
|
115
|
+
{ flags: ['-h', '--help'], description: 'Show help.' },
|
|
116
|
+
{ flags: ['-v', '--version'], description: 'Show the CLI version.' },
|
|
117
|
+
{ flags: ['--pretty'], description: 'Use the human-readable Korean interface instead of JSON.' },
|
|
118
|
+
{
|
|
119
|
+
flags: [LOGIN_TIMEOUT_OPTION],
|
|
120
|
+
description: `Seconds to wait for the browser sign-in window, 1-${LOGIN_TIMEOUT_MS / 1000} (default ${LOGIN_TIMEOUT_MS / 1000}). The window still opens. When the seconds run out the command fails with login_timeout and that window can no longer sign in. Set it below the time limit of your shell.`
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
docs: { agents: `${SITE_URL}/llms.txt`, developers: `${SITE_URL}/docs/dev`, cli: `${SITE_URL}/cli.md` },
|
|
124
|
+
exitCodes: { 0: 'Success', 1: 'Command failed', 2: 'Invalid command or arguments', 3: 'Confirmation required: nothing was sent. Ask the user, then run error.next' }
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export function renderHome(depth) {
|
|
128
|
+
const { bold } = paint(depth);
|
|
129
|
+
const lines = commands.map(({ prettyUsage, summary }) => [requiredUsage(prettyUsage), summary]);
|
|
130
|
+
const labels = [...lines.map(([label]) => label), ...[...options, ...docs].map(([label]) => label)];
|
|
131
|
+
const labelWidth = Math.max(...labels.map(displayWidth));
|
|
132
|
+
const item = (label, text) => ` ${pad(label, labelWidth)} ${text}`;
|
|
133
|
+
return [
|
|
134
|
+
'정적·동적 사이트를 DeepDynamic Cloud에 배포하는 공식 CLI입니다.',
|
|
135
|
+
'',
|
|
136
|
+
bold('사용법'),
|
|
137
|
+
' deepdynamic <명령> [옵션]',
|
|
138
|
+
'',
|
|
139
|
+
bold('명령'),
|
|
140
|
+
...lines.map(([label, summary]) => item(label, summary)),
|
|
141
|
+
'',
|
|
142
|
+
bold('옵션'),
|
|
143
|
+
...options.map(([label, text]) => item(label, text)),
|
|
144
|
+
'',
|
|
145
|
+
bold('문서'),
|
|
146
|
+
...docs.map(([label, url]) => item(label, url)),
|
|
147
|
+
''
|
|
148
|
+
].join('\n');
|
|
149
|
+
}
|