@instahost/cli 0.1.2 → 0.2.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/README.md +17 -1
- package/dist/commands/publish.js +29 -13
- package/dist/config.js +1 -1
- package/dist/main.js +9 -5
- package/dist/output.js +10 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ instahost publish ./dist --json
|
|
|
26
26
|
|
|
27
27
|
```text
|
|
28
28
|
instahost share <file> [--ttl 24h] [--access unlisted|public|private] [--name <filename>] [--content-type <type>]
|
|
29
|
-
instahost publish <dir> [--ttl 24h] [--access unlisted|public] [--include-dotfiles] [--concurrency 6]
|
|
29
|
+
instahost publish <dir> [--ttl 24h] [--access unlisted|public] [--include-dotfiles] [--concurrency 6] [--dry-run]
|
|
30
30
|
instahost delete <id|url> [--token <ihd_...>]
|
|
31
31
|
```
|
|
32
32
|
|
|
@@ -54,6 +54,7 @@ A site is a directory with `index.html` at its root. Its pages must use relative
|
|
|
54
54
|
| `--content-type <type>` | share | Declare the media type instead of deriving it from the extension. |
|
|
55
55
|
| `--include-dotfiles` | publish | Also publish dot-prefixed files and directories. Credentials, VCS data and OS metadata stay excluded. |
|
|
56
56
|
| `--concurrency <n>` | publish | Parallel uploads, 1 to 16 (default 6). |
|
|
57
|
+
| `--dry-run` | publish | Show which files would be published and which skipped, without contacting InstaHost. |
|
|
57
58
|
| `--token <ihd_...>` | delete | The artifact's delete token. |
|
|
58
59
|
|
|
59
60
|
An option given to a command it does not belong to is a usage error. `delete` takes an artifact id or any of its URLs. Its credential is the first of `--token`, `--api-key`, `INSTAHOST_DELETE_TOKEN` and `INSTAHOST_API_KEY`; the environment keeps the token out of the process list.
|
|
@@ -76,6 +77,21 @@ An option given to a command it does not belong to is a usage error. `delete` ta
|
|
|
76
77
|
|
|
77
78
|
Detection is by name only: the CLI does not read file contents to find secrets. Publish a build output directory (`dist/`, `build/`, `out/`), never a repository root or home directory.
|
|
78
79
|
|
|
80
|
+
## Preview a publish
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
npx -y @instahost/cli publish ./dist --dry-run --json
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The preview runs every local check that `publish` runs: the options, the API key's format and the file checks, including `--include-dotfiles` if set. It then stops without contacting InstaHost, so it cannot create an artifact or confirm server-side limits, quotas or that the API key is accepted. Without `--json`, it prints included paths and sizes to stdout, and skips and warnings to stderr. With `--json`, it prints one document:
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
{"ok": true, "dry_run": true, "type": "site", "files": [{"path": "index.html", "size": 42}],
|
|
90
|
+
"file_count": 1, "total_bytes": 42, "skipped": [{"path": ".env", "reason": "sensitive"}], "warnings": []}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Paths are relative to the site root and sizes are in bytes. Warnings can flag root-absolute URLs that may break if the published site is served under a path. Local failures use the usual error document and exit code.
|
|
94
|
+
|
|
79
95
|
## Output
|
|
80
96
|
|
|
81
97
|
Without `--json`, the result goes to stdout (URL, access URL, expiry and the delete command, `npx -y @instahost/cli delete <id> --token ...`), and skipped files, warnings and errors go to stderr. With `--json`, `share` and `publish` print:
|
package/dist/commands/publish.js
CHANGED
|
@@ -9,7 +9,7 @@ import { lifetimeFields } from "../ttl.js";
|
|
|
9
9
|
import { afterCreate, checkCreated, uploadAndComplete } from "../upload.js";
|
|
10
10
|
import { findRootAbsoluteReferences, walkSite } from "../walk.js";
|
|
11
11
|
const MAX_WARNING_PATHS = 20;
|
|
12
|
-
|
|
12
|
+
async function prepareSite(options) {
|
|
13
13
|
const display = options.dir;
|
|
14
14
|
try {
|
|
15
15
|
if (!(await stat(options.dir)).isDirectory())
|
|
@@ -30,7 +30,33 @@ export async function publish(ctx, options) {
|
|
|
30
30
|
if (!walked.files.some((f) => f.path === "index.html")) {
|
|
31
31
|
throw inputError("missing_index", `${display} has no index.html at its root; a site needs one.`, { path: display });
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
return { ...walked, rootAbsolute: await findRootAbsoluteReferences(walked.files) };
|
|
34
|
+
}
|
|
35
|
+
function siteWarnings(rootAbsolute, pathname) {
|
|
36
|
+
if (!rootAbsolute.length || pathname === "/")
|
|
37
|
+
return [];
|
|
38
|
+
const impact = pathname ? `break under ${pathname}` : "can break when a site is served under a path";
|
|
39
|
+
return [{
|
|
40
|
+
code: "root_absolute_reference",
|
|
41
|
+
message: `${rootAbsolute.length} file(s) use root-absolute URLs ("/app.js")${rootAbsolute.some((ref) => ref.base) ? " or <base href=\"/\">" : ""}, which ${impact}; use relative URLs (for example Vite base: "./")`,
|
|
42
|
+
paths: rootAbsolute.slice(0, MAX_WARNING_PATHS).map((ref) => ref.path),
|
|
43
|
+
}];
|
|
44
|
+
}
|
|
45
|
+
export async function previewPublish(options) {
|
|
46
|
+
const walked = await prepareSite(options);
|
|
47
|
+
return {
|
|
48
|
+
ok: true,
|
|
49
|
+
dry_run: true,
|
|
50
|
+
type: "site",
|
|
51
|
+
files: walked.files.map(({ path, size }) => ({ path, size })),
|
|
52
|
+
file_count: walked.files.length,
|
|
53
|
+
total_bytes: walked.totalBytes,
|
|
54
|
+
skipped: walked.skipped,
|
|
55
|
+
warnings: siteWarnings(walked.rootAbsolute),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export async function publish(ctx, options) {
|
|
59
|
+
const walked = await prepareSite(options);
|
|
34
60
|
const created = await ctx.client.call("POST", "/v1/artifacts", {
|
|
35
61
|
body: { type: "site", access: options.access, ...lifetimeFields(options.lifetime), files: walked.files.map((f) => ({ path: f.path, size: f.size, md5: f.md5 })) },
|
|
36
62
|
token: ctx.apiKey,
|
|
@@ -47,16 +73,6 @@ export async function publish(ctx, options) {
|
|
|
47
73
|
onProgress: ctx.onProgress,
|
|
48
74
|
fetch: ctx.fetch,
|
|
49
75
|
}));
|
|
50
|
-
// Root-absolute references only break when the site lives under a path (path mode).
|
|
51
|
-
const warnings = [];
|
|
52
|
-
if (rootAbsolute.length && new URL(artifact.url).pathname !== "/") {
|
|
53
|
-
const paths = rootAbsolute.map((r) => r.path);
|
|
54
|
-
warnings.push({
|
|
55
|
-
code: "root_absolute_reference",
|
|
56
|
-
message: `${paths.length} file(s) use root-absolute URLs ("/app.js")${rootAbsolute.some((r) => r.base) ? " or <base href=\"/\">" : ""}, which break under ${new URL(artifact.url).pathname}; use relative URLs (for example Vite base: "./")`,
|
|
57
|
-
paths: paths.slice(0, MAX_WARNING_PATHS),
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
76
|
return {
|
|
61
77
|
ok: true,
|
|
62
78
|
id: artifact.id,
|
|
@@ -70,6 +86,6 @@ export async function publish(ctx, options) {
|
|
|
70
86
|
file_count: artifact.file_count,
|
|
71
87
|
total_bytes: artifact.total_bytes,
|
|
72
88
|
skipped: walked.skipped,
|
|
73
|
-
warnings,
|
|
89
|
+
warnings: walked.rootAbsolute.length ? siteWarnings(walked.rootAbsolute, new URL(artifact.url).pathname) : [],
|
|
74
90
|
};
|
|
75
91
|
}
|
package/dist/config.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Precedence: flag, then environment, then DEFAULT_API_URL, the production API origin. Empty
|
|
3
3
|
// means the CLI asks for an API URL.
|
|
4
4
|
import { usageError } from "./errors.js";
|
|
5
|
-
export const VERSION = "0.
|
|
5
|
+
export const VERSION = "0.2.0";
|
|
6
6
|
/**
|
|
7
7
|
* The production API origin. The service's deploy preflight refuses to deploy an API origin that
|
|
8
8
|
* differs from this value in the CLI version it pins, so changing the API domain needs a CLI release
|
package/dist/main.js
CHANGED
|
@@ -10,13 +10,13 @@ import { redact } from "./redact.js";
|
|
|
10
10
|
import { parseTtl } from "./ttl.js";
|
|
11
11
|
import { DEFAULT_CONCURRENCY } from "./upload.js";
|
|
12
12
|
import { deleteArtifact } from "./commands/delete.js";
|
|
13
|
-
import { publish } from "./commands/publish.js";
|
|
13
|
+
import { previewPublish, publish } from "./commands/publish.js";
|
|
14
14
|
import { share } from "./commands/share.js";
|
|
15
15
|
export const HELP = `instahost ${VERSION}: instant hosting and sharing for AI agents.
|
|
16
16
|
|
|
17
17
|
Usage:
|
|
18
18
|
instahost share <file> [--ttl 24h] [--access unlisted|public|private] [--name <filename>] [--content-type <type>]
|
|
19
|
-
instahost publish <dir> [--ttl 24h] [--access unlisted|public] [--include-dotfiles] [--concurrency 6]
|
|
19
|
+
instahost publish <dir> [--ttl 24h] [--access unlisted|public] [--include-dotfiles] [--concurrency 6] [--dry-run]
|
|
20
20
|
instahost delete <id|url> [--token <ihd_...>] (or the owner's API key)
|
|
21
21
|
|
|
22
22
|
Options for every command:
|
|
@@ -29,6 +29,7 @@ Options for every command:
|
|
|
29
29
|
Anonymous artifacts live 24 hours by default and at most 7 days.
|
|
30
30
|
publish skips dotfiles (except .well-known), credentials (.env*, keys, .git, ...) and OS metadata,
|
|
31
31
|
and lists them under "skipped". Sites must use relative URLs (Vite: base: "./").
|
|
32
|
+
publish --dry-run lists what would be published or skipped without contacting InstaHost.
|
|
32
33
|
delete uses --token, else --api-key, else INSTAHOST_DELETE_TOKEN, else INSTAHOST_API_KEY; the
|
|
33
34
|
environment keeps the token out of the process list.
|
|
34
35
|
|
|
@@ -56,6 +57,7 @@ export const OPTIONS = {
|
|
|
56
57
|
"content-type": { type: "string" },
|
|
57
58
|
"include-dotfiles": { type: "boolean" },
|
|
58
59
|
concurrency: { type: "string" },
|
|
60
|
+
"dry-run": { type: "boolean" },
|
|
59
61
|
token: { type: "string" },
|
|
60
62
|
};
|
|
61
63
|
/**
|
|
@@ -69,7 +71,7 @@ export const GLOBAL = ["json", "api-url", "api-key", "verbose", "help", "version
|
|
|
69
71
|
/** Options per command, on top of GLOBAL. */
|
|
70
72
|
export const PER_COMMAND = {
|
|
71
73
|
share: ["ttl", "access", "name", "content-type"],
|
|
72
|
-
publish: ["ttl", "access", "include-dotfiles", "concurrency"],
|
|
74
|
+
publish: ["ttl", "access", "include-dotfiles", "concurrency", "dry-run"],
|
|
73
75
|
delete: ["token"],
|
|
74
76
|
};
|
|
75
77
|
function defaultStreams() {
|
|
@@ -144,13 +146,15 @@ async function run(argv, deps, streams, json) {
|
|
|
144
146
|
const concurrency = values.concurrency === undefined ? DEFAULT_CONCURRENCY : Number(values.concurrency);
|
|
145
147
|
if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 16)
|
|
146
148
|
throw usageError("--concurrency must be an integer from 1 to 16.");
|
|
147
|
-
|
|
149
|
+
const options = {
|
|
148
150
|
dir: target,
|
|
149
151
|
lifetime,
|
|
150
152
|
access: choice("access", values.access, ["unlisted", "public"], "unlisted"),
|
|
151
153
|
includeDotfiles: values["include-dotfiles"] ?? false,
|
|
152
154
|
concurrency,
|
|
153
|
-
}
|
|
155
|
+
};
|
|
156
|
+
// A dry run has passed the same option and API key checks as a publish; it stops before any request.
|
|
157
|
+
return values["dry-run"] ? previewPublish(options) : publish(ctx, options);
|
|
154
158
|
}
|
|
155
159
|
if (command === "delete") {
|
|
156
160
|
// Flags before the environment: --token, then --api-key, then
|
package/dist/output.js
CHANGED
|
@@ -44,11 +44,20 @@ const SKIP_LABEL = {
|
|
|
44
44
|
// otherwise carry terminal escape sequences (clipboard writes, hidden or rewritten lines).
|
|
45
45
|
export function printHuman(streams, doc) {
|
|
46
46
|
const t = terminalSafe;
|
|
47
|
-
if ("
|
|
47
|
+
if ("skipped" in doc) {
|
|
48
48
|
for (const s of doc.skipped)
|
|
49
49
|
streams.stderr(`skipped ${t(s.path)} (${SKIP_LABEL[s.reason]})\n`);
|
|
50
50
|
for (const w of doc.warnings)
|
|
51
51
|
streams.stderr(`warning ${t(w.message)}${w.paths?.length ? `: ${t(w.paths.join(", "))}` : ""}\n`);
|
|
52
|
+
}
|
|
53
|
+
if ("dry_run" in doc) {
|
|
54
|
+
const lines = [`Dry run: would publish ${doc.file_count} file(s) (${doc.total_bytes} bytes). Nothing uploaded.`];
|
|
55
|
+
for (const file of doc.files)
|
|
56
|
+
lines.push(` ${t(file.path)} (${file.size} bytes)`);
|
|
57
|
+
streams.stdout(`${lines.join("\n")}\n`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if ("delete_token" in doc) {
|
|
52
61
|
const lines = [`URL ${t(doc.url)}`];
|
|
53
62
|
if (doc.access_url)
|
|
54
63
|
lines.push(`Access ${t(doc.access_url)}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instahost/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Instant hosting and sharing for AI agents: share a file or publish a static site and get an HTTPS URL. The unscoped npm package named instahost is unrelated.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hosting",
|