@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,15 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { win32 } from 'node:path';
|
|
3
|
+
export function browserCommand(url, platform, systemRoot = process.env.SystemRoot || 'C:\\Windows') {
|
|
4
|
+
if (platform === 'darwin')
|
|
5
|
+
return ['open', [url]];
|
|
6
|
+
if (platform === 'win32')
|
|
7
|
+
return [win32.join(systemRoot, 'System32', 'rundll32.exe'), ['url.dll,FileProtocolHandler', url]];
|
|
8
|
+
return ['xdg-open', [url]];
|
|
9
|
+
}
|
|
10
|
+
export function openBrowser(url) {
|
|
11
|
+
const [command, args] = browserCommand(url, process.platform);
|
|
12
|
+
const child = spawn(command, args, { stdio: 'ignore', detached: true });
|
|
13
|
+
child.on('error', () => { });
|
|
14
|
+
child.unref();
|
|
15
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { postJson, request } from "../http/request.js";
|
|
2
|
+
import { agentResult } from "../output.js";
|
|
3
|
+
import { prettyResult } from "../pretty.js";
|
|
4
|
+
import { openBrowser } from "./browser.js";
|
|
5
|
+
export const PUBLIC_IP_URL = 'https://ipc.artsnoa.com/api/v1/ip';
|
|
6
|
+
export const CARD_REQUESTS_PATH = '/api/v1/payments/card-requests';
|
|
7
|
+
export const REGISTER_PATH = '/payments/register';
|
|
8
|
+
const PUBLIC_IP_TIMEOUT_MS = 5_000;
|
|
9
|
+
const IP = /^[0-9A-Fa-f:.]{2,39}$/;
|
|
10
|
+
const AGENT_ENV = [['CLAUDECODE', 'CCD']];
|
|
11
|
+
export const detectAgent = (env = process.env) => AGENT_ENV.find(([name]) => env[name])?.[1] ?? 'OTH';
|
|
12
|
+
export const cardRequired = (result) => !('failure' in result) && result.status === 402 && result.body?.code === 'card_required';
|
|
13
|
+
async function publicIp(deps) {
|
|
14
|
+
const result = await request(PUBLIC_IP_URL, { method: 'GET' }, { ...deps, timeoutMs: Math.min(deps.timeoutMs, PUBLIC_IP_TIMEOUT_MS) }, null);
|
|
15
|
+
if ('failure' in result || result.status !== 200)
|
|
16
|
+
return null;
|
|
17
|
+
const ip = result.body?.ip;
|
|
18
|
+
return typeof ip === 'string' && IP.test(ip) ? ip : null;
|
|
19
|
+
}
|
|
20
|
+
async function registrationUrl(session, agent, ip, deps) {
|
|
21
|
+
const result = await postJson(new URL(CARD_REQUESTS_PATH, session.siteUrl).href, session.token, { agent, ip }, deps, null);
|
|
22
|
+
if ('failure' in result || result.status !== 200)
|
|
23
|
+
return null;
|
|
24
|
+
const body = result.body;
|
|
25
|
+
if (body?.ok !== true || typeof body.url !== 'string' || !URL.canParse(body.url))
|
|
26
|
+
return null;
|
|
27
|
+
const url = new URL(body.url);
|
|
28
|
+
return url.origin === new URL(session.siteUrl).origin && url.pathname === REGISTER_PATH ? url.href : null;
|
|
29
|
+
}
|
|
30
|
+
export async function requestCard(command, pretty, depth, session, deps, extra = {}) {
|
|
31
|
+
const agent = detectAgent();
|
|
32
|
+
const ip = await publicIp(deps);
|
|
33
|
+
const url = await registrationUrl(session, agent, ip, deps) ?? new URL(REGISTER_PATH, session.siteUrl).href;
|
|
34
|
+
(deps.openBrowser ?? openBrowser)(url);
|
|
35
|
+
if (pretty) {
|
|
36
|
+
return prettyResult(1, depth, command, '결제 카드를 등록해야 합니다.', [
|
|
37
|
+
['서버', session.siteUrl],
|
|
38
|
+
['원인', '무료 이용 범위를 넘어서 결제 카드가 필요합니다. 아무것도 바꾸지 않았습니다.'],
|
|
39
|
+
['카드 등록', url],
|
|
40
|
+
['로그인', '이 주소는 한 시간 안에 한 번 자동으로 로그인됩니다. 다른 곳에 보내지 마세요.'],
|
|
41
|
+
['다음', '브라우저에서 카드를 등록한 뒤 같은 명령을 다시 실행하세요.']
|
|
42
|
+
]);
|
|
43
|
+
}
|
|
44
|
+
return agentResult(1, {
|
|
45
|
+
command,
|
|
46
|
+
siteUrl: session.siteUrl,
|
|
47
|
+
...extra,
|
|
48
|
+
error: {
|
|
49
|
+
code: 'card_required',
|
|
50
|
+
message: 'This goes beyond the free tier and the account has no billing card, so nothing was changed. The card registration page was opened in the user\'s browser. Never send the link anywhere other than the user\'s browser. If no browser opened, show cardRegistration.url to the user. After the user adds a card, run the same command again.',
|
|
51
|
+
retryable: false
|
|
52
|
+
},
|
|
53
|
+
cardRegistration: { url, agent, ip }
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { agentResult } from "../output.js";
|
|
2
|
+
import { prettyResult } from "../pretty.js";
|
|
3
|
+
export const YES_OPTION = '--yes';
|
|
4
|
+
const SHELL_SAFE = /^[\w@%+=:,./-]+$/;
|
|
5
|
+
export function splitYes(args) {
|
|
6
|
+
return { args: args.filter((arg) => arg !== YES_OPTION), yes: args.includes(YES_OPTION) };
|
|
7
|
+
}
|
|
8
|
+
const LINE_BREAKS = /[\r\n]+/g;
|
|
9
|
+
const quote = (raw) => {
|
|
10
|
+
const arg = raw.replace(LINE_BREAKS, ' ');
|
|
11
|
+
return SHELL_SAFE.test(arg) ? arg : `'${arg.replace(/['‘’‚‛]/g, (mark) => `'"${mark}"'`)}'`;
|
|
12
|
+
};
|
|
13
|
+
export function confirmCommand(command, args) {
|
|
14
|
+
return ['deepdynamic', command, ...args.filter((arg) => arg !== YES_OPTION).map(quote), YES_OPTION].join(' ');
|
|
15
|
+
}
|
|
16
|
+
export function confirmationRequired(command, args, pretty, depth, reason, data = {}) {
|
|
17
|
+
const next = confirmCommand(command, args);
|
|
18
|
+
return pretty
|
|
19
|
+
? prettyResult(3, depth, command, reason.display, [['실행', next]])
|
|
20
|
+
: agentResult(3, { command, ...data, error: { code: 'confirmation_required', message: `${reason.message} Confirm with the user, then run: ${next}`, next, retryable: false } });
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LOGIN_TIMEOUT_MS } from "../commands/login/flow.js";
|
|
2
|
+
import { commands } from "../registry.js";
|
|
3
|
+
import { SERVER_OPTION } from "./server-options.js";
|
|
4
|
+
import { LOGIN_TIMEOUT_OPTION, parseTimeout } from "./timeout.js";
|
|
5
|
+
export const LOCAL_SITE_URL = 'http://localhost:5173';
|
|
6
|
+
export const SERVER_COMMANDS = commands.filter(({ usage }) => usage.includes(SERVER_OPTION)).map(({ name }) => name);
|
|
7
|
+
export function developmentArgs(args) {
|
|
8
|
+
const timeout = parseTimeout(args.filter((arg) => arg !== '--pretty'), LOGIN_TIMEOUT_MS / 1000, false, LOGIN_TIMEOUT_OPTION, 1);
|
|
9
|
+
const [command, action] = 'error' in timeout ? [] : timeout.rest;
|
|
10
|
+
return SERVER_COMMANDS.includes(`${command} ${action}`) || SERVER_COMMANDS.includes(command ?? '')
|
|
11
|
+
? [...args, SERVER_OPTION, LOCAL_SITE_URL]
|
|
12
|
+
: args;
|
|
13
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const HOST = /^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/;
|
|
2
|
+
export function cleanDomain(input) {
|
|
3
|
+
return input.trim().toLowerCase().replace(/^https?:\/\//, '').replace(/[/?#].*$/, '').replace(/\.$/, '').replace(/^www\./, '');
|
|
4
|
+
}
|
|
5
|
+
export const isDomain = (name) => name.length <= 253 && HOST.test(name) && name.split('.').every((label) => label.length <= 63);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { agentResult } from "../output.js";
|
|
2
|
+
import { prettyResult } from "../pretty.js";
|
|
3
|
+
import { startSpinner } from "./spinner.js";
|
|
4
|
+
export const DRY_RUN_OPTION = '--dry-run';
|
|
5
|
+
export const DRY_RUN_STEP_MS = 400;
|
|
6
|
+
export const pauseFor = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
7
|
+
export function splitDryRun(args) {
|
|
8
|
+
return { args: args.filter((arg) => arg !== DRY_RUN_OPTION), dryRun: args.includes(DRY_RUN_OPTION) };
|
|
9
|
+
}
|
|
10
|
+
export function plannedRequest(command, pretty, depth, siteUrl, url) {
|
|
11
|
+
return pretty
|
|
12
|
+
? prettyResult(0, depth, command, '요청을 보내지 않고 확인만 했습니다.', [['서버', siteUrl], ['요청', `GET ${url}`]])
|
|
13
|
+
: agentResult(0, { command, siteUrl, dryRun: true, request: { method: 'GET', url } });
|
|
14
|
+
}
|
|
15
|
+
export async function rehearse(command, steps, pretty, stream, pause = pauseFor) {
|
|
16
|
+
for (const [index, { stage, message }] of steps.entries()) {
|
|
17
|
+
const stop = pretty ? startSpinner(message, stream) : () => { };
|
|
18
|
+
await pause(DRY_RUN_STEP_MS);
|
|
19
|
+
stop();
|
|
20
|
+
const percent = Math.round(((index + 1) * 100) / steps.length);
|
|
21
|
+
stream.write(pretty ? `[${percent}%] ${message}\n` : `${JSON.stringify({ event: 'dry_run_progress', command, percent, stage, message })}\n`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function plannedChange(command, pretty, depth, siteUrl, request, message, rows, plan) {
|
|
25
|
+
return pretty
|
|
26
|
+
? prettyResult(0, depth, command, message, [['서버', siteUrl], ...rows, ['요청', `POST ${request.url}`]])
|
|
27
|
+
: agentResult(0, { command, siteUrl, dryRun: true, applied: false, plan, request: { method: 'POST', ...request } });
|
|
28
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createCipheriv, createHash, createPublicKey, diffieHellman, generateKeyPairSync, hkdfSync, randomBytes } from 'node:crypto';
|
|
2
|
+
import { parseEnv } from 'node:util';
|
|
3
|
+
export const ENV_COUNT_MAX = 200;
|
|
4
|
+
export const ENV_FILE_MAX = 48 * 1024;
|
|
5
|
+
export const ENV_SEALED_MAX = 100_000;
|
|
6
|
+
const NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
7
|
+
const RESERVED = ['PATH', 'HOME', 'PORT', 'PWD', 'OLDPWD', 'SHELL', 'USER', 'LOGNAME', 'IFS', 'ENV', 'BASH_ENV', 'PS4'];
|
|
8
|
+
const PUBLIC_KEY = /^[0-9a-f]{64}$/;
|
|
9
|
+
const X25519_SPKI = Buffer.from('302a300506032b656e032100', 'hex');
|
|
10
|
+
const INFO = 'dd-env-v1';
|
|
11
|
+
const randomSource = { key: () => generateKeyPairSync('x25519').privateKey, nonce: () => randomBytes(12) };
|
|
12
|
+
export const validEnvName = (name) => NAME.test(name) && !RESERVED.includes(name) && !name.startsWith('LD_');
|
|
13
|
+
export const envKid = (publicKey) => createHash('sha256').update(Buffer.from(publicKey, 'hex')).digest('hex').slice(0, 16);
|
|
14
|
+
export const validSeal = (value) => {
|
|
15
|
+
const seal = value;
|
|
16
|
+
return typeof seal?.publicKey === 'string' && PUBLIC_KEY.test(seal.publicKey) && seal.kid === envKid(seal.publicKey)
|
|
17
|
+
&& typeof seal.context === 'string' && /^projects\/[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/.test(seal.context);
|
|
18
|
+
};
|
|
19
|
+
const shellSize = (vars) => Object.entries(vars)
|
|
20
|
+
.reduce((size, [name, value]) => size + Buffer.byteLength(`export ${name}='${value.replaceAll("'", `'\\''`)}'\n`), 0);
|
|
21
|
+
export function readEnv(text) {
|
|
22
|
+
let vars;
|
|
23
|
+
try {
|
|
24
|
+
vars = { ...parseEnv(text.replace(/^/, '')) };
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return { error: ['The env file could not be parsed. Use KEY=value lines.', '환경변수 파일을 읽지 못했습니다. KEY=값 형식으로 적어 주세요.'] };
|
|
28
|
+
}
|
|
29
|
+
const names = Object.keys(vars);
|
|
30
|
+
if (names.length === 0)
|
|
31
|
+
return { error: ['The env file has no variables. Use deepdynamic projects env clear to remove all variables.', '환경변수 파일에 변수가 없습니다. 모두 지우려면 deepdynamic projects env clear 를 쓰세요.'] };
|
|
32
|
+
if (names.length > ENV_COUNT_MAX)
|
|
33
|
+
return { error: [`The env file has ${names.length} variables; at most ${ENV_COUNT_MAX} are allowed.`, `변수는 ${ENV_COUNT_MAX}개까지 넣을 수 있습니다. 지금 ${names.length}개입니다.`] };
|
|
34
|
+
const invalid = names.find((name) => !validEnvName(name));
|
|
35
|
+
if (invalid !== undefined) {
|
|
36
|
+
return { error: [
|
|
37
|
+
`${JSON.stringify(invalid)} is not allowed. Names must match [A-Za-z_][A-Za-z0-9_]* (up to 128 characters) and must not be ${RESERVED.join(', ')} or start with LD_.`,
|
|
38
|
+
`${JSON.stringify(invalid)} 은(는) 쓸 수 없는 이름입니다. 영문·숫자·밑줄로 128자까지이고 숫자로 시작할 수 없으며, ${RESERVED.join('·')}·LD_ 로 시작하는 이름은 쓸 수 없습니다.`
|
|
39
|
+
] };
|
|
40
|
+
}
|
|
41
|
+
if (Object.values(vars).some((value) => value.includes('\0')))
|
|
42
|
+
return { error: ['Values must not contain NUL characters.', '값에 NUL 문자를 넣을 수 없습니다.'] };
|
|
43
|
+
if (shellSize(vars) > ENV_FILE_MAX)
|
|
44
|
+
return { error: [`The variables are larger than ${ENV_FILE_MAX} bytes.`, `변수 전체 크기가 ${ENV_FILE_MAX} 바이트를 넘습니다.`] };
|
|
45
|
+
return { vars };
|
|
46
|
+
}
|
|
47
|
+
export function sealEnv(vars, seal, source = randomSource) {
|
|
48
|
+
const recipient = Buffer.from(seal.publicKey, 'hex');
|
|
49
|
+
const privateKey = source.key();
|
|
50
|
+
const ephemeral = createPublicKey(privateKey).export({ format: 'der', type: 'spki' }).subarray(X25519_SPKI.length);
|
|
51
|
+
const shared = diffieHellman({ privateKey, publicKey: createPublicKey({ key: Buffer.concat([X25519_SPKI, recipient]), format: 'der', type: 'spki' }) });
|
|
52
|
+
const key = Buffer.from(hkdfSync('sha256', shared, Buffer.concat([ephemeral, recipient]), INFO, 32));
|
|
53
|
+
const nonce = source.nonce();
|
|
54
|
+
const cipher = createCipheriv('aes-256-gcm', key, nonce);
|
|
55
|
+
cipher.setAAD(Buffer.from(`${INFO}\n${seal.context}`));
|
|
56
|
+
const body = Buffer.concat([cipher.update(JSON.stringify(vars), 'utf8'), cipher.final(), cipher.getAuthTag()]);
|
|
57
|
+
return ['dde1', seal.kid, ephemeral.toString('base64url'), nonce.toString('base64url'), body.toString('base64url')].join('.');
|
|
58
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { optionSuggestion } from "./flags.js";
|
|
2
|
+
const RETRYABLE = [
|
|
3
|
+
'connection_failed', 'connection_timeout', 'rate_limited', 'backend_unavailable', 'server_updating', 'server_busy', 'publish_timeout', 'deploy_stopped',
|
|
4
|
+
'upload_failed', 'repository_failed', 'invalid_repository', 'unexpected_response', 'git_verification_failed',
|
|
5
|
+
'login_timeout', 'login_failed', 'token_exchange_failed', 'account_fetch_failed'
|
|
6
|
+
];
|
|
7
|
+
const NEXT = [
|
|
8
|
+
[['login_required', 'login_timeout', 'login_failed', 'token_exchange_failed', 'account_fetch_failed'], () => 'deepdynamic login'],
|
|
9
|
+
[['unknown_command', 'unknown_option'], () => 'deepdynamic --help'],
|
|
10
|
+
[['unknown_subcommand', 'invalid_arguments'], ({ command }) => command ? `deepdynamic ${command} --help` : 'deepdynamic --help'],
|
|
11
|
+
[['agent_required', 'invalid_manifest'], () => 'deepdynamic projects deploy --help'],
|
|
12
|
+
[['project_not_found'], () => 'deepdynamic projects'],
|
|
13
|
+
[['project_taken'], () => 'deepdynamic projects create --help'],
|
|
14
|
+
[['server_pending'], ({ project }) => `deepdynamic projects status ${project}`],
|
|
15
|
+
[['server_failed'], () => 'deepdynamic support contact --help'],
|
|
16
|
+
[['publish_pending', 'upload_unverified', 'progress_unavailable'], ({ id }) => id ? `deepdynamic deployments ${id}` : null],
|
|
17
|
+
[['commit_not_found', 'deployment_not_found'], ({ project }) => project ? `deepdynamic projects history ${project}` : null]
|
|
18
|
+
];
|
|
19
|
+
export function errorHints(data) {
|
|
20
|
+
const error = data.error;
|
|
21
|
+
const id = data.progress?.id;
|
|
22
|
+
const next = NEXT.find(([codes]) => codes.includes(error.code))?.[1]({ command: data.command, project: data.project, id }) ?? null;
|
|
23
|
+
const retryable = error.retryable ?? (error.code === 'progress_unavailable' ? !id : RETRYABLE.includes(error.code));
|
|
24
|
+
const suggestion = error.code === 'invalid_arguments' && typeof data.usage === 'string' ? optionSuggestion(error.message, data.usage) : null;
|
|
25
|
+
return { error: { ...error, ...(next ? { next } : {}), retryable }, ...(suggestion ? { suggestions: [suggestion] } : {}) };
|
|
26
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { closest } from "./suggest.js";
|
|
2
|
+
const UNKNOWN_OPTION = /^(?:Unknown option|알 수 없는 옵션입니다): (-.*)$/;
|
|
3
|
+
const COMMAND_OPTIONS = ['--help', '--pretty', '--login-timeout'];
|
|
4
|
+
export function unknownArgument(arg, pretty) {
|
|
5
|
+
return pretty
|
|
6
|
+
? `알 수 없는 ${arg.startsWith('-') ? '옵션' : '인자'}입니다: ${arg}`
|
|
7
|
+
: `Unknown ${arg.startsWith('-') ? 'option' : 'argument'}: ${arg}`;
|
|
8
|
+
}
|
|
9
|
+
export function optionSuggestion(message, usage) {
|
|
10
|
+
const option = UNKNOWN_OPTION.exec(message)?.[1].split('=')[0];
|
|
11
|
+
return option ? closest(option, [...new Set([...(usage.match(/--[a-z][a-z-]*/g) ?? []), ...COMMAND_OPTIONS])]) : null;
|
|
12
|
+
}
|
|
13
|
+
export function parseFlags(args, flags, pretty) {
|
|
14
|
+
const entries = [];
|
|
15
|
+
for (let index = 0; index < args.length; index++) {
|
|
16
|
+
const arg = args[index];
|
|
17
|
+
const flag = flags.find((name) => arg === name || arg.startsWith(`${name}=`));
|
|
18
|
+
if (!flag) {
|
|
19
|
+
return { error: unknownArgument(arg, pretty) };
|
|
20
|
+
}
|
|
21
|
+
const value = arg === flag ? args[++index] : arg.slice(flag.length + 1);
|
|
22
|
+
if (value === undefined || !value.trim()) {
|
|
23
|
+
return { error: missingValue(flag, pretty) };
|
|
24
|
+
}
|
|
25
|
+
entries.push([flag, value]);
|
|
26
|
+
}
|
|
27
|
+
return { entries };
|
|
28
|
+
}
|
|
29
|
+
export function parseCommand(args, flags, pretty) {
|
|
30
|
+
const names = [];
|
|
31
|
+
const entries = [];
|
|
32
|
+
for (let index = 0; index < args.length; index++) {
|
|
33
|
+
const arg = args[index];
|
|
34
|
+
if (!arg.startsWith('-')) {
|
|
35
|
+
names.push(arg);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const flag = flags.find((name) => arg === name || arg.startsWith(`${name}=`));
|
|
39
|
+
if (!flag)
|
|
40
|
+
return { error: unknownArgument(arg, pretty) };
|
|
41
|
+
const value = arg !== flag ? arg.slice(flag.length + 1) : args[index + 1]?.startsWith('-') ? undefined : args[++index];
|
|
42
|
+
if (value === undefined || !value.trim())
|
|
43
|
+
return { error: missingValue(flag, pretty) };
|
|
44
|
+
entries.push([flag, value]);
|
|
45
|
+
}
|
|
46
|
+
return { names, entries };
|
|
47
|
+
}
|
|
48
|
+
function missingValue(flag, pretty) {
|
|
49
|
+
return pretty ? `${flag} 에 값을 지정하세요.` : `${flag} requires a value.`;
|
|
50
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { displayWidth } from "../pretty.js";
|
|
2
|
+
const wordmark = [
|
|
3
|
+
'// ____ ____ _ ____ _ _',
|
|
4
|
+
'// | _ \\ ___ ___ _ __ | _ \\ _ _ _ __ __ _ _ __ ___ (_) ___ / ___| | ___ _ _ __| |',
|
|
5
|
+
'// | | | |/ _ \\/ _ \\ \'_ \\| | | | | | | \'_ \\ / _` | \'_ ` _ \\| |/ __| | | | |/ _ \\| | | |/ _` |',
|
|
6
|
+
'// | |_| | __/ __/ |_) | |_| | |_| | | | | (_| | | | | | | | (__ | |___| | (_) | |_| | (_| |',
|
|
7
|
+
'// |____/ \\___|\\___| .__/|____/ \\__, |_| |_|\\__,_|_| |_| |_|_|\\___| \\____|_|\\___/ \\__,_|\\__,_|',
|
|
8
|
+
'// |_| |___/'
|
|
9
|
+
];
|
|
10
|
+
export function startLoginScreen(url, stream) {
|
|
11
|
+
if (!stream?.isTTY || process.env.TERM === 'dumb')
|
|
12
|
+
return;
|
|
13
|
+
const columns = stream.columns || 80;
|
|
14
|
+
const rows = stream.rows || 24;
|
|
15
|
+
const depth = stream.getColorDepth?.() ?? 1;
|
|
16
|
+
const style = (codes, text) => depth > 1 ? `\x1b[${codes}m${text}\x1b[0m` : text;
|
|
17
|
+
const blue = depth >= 24 ? '38;2;97;121;139' : depth >= 8 ? '38;5;67' : '34';
|
|
18
|
+
const warm = depth >= 24 ? '38;2;198;172;140' : depth >= 8 ? '38;5;180' : '33';
|
|
19
|
+
const wordmarkWidth = Math.max(...wordmark.map(displayWidth));
|
|
20
|
+
const logo = wordmark.map((line) => `${style(blue, line.slice(0, 2))}${style('1', line.slice(2))}`);
|
|
21
|
+
const rail = (shape, text = '') => ` ${style(blue, shape)}${text && ` ${text}`}`;
|
|
22
|
+
const wrap = (shape, text, tone = (line) => line) => {
|
|
23
|
+
const lines = [''];
|
|
24
|
+
for (const word of text.split(' ')) {
|
|
25
|
+
const last = lines.length - 1;
|
|
26
|
+
const next = lines[last] ? `${lines[last]} ${word}` : word;
|
|
27
|
+
if (!lines[last] || displayWidth(next) <= columns - 6)
|
|
28
|
+
lines[last] = next;
|
|
29
|
+
else
|
|
30
|
+
lines.push(word);
|
|
31
|
+
}
|
|
32
|
+
return lines.map((line, index) => rail(index ? '│' : shape, tone(line)));
|
|
33
|
+
};
|
|
34
|
+
const link = (text) => `\x1b]8;id=dd-login;${url}\x1b\\${text}\x1b]8;;\x1b\\`;
|
|
35
|
+
const urlLines = url.match(new RegExp(`.{1,${Math.max(1, columns - 6)}}`, 'g')).map((part) => rail('│', link(part)));
|
|
36
|
+
const status = `${style(warm, '●')} ${style('1', '로그인 진행 중')}`;
|
|
37
|
+
const render = (compact) => [
|
|
38
|
+
...(compact ? [
|
|
39
|
+
` ${style(blue, '//')} ${style('1', 'DeepDynamic Cloud')}`,
|
|
40
|
+
rail('╭', status)
|
|
41
|
+
] : [
|
|
42
|
+
'',
|
|
43
|
+
...logo.map((line) => ` ${line}`),
|
|
44
|
+
'',
|
|
45
|
+
rail('╭', `${style('2', 'CLI / 계정 연결')} ${status}`),
|
|
46
|
+
rail('│')
|
|
47
|
+
]),
|
|
48
|
+
...wrap('├', '브라우저에서 로그인을 마무리하세요.'),
|
|
49
|
+
...wrap('│', '브라우저가 열리지 않으면 아래 주소를 직접 여세요.', (line) => style('2', line)),
|
|
50
|
+
...urlLines,
|
|
51
|
+
...(compact ? [] : [rail('│')]),
|
|
52
|
+
rail('╰', style('2', 'Ctrl+C 취소'))
|
|
53
|
+
];
|
|
54
|
+
const height = (lines) => lines.reduce((total, line) => total + Math.max(1, Math.ceil(displayWidth(line) / columns)), 0);
|
|
55
|
+
let lines = render(columns < wordmarkWidth + 4);
|
|
56
|
+
if (height(lines) >= rows)
|
|
57
|
+
lines = render(true);
|
|
58
|
+
if (height(lines) >= rows || columns < 24)
|
|
59
|
+
return;
|
|
60
|
+
const screen = lines.join('\r\n');
|
|
61
|
+
let stopped = false;
|
|
62
|
+
const stop = () => {
|
|
63
|
+
if (stopped)
|
|
64
|
+
return;
|
|
65
|
+
stopped = true;
|
|
66
|
+
process.removeListener('exit', stop);
|
|
67
|
+
process.removeListener('SIGTERM', terminate);
|
|
68
|
+
stream.write('\x1b[?1049l\x1b[?25h');
|
|
69
|
+
};
|
|
70
|
+
const terminate = () => {
|
|
71
|
+
stop();
|
|
72
|
+
process.exit(143);
|
|
73
|
+
};
|
|
74
|
+
process.once('exit', stop);
|
|
75
|
+
process.once('SIGTERM', terminate);
|
|
76
|
+
stream.write(`\x1b[?1049h\x1b[?25l\x1b[2J\x1b[H${screen}`);
|
|
77
|
+
return stop;
|
|
78
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { parseFlags } from "./flags.js";
|
|
2
|
+
const PAGE = /^[1-9]\d{0,5}$/;
|
|
3
|
+
export function parsePage(args, pretty) {
|
|
4
|
+
const parsed = parseFlags(args, ['--page'], pretty);
|
|
5
|
+
if ('error' in parsed)
|
|
6
|
+
return parsed;
|
|
7
|
+
const values = parsed.entries.map(([, value]) => value);
|
|
8
|
+
const [page = '1'] = values;
|
|
9
|
+
if (values.length > 1 || !PAGE.test(page))
|
|
10
|
+
return { error: pretty ? '--page 에는 1 이상의 정수를 한 번만 지정하세요.' : 'Give --page once, as a positive integer.' };
|
|
11
|
+
return Number(page);
|
|
12
|
+
}
|
|
13
|
+
export function pagination({ total, page, pageSize, totalPages }, command) {
|
|
14
|
+
return { total, page, pageSize, totalPages, next: Number.isSafeInteger(page) && Number.isSafeInteger(totalPages) && page < totalPages ? `deepdynamic ${command} --page ${page + 1}` : null };
|
|
15
|
+
}
|
|
16
|
+
export function pageRows({ total, page, totalPages, next }) {
|
|
17
|
+
return [['페이지', `${page} / ${totalPages} (${total}개)`], ...(next ? [['다음', next]] : [])];
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PROJECT = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SITE_URL } from "../metadata.js";
|
|
2
|
+
let development = false;
|
|
3
|
+
export function setDevelopmentRun(enabled) {
|
|
4
|
+
development = enabled;
|
|
5
|
+
}
|
|
6
|
+
export const developmentRun = () => development;
|
|
7
|
+
export const allowedServer = (origin) => development || origin === SITE_URL;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SITE_URL } from "../metadata.js";
|
|
2
|
+
import { unknownArgument } from "./flags.js";
|
|
3
|
+
import { allowedServer } from "./run-mode.js";
|
|
4
|
+
export const SERVER_OPTION = '--server';
|
|
5
|
+
export function parseServerArgs(args, pretty = false) {
|
|
6
|
+
let siteUrl = null;
|
|
7
|
+
for (let index = 0; index < args.length; index++) {
|
|
8
|
+
const arg = args[index];
|
|
9
|
+
const inline = arg.startsWith(`${SERVER_OPTION}=`);
|
|
10
|
+
if (arg !== SERVER_OPTION && !inline) {
|
|
11
|
+
return { error: unknownArgument(arg, pretty) };
|
|
12
|
+
}
|
|
13
|
+
const value = inline ? arg.slice(SERVER_OPTION.length + 1) : (args[++index] ?? '');
|
|
14
|
+
const url = URL.canParse(value) ? new URL(value) : null;
|
|
15
|
+
if (!url || (url.protocol !== 'http:' && url.protocol !== 'https:')) {
|
|
16
|
+
return {
|
|
17
|
+
error: pretty
|
|
18
|
+
? `${SERVER_OPTION} 에는 http:// 또는 https:// 로 시작하는 주소를 지정하세요${value ? `: ${value}` : ''}`
|
|
19
|
+
: `${SERVER_OPTION} requires a URL starting with http:// or https://${value ? `: ${value}` : ''}`
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (!allowedServer(url.origin)) {
|
|
23
|
+
return {
|
|
24
|
+
error: pretty
|
|
25
|
+
? `${SERVER_OPTION} 에는 ${SITE_URL} 만 지정할 수 있습니다. 다른 서버 주소는 저장소의 개발 실행(pnpm cli)에서만 씁니다: ${value}`
|
|
26
|
+
: `The released CLI only accepts ${SERVER_OPTION} ${SITE_URL}. Other servers work only in development runs from the repository (pnpm cli): ${value}`
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
siteUrl = url.origin;
|
|
30
|
+
}
|
|
31
|
+
return { siteUrl };
|
|
32
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { paint } from "../pretty.js";
|
|
2
|
+
export function startSpinner(message, stream = process.stderr) {
|
|
3
|
+
if (!stream.isTTY)
|
|
4
|
+
return () => { };
|
|
5
|
+
const { accent } = paint(stream.getColorDepth?.() ?? 1);
|
|
6
|
+
const frames = ['┤', '┘', '┴', '└', '├', '┌', '┬', '┐'];
|
|
7
|
+
let frame = 0;
|
|
8
|
+
const draw = () => stream.write(`\r${accent(frames[frame++ % frames.length])} ${message}`);
|
|
9
|
+
draw();
|
|
10
|
+
const timer = setInterval(draw, 100);
|
|
11
|
+
return () => {
|
|
12
|
+
clearInterval(timer);
|
|
13
|
+
stream.write('\r\x1b[2K');
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const SUGGEST_DISTANCE = 2;
|
|
2
|
+
function distance(a, b) {
|
|
3
|
+
const rows = Array.from({ length: a.length + 1 }, (_, i) => Array.from({ length: b.length + 1 }, (_, j) => (i === 0 ? j : j === 0 ? i : 0)));
|
|
4
|
+
for (let i = 1; i <= a.length; i++) {
|
|
5
|
+
for (let j = 1; j <= b.length; j++) {
|
|
6
|
+
rows[i][j] = Math.min(rows[i - 1][j] + 1, rows[i][j - 1] + 1, rows[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
7
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1])
|
|
8
|
+
rows[i][j] = Math.min(rows[i][j], rows[i - 2][j - 2] + 1);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return rows[a.length][b.length];
|
|
12
|
+
}
|
|
13
|
+
export function closest(input, candidates) {
|
|
14
|
+
let best = null;
|
|
15
|
+
let bestDistance = SUGGEST_DISTANCE + 1;
|
|
16
|
+
for (const candidate of candidates.filter((name) => name !== input)) {
|
|
17
|
+
const value = distance(input, candidate);
|
|
18
|
+
if (value < bestDistance)
|
|
19
|
+
[best, bestDistance] = [candidate, value];
|
|
20
|
+
}
|
|
21
|
+
return best;
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SITE_URL } from "../metadata.js";
|
|
2
|
+
export const CONTACT_PAGE = `${SITE_URL}/contact`;
|
|
3
|
+
export const SUPPORT_EMAIL = 'mail@deepdynamic.net';
|
|
4
|
+
export const SUPPORT_HELP = `Contact support with the error code: deepdynamic support contact, ${CONTACT_PAGE} or ${SUPPORT_EMAIL}.`;
|
|
5
|
+
export const supportMessage = (code, note) => `Error ${code}.${note ? ` ${note.en}` : ''} Contact support with this code: deepdynamic support contact, ${CONTACT_PAGE} or ${SUPPORT_EMAIL}.`;
|
|
6
|
+
export const supportDisplay = (code, note) => `오류 코드 ${code}.${note ? ` ${note.ko}` : ''} 이 코드로 문의해 주세요: deepdynamic support contact, ${CONTACT_PAGE}, ${SUPPORT_EMAIL}`;
|
|
7
|
+
export function supportFailure(code, options = {}) {
|
|
8
|
+
return {
|
|
9
|
+
code,
|
|
10
|
+
message: supportMessage(code, options.note),
|
|
11
|
+
display: supportDisplay(code, options.note),
|
|
12
|
+
...(options.retryable === undefined ? {} : { retryable: options.retryable })
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
export async function readText(flag, text, path, pretty) {
|
|
3
|
+
const fileFlag = `${flag}-file`;
|
|
4
|
+
if (text !== undefined && path !== undefined) {
|
|
5
|
+
return { error: pretty ? `${flag} 와 ${fileFlag} 중 하나만 지정하세요.` : `Give either ${flag} or ${fileFlag}, not both.` };
|
|
6
|
+
}
|
|
7
|
+
if (path === undefined) {
|
|
8
|
+
return text === undefined ? { error: pretty ? `${flag} 또는 ${fileFlag} 를 지정하세요.` : `${flag} or ${fileFlag} is required.` } : { text };
|
|
9
|
+
}
|
|
10
|
+
let content;
|
|
11
|
+
try {
|
|
12
|
+
content = await readFile(path, 'utf8');
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
const reason = error.code ?? String(error);
|
|
16
|
+
return { error: pretty ? `${fileFlag} 파일을 읽지 못했습니다(${reason}): ${path}` : `Cannot read the ${fileFlag} file (${reason}): ${path}` };
|
|
17
|
+
}
|
|
18
|
+
const stripped = content.replace(/^/, '').replace(/\r?\n$/, '');
|
|
19
|
+
return stripped.trim() ? { text: stripped } : { error: pretty ? `${fileFlag} 파일이 비어 있습니다: ${path}` : `The ${fileFlag} file is empty: ${path}` };
|
|
20
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const TIMEOUT_OPTION = '--timeout';
|
|
2
|
+
export const LOGIN_TIMEOUT_OPTION = '--login-timeout';
|
|
3
|
+
export function parseTimeout(args, maxSeconds, pretty, option = TIMEOUT_OPTION, minSeconds = 0) {
|
|
4
|
+
const rest = [];
|
|
5
|
+
const values = [];
|
|
6
|
+
for (let index = 0; index < args.length; index++) {
|
|
7
|
+
const arg = args[index];
|
|
8
|
+
if (arg === option)
|
|
9
|
+
values.push(args[++index] ?? '');
|
|
10
|
+
else if (arg.startsWith(`${option}=`))
|
|
11
|
+
values.push(arg.slice(option.length + 1));
|
|
12
|
+
else
|
|
13
|
+
rest.push(arg);
|
|
14
|
+
}
|
|
15
|
+
if (values.length === 0)
|
|
16
|
+
return { rest, waitMs: maxSeconds * 1000 };
|
|
17
|
+
const seconds = Number(values[0]);
|
|
18
|
+
if (values.length > 1 || !/^\d+$/.test(values[0]) || seconds < minSeconds || seconds > maxSeconds) {
|
|
19
|
+
return { error: pretty ? `${option} 에는 ${minSeconds}~${maxSeconds} 사이의 초를 한 번만 지정하세요.` : `Give ${option} once, as whole seconds from ${minSeconds} to ${maxSeconds}.` };
|
|
20
|
+
}
|
|
21
|
+
return { rest, waitMs: seconds * 1000 };
|
|
22
|
+
}
|