@jango-blockchained/hoox-cli 0.5.2 → 0.5.7
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/bin/hoox.js +3 -4
- package/dist/index.js +32989 -0
- package/package.json +10 -15
- package/src/commands/check/check-command.test.ts +0 -476
- package/src/commands/check/check-command.ts +0 -1087
- package/src/commands/check/index.ts +0 -10
- package/src/commands/check/prerequisites-command.test.ts +0 -19
- package/src/commands/check/prerequisites-command.ts +0 -97
- package/src/commands/check/types.ts +0 -103
- package/src/commands/clone/clone-command.test.ts +0 -440
- package/src/commands/clone/clone-command.ts +0 -431
- package/src/commands/clone/index.ts +0 -1
- package/src/commands/config/config-command.test.ts +0 -583
- package/src/commands/config/config-command.ts +0 -896
- package/src/commands/config/env-command.test.ts +0 -43
- package/src/commands/config/env-command.ts +0 -292
- package/src/commands/config/index.ts +0 -3
- package/src/commands/config/kv-command.test.ts +0 -14
- package/src/commands/config/kv-command.ts +0 -290
- package/src/commands/dashboard/dashboard-command.test.ts +0 -47
- package/src/commands/dashboard/dashboard-command.ts +0 -130
- package/src/commands/dashboard/index.ts +0 -1
- package/src/commands/db/db-command.test.ts +0 -21
- package/src/commands/db/db-command.ts +0 -311
- package/src/commands/db/index.ts +0 -1
- package/src/commands/deploy/deploy-command.test.ts +0 -324
- package/src/commands/deploy/deploy-command.ts +0 -1054
- package/src/commands/deploy/index.ts +0 -2
- package/src/commands/deploy/telegram-service.ts +0 -76
- package/src/commands/deploy/types.ts +0 -34
- package/src/commands/dev/dev-command.test.ts +0 -405
- package/src/commands/dev/dev-command.ts +0 -398
- package/src/commands/dev/index.ts +0 -1
- package/src/commands/disclaimer/disclaimer-command.ts +0 -21
- package/src/commands/disclaimer/index.ts +0 -1
- package/src/commands/infra/index.ts +0 -5
- package/src/commands/infra/infra-command.test.ts +0 -719
- package/src/commands/infra/infra-command.ts +0 -974
- package/src/commands/infra/types.ts +0 -23
- package/src/commands/init/__tests__/cli-provisioner.test.ts +0 -17
- package/src/commands/init/cli-provisioner.ts +0 -71
- package/src/commands/init/index.ts +0 -1
- package/src/commands/init/init-command.test.ts +0 -854
- package/src/commands/init/init-command.ts +0 -597
- package/src/commands/init/types.ts +0 -23
- package/src/commands/logs/index.ts +0 -1
- package/src/commands/logs/logs-command.test.ts +0 -293
- package/src/commands/logs/logs-command.ts +0 -452
- package/src/commands/monitor/index.ts +0 -2
- package/src/commands/monitor/monitor-command.test.ts +0 -271
- package/src/commands/monitor/monitor-command.ts +0 -269
- package/src/commands/monitor/monitor-service.ts +0 -65
- package/src/commands/monitor/types.ts +0 -13
- package/src/commands/repair/index.ts +0 -2
- package/src/commands/repair/repair-command.test.ts +0 -243
- package/src/commands/repair/repair-command.ts +0 -220
- package/src/commands/repair/repair-service.ts +0 -164
- package/src/commands/repair/types.ts +0 -13
- package/src/commands/schema/index.ts +0 -1
- package/src/commands/schema/schema-command.ts +0 -137
- package/src/commands/test/index.ts +0 -2
- package/src/commands/test/test-command.test.ts +0 -318
- package/src/commands/test/test-command.ts +0 -406
- package/src/commands/tui/index.ts +0 -1
- package/src/commands/tui/tui-command.ts +0 -87
- package/src/commands/update/index.ts +0 -1
- package/src/commands/update/update-command.ts +0 -109
- package/src/commands/waf/index.ts +0 -2
- package/src/commands/waf/types.ts +0 -48
- package/src/commands/waf/waf-command.test.ts +0 -506
- package/src/commands/waf/waf-command.ts +0 -545
- package/src/index.ts +0 -261
- package/src/services/cloudflare/cloudflare-service.test.ts +0 -658
- package/src/services/cloudflare/cloudflare-service.ts +0 -433
- package/src/services/cloudflare/index.ts +0 -2
- package/src/services/cloudflare/types.ts +0 -30
- package/src/services/config/config-service.test.ts +0 -395
- package/src/services/config/config-service.ts +0 -202
- package/src/services/config/index.ts +0 -9
- package/src/services/config/types.ts +0 -66
- package/src/services/db/db-service.test.ts +0 -63
- package/src/services/db/db-service.ts +0 -131
- package/src/services/db/index.ts +0 -1
- package/src/services/docker/docker-service.ts +0 -155
- package/src/services/docker/index.ts +0 -1
- package/src/services/env/env-service.test.ts +0 -259
- package/src/services/env/env-service.ts +0 -372
- package/src/services/env/index.ts +0 -1
- package/src/services/kv/index.ts +0 -1
- package/src/services/kv/kv-sync-service.test.ts +0 -38
- package/src/services/kv/kv-sync-service.ts +0 -243
- package/src/services/prerequisites/index.ts +0 -1
- package/src/services/prerequisites/prerequisites-service.test.ts +0 -89
- package/src/services/prerequisites/prerequisites-service.ts +0 -377
- package/src/services/prerequisites/types.ts +0 -48
- package/src/services/schema/index.ts +0 -1
- package/src/services/schema/schema-service.ts +0 -99
- package/src/services/secrets/index.ts +0 -11
- package/src/services/secrets/secrets-service.test.ts +0 -502
- package/src/services/secrets/secrets-service.ts +0 -287
- package/src/services/secrets/types.ts +0 -50
- package/src/services/update/index.ts +0 -2
- package/src/services/update/update-service.test.ts +0 -76
- package/src/services/update/update-service.ts +0 -193
- package/src/ui/banner.ts +0 -141
- package/src/ui/index.ts +0 -8
- package/src/ui/menu.ts +0 -490
- package/src/utils/error-handler.ts +0 -62
- package/src/utils/errors.test.ts +0 -69
- package/src/utils/errors.ts +0 -24
- package/src/utils/formatters.test.ts +0 -180
- package/src/utils/formatters.ts +0 -269
- package/src/utils/git.ts +0 -134
- package/src/utils/theme.ts +0 -92
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import type { Command } from "commander";
|
|
2
|
-
import { ConfigService } from "../../services/config/index.js";
|
|
3
|
-
import { CLIError, ExitCode } from "../../utils/errors.js";
|
|
4
|
-
import { formatSuccess, formatTable } from "../../utils/formatters.js";
|
|
5
|
-
import { withErrorHandling } from "../../utils/error-handler.js";
|
|
6
|
-
import type { FormatOptions } from "../../utils/formatters.js";
|
|
7
|
-
import { theme } from "../../utils/theme.js";
|
|
8
|
-
import * as jsonc from "jsonc-parser";
|
|
9
|
-
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
10
|
-
import { resolve } from "node:path";
|
|
11
|
-
|
|
12
|
-
interface ServiceUrl {
|
|
13
|
-
worker: string;
|
|
14
|
-
url: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function getServiceUrls(config: ConfigService): ServiceUrl[] {
|
|
18
|
-
const global = config.getGlobal();
|
|
19
|
-
const prefix = global.subdomain_prefix ?? "hoox";
|
|
20
|
-
const workers = config.listEnabledWorkers();
|
|
21
|
-
|
|
22
|
-
return workers.map((name) => ({
|
|
23
|
-
worker: name,
|
|
24
|
-
url: `https://${name}.${prefix}.workers.dev`,
|
|
25
|
-
}));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function updateWranglerVars(
|
|
29
|
-
filePath: string,
|
|
30
|
-
urls: ServiceUrl[],
|
|
31
|
-
dryRun: boolean,
|
|
32
|
-
opts: FormatOptions
|
|
33
|
-
): void {
|
|
34
|
-
if (!existsSync(filePath)) {
|
|
35
|
-
throw new CLIError(
|
|
36
|
-
`Dashboard wrangler.jsonc not found at ${filePath}`,
|
|
37
|
-
ExitCode.ERROR
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const content = readFileSync(filePath, "utf-8");
|
|
42
|
-
const errors: jsonc.ParseError[] = [];
|
|
43
|
-
const parsed = jsonc.parse(content, errors) as Record<string, unknown>;
|
|
44
|
-
|
|
45
|
-
if (errors.length > 0) {
|
|
46
|
-
throw new CLIError(`Invalid JSONC in ${filePath}`, ExitCode.ERROR);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const vars = (parsed.vars as Record<string, string>) ?? {};
|
|
50
|
-
const changes: { key: string; oldValue: string; newValue: string }[] = [];
|
|
51
|
-
|
|
52
|
-
for (const { worker, url } of urls) {
|
|
53
|
-
const key = `${worker.toUpperCase().replace(/-/g, "_")}_URL`;
|
|
54
|
-
const oldValue = vars[key] ?? "(not set)";
|
|
55
|
-
changes.push({ key, oldValue, newValue: url });
|
|
56
|
-
vars[key] = url;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (changes.length === 0) {
|
|
60
|
-
formatSuccess("No service URLs to update.", opts);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!opts.quiet) {
|
|
65
|
-
const rows = changes.map((c) => ({
|
|
66
|
-
Key: c.key,
|
|
67
|
-
Old: c.oldValue,
|
|
68
|
-
New: theme.success(c.newValue),
|
|
69
|
-
}));
|
|
70
|
-
console.log(theme.heading("\nService URL changes:"));
|
|
71
|
-
formatTable(rows, opts);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (dryRun) {
|
|
75
|
-
formatSuccess("Dry run — no changes written.", opts);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const fresh = readFileSync(filePath, "utf-8");
|
|
80
|
-
const edits = jsonc.modify(fresh, ["vars"], vars, {
|
|
81
|
-
formattingOptions: { tabSize: 2, insertSpaces: true },
|
|
82
|
-
});
|
|
83
|
-
const updated = jsonc.applyEdits(fresh, edits);
|
|
84
|
-
writeFileSync(filePath, updated, "utf-8");
|
|
85
|
-
|
|
86
|
-
formatSuccess(
|
|
87
|
-
`Updated ${changes.length} service URL(s) in dashboard wrangler.jsonc`,
|
|
88
|
-
opts
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function registerDashboardCommand(program: Command): void {
|
|
93
|
-
const dashboardCmd = program
|
|
94
|
-
.command("dashboard")
|
|
95
|
-
.description("Dashboard-specific operations");
|
|
96
|
-
|
|
97
|
-
dashboardCmd
|
|
98
|
-
.command("update-urls")
|
|
99
|
-
.description("Update dashboard wrangler.jsonc with current service URLs")
|
|
100
|
-
.option("--dry-run", "Show changes without applying")
|
|
101
|
-
.action(
|
|
102
|
-
withErrorHandling(
|
|
103
|
-
async (options: { dryRun?: boolean }) => {
|
|
104
|
-
const opts: FormatOptions = {
|
|
105
|
-
json: program.opts<{ json?: boolean }>().json,
|
|
106
|
-
quiet: program.opts<{ quiet?: boolean }>().quiet,
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const config = new ConfigService();
|
|
110
|
-
await config.load();
|
|
111
|
-
|
|
112
|
-
const urls = getServiceUrls(config);
|
|
113
|
-
const dashboardPath = resolve(
|
|
114
|
-
process.cwd(),
|
|
115
|
-
"pages",
|
|
116
|
-
"dashboard",
|
|
117
|
-
"wrangler.jsonc"
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
updateWranglerVars(
|
|
121
|
-
dashboardPath,
|
|
122
|
-
urls,
|
|
123
|
-
options.dryRun === true,
|
|
124
|
-
opts
|
|
125
|
-
);
|
|
126
|
-
},
|
|
127
|
-
{ service: "dashboard" }
|
|
128
|
-
)
|
|
129
|
-
);
|
|
130
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { registerDashboardCommand } from "./dashboard-command.js";
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
2
|
-
import { DbService } from "../../services/db/index.js";
|
|
3
|
-
|
|
4
|
-
describe("db command", () => {
|
|
5
|
-
describe("DbService integration", () => {
|
|
6
|
-
it("resolves database name from explicit arg", async () => {
|
|
7
|
-
const svc = new DbService();
|
|
8
|
-
const name = await svc.resolveDbName("my-test-db");
|
|
9
|
-
expect(name).toBe("my-test-db");
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("parses table names from wrangler output", () => {
|
|
13
|
-
const output = JSON.stringify([
|
|
14
|
-
{ results: [{ name: "trades" }, { name: "signals" }] },
|
|
15
|
-
]);
|
|
16
|
-
const tables = DbService.parseTableNames(output);
|
|
17
|
-
expect(tables).toContain("trades");
|
|
18
|
-
expect(tables).toContain("signals");
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `hoox db` command group — database management.
|
|
3
|
-
*
|
|
4
|
-
* Subcommands:
|
|
5
|
-
* apply [--remote] [--file <path>] — Apply schema.sql to D1
|
|
6
|
-
* migrate [--remote] — Run tracking migrations
|
|
7
|
-
* list [--remote] — List database tables
|
|
8
|
-
* query <sql> [--remote] — Execute a SQL query
|
|
9
|
-
* export [--output <path>] — Export database
|
|
10
|
-
* reset [--confirm] — Drop and recreate (DESTRUCTIVE)
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { Command } from "commander";
|
|
14
|
-
import * as p from "@clack/prompts";
|
|
15
|
-
import { DbService } from "../../services/db/index.js";
|
|
16
|
-
import {
|
|
17
|
-
formatSuccess,
|
|
18
|
-
formatTable,
|
|
19
|
-
formatJson,
|
|
20
|
-
getFormatOptions,
|
|
21
|
-
} from "../../utils/formatters.js";
|
|
22
|
-
import { withErrorHandling } from "../../utils/error-handler.js";
|
|
23
|
-
import type { FormatOptions } from "../../utils/formatters.js";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Resolve database name from config or --database flag.
|
|
27
|
-
*/
|
|
28
|
-
async function resolveDb(cmd: Command, svc: DbService): Promise<string> {
|
|
29
|
-
const opts = cmd.optsWithGlobals<{ database?: string }>();
|
|
30
|
-
return await svc.resolveDbName(opts.database);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
// db apply
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
|
|
37
|
-
async function handleApply(
|
|
38
|
-
opts: FormatOptions,
|
|
39
|
-
dbName: string,
|
|
40
|
-
remote: boolean,
|
|
41
|
-
file?: string
|
|
42
|
-
): Promise<void> {
|
|
43
|
-
const svc = new DbService();
|
|
44
|
-
const output = await svc.apply(dbName, remote, file);
|
|
45
|
-
formatSuccess(
|
|
46
|
-
`Schema applied to ${dbName}${remote ? " (remote)" : " (local)"}`,
|
|
47
|
-
opts
|
|
48
|
-
);
|
|
49
|
-
if (!opts.quiet && output) {
|
|
50
|
-
process.stdout.write(`${output}\n`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// ---------------------------------------------------------------------------
|
|
55
|
-
// db migrate
|
|
56
|
-
// ---------------------------------------------------------------------------
|
|
57
|
-
|
|
58
|
-
async function handleMigrate(
|
|
59
|
-
opts: FormatOptions,
|
|
60
|
-
dbName: string,
|
|
61
|
-
remote: boolean
|
|
62
|
-
): Promise<void> {
|
|
63
|
-
const svc = new DbService();
|
|
64
|
-
const output = await svc.migrate(dbName, remote);
|
|
65
|
-
formatSuccess(
|
|
66
|
-
`Migrations applied to ${dbName}${remote ? " (remote)" : " (local)"}`,
|
|
67
|
-
opts
|
|
68
|
-
);
|
|
69
|
-
if (!opts.quiet && output) {
|
|
70
|
-
process.stdout.write(`${output}\n`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// ---------------------------------------------------------------------------
|
|
75
|
-
// db list
|
|
76
|
-
// ---------------------------------------------------------------------------
|
|
77
|
-
|
|
78
|
-
async function handleList(
|
|
79
|
-
opts: FormatOptions,
|
|
80
|
-
dbName: string,
|
|
81
|
-
remote: boolean
|
|
82
|
-
): Promise<void> {
|
|
83
|
-
const svc = new DbService();
|
|
84
|
-
const tables = await svc.listTables(dbName, remote);
|
|
85
|
-
|
|
86
|
-
if (opts.json) {
|
|
87
|
-
formatJson(tables, opts);
|
|
88
|
-
} else if (!opts.quiet) {
|
|
89
|
-
if (tables.length === 0) {
|
|
90
|
-
process.stdout.write("No tables found.\n");
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const rows = tables.map((t) => ({ Table: t }));
|
|
94
|
-
formatTable(rows, opts);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// ---------------------------------------------------------------------------
|
|
99
|
-
// db query
|
|
100
|
-
// ---------------------------------------------------------------------------
|
|
101
|
-
|
|
102
|
-
async function handleQuery(
|
|
103
|
-
opts: FormatOptions,
|
|
104
|
-
dbName: string,
|
|
105
|
-
sql: string,
|
|
106
|
-
remote: boolean
|
|
107
|
-
): Promise<void> {
|
|
108
|
-
const svc = new DbService();
|
|
109
|
-
const output = await svc.query(dbName, sql, remote);
|
|
110
|
-
|
|
111
|
-
if (opts.json) {
|
|
112
|
-
// Already JSON from wrangler — try to parse for cleaner output
|
|
113
|
-
try {
|
|
114
|
-
const parsed = JSON.parse(output);
|
|
115
|
-
formatJson(parsed, opts);
|
|
116
|
-
} catch {
|
|
117
|
-
process.stdout.write(`${output}\n`);
|
|
118
|
-
}
|
|
119
|
-
} else {
|
|
120
|
-
process.stdout.write(`${output}\n`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// ---------------------------------------------------------------------------
|
|
125
|
-
// db export
|
|
126
|
-
// ---------------------------------------------------------------------------
|
|
127
|
-
|
|
128
|
-
async function handleExport(
|
|
129
|
-
opts: FormatOptions,
|
|
130
|
-
dbName: string,
|
|
131
|
-
outputPath?: string
|
|
132
|
-
): Promise<void> {
|
|
133
|
-
const svc = new DbService();
|
|
134
|
-
const path = await svc.export(dbName, outputPath);
|
|
135
|
-
formatSuccess(`Database exported to ${path}`, opts);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// ---------------------------------------------------------------------------
|
|
139
|
-
// db reset
|
|
140
|
-
// ---------------------------------------------------------------------------
|
|
141
|
-
|
|
142
|
-
async function handleReset(
|
|
143
|
-
opts: FormatOptions,
|
|
144
|
-
dbName: string,
|
|
145
|
-
confirmed: boolean
|
|
146
|
-
): Promise<void> {
|
|
147
|
-
if (!confirmed) {
|
|
148
|
-
const answer = await p.confirm({
|
|
149
|
-
message: `WARNING: This will DELETE and recreate the "${dbName}" database. ALL DATA WILL BE LOST. Continue?`,
|
|
150
|
-
initialValue: false,
|
|
151
|
-
});
|
|
152
|
-
if (p.isCancel(answer) || !answer) {
|
|
153
|
-
p.cancel("Reset cancelled.");
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const svc = new DbService();
|
|
159
|
-
const output = await svc.reset(dbName);
|
|
160
|
-
formatSuccess(`Database "${dbName}" has been recreated`, opts);
|
|
161
|
-
if (!opts.quiet && output) {
|
|
162
|
-
process.stdout.write(`${output}\n`);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// ---------------------------------------------------------------------------
|
|
167
|
-
// Registration
|
|
168
|
-
// ---------------------------------------------------------------------------
|
|
169
|
-
|
|
170
|
-
export function registerDbCommand(program: Command): void {
|
|
171
|
-
const dbCmd = program
|
|
172
|
-
.command("db")
|
|
173
|
-
.summary("Manage D1 databases")
|
|
174
|
-
.description(
|
|
175
|
-
`Manage Cloudflare D1 databases — schema, queries, migrations, backup.
|
|
176
|
-
|
|
177
|
-
SUBCOMMANDS:
|
|
178
|
-
apply Apply schema.sql to D1
|
|
179
|
-
migrate Run tracking migrations
|
|
180
|
-
list List database tables
|
|
181
|
-
query <sql> Execute a SQL query
|
|
182
|
-
export Export database to .sql file
|
|
183
|
-
reset Drop and recreate database (DESTRUCTIVE)
|
|
184
|
-
|
|
185
|
-
OPTIONS:
|
|
186
|
-
--database <name> Database name (auto-detected from config if omitted)
|
|
187
|
-
--remote Operate on production (remote) database
|
|
188
|
-
|
|
189
|
-
EXAMPLES:
|
|
190
|
-
hoox db apply
|
|
191
|
-
hoox db apply --remote
|
|
192
|
-
hoox db migrate
|
|
193
|
-
hoox db list
|
|
194
|
-
hoox db query "SELECT * FROM trade_signals LIMIT 5"
|
|
195
|
-
hoox db export
|
|
196
|
-
hoox db reset`
|
|
197
|
-
)
|
|
198
|
-
.option("--database <name>", "Database name (auto-detected if omitted)")
|
|
199
|
-
.option("--remote", "Operate on production (remote) database");
|
|
200
|
-
|
|
201
|
-
// -- apply
|
|
202
|
-
dbCmd
|
|
203
|
-
.command("apply")
|
|
204
|
-
.description("Apply schema.sql to the database")
|
|
205
|
-
.option("--file <path>", "Path to schema.sql file")
|
|
206
|
-
.action(
|
|
207
|
-
withErrorHandling(
|
|
208
|
-
async (options: { file?: string }, cmd: Command) => {
|
|
209
|
-
const opts = getFormatOptions(cmd);
|
|
210
|
-
const svc = new DbService();
|
|
211
|
-
const dbName = await resolveDb(cmd, svc);
|
|
212
|
-
const remote = Boolean(
|
|
213
|
-
cmd.optsWithGlobals<{ remote?: boolean }>().remote
|
|
214
|
-
);
|
|
215
|
-
await handleApply(opts, dbName, remote, options.file);
|
|
216
|
-
},
|
|
217
|
-
{ service: "db" }
|
|
218
|
-
)
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
// -- migrate
|
|
222
|
-
dbCmd
|
|
223
|
-
.command("migrate")
|
|
224
|
-
.description("Run tracking migrations")
|
|
225
|
-
.action(
|
|
226
|
-
withErrorHandling(
|
|
227
|
-
async (_, cmd: Command) => {
|
|
228
|
-
const opts = getFormatOptions(cmd);
|
|
229
|
-
const svc = new DbService();
|
|
230
|
-
const dbName = await resolveDb(cmd, svc);
|
|
231
|
-
const remote = Boolean(
|
|
232
|
-
cmd.optsWithGlobals<{ remote?: boolean }>().remote
|
|
233
|
-
);
|
|
234
|
-
await handleMigrate(opts, dbName, remote);
|
|
235
|
-
},
|
|
236
|
-
{ service: "db" }
|
|
237
|
-
)
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
// -- list
|
|
241
|
-
dbCmd
|
|
242
|
-
.command("list")
|
|
243
|
-
.description("List database tables")
|
|
244
|
-
.action(
|
|
245
|
-
withErrorHandling(
|
|
246
|
-
async (_, cmd: Command) => {
|
|
247
|
-
const opts = getFormatOptions(cmd);
|
|
248
|
-
const svc = new DbService();
|
|
249
|
-
const dbName = await resolveDb(cmd, svc);
|
|
250
|
-
const remote = Boolean(
|
|
251
|
-
cmd.optsWithGlobals<{ remote?: boolean }>().remote
|
|
252
|
-
);
|
|
253
|
-
await handleList(opts, dbName, remote);
|
|
254
|
-
},
|
|
255
|
-
{ service: "db" }
|
|
256
|
-
)
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
// -- query
|
|
260
|
-
dbCmd
|
|
261
|
-
.command("query <sql>")
|
|
262
|
-
.description("Execute a SQL query")
|
|
263
|
-
.action(
|
|
264
|
-
withErrorHandling(
|
|
265
|
-
async (sql: string, _, cmd: Command) => {
|
|
266
|
-
const opts = getFormatOptions(cmd);
|
|
267
|
-
const svc = new DbService();
|
|
268
|
-
const dbName = await resolveDb(cmd, svc);
|
|
269
|
-
const remote = Boolean(
|
|
270
|
-
cmd.optsWithGlobals<{ remote?: boolean }>().remote
|
|
271
|
-
);
|
|
272
|
-
await handleQuery(opts, dbName, sql, remote);
|
|
273
|
-
},
|
|
274
|
-
{ service: "db" }
|
|
275
|
-
)
|
|
276
|
-
);
|
|
277
|
-
|
|
278
|
-
// -- export
|
|
279
|
-
dbCmd
|
|
280
|
-
.command("export")
|
|
281
|
-
.description("Export database to .sql file")
|
|
282
|
-
.option("--output <path>", "Output file path")
|
|
283
|
-
.action(
|
|
284
|
-
withErrorHandling(
|
|
285
|
-
async (options: { output?: string }, cmd: Command) => {
|
|
286
|
-
const opts = getFormatOptions(cmd);
|
|
287
|
-
const svc = new DbService();
|
|
288
|
-
const dbName = await resolveDb(cmd, svc);
|
|
289
|
-
await handleExport(opts, dbName, options.output);
|
|
290
|
-
},
|
|
291
|
-
{ service: "db" }
|
|
292
|
-
)
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
// -- reset
|
|
296
|
-
dbCmd
|
|
297
|
-
.command("reset")
|
|
298
|
-
.description("Drop and recreate the database (DESTRUCTIVE)")
|
|
299
|
-
.option("--confirm", "Skip confirmation prompt")
|
|
300
|
-
.action(
|
|
301
|
-
withErrorHandling(
|
|
302
|
-
async (options: { confirm?: boolean }, cmd: Command) => {
|
|
303
|
-
const opts = getFormatOptions(cmd);
|
|
304
|
-
const svc = new DbService();
|
|
305
|
-
const dbName = await resolveDb(cmd, svc);
|
|
306
|
-
await handleReset(opts, dbName, Boolean(options.confirm));
|
|
307
|
-
},
|
|
308
|
-
{ service: "db" }
|
|
309
|
-
)
|
|
310
|
-
);
|
|
311
|
-
}
|
package/src/commands/db/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { registerDbCommand } from "./db-command.js";
|