@votrix-ai/cli 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +192 -2
- package/SITE-TRACKING-CLI-DESIGN.md +117 -0
- package/dist/src/agent.js +366 -0
- package/dist/src/auth.js +283 -0
- package/dist/src/cli.js +170 -0
- package/dist/src/commands.js +116 -0
- package/dist/src/core.js +373 -0
- package/dist/src/integrations.js +156 -0
- package/dist/src/site.js +278 -0
- package/dist/src/tools.js +289 -0
- package/dist/src/zip.js +112 -0
- package/docs/API.md +98 -0
- package/docs/cli/account.md +77 -0
- package/docs/cli/agent.md +105 -0
- package/docs/cli/files.md +65 -0
- package/docs/cli/integrations.md +67 -0
- package/docs/cli/media.md +45 -0
- package/docs/cli/runs.md +44 -0
- package/docs/cli/scraper.md +45 -0
- package/docs/cli/seo.md +45 -0
- package/docs/cli/site.md +137 -0
- package/docs/cli/social.md +85 -0
- package/docs/cli/ui.md +45 -0
- package/package.json +30 -4
- package/production.json +5 -0
- package/skills/votrix/SKILL.md +97 -0
- package/skills/votrix/agents/openai.yaml +4 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { emit, readStdin, usage, VotrixError } from "./core.js";
|
|
3
|
+
const TOOLKITS = [
|
|
4
|
+
{ slug: "gmail", name: "Gmail" },
|
|
5
|
+
{ slug: "outlook", name: "Outlook" },
|
|
6
|
+
{ slug: "googlesheets", name: "Google Sheets" },
|
|
7
|
+
{ slug: "hubspot", name: "HubSpot" },
|
|
8
|
+
{ slug: "googlecalendar", name: "Google Calendar" },
|
|
9
|
+
{ slug: "calendly", name: "Calendly" },
|
|
10
|
+
{ slug: "slack", name: "Slack" },
|
|
11
|
+
{ slug: "google_search_console", name: "Google Search Console" },
|
|
12
|
+
{ slug: "google_analytics", name: "Google Analytics 4" },
|
|
13
|
+
{ slug: "semrush_mcp", name: "Semrush" },
|
|
14
|
+
{ slug: "ahrefs_mcp", name: "Ahrefs" },
|
|
15
|
+
];
|
|
16
|
+
const OPTIONS = {
|
|
17
|
+
toolkits: [],
|
|
18
|
+
connections: ["toolkit"],
|
|
19
|
+
link: ["no-browser", "no-wait"],
|
|
20
|
+
// --toolkits is archived (0.2.0, a comma list): still accepted, no longer documented.
|
|
21
|
+
search: ["toolkit", "toolkits", "limit"],
|
|
22
|
+
execute: ["get-schema", "data", "account", "dry-run"],
|
|
23
|
+
};
|
|
24
|
+
const SHARED_FLAGS = ["workspace", "json"];
|
|
25
|
+
function option(ctx, name) {
|
|
26
|
+
const value = ctx.flags[name];
|
|
27
|
+
if (value === undefined)
|
|
28
|
+
return undefined;
|
|
29
|
+
if (typeof value !== "string" || !value.trim())
|
|
30
|
+
throw usage(`--${name} requires one value.`);
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
async function argumentsOf(input) {
|
|
34
|
+
if (input === undefined)
|
|
35
|
+
return {};
|
|
36
|
+
let value;
|
|
37
|
+
try {
|
|
38
|
+
const source = input === "-" ? await readStdin() : input.startsWith("@") ? readFileSync(input.slice(1), "utf8") : input;
|
|
39
|
+
value = JSON.parse(source);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
throw usage("--data must contain a JSON object. Use inline JSON, @file, or - for stdin.");
|
|
43
|
+
}
|
|
44
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
45
|
+
throw usage("--data must contain a JSON object.");
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
function switchOn(ctx, name) {
|
|
50
|
+
const value = ctx.flags[name];
|
|
51
|
+
if (value === undefined)
|
|
52
|
+
return false;
|
|
53
|
+
if (value !== true)
|
|
54
|
+
throw usage(`--${name} is a switch.`);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
// --toolkit takes one app. Leave it out to cover every app.
|
|
58
|
+
function toolkitFlag(ctx) {
|
|
59
|
+
const one = option(ctx, "toolkit");
|
|
60
|
+
if (one?.includes(","))
|
|
61
|
+
throw usage("--toolkit takes one app, e.g. --toolkit gmail. Leave it out to cover every app.");
|
|
62
|
+
return one;
|
|
63
|
+
}
|
|
64
|
+
function toolkit(value) {
|
|
65
|
+
if (!/^[a-z][a-z0-9_]*$/.test(value))
|
|
66
|
+
throw usage("Use lowercase toolkit slugs, such as gmail or google_analytics.");
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
export async function runIntegrations(ctx, command) {
|
|
70
|
+
if (!Object.hasOwn(OPTIONS, command))
|
|
71
|
+
throw usage(`Unknown integrations command '${command}'.`, "Run votrix tools integrations --help.");
|
|
72
|
+
for (const key of Object.keys(ctx.flags)) {
|
|
73
|
+
if (!SHARED_FLAGS.includes(key) && !OPTIONS[command].includes(key)) {
|
|
74
|
+
throw usage(`Unknown option --${key} for integrations ${command}.`, "Run votrix tools integrations --help.");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// `connections` alone lists them: it has no other subcommand.
|
|
78
|
+
const [target] = command === "connections" && !ctx.positional.length ? ["list"] : ctx.positional;
|
|
79
|
+
const count = Math.max(ctx.positional.length, target ? 1 : 0);
|
|
80
|
+
if (command === "search" ? count === 0 : count !== 1) {
|
|
81
|
+
throw usage(`Invalid arguments for integrations ${command}.`, "Run votrix tools integrations --help.");
|
|
82
|
+
}
|
|
83
|
+
if (command === "toolkits") {
|
|
84
|
+
if (target !== "list")
|
|
85
|
+
throw usage("Expected integrations toolkits list.", "Run votrix tools integrations --help.");
|
|
86
|
+
emit({ toolkits: TOOLKITS });
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
const request = async (method, path, body) => {
|
|
90
|
+
return ctx.client.request(method, "/tools/integrations" + path, {
|
|
91
|
+
workspace: await ctx.workspace(), body, timeoutMs: 360_000,
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
if (command === "connections") {
|
|
95
|
+
if (target !== "list")
|
|
96
|
+
throw usage("Expected integrations connections list.", "Run votrix tools integrations --help.");
|
|
97
|
+
const app = toolkitFlag(ctx);
|
|
98
|
+
emit(await request("GET", app ? `?toolkit=${toolkit(app)}` : ""));
|
|
99
|
+
}
|
|
100
|
+
else if (command === "link") {
|
|
101
|
+
switchOn(ctx, "no-browser");
|
|
102
|
+
switchOn(ctx, "no-wait");
|
|
103
|
+
emit(await request("POST", "/connect", { app: toolkit(target) }));
|
|
104
|
+
}
|
|
105
|
+
else if (command === "search") {
|
|
106
|
+
const query = ctx.positional.join(" ").trim();
|
|
107
|
+
if (!query)
|
|
108
|
+
throw usage("Provide a search query.");
|
|
109
|
+
const one = toolkitFlag(ctx), archived = option(ctx, "toolkits");
|
|
110
|
+
if (one !== undefined && archived !== undefined)
|
|
111
|
+
throw usage("Pass --toolkit only.");
|
|
112
|
+
const toolkits = one !== undefined ? [toolkit(one)]
|
|
113
|
+
: archived?.split(",").map((slug) => toolkit(slug.trim()));
|
|
114
|
+
const rawLimit = option(ctx, "limit");
|
|
115
|
+
const limit = rawLimit === undefined ? undefined : Number(rawLimit);
|
|
116
|
+
if (limit !== undefined && (!/^\d+$/.test(rawLimit) || limit < 1 || limit > 1000)) {
|
|
117
|
+
throw usage("--limit must be an integer from 1 to 1000.");
|
|
118
|
+
}
|
|
119
|
+
emit(await request("POST", "/search", { query, toolkits, limit }));
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
if (!/^[A-Z][A-Z0-9_]*$/.test(target))
|
|
123
|
+
throw usage("ACTION must be an uppercase slug returned by search.");
|
|
124
|
+
const schema = switchOn(ctx, "get-schema");
|
|
125
|
+
const dryRun = switchOn(ctx, "dry-run");
|
|
126
|
+
if (schema) {
|
|
127
|
+
if (ctx.flags.data !== undefined || ctx.flags.account !== undefined || dryRun) {
|
|
128
|
+
throw usage("--get-schema cannot be combined with --data, --account or --dry-run.");
|
|
129
|
+
}
|
|
130
|
+
emit(await request("GET", `/actions/${target}/schema`));
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const account = option(ctx, "account");
|
|
134
|
+
const args = await argumentsOf(option(ctx, "data"));
|
|
135
|
+
const body = { arguments: args, account };
|
|
136
|
+
if (dryRun) {
|
|
137
|
+
const preview = await request("POST", `/actions/${target}/validate`, body);
|
|
138
|
+
emit(preview);
|
|
139
|
+
return preview?.ok === false || preview?.valid === false ? 1 : 0;
|
|
140
|
+
}
|
|
141
|
+
let result;
|
|
142
|
+
try {
|
|
143
|
+
result = await request("POST", `/actions/${target}/execute`, body);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
if (error instanceof VotrixError && error.kind === "network") {
|
|
147
|
+
throw new VotrixError("network", error.message, "The action may have run. Check the connected app before retrying.");
|
|
148
|
+
}
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
emit(result);
|
|
152
|
+
return result?.ok === false ? 1 : 0;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
package/dist/src/site.js
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// `votrix tools site`: the workspace's websites — deploy, versions, status,
|
|
2
|
+
// environment variables, custom domains. One JSON object on stdout.
|
|
3
|
+
//
|
|
4
|
+
// A deploy packs a folder (or takes a zip already in the workspace), uploads it,
|
|
5
|
+
// and the backend deploys it as the site's next version. By default the command
|
|
6
|
+
// waits until the site answers on its address.
|
|
7
|
+
import { readdirSync, readFileSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join, relative } from "node:path";
|
|
10
|
+
import { emit, note, readStdin, sleep, usage, uuidOf, VotrixError } from "./core.js";
|
|
11
|
+
import { zipFolder } from "./zip.js";
|
|
12
|
+
const WAIT_MS = 10 * 60_000;
|
|
13
|
+
const POLL_MS = Number(process.env.VOTRIX_SITE_POLL_MS) || 4000;
|
|
14
|
+
// Never part of a site: tooling, VCS, OS junk, and local secrets.
|
|
15
|
+
const SKIP_DIRS = new Set(["node_modules", ".git", ".svn", ".hg", "__MACOSX", ".vercel", ".votrix", ".cache"]);
|
|
16
|
+
const SKIP_FILES = new Set([".DS_Store", "Thumbs.db", "desktop.ini"]);
|
|
17
|
+
const isSecretFile = (name) => name === ".env" || name.startsWith(".env.");
|
|
18
|
+
// --- packing ------------------------------------------------------------------
|
|
19
|
+
export function siteFiles(root) {
|
|
20
|
+
const out = [];
|
|
21
|
+
const walk = (dir) => {
|
|
22
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
23
|
+
const path = join(dir, entry.name);
|
|
24
|
+
if (entry.isDirectory()) {
|
|
25
|
+
if (!SKIP_DIRS.has(entry.name))
|
|
26
|
+
walk(path);
|
|
27
|
+
}
|
|
28
|
+
else if (entry.isFile() && !SKIP_FILES.has(entry.name) && !isSecretFile(entry.name))
|
|
29
|
+
out.push(path);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
walk(root);
|
|
33
|
+
return out.sort();
|
|
34
|
+
}
|
|
35
|
+
// The folder's zip in a temp file; the caller removes it.
|
|
36
|
+
function packFolder(dir, name) {
|
|
37
|
+
const info = statSync(dir, { throwIfNoEntry: false });
|
|
38
|
+
if (!info)
|
|
39
|
+
throw usage(`Not found: ${dir}`);
|
|
40
|
+
if (info.isFile()) {
|
|
41
|
+
if (!dir.toLowerCase().endsWith(".zip"))
|
|
42
|
+
throw usage(`${dir} is a file; pass the site's folder or a .zip.`);
|
|
43
|
+
return { path: dir, count: -1 };
|
|
44
|
+
}
|
|
45
|
+
const files = siteFiles(dir);
|
|
46
|
+
if (!files.some((f) => relative(dir, f) === "index.html")) {
|
|
47
|
+
throw usage(`${dir} has no index.html at its top level. Pass the folder that holds index.html.`);
|
|
48
|
+
}
|
|
49
|
+
const path = join(tmpdir(), `${name}-${process.pid}-${Date.now()}.zip`);
|
|
50
|
+
writeFileSync(path, zipFolder(dir, files));
|
|
51
|
+
return { path, count: files.length };
|
|
52
|
+
}
|
|
53
|
+
// KEY=VALUE lines; blank lines, comments and `export ` are allowed, quotes are removed.
|
|
54
|
+
export function parseEnv(text) {
|
|
55
|
+
const out = {};
|
|
56
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
57
|
+
const line = raw.trim().replace(/^export\s+/, "");
|
|
58
|
+
if (!line || line.startsWith("#"))
|
|
59
|
+
continue;
|
|
60
|
+
const eq = line.indexOf("=");
|
|
61
|
+
if (eq <= 0)
|
|
62
|
+
throw usage(`Not a KEY=VALUE line: ${line.split("=")[0]}`);
|
|
63
|
+
let value = line.slice(eq + 1).trim();
|
|
64
|
+
if (value.length >= 2 && (value[0] === '"' || value[0] === "'") && value.endsWith(value[0]))
|
|
65
|
+
value = value.slice(1, -1);
|
|
66
|
+
out[line.slice(0, eq).trim()] = value;
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
// --- commands -----------------------------------------------------------------
|
|
71
|
+
async function waitLive(ctx, site, started) {
|
|
72
|
+
const workspace = await ctx.workspace();
|
|
73
|
+
let answer = started;
|
|
74
|
+
const begin = Date.now();
|
|
75
|
+
let last = 0;
|
|
76
|
+
while (answer.status === "building") {
|
|
77
|
+
if (Date.now() - begin > WAIT_MS) {
|
|
78
|
+
return { ...answer, note: `Still deploying. votrix tools site status ${site} picks it up.` };
|
|
79
|
+
}
|
|
80
|
+
await sleep(POLL_MS);
|
|
81
|
+
try {
|
|
82
|
+
answer = await ctx.client.request("GET", `/tools/sites/${encodeURIComponent(site)}/status?version=${started.version}`, { workspace });
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (!(error instanceof VotrixError) || error.kind !== "network")
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
const seconds = Math.floor((Date.now() - begin) / 30_000) * 30;
|
|
89
|
+
if (answer.status === "building" && seconds > last) {
|
|
90
|
+
last = seconds;
|
|
91
|
+
note(`Deploying version ${started.version}${answer.waiting_for === "address" ? " (address coming up)" : ""}...`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return answer;
|
|
95
|
+
}
|
|
96
|
+
const BIG_BYTES = 30 * 1048576;
|
|
97
|
+
const START_TIMEOUT_MS = 20 * 60_000;
|
|
98
|
+
async function versionCount(ctx, site) {
|
|
99
|
+
try {
|
|
100
|
+
const listing = await ctx.client.request("GET", `/tools/sites/${encodeURIComponent(site)}/versions`, { workspace: await ctx.workspace() });
|
|
101
|
+
return Math.max(0, ...(listing.versions ?? []).map((v) => v.version));
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (error instanceof VotrixError && error.kind === "not_found")
|
|
105
|
+
return 0;
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// A dropped connection does not tell whether the deploy started: look for the
|
|
110
|
+
// version before sending it again, so one deploy never becomes two.
|
|
111
|
+
async function startVersion(ctx, site, body) {
|
|
112
|
+
const workspace = await ctx.workspace();
|
|
113
|
+
const path = `/tools/sites/${encodeURIComponent(site)}/versions`;
|
|
114
|
+
const before = await versionCount(ctx, site);
|
|
115
|
+
for (let attempt = 1;; attempt++) {
|
|
116
|
+
try {
|
|
117
|
+
return await ctx.client.request("POST", path, { workspace, body, timeoutMs: START_TIMEOUT_MS });
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (!(error instanceof VotrixError) || error.kind !== "network" || attempt > 2)
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
note("The connection dropped while starting the deploy; checking whether it started...");
|
|
124
|
+
for (let i = 0; i < 12; i++) {
|
|
125
|
+
await sleep(5000);
|
|
126
|
+
const latest = await versionCount(ctx, site).catch(() => before);
|
|
127
|
+
if (latest > before)
|
|
128
|
+
return { site, version: latest, status: "building" };
|
|
129
|
+
}
|
|
130
|
+
note(`It did not start; trying again (${attempt + 1} of 3).`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function needSite(ctx, at = 0) {
|
|
134
|
+
const site = ctx.positional[at];
|
|
135
|
+
if (!site)
|
|
136
|
+
throw usage("A site name is required (votrix tools site list).");
|
|
137
|
+
return site;
|
|
138
|
+
}
|
|
139
|
+
function trackFilters(raw) {
|
|
140
|
+
if (raw === undefined)
|
|
141
|
+
return undefined;
|
|
142
|
+
const filters = new Map();
|
|
143
|
+
for (const entry of Array.isArray(raw) ? raw : [raw]) {
|
|
144
|
+
const [field, values] = typeof entry === "string" ? entry.split(/=(.*)/s) : [];
|
|
145
|
+
if (!field || !values || values.split(",").some((value) => !value)) {
|
|
146
|
+
throw usage("--where requires FIELD=VALUE[,VALUE...], e.g. --where source=utm:instagram.");
|
|
147
|
+
}
|
|
148
|
+
filters.set(field, [...(filters.get(field) ?? []), ...values.split(",")]);
|
|
149
|
+
}
|
|
150
|
+
return Object.fromEntries(filters);
|
|
151
|
+
}
|
|
152
|
+
function trackOption(ctx, name) {
|
|
153
|
+
const value = ctx.flags[name];
|
|
154
|
+
if (value === undefined)
|
|
155
|
+
return undefined;
|
|
156
|
+
if (typeof value !== "string" || !value.trim())
|
|
157
|
+
throw usage(`--${name} requires one value.`);
|
|
158
|
+
return value;
|
|
159
|
+
}
|
|
160
|
+
export async function runSite(ctx, action, sub) {
|
|
161
|
+
const workspace = await ctx.workspace();
|
|
162
|
+
const call = (method, path, body) => ctx.client.request(method, `/tools/sites${path}`, { workspace, body, timeoutMs: 360_000 });
|
|
163
|
+
const finish = (answer) => (emit(answer), answer.status === "failed" ? 1 : 0);
|
|
164
|
+
if (action === "list")
|
|
165
|
+
return emit(await call("GET", "")), 0;
|
|
166
|
+
if (action === "track") {
|
|
167
|
+
if (sub !== "enable" && sub !== "disable" && sub !== "events" && sub !== "funnel") {
|
|
168
|
+
throw usage("Choose track enable, disable, events or funnel.", "Run votrix tools site --help.");
|
|
169
|
+
}
|
|
170
|
+
const path = `/${encodeURIComponent(needSite(ctx))}/track`;
|
|
171
|
+
if (sub === "enable" || sub === "disable") {
|
|
172
|
+
return finish(await call("POST", path, { enabled: sub === "enable" }));
|
|
173
|
+
}
|
|
174
|
+
const common = { period: trackOption(ctx, "period"), by: trackOption(ctx, "by"), where: trackFilters(ctx.flags.where) };
|
|
175
|
+
if (sub === "events") {
|
|
176
|
+
const rawLimit = trackOption(ctx, "limit");
|
|
177
|
+
const limit = rawLimit === undefined ? undefined : Number(rawLimit);
|
|
178
|
+
if (limit !== undefined && (!Number.isInteger(limit) || limit < 1 || limit > 200)) {
|
|
179
|
+
throw usage("--limit must be an integer from 1 to 200.");
|
|
180
|
+
}
|
|
181
|
+
return emit(await call("POST", `${path}/events`, {
|
|
182
|
+
...common, event: trackOption(ctx, "event"), search: trackOption(ctx, "search"), limit,
|
|
183
|
+
})), 0;
|
|
184
|
+
}
|
|
185
|
+
const steps = trackOption(ctx, "steps")?.split(",").map((step) => step.trim());
|
|
186
|
+
if (!steps || steps.length < 2 || steps.length > 5 || steps.some((step) => !step)) {
|
|
187
|
+
throw usage("--steps requires 2-5 comma-separated event names, e.g. visit,login,signup_completed.");
|
|
188
|
+
}
|
|
189
|
+
return emit(await call("POST", `${path}/funnel`, { ...common, steps, window: trackOption(ctx, "window") })), 0;
|
|
190
|
+
}
|
|
191
|
+
if (action === "deploy") {
|
|
192
|
+
const site = ctx.flags.name;
|
|
193
|
+
if (!site || typeof site !== "string")
|
|
194
|
+
throw usage("--name is required: the site's name, e.g. --name acme-shop.");
|
|
195
|
+
const path = `/${encodeURIComponent(site)}`;
|
|
196
|
+
let started;
|
|
197
|
+
if (ctx.flags.version !== undefined) {
|
|
198
|
+
if (ctx.positional.length || ctx.flags.asset || ctx.flags["no-track"]) {
|
|
199
|
+
throw usage("--version puts an earlier version back; omit a folder, --asset and --no-track.");
|
|
200
|
+
}
|
|
201
|
+
started = await call("POST", `${path}/live`, { version: Number(ctx.flags.version) });
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
let asset = ctx.flags.asset ? uuidOf(ctx.flags.asset) : undefined;
|
|
205
|
+
if (ctx.flags.asset && !asset)
|
|
206
|
+
throw usage(`'${ctx.flags.asset}' is not an asset id.`);
|
|
207
|
+
if (!asset) {
|
|
208
|
+
const dir = ctx.positional[0];
|
|
209
|
+
if (!dir)
|
|
210
|
+
throw usage("Pass the site's folder (or a .zip), or --asset ID.");
|
|
211
|
+
const packed = packFolder(dir, site);
|
|
212
|
+
try {
|
|
213
|
+
const size = statSync(packed.path).size;
|
|
214
|
+
if (packed.count >= 0)
|
|
215
|
+
note(`Packed ${packed.count} files from ${dir} (${(size / 1048576).toFixed(1)} MB).`);
|
|
216
|
+
if (size > BIG_BYTES)
|
|
217
|
+
note(`The site is over ${BIG_BYTES / 1048576} MB; it deploys slower. Compress large videos and images to speed it up.`);
|
|
218
|
+
asset = (await ctx.client.upload(packed.path, workspace)).id;
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
if (packed.count >= 0)
|
|
222
|
+
unlinkSync(packed.path);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const body = { asset_id: asset };
|
|
226
|
+
if (ctx.flags.address)
|
|
227
|
+
body.address = ctx.flags.address;
|
|
228
|
+
if (ctx.flags["no-track"])
|
|
229
|
+
body.track = false;
|
|
230
|
+
started = await startVersion(ctx, site, body);
|
|
231
|
+
}
|
|
232
|
+
if (ctx.flags["no-wait"])
|
|
233
|
+
return finish(started);
|
|
234
|
+
note(`Deploying ${site} version ${started.version}...`);
|
|
235
|
+
const done = await waitLive(ctx, site, started);
|
|
236
|
+
// What the start said about the site stays in the answer.
|
|
237
|
+
const kept = Object.fromEntries(["new_site", "replaces_version", "undo", "tracking", "tracking_note", "tracking_help"]
|
|
238
|
+
.filter((k) => started[k] !== undefined).map((k) => [k, started[k]]));
|
|
239
|
+
return finish({ ...done, ...kept });
|
|
240
|
+
}
|
|
241
|
+
if (action === "versions")
|
|
242
|
+
return emit(await call("GET", `/${encodeURIComponent(needSite(ctx))}/versions`)), 0;
|
|
243
|
+
if (action === "status") {
|
|
244
|
+
const query = new URLSearchParams();
|
|
245
|
+
if (ctx.flags.version !== undefined)
|
|
246
|
+
query.set("version", String(ctx.flags.version));
|
|
247
|
+
if (ctx.flags.logs)
|
|
248
|
+
query.set("logs", "true");
|
|
249
|
+
const q = query.toString() ? `?${query}` : "";
|
|
250
|
+
return finish(await call("GET", `/${encodeURIComponent(needSite(ctx))}/status${q}`));
|
|
251
|
+
}
|
|
252
|
+
if (action === "env") {
|
|
253
|
+
const site = encodeURIComponent(needSite(ctx));
|
|
254
|
+
if (sub === "list")
|
|
255
|
+
return emit(await call("GET", `/${site}/env`)), 0;
|
|
256
|
+
if (sub === "set") {
|
|
257
|
+
const from = ctx.flags["from-file"];
|
|
258
|
+
if (!from)
|
|
259
|
+
throw usage("--from-file FILE is required (KEY=VALUE lines; - reads stdin). Values never go on the command line.");
|
|
260
|
+
const text = from === "-" ? await readStdin() : readFileSync(String(from), "utf8");
|
|
261
|
+
const body = { variables: parseEnv(text), target: ctx.flags.target ?? "all" };
|
|
262
|
+
return emit(await call("PUT", `/${site}/env`, body)), 0;
|
|
263
|
+
}
|
|
264
|
+
throw usage(`Unknown command 'votrix tools site env ${sub ?? ""}'.`, "Run votrix tools site --help.");
|
|
265
|
+
}
|
|
266
|
+
if (action === "domain") {
|
|
267
|
+
const site = encodeURIComponent(needSite(ctx));
|
|
268
|
+
const domain = ctx.positional[1];
|
|
269
|
+
if (!domain)
|
|
270
|
+
throw usage("A domain is required, e.g. example.com.");
|
|
271
|
+
if (sub === "add")
|
|
272
|
+
return emit(await call("POST", `/${site}/domains`, { domain })), 0;
|
|
273
|
+
if (sub === "status")
|
|
274
|
+
return emit(await call("GET", `/${site}/domains/${encodeURIComponent(domain)}`)), 0;
|
|
275
|
+
throw usage(`Unknown command 'votrix tools site domain ${sub ?? ""}'.`, "Run votrix tools site --help.");
|
|
276
|
+
}
|
|
277
|
+
throw usage(`Unknown command 'votrix tools site ${action ?? ""}'.`, "Run votrix tools site --help.");
|
|
278
|
+
}
|