@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,124 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { credentialsPath } from "../auth/credentials.js";
|
|
6
|
+
import { call } from "../http/call.js";
|
|
7
|
+
import { jsonLine } from "../output.js";
|
|
8
|
+
import { developmentRun } from "./run-mode.js";
|
|
9
|
+
export const PACKAGE_NAME = '@deepdynamic/cli';
|
|
10
|
+
export const REGISTRY_URL = 'https://registry.npmjs.org/-/package/@deepdynamic%2fcli/dist-tags';
|
|
11
|
+
export const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
12
|
+
export const REFRESH_TIMEOUT_MS = 10_000;
|
|
13
|
+
export const LOCK_STALE_MS = 30 * 60 * 1000;
|
|
14
|
+
export const UPDATE_NEXT = 'deepdynamic update --yes';
|
|
15
|
+
export const REFRESH_ENTRY = fileURLToPath(new URL('../update-refresh.js', import.meta.url));
|
|
16
|
+
const VERSION = /^(\d+)\.(\d+)\.(\d+)(-[0-9A-Za-z.-]+)?$/;
|
|
17
|
+
export const isVersion = (value) => typeof value === 'string' && VERSION.test(value);
|
|
18
|
+
export function latestOf(body) {
|
|
19
|
+
const latest = body?.latest;
|
|
20
|
+
return isVersion(latest) ? latest : null;
|
|
21
|
+
}
|
|
22
|
+
export function isNewer(latest, current) {
|
|
23
|
+
const next = VERSION.exec(latest);
|
|
24
|
+
const now = VERSION.exec(current);
|
|
25
|
+
if (!next || !now)
|
|
26
|
+
return false;
|
|
27
|
+
for (const index of [1, 2, 3]) {
|
|
28
|
+
const [a, b] = [Number(next[index]), Number(now[index])];
|
|
29
|
+
if (a !== b)
|
|
30
|
+
return a > b;
|
|
31
|
+
}
|
|
32
|
+
return !next[4] && !!now[4];
|
|
33
|
+
}
|
|
34
|
+
const isSet = (value) => !!value && value !== '0' && value !== 'false';
|
|
35
|
+
export const updateCheckEnabled = (env) => !isSet(env.DEEPDYNAMIC_NO_UPDATE_CHECK) && !isSet(env.CI);
|
|
36
|
+
export const updateCachePath = (env = process.env) => join(dirname(credentialsPath(env)), 'update-check.json');
|
|
37
|
+
export const updateLockPath = (cachePath) => join(dirname(cachePath), 'update.lock');
|
|
38
|
+
export async function readUpdateCache(path) {
|
|
39
|
+
try {
|
|
40
|
+
const { checkedAt, latest, installed } = JSON.parse(await readFile(path, 'utf8'));
|
|
41
|
+
if (!Number.isFinite(checkedAt) || !(latest === null || isVersion(latest)))
|
|
42
|
+
return null;
|
|
43
|
+
return isVersion(installed?.previous) && isVersion(installed?.version)
|
|
44
|
+
? { checkedAt, latest, installed: { previous: installed.previous, version: installed.version } }
|
|
45
|
+
: { checkedAt, latest };
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export async function saveUpdateCache(path, cache) {
|
|
52
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
53
|
+
await writeFile(path, `${JSON.stringify(cache)}\n`);
|
|
54
|
+
}
|
|
55
|
+
export async function withUpdateLock(path, task, now = Date.now) {
|
|
56
|
+
const age = await stat(path).then(({ mtimeMs }) => now() - mtimeMs, () => null);
|
|
57
|
+
if (age !== null && age < LOCK_STALE_MS)
|
|
58
|
+
return null;
|
|
59
|
+
if (age !== null)
|
|
60
|
+
await rm(path, { force: true });
|
|
61
|
+
try {
|
|
62
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
63
|
+
await writeFile(path, `${process.pid}\n`, { flag: 'wx' });
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
return await task();
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
await rm(path, { force: true });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export async function refreshUpdateCache(path, current, install, fetcher = fetch, now = Date.now) {
|
|
76
|
+
try {
|
|
77
|
+
const response = await call(REGISTRY_URL, { method: 'GET', redirect: 'manual', signal: AbortSignal.timeout(REFRESH_TIMEOUT_MS) }, fetcher);
|
|
78
|
+
const latest = response.status === 200 ? latestOf(await response.json()) : null;
|
|
79
|
+
if (!latest)
|
|
80
|
+
return;
|
|
81
|
+
const installed = install !== null && isNewer(latest, current) && await install(latest).catch(() => false);
|
|
82
|
+
await saveUpdateCache(path, { checkedAt: now(), latest, ...(installed ? { installed: { previous: current, version: latest } } : {}) });
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export const refreshArgs = () => [REFRESH_ENTRY, developmentRun() ? 'check' : 'install'];
|
|
89
|
+
export function startRefresh() {
|
|
90
|
+
const child = spawn(process.execPath, refreshArgs(), { detached: true, stdio: 'ignore', windowsHide: true });
|
|
91
|
+
child.on('error', () => { });
|
|
92
|
+
child.unref();
|
|
93
|
+
}
|
|
94
|
+
export const defaultUpdateDeps = () => ({ path: updateCachePath(), env: process.env, now: Date.now, startRefresh });
|
|
95
|
+
export async function pendingUpdate(current, deps = defaultUpdateDeps()) {
|
|
96
|
+
if (!updateCheckEnabled(deps.env))
|
|
97
|
+
return null;
|
|
98
|
+
const cache = await readUpdateCache(deps.path);
|
|
99
|
+
const now = deps.now();
|
|
100
|
+
const stale = !cache || now - cache.checkedAt >= CHECK_INTERVAL_MS || cache.checkedAt > now;
|
|
101
|
+
const updated = cache?.installed?.version === current ? cache.installed : null;
|
|
102
|
+
if (stale || updated) {
|
|
103
|
+
const kept = cache?.installed && !updated ? { installed: cache.installed } : {};
|
|
104
|
+
await saveUpdateCache(deps.path, { checkedAt: stale ? now : cache.checkedAt, latest: cache?.latest ?? null, ...kept })
|
|
105
|
+
.then(() => stale && deps.startRefresh(), () => { });
|
|
106
|
+
}
|
|
107
|
+
if (updated)
|
|
108
|
+
return { event: 'updated', previous: updated.previous };
|
|
109
|
+
return cache?.latest && isNewer(cache.latest, current) ? { event: 'update_available', latest: cache.latest } : null;
|
|
110
|
+
}
|
|
111
|
+
export const updateLine = (current, notice) => jsonLine(notice.event === 'updated'
|
|
112
|
+
? {
|
|
113
|
+
event: 'updated',
|
|
114
|
+
previous: notice.previous,
|
|
115
|
+
current,
|
|
116
|
+
message: `DeepDynamic CLI was updated in the background from ${notice.previous} to ${current}. This run uses ${current}.`
|
|
117
|
+
}
|
|
118
|
+
: {
|
|
119
|
+
event: 'update_available',
|
|
120
|
+
current,
|
|
121
|
+
latest: notice.latest,
|
|
122
|
+
next: UPDATE_NEXT,
|
|
123
|
+
message: `DeepDynamic CLI ${notice.latest} is available (current ${current}) and was not installed automatically. Confirm with the user, then run: ${UPDATE_NEXT}`
|
|
124
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { realpath } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { PACKAGE_NAME } from "./update-check.js";
|
|
7
|
+
export const PACKAGE_DIR = fileURLToPath(new URL('../..', import.meta.url));
|
|
8
|
+
export const packageManagerOf = (path) => (/[\\/]\.pnpm[\\/]/.test(path) ? 'pnpm' : 'npm');
|
|
9
|
+
export const installArgs = (manager, version) => [manager === 'pnpm' ? 'add' : 'install', '--global', `${PACKAGE_NAME}@${version}`];
|
|
10
|
+
export function runProgram(path, args, platform = process.platform) {
|
|
11
|
+
const options = { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true };
|
|
12
|
+
const child = platform === 'win32' && /\.(cmd|bat)$/i.test(path)
|
|
13
|
+
? spawn(`"${path}" ${args.join(' ')}`, { ...options, shell: true })
|
|
14
|
+
: spawn(path, args, options);
|
|
15
|
+
let stdout = '';
|
|
16
|
+
let output = '';
|
|
17
|
+
child.stdout?.on('data', (chunk) => {
|
|
18
|
+
stdout = `${stdout}${chunk.toString('utf8')}`.slice(-4000);
|
|
19
|
+
output = `${output}${chunk.toString('utf8')}`.slice(-4000);
|
|
20
|
+
});
|
|
21
|
+
child.stderr?.on('data', (chunk) => {
|
|
22
|
+
output = `${output}${chunk.toString('utf8')}`.slice(-4000);
|
|
23
|
+
});
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
child.on('error', (error) => resolve({ status: null, stdout: '', output: error.message }));
|
|
26
|
+
child.on('close', (status) => resolve({ status, stdout, output: output.trim().slice(-500) }));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export const findPackageManager = async (name) => (await import("../agents/install.js")).systemCommands({ home: homedir(), platform: process.platform, vars: process.env }).find(name);
|
|
30
|
+
export const defaultAutoInstallDeps = () => ({ packageDir: PACKAGE_DIR, platform: process.platform, find: findPackageManager, run: runProgram });
|
|
31
|
+
export async function isGlobalInstall(path, { packageDir, platform, run }) {
|
|
32
|
+
const { status, stdout } = await run(path, ['root', '--global']);
|
|
33
|
+
const root = status === 0 ? stdout.trim().split(/\r?\n/).pop() : undefined;
|
|
34
|
+
if (!root)
|
|
35
|
+
return false;
|
|
36
|
+
const [global, own] = await Promise.all([
|
|
37
|
+
realpath(join(root, ...PACKAGE_NAME.split('/'))).catch(() => null),
|
|
38
|
+
realpath(packageDir).catch(() => null)
|
|
39
|
+
]);
|
|
40
|
+
if (!global || !own)
|
|
41
|
+
return false;
|
|
42
|
+
return platform === 'win32' ? global.toLowerCase() === own.toLowerCase() : global === own;
|
|
43
|
+
}
|
|
44
|
+
export async function autoInstall(latest, deps = defaultAutoInstallDeps()) {
|
|
45
|
+
const manager = packageManagerOf(deps.packageDir);
|
|
46
|
+
const path = await deps.find(manager);
|
|
47
|
+
if (!path || !(await isGlobalInstall(path, deps)))
|
|
48
|
+
return false;
|
|
49
|
+
return (await deps.run(path, installArgs(manager, latest))).status === 0;
|
|
50
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { agentResult } from "../output.js";
|
|
2
|
+
import { prettyResult } from "../pretty.js";
|
|
3
|
+
import { spec } from "../registry.js";
|
|
4
|
+
export function usageError(command, message, pretty, depth) {
|
|
5
|
+
const { usage, prettyUsage } = spec(command);
|
|
6
|
+
return pretty
|
|
7
|
+
? prettyResult(2, depth, command, message, [['사용법', prettyUsage]])
|
|
8
|
+
: agentResult(2, { command, error: { code: 'invalid_arguments', message }, usage });
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { systemCommands } from "./agents/install.js";
|
|
3
|
+
import { runAgentSetup } from "./agents/setup.js";
|
|
4
|
+
const env = { home: homedir(), platform: process.platform, vars: process.env };
|
|
5
|
+
const result = await runAgentSetup(env, systemCommands(env), process.getuid?.() ?? null);
|
|
6
|
+
process.stdout.write(result.stdout);
|
|
7
|
+
process.stderr.write(result.stderr);
|
|
8
|
+
process.exitCode = result.code;
|
package/dist/site.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SITE_URL = 'https://cloud.deepdynamic.net';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { version } from "./metadata.js";
|
|
2
|
+
import { refreshUpdateCache, updateCachePath, updateLockPath, withUpdateLock } from "./runtime/update-check.js";
|
|
3
|
+
import { autoInstall } from "./runtime/update-install.js";
|
|
4
|
+
const path = updateCachePath();
|
|
5
|
+
await withUpdateLock(updateLockPath(path), () => refreshUpdateCache(path, version, process.argv[2] === 'install' ? autoInstall : null)).catch(() => null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepdynamic/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Command-line tool for deploying and managing sites on DeepDynamic Cloud.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"deepdynamic",
|
|
7
|
+
"cli",
|
|
8
|
+
"deploy",
|
|
9
|
+
"hosting",
|
|
10
|
+
"static-site",
|
|
11
|
+
"mcp",
|
|
12
|
+
"ai-agent"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://cloud.deepdynamic.net",
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"author": "DeepDynamic <mail@deepdynamic.net>",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"email": "mail@deepdynamic.net"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"bin": {
|
|
22
|
+
"deepdynamic": "dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"!dist/dev.js",
|
|
27
|
+
"THIRD_PARTY_NOTICES.txt"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22.12.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/html-minifier-terser": "^7.0.2",
|
|
34
|
+
"@types/node": "^22.12.0",
|
|
35
|
+
"typescript": "^6.0.3"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"esbuild": "0.28.2",
|
|
39
|
+
"html-minifier-terser": "7.2.0",
|
|
40
|
+
"jsonc-parser": "3.3.1",
|
|
41
|
+
"yaml": "2.9.1"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"dev": "pnpm build && node dist/dev.js",
|
|
45
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json",
|
|
46
|
+
"start": "node dist/index.js",
|
|
47
|
+
"check": "tsc -p tsconfig.json --noEmit"
|
|
48
|
+
}
|
|
6
49
|
}
|